Search in sources :

Example 6 with LifecycleStateDTO

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

the class ApiProductsApiServiceImpl method getAPIProductLifecycleState.

@Override
public Response getAPIProductLifecycleState(String apiProductId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    LifecycleStateDTO lifecycleStateDTO = getLifecycleState(apiProductId, organization);
    return Response.ok().entity(lifecycleStateDTO).build();
}
Also used : LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO)

Example 7 with LifecycleStateDTO

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

the class ApisApiServiceImpl method changeAPILifecycle.

@Override
public Response changeAPILifecycle(String action, String apiId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        ApiTypeWrapper apiWrapper = new ApiTypeWrapper(apiProvider.getAPIbyUUID(apiId, organization));
        APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, apiWrapper, lifecycleChecklist, organization);
        // returns the current lifecycle state
        // todo try to prevent this call
        LifecycleStateDTO stateDTO = getLifecycleState(apiId, organization);
        WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
        return Response.ok().entity(workflowResponseDTO).build();
    } catch (APIManagementException e) {
        // Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while updating the lifecycle of API " + apiId, e, log);
        } else {
            RestApiUtil.handleInternalServerError("Error while updating lifecycle of API " + apiId, e, log);
        }
    }
    return null;
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 8 with LifecycleStateDTO

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

the class ApiProductsApiServiceImpl method changeAPIProductLifecycle.

@Override
public Response changeAPIProductLifecycle(String action, String apiProductId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    ApiTypeWrapper productWrapper = new ApiTypeWrapper(apiProvider.getAPIProductbyUUID(apiProductId, organization));
    APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, productWrapper, lifecycleChecklist, organization);
    LifecycleStateDTO stateDTO = getLifecycleState(apiProductId, organization);
    WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
    return Response.ok().entity(workflowResponseDTO).build();
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 9 with LifecycleStateDTO

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

the class PublisherCommonUtils method getLifecycleStateInformation.

/**
 * Get lifecycle state information of API or API Product
 *
 * @param identifier   Unique identifier of API or API Product
 * @param organization Organization of logged-in user
 * @return LifecycleStateDTO object
 * @throws APIManagementException if there is en error while retrieving the lifecycle state information
 */
public static LifecycleStateDTO getLifecycleStateInformation(Identifier identifier, String organization) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    Map<String, Object> apiLCData = apiProvider.getAPILifeCycleData(identifier.getUUID(), organization);
    if (apiLCData == null) {
        String type;
        if (identifier instanceof APIProductIdentifier) {
            type = APIConstants.API_PRODUCT;
        } else {
            type = APIConstants.API_IDENTIFIER_TYPE;
        }
        throw new APIManagementException("Error while getting lifecycle state for " + type + " with ID " + identifier, ExceptionCodes.from(ExceptionCodes.LIFECYCLE_STATE_INFORMATION_NOT_FOUND, type, identifier.getUUID()));
    } else {
        boolean apiOlderVersionExist = false;
        // check whether other versions of the current API exists
        APIVersionStringComparator comparator = new APIVersionStringComparator();
        Set<String> versions = apiProvider.getAPIVersions(APIUtil.replaceEmailDomain(identifier.getProviderName()), identifier.getName(), organization);
        for (String tempVersion : versions) {
            if (comparator.compare(tempVersion, identifier.getVersion()) < 0) {
                apiOlderVersionExist = true;
                break;
            }
        }
        return APIMappingUtil.fromLifecycleModelToDTO(apiLCData, apiOlderVersionExist);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) JSONObject(org.json.simple.JSONObject) APIVersionStringComparator(org.wso2.carbon.apimgt.impl.utils.APIVersionStringComparator) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

LifecycleStateDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)3 WorkflowResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO)3 JSONObject (org.json.simple.JSONObject)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 APIStateChangeResponse (org.wso2.carbon.apimgt.api.model.APIStateChangeResponse)2 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 APIVersionStringComparator (org.wso2.carbon.apimgt.impl.utils.APIVersionStringComparator)1 LifecycleStateAvailableTransitionsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateAvailableTransitionsDTO)1 LifecycleStateCheckItemsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateCheckItemsDTO)1 CheckListItem (org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem)1