Skip to content
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Apollo 2.5.0
* [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337)
* [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336)
* [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361)
* [Feature: Provide a new open API to return the organization list](https://github.com/apolloconfig/apollo/pull/5365)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/16?closed=1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.server.service;

import com.ctrip.framework.apollo.openapi.api.OrganizationOpenApiService;
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
Comment thread
wjwang00 marked this conversation as resolved.
public class ServerOrganizationOpenApiService implements OrganizationOpenApiService {

private final PortalConfig portalConfig;

public ServerOrganizationOpenApiService(PortalConfig portalConfig) {
this.portalConfig = portalConfig;
}

@Override
public List<OpenOrganizationDto> getOrganizations() {
return OpenApiBeanUtils.transformFromOrganizations(portalConfig.organizations());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
import com.ctrip.framework.apollo.portal.entity.vo.Organization;
import org.springframework.util.CollectionUtils;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO;
Expand All @@ -33,15 +45,6 @@
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenGrayReleaseRuleItemDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;
import com.ctrip.framework.apollo.portal.entity.bo.ItemBO;
import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -188,4 +191,16 @@ public static ClusterDTO transformToClusterDTO(OpenClusterDTO openClusterDTO) {
Preconditions.checkArgument(openClusterDTO != null);
return BeanUtils.transform(ClusterDTO.class, openClusterDTO);
}

public static OpenOrganizationDto transformFromOrganization(final Organization organization){
Comment thread
wjwang00 marked this conversation as resolved.
Preconditions.checkArgument(organization != null);
return BeanUtils.transform(OpenOrganizationDto.class, organization);
}

public static List<OpenOrganizationDto> transformFromOrganizations(final List<Organization> organizations){
Comment thread
wjwang00 marked this conversation as resolved.
if (CollectionUtils.isEmpty(organizations)) {
return Collections.emptyList();
}
return organizations.stream().map(OpenApiBeanUtils::transformFromOrganization).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.v1.controller;

import com.ctrip.framework.apollo.openapi.api.OrganizationOpenApiService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.openapi.dto.OpenOrganizationDto;
import java.util.List;

@RestController("openapiOrganizationController")
@RequestMapping("/openapi/v1")
public class OrganizationController {
private final OrganizationOpenApiService organizationOpenApiService;

public OrganizationController(OrganizationOpenApiService organizationOpenApiService) {
this.organizationOpenApiService = organizationOpenApiService;
}

@RequestMapping("/organizations")
public List<OpenOrganizationDto> getOrganization() {
return organizationOpenApiService.getOrganizations();
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<revision>2.5.0-SNAPSHOT</revision>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<apollo-java.version>2.4.0</apollo-java.version>
<apollo-java.version>2.5.0-SNAPSHOT</apollo-java.version>
<spring-boot.version>2.7.11</spring-boot.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
<!-- sort by alphabet -->
Expand Down