Search in sources :

Example 1 with APIRevisionDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromListAPIRevisiontoDTO.

public static APIRevisionListDTO fromListAPIRevisiontoDTO(List<APIRevision> apiRevisionList) throws APIManagementException {
    APIRevisionListDTO apiRevisionListDTO = new APIRevisionListDTO();
    List<APIRevisionDTO> apiRevisionDTOS = new ArrayList<>();
    for (APIRevision apiRevision : apiRevisionList) {
        apiRevisionDTOS.add(fromAPIRevisiontoDTO(apiRevision));
    }
    apiRevisionListDTO.setCount(apiRevisionList.size());
    apiRevisionListDTO.setList(apiRevisionDTOS);
    return apiRevisionListDTO;
}
Also used : APIRevisionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) ArrayList(java.util.ArrayList) APIRevisionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)

Example 2 with APIRevisionDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.

the class ApiProductsApiServiceImpl method createAPIProductRevision.

@Override
public Response createAPIProductRevision(String apiProductId, APIRevisionDTO apIRevisionDTO, MessageContext messageContext) throws APIManagementException {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        APIRevision apiRevision = new APIRevision();
        apiRevision.setApiUUID(apiProductId);
        apiRevision.setDescription(apIRevisionDTO.getDescription());
        // adding the api revision
        String revisionId = apiProvider.addAPIProductRevision(apiRevision, organization);
        // Retrieve the newly added APIRevision to send in the response payload
        APIRevision createdApiRevision = apiProvider.getAPIRevision(revisionId);
        APIRevisionDTO createdApiRevisionDTO = APIMappingUtil.fromAPIRevisiontoDTO(createdApiRevision);
        // This URI used to set the location header of the POST response
        URI createdApiUri = new URI(RestApiConstants.RESOURCE_PATH_API_PRODUCTS + "/" + createdApiRevisionDTO.getApiInfo().getId() + "/" + RestApiConstants.RESOURCE_PATH_REVISIONS + "/" + createdApiRevisionDTO.getId());
        return Response.created(createdApiUri).entity(createdApiRevisionDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while adding new API Revision for API Product: " + apiProductId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    } catch (URISyntaxException e) {
        String errorMessage = "Error while retrieving created revision API location for API Product: " + apiProductId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) URISyntaxException(java.net.URISyntaxException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) URI(java.net.URI) APIRevisionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)

Example 3 with APIRevisionDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method createAPIRevision.

/**
 * Create a new API revision
 *
 * @param apiId             UUID of the API
 * @param apIRevisionDTO    API object that needs to be added
 * @param messageContext    message context object
 * @return response containing newly created APIRevision object
 */
@Override
public Response createAPIRevision(String apiId, APIRevisionDTO apIRevisionDTO, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        // validate if api exists
        APIInfo apiInfo = validateAPIExistence(apiId);
        // validate whether the API is advertise only
        APIDTO apiDto = getAPIByID(apiId, apiProvider, organization);
        if (apiDto != null && apiDto.getAdvertiseInfo() != null && apiDto.getAdvertiseInfo().isAdvertised()) {
            throw new APIManagementException("Creating API Revisions is not supported for third party APIs: " + apiId);
        }
        // validate API update operation permitted based on the LC state
        validateAPIOperationsPerLC(apiInfo.getStatus().toString());
        APIRevision apiRevision = new APIRevision();
        apiRevision.setApiUUID(apiId);
        apiRevision.setDescription(apIRevisionDTO.getDescription());
        // adding the api revision
        String revisionId = apiProvider.addAPIRevision(apiRevision, organization);
        // Retrieve the newly added APIRevision to send in the response payload
        APIRevision createdApiRevision = apiProvider.getAPIRevision(revisionId);
        APIRevisionDTO createdApiRevisionDTO = APIMappingUtil.fromAPIRevisiontoDTO(createdApiRevision);
        // This URI used to set the location header of the POST response
        URI createdApiUri = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + createdApiRevisionDTO.getApiInfo().getId() + "/" + RestApiConstants.RESOURCE_PATH_REVISIONS + "/" + createdApiRevisionDTO.getId());
        return Response.created(createdApiUri).entity(createdApiRevisionDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while adding new API Revision for API : " + apiId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    } catch (URISyntaxException e) {
        String errorMessage = "Error while retrieving created revision API location for API : " + apiId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) URISyntaxException(java.net.URISyntaxException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) URI(java.net.URI) APIRevisionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)

Example 4 with APIRevisionDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIRevisiontoDTO.

public static APIRevisionDTO fromAPIRevisiontoDTO(APIRevision model) throws APIManagementException {
    APIRevisionDTO apiRevisionDTO = new APIRevisionDTO();
    apiRevisionDTO.setId(model.getRevisionUUID());
    String key = "Revision " + model.getId();
    apiRevisionDTO.setDisplayName(key);
    apiRevisionDTO.setDescription(model.getDescription());
    if (model.getCreatedTime() != null) {
        try {
            apiRevisionDTO.setCreatedTime(parseStringToDate(model.getCreatedTime()));
        } catch (java.text.ParseException e) {
            throw new APIManagementException("Error while parsing the created time:" + model.getCreatedTime(), e);
        }
    }
    APIRevisionAPIInfoDTO apiRevisionAPIInfoDTO = new APIRevisionAPIInfoDTO();
    apiRevisionAPIInfoDTO.setId(model.getApiUUID());
    apiRevisionDTO.setApiInfo(apiRevisionAPIInfoDTO);
    List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
    if (model.getApiRevisionDeploymentList() != null) {
        for (APIRevisionDeployment apiRevisionDeployment : model.getApiRevisionDeploymentList()) {
            apiRevisionDeploymentDTOS.add(fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
        }
    }
    apiRevisionDTO.setDeploymentInfo(apiRevisionDeploymentDTOS);
    return apiRevisionDTO;
}
Also used : APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) ArrayList(java.util.ArrayList) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIRevisionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)

Aggregations

APIRevisionDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)1 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)1 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)1 APIRevisionAPIInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO)1 APIRevisionDeploymentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO)1 APIRevisionListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO)1