diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java index cc2cf13f829..5ae1ebbdf6f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java @@ -58,9 +58,9 @@ public ServerNamespaceOpenApiService( @Override public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, - String namespaceName) { + String namespaceName, boolean fillItemDetail) { NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, fillItemDetail, false); if (namespaceBO == null) { return null; } @@ -68,10 +68,10 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam } @Override - public List getNamespaces(String appId, String env, String clusterName) { + public List getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) { return OpenApiBeanUtils .batchTransformFromNamespaceBOs(namespaceService.findNamespaceBOs(appId, Env - .valueOf(env), clusterName, false)); + .valueOf(env), clusterName, fillItemDetail, false)); } @Override diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java index bbe3ba8e422..69e88fb4cb9 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @@ -81,15 +82,16 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces") public List findNamespaces(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName) { - return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName); + @PathVariable String clusterName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespaces(appId, env, clusterName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}") public OpenNamespaceDTO loadNamespace(@PathVariable String appId, @PathVariable String env, - @PathVariable String clusterName, @PathVariable String - namespaceName) { - return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName); + @PathVariable String clusterName, @PathVariable String namespaceName, + @RequestParam(defaultValue="true") boolean fillItemDetail) { + return this.namespaceOpenApiService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail); } @GetMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java index 1d3c7d79c2d..fc6ae086f4d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java @@ -93,7 +93,7 @@ public void exportItems(@PathVariable String appId, @PathVariable String env, } NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf - (env), clusterName, namespaceName, false); + (env), clusterName, namespaceName, true, false); //generate a file. res.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java index aa524105169..1dc32fd4586 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java @@ -235,7 +235,7 @@ private void exportNamespaces(final Env env, final App exportApp, final ClusterD ZipOutputStream zipOutputStream) { String clusterName = exportCluster.getName(); - List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, false); + List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName, true, false); if (CollectionUtils.isEmpty(namespaceBOS)) { return; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java index 183a58b891e..3d3e56c0a3a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java @@ -186,7 +186,7 @@ public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterN /** * load cluster all namespace info with items */ - public List findNamespaceBOs(String appId, Env env, String clusterName, boolean includeDeletedItems) { + public List findNamespaceBOs(String appId, Env env, String clusterName, boolean fillItemDetail, boolean includeDeletedItems) { List namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName); if (namespaces == null || namespaces.size() == 0) { @@ -200,7 +200,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN executorService.submit(() -> { NamespaceBO namespaceBO; try { - namespaceBO = transformNamespace2BO(env, namespace, includeDeletedItems); + namespaceBO = transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); namespaceBOs.add(namespaceBO); } catch (Exception e) { LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", @@ -229,7 +229,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN } public List findNamespaceBOs(String appId, Env env, String clusterName) { - return findNamespaceBOs(appId, env, clusterName, true); + return findNamespaceBOs(appId, env, clusterName, true, true); } public List findNamespaces(String appId, Env env, String clusterName) { @@ -250,17 +250,17 @@ public List getPublicAppNamespaceAllNamespaces(Env env, String pub } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, - String namespaceName, boolean includeDeletedItems) { + String namespaceName, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); if (namespace == null) { throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName); } - return transformNamespace2BO(env, namespace, includeDeletedItems); + return transformNamespace2BO(env, namespace, fillItemDetail, includeDeletedItems); } public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, String namespaceName) { - return loadNamespaceBO(appId, env, clusterName, namespaceName, true); + return loadNamespaceBO(appId, env, clusterName, namespaceName, true, true); } public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) { @@ -293,7 +293,7 @@ public Map> getNamespacesPublishInfo(String appId) return result; } - private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean includeDeletedItems) { + private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean fillItemDetail, boolean includeDeletedItems) { NamespaceBO namespaceBO = new NamespaceBO(); namespaceBO.setBaseInfo(namespace); @@ -306,6 +306,10 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole List itemBOs = new LinkedList<>(); namespaceBO.setItems(itemBOs); + if (!fillItemDetail) { + return namespaceBO; + } + //latest Release ReleaseDTO latestRelease; Map releaseItems = new HashMap<>(); @@ -347,7 +351,7 @@ private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boole } private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) { - return transformNamespace2BO(env, namespace, true); + return transformNamespace2BO(env, namespace, true, true); } private void fillAppNamespaceProperties(NamespaceBO namespace) { diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index 05391706e3f..c7b0ba3f874 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -146,10 +146,10 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(permissionValidator.isAppAdmin(any())).thenReturn(true); when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters); when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, false)).thenReturn(app1Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, false)).thenReturn(app1Cluster2Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, false)).thenReturn(app2Cluster1Namespace); - when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, false)).thenReturn(app2Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace); + when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace); FileOutputStream fileOutputStream = new FileOutputStream(filePath); diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java index 8efecccb82e..7f14639223a 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java @@ -265,7 +265,7 @@ public void testLoadNamespaceBO() { assertThat(namespaceBO1.getItems().size()).isEqualTo(3); assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3")); - NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false); + NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false); List namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList()); assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2); assertThat(namespaceBO2.getItems().size()).isEqualTo(2); diff --git a/pom.xml b/pom.xml index 465a1c01343..31929d5d2bc 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 2.4.0-SNAPSHOT 1.8 UTF-8 - 2.2.0 + 2.4.0-SNAPSHOT 2.7.11 2021.0.5 @@ -649,4 +649,4 @@ - \ No newline at end of file +