Search in sources :

Example 1 with APIRevisionListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO 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 APIRevisionListDTO

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

the class ApisApiServiceImpl method getAPIRevisions.

/**
 * Retrieve available revisions of an API
 *
 * @param apiId UUID of the API
 * @param query Search query string
 * @param messageContext    message context object
 * @return response containing list of API revisions
 */
@Override
public Response getAPIRevisions(String apiId, String query, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        APIRevisionListDTO apiRevisionListDTO;
        List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiId);
        if (StringUtils.equalsIgnoreCase(query, "deployed:true")) {
            List<APIRevision> apiDeployedRevisions = new ArrayList<>();
            for (APIRevision apiRevision : apiRevisions) {
                if (!apiRevision.getApiRevisionDeploymentList().isEmpty()) {
                    apiDeployedRevisions.add(apiRevision);
                }
            }
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiDeployedRevisions);
        } else if (StringUtils.equalsIgnoreCase(query, "deployed:false")) {
            List<APIRevision> apiNotDeployedRevisions = new ArrayList<>();
            for (APIRevision apiRevision : apiRevisions) {
                if (apiRevision.getApiRevisionDeploymentList().isEmpty()) {
                    apiNotDeployedRevisions.add(apiRevision);
                }
            }
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiNotDeployedRevisions);
        } else {
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiRevisions);
        }
        return Response.ok().entity(apiRevisionListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while adding retrieving API Revision for api id : " + apiId + " - " + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIRevisionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) CommentList(org.wso2.carbon.apimgt.api.model.CommentList) ArrayList(java.util.ArrayList) List(java.util.List) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 3 with APIRevisionListDTO

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

the class ApiProductsApiServiceImpl method deleteAPIProductRevision.

@Override
public Response deleteAPIProductRevision(String apiProductId, String revisionId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    apiProvider.deleteAPIProductRevision(apiProductId, revisionId, organization);
    List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiProductId);
    APIRevisionListDTO apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiRevisions);
    return Response.ok().entity(apiRevisionListDTO).build();
}
Also used : APIRevisionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 4 with APIRevisionListDTO

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

the class ApiProductsApiServiceImpl method getAPIProductRevisions.

@Override
public Response getAPIProductRevisions(String apiProductId, String query, MessageContext messageContext) throws APIManagementException {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        APIRevisionListDTO apiRevisionListDTO;
        List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiProductId);
        if (StringUtils.equalsIgnoreCase(query, "deployed:true")) {
            List<APIRevision> apiDeployedRevisions = new ArrayList<>();
            for (APIRevision apiRevision : apiRevisions) {
                if (!apiRevision.getApiRevisionDeploymentList().isEmpty()) {
                    apiDeployedRevisions.add(apiRevision);
                }
            }
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiDeployedRevisions);
        } else if (StringUtils.equalsIgnoreCase(query, "deployed:false")) {
            List<APIRevision> apiProductNotDeployedRevisions = new ArrayList<>();
            for (APIRevision apiRevision : apiRevisions) {
                if (apiRevision.getApiRevisionDeploymentList().isEmpty()) {
                    apiProductNotDeployedRevisions.add(apiRevision);
                }
            }
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiProductNotDeployedRevisions);
        } else {
            apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiRevisions);
        }
        return Response.ok().entity(apiRevisionListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while adding retrieving API Revision for API Product id : " + apiProductId + " - " + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIRevisionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 5 with APIRevisionListDTO

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

the class ApisApiServiceImpl method deleteAPIRevision.

/**
 * Delete a revision of an API
 *
 * @param apiId             UUID of the API
 * @param revisionId     Revision ID of the API
 * @param messageContext    message context object
 * @return response with 204 status code and no content
 */
@Override
public Response deleteAPIRevision(String apiId, String revisionId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    // validate if api exists
    APIInfo apiInfo = validateAPIExistence(apiId);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(apiInfo.getStatus().toString());
    apiProvider.deleteAPIRevision(apiId, revisionId, organization);
    List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiId);
    APIRevisionListDTO apiRevisionListDTO = APIMappingUtil.fromListAPIRevisiontoDTO(apiRevisions);
    return Response.ok().entity(apiRevisionListDTO).build();
}
Also used : APIRevisionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)5 APIRevisionListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionListDTO)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)1 CommentList (org.wso2.carbon.apimgt.api.model.CommentList)1 APIRevisionDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO)1