Skip to content

Commit ef64dc7

Browse files
authored
Merge branch 'master' into fix-typo
2 parents 3569140 + e16a1ef commit ef64dc7

File tree

7 files changed

+121
-12
lines changed

7 files changed

+121
-12
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Apollo 2.5.0
88
* [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337)
99
* [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336)
1010
* [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361)
11+
* [Feature: Provide a new open API to return the organization list](https://github.com/apolloconfig/apollo/pull/5365)
12+
* [Refactor: Exception handler adds root cause information](https://github.com/apolloconfig/apollo/pull/5367)
13+
* [Feature: Enhanced parameter verification for edit item](https://github.com/apolloconfig/apollo/pull/5376)
1114

1215
------------------
1316
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/16?closed=1)

apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.slf4j.Logger;
3434
import org.slf4j.LoggerFactory;
3535
import org.slf4j.event.Level;
36+
import org.springframework.core.NestedExceptionUtils;
3637
import org.springframework.http.HttpHeaders;
3738
import org.springframework.http.HttpStatus;
3839
import org.springframework.http.MediaType;
@@ -53,6 +54,7 @@
5354

5455
@ControllerAdvice
5556
public class GlobalDefaultExceptionHandler {
57+
5658
private Gson gson = new Gson();
5759
private static Type mapType = new TypeToken<Map<String, Object>>() {
5860
}.getType();
@@ -115,7 +117,7 @@ private ResponseEntity<Map<String, Object>> handleError(HttpServletRequest reque
115117

116118
private ResponseEntity<Map<String, Object>> handleError(HttpServletRequest request,
117119
HttpStatus status, Throwable ex, Level logLevel) {
118-
String message = ex.getMessage();
120+
String message = getMessageWithRootCause(ex);
119121
printLog(message, ex, logLevel);
120122

121123
Map<String, Object> errorAttributes = new HashMap<>();
@@ -169,4 +171,13 @@ private void printLog(String message, Throwable ex, Level logLevel) {
169171
Tracer.logError(ex);
170172
}
171173

174+
private String getMessageWithRootCause(Throwable ex) {
175+
String message = ex.getMessage();
176+
Throwable rootCause = NestedExceptionUtils.getMostSpecificCause(ex);
177+
if (rootCause != ex) {
178+
message += " [Cause: " + rootCause.getMessage() + "]";
179+
}
180+
return message;
181+
}
182+
172183
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.server.service;
18+
19+
import com.ctrip.framework.apollo.openapi.api.OrganizationOpenApiService;
20+
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
21+
import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils;
22+
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
23+
import org.springframework.stereotype.Service;
24+
import java.util.List;
25+
26+
@Service
27+
public class ServerOrganizationOpenApiService implements OrganizationOpenApiService {
28+
29+
private final PortalConfig portalConfig;
30+
31+
public ServerOrganizationOpenApiService(PortalConfig portalConfig) {
32+
this.portalConfig = portalConfig;
33+
}
34+
35+
@Override
36+
public List<OpenOrganizationDto> getOrganizations() {
37+
return OpenApiBeanUtils.transformFromOrganizations(portalConfig.organizations());
38+
}
39+
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/util/OpenApiBeanUtils.java

+24-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
import java.util.Map;
2424
import java.util.Set;
2525
import java.util.stream.Collectors;
26+
27+
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
28+
import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
29+
import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;
30+
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO;
31+
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO;
32+
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
33+
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
34+
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
35+
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;
36+
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
37+
import com.ctrip.framework.apollo.portal.entity.vo.Organization;
2638
import org.springframework.util.CollectionUtils;
2739
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
2840
import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO;
@@ -33,15 +45,6 @@
3345
import com.ctrip.framework.apollo.common.entity.App;
3446
import com.ctrip.framework.apollo.common.entity.AppNamespace;
3547
import com.ctrip.framework.apollo.common.utils.BeanUtils;
36-
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
37-
import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
38-
import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;
39-
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO;
40-
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO;
41-
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
42-
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
43-
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
44-
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;
4548
import com.ctrip.framework.apollo.portal.entity.bo.ItemBO;
4649
import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO;
4750
import com.google.common.base.Preconditions;
@@ -188,4 +191,16 @@ public static ClusterDTO transformToClusterDTO(OpenClusterDTO openClusterDTO) {
188191
Preconditions.checkArgument(openClusterDTO != null);
189192
return BeanUtils.transform(ClusterDTO.class, openClusterDTO);
190193
}
194+
195+
public static OpenOrganizationDto transformFromOrganization(final Organization organization){
196+
Preconditions.checkArgument(organization != null);
197+
return BeanUtils.transform(OpenOrganizationDto.class, organization);
198+
}
199+
200+
public static List<OpenOrganizationDto> transformFromOrganizations(final List<Organization> organizations){
201+
if (CollectionUtils.isEmpty(organizations)) {
202+
return Collections.emptyList();
203+
}
204+
return organizations.stream().map(OpenApiBeanUtils::transformFromOrganization).collect(Collectors.toList());
205+
}
191206
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.ctrip.framework.apollo.portal.spi.UserService;
3030
import java.nio.charset.StandardCharsets;
3131
import java.util.Base64;
32+
import java.util.Objects;
3233
import org.springframework.security.access.prepost.PreAuthorize;
3334
import org.springframework.validation.annotation.Validated;
3435
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -41,7 +42,6 @@
4142
import org.springframework.web.bind.annotation.RequestParam;
4243
import org.springframework.web.bind.annotation.RestController;
4344

44-
import javax.servlet.http.HttpServletRequest;
4545
import javax.validation.Valid;
4646
import javax.validation.constraints.Positive;
4747
import javax.validation.constraints.PositiveOrZero;
@@ -88,6 +88,8 @@ public OpenItemDTO createItem(@PathVariable String appId, @PathVariable String e
8888
!StringUtils.isContainEmpty(item.getKey(), item.getDataChangeCreatedBy()),
8989
"key and dataChangeCreatedBy should not be null or empty");
9090

91+
RequestPrecondition.checkArguments(!Objects.isNull(item.getValue()), "value should not be null");
92+
9193
if (userService.findByUserId(item.getDataChangeCreatedBy()) == null) {
9294
throw BadRequestException.userNotExists(item.getDataChangeCreatedBy());
9395
}
@@ -113,6 +115,7 @@ public void updateItem(@PathVariable String appId, @PathVariable String env,
113115
"key and dataChangeLastModifiedBy can not be empty");
114116

115117
RequestPrecondition.checkArguments(item.getKey().equals(key), "Key in path and payload is not consistent");
118+
RequestPrecondition.checkArguments(!Objects.isNull(item.getValue()), "value should not be null");
116119

117120
if (userService.findByUserId(item.getDataChangeLastModifiedBy()) == null) {
118121
throw BadRequestException.userNotExists(item.getDataChangeLastModifiedBy());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.v1.controller;
18+
19+
import com.ctrip.framework.apollo.openapi.api.OrganizationOpenApiService;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RestController;
22+
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
23+
import java.util.List;
24+
25+
@RestController("openapiOrganizationController")
26+
@RequestMapping("/openapi/v1")
27+
public class OrganizationController {
28+
private final OrganizationOpenApiService organizationOpenApiService;
29+
30+
public OrganizationController(OrganizationOpenApiService organizationOpenApiService) {
31+
this.organizationOpenApiService = organizationOpenApiService;
32+
}
33+
34+
@RequestMapping("/organizations")
35+
public List<OpenOrganizationDto> getOrganization() {
36+
return organizationOpenApiService.getOrganizations();
37+
}
38+
}

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<revision>2.5.0-SNAPSHOT</revision>
6464
<java.version>1.8</java.version>
6565
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
66-
<apollo-java.version>2.4.0</apollo-java.version>
66+
<apollo-java.version>2.5.0-SNAPSHOT</apollo-java.version>
6767
<spring-boot.version>2.7.11</spring-boot.version>
6868
<spring-cloud.version>2021.0.5</spring-cloud.version>
6969
<!-- sort by alphabet -->

0 commit comments

Comments
 (0)