Search in sources :

Example 1 with DeployedAPIRevisionDTO

use of org.wso2.carbon.apimgt.internal.service.dto.DeployedAPIRevisionDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method deployedAPIRevision.

public Response deployedAPIRevision(List<DeployedAPIRevisionDTO> deployedAPIRevisionDTOList, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    List<String> revisionUUIDs = new ArrayList<>();
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    for (DeployedAPIRevisionDTO deployedAPIRevisionDTO : deployedAPIRevisionDTOList) {
        // get revision uuid
        String revisionUUID = apiProvider.getAPIRevisionUUID(Integer.toString(deployedAPIRevisionDTO.getRevisionId()), deployedAPIRevisionDTO.getApiId());
        if (revisionUUID == null) {
            return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
        }
        if (!revisionUUIDs.contains(revisionUUID)) {
            revisionUUIDs.add(revisionUUID);
            Map<String, Environment> environments = APIUtil.getEnvironments(tenantDomain);
            List<DeployedAPIRevision> deployedAPIRevisions = new ArrayList<>();
            for (DeployedEnvInfoDTO deployedEnvInfoDTO : deployedAPIRevisionDTO.getEnvInfo()) {
                DeployedAPIRevision deployedAPIRevision = new DeployedAPIRevision();
                deployedAPIRevision.setRevisionUUID(revisionUUID);
                String environment = deployedEnvInfoDTO.getName();
                if (environments.get(environment) == null) {
                    RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
                }
                deployedAPIRevision.setDeployment(environment);
                deployedAPIRevision.setVhost(deployedEnvInfoDTO.getVhost());
                if (StringUtils.isEmpty(deployedEnvInfoDTO.getVhost())) {
                    RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
                }
                deployedAPIRevisions.add(deployedAPIRevision);
            }
            apiProvider.addDeployedAPIRevision(deployedAPIRevisionDTO.getApiId(), revisionUUID, deployedAPIRevisions);
        }
    }
    return Response.ok().build();
}
Also used : DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) ArrayList(java.util.ArrayList) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) DeployedAPIRevisionDTO(org.wso2.carbon.apimgt.internal.service.dto.DeployedAPIRevisionDTO) UnDeployedAPIRevisionDTO(org.wso2.carbon.apimgt.internal.service.dto.UnDeployedAPIRevisionDTO) DeployedEnvInfoDTO(org.wso2.carbon.apimgt.internal.service.dto.DeployedEnvInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)1 Environment (org.wso2.carbon.apimgt.api.model.Environment)1 DeployedAPIRevisionDTO (org.wso2.carbon.apimgt.internal.service.dto.DeployedAPIRevisionDTO)1 DeployedEnvInfoDTO (org.wso2.carbon.apimgt.internal.service.dto.DeployedEnvInfoDTO)1 UnDeployedAPIRevisionDTO (org.wso2.carbon.apimgt.internal.service.dto.UnDeployedAPIRevisionDTO)1