Search in sources :

Example 1 with LifecycleStateDTO

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

the class APIMappingUtil method toWorkflowResponseDTO.

/**
 * Returns workflow state DTO from the provided information.
 *
 * @param lifecycleStateDTO   Lifecycle state DTO
 * @param stateChangeResponse workflow response from API lifecycle change
 * @return workflow state DTO
 */
public static WorkflowResponseDTO toWorkflowResponseDTO(LifecycleStateDTO lifecycleStateDTO, APIStateChangeResponse stateChangeResponse) {
    WorkflowResponseDTO workflowResponseDTO = new WorkflowResponseDTO();
    if (WorkflowStatus.APPROVED.toString().equals(stateChangeResponse.getStateChangeStatus())) {
        workflowResponseDTO.setWorkflowStatus(WorkflowResponseDTO.WorkflowStatusEnum.APPROVED);
    } else if (WorkflowStatus.CREATED.toString().equals(stateChangeResponse.getStateChangeStatus())) {
        workflowResponseDTO.setWorkflowStatus(WorkflowResponseDTO.WorkflowStatusEnum.CREATED);
    } else if ((WorkflowStatus.REGISTERED.toString().equals(stateChangeResponse.getStateChangeStatus()))) {
        workflowResponseDTO.setWorkflowStatus(WorkflowResponseDTO.WorkflowStatusEnum.REGISTERED);
    } else if ((WorkflowStatus.REJECTED.toString().equals(stateChangeResponse.getStateChangeStatus()))) {
        workflowResponseDTO.setWorkflowStatus(WorkflowResponseDTO.WorkflowStatusEnum.REJECTED);
    } else {
        log.error("Unrecognized state : " + stateChangeResponse.getStateChangeStatus());
        workflowResponseDTO.setWorkflowStatus(WorkflowResponseDTO.WorkflowStatusEnum.CREATED);
    }
    workflowResponseDTO.setLifecycleState(lifecycleStateDTO);
    return workflowResponseDTO;
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO)

Example 2 with LifecycleStateDTO

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

the class APIMappingUtil method fromLifecycleModelToDTO.

/**
 * Return the REST API DTO representation of API Lifecycle state information.
 *
 * @param apiLCData API lifecycle state information
 * @return REST API DTO representation of API Lifecycle state information
 */
public static LifecycleStateDTO fromLifecycleModelToDTO(Map<String, Object> apiLCData, boolean apiOlderVersionExist) {
    LifecycleStateDTO lifecycleStateDTO = new LifecycleStateDTO();
    String currentState = (String) apiLCData.get(APIConstants.LC_STATUS);
    lifecycleStateDTO.setState(currentState);
    String[] nextStates = (String[]) apiLCData.get(APIConstants.LC_NEXT_STATES);
    if (nextStates != null) {
        List<LifecycleStateAvailableTransitionsDTO> transitionDTOList = new ArrayList<>();
        for (String state : nextStates) {
            LifecycleStateAvailableTransitionsDTO transitionDTO = new LifecycleStateAvailableTransitionsDTO();
            transitionDTO.setEvent(state);
            // todo: Set target state properly
            transitionDTO.setTargetState("");
            transitionDTOList.add(transitionDTO);
        }
        lifecycleStateDTO.setAvailableTransitions(transitionDTOList);
    }
    List checkListItems = (List) apiLCData.get(APIConstants.LC_CHECK_ITEMS);
    if (checkListItems != null) {
        List<LifecycleStateCheckItemsDTO> checkItemsDTOList = new ArrayList<>();
        for (Object checkListItemObj : checkListItems) {
            CheckListItem checkListItem = (CheckListItem) checkListItemObj;
            if (!apiOlderVersionExist && (checkListItem.getName().equals(APIConstants.DEPRECATE_CHECK_LIST_ITEM) || checkListItem.getName().equals(APIConstants.RESUBSCRIBE_CHECK_LIST_ITEM))) {
                continue;
            }
            LifecycleStateCheckItemsDTO checkItemsDTO = new LifecycleStateCheckItemsDTO();
            checkItemsDTO.setName(checkListItem.getName());
            checkItemsDTO.setValue(Boolean.getBoolean(checkListItem.getValue()));
            // todo: Set targets properly
            checkItemsDTO.setRequiredStates(new ArrayList<>());
            checkItemsDTOList.add(checkItemsDTO);
        }
        lifecycleStateDTO.setCheckItems(checkItemsDTOList);
    }
    return lifecycleStateDTO;
}
Also used : LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) LifecycleStateAvailableTransitionsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateAvailableTransitionsDTO) CheckListItem(org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem) ArrayList(java.util.ArrayList) LifecycleStateCheckItemsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateCheckItemsDTO) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject)

Example 3 with LifecycleStateDTO

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

the class ApisApiServiceImpl method getAPILifecycleState.

/**
 * Retrieves API Lifecycle state information
 *
 * @param apiId API Id
 * @param ifNoneMatch If-None-Match header value
 * @return API Lifecycle state information
 */
@Override
public Response getAPILifecycleState(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    LifecycleStateDTO lifecycleStateDTO = getLifecycleState(apiId, organization);
    return Response.ok().entity(lifecycleStateDTO).build();
}
Also used : LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO)

Example 4 with LifecycleStateDTO

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

the class ApisApiServiceImpl method getLifecycleState.

/**
 * Retrieves API Lifecycle state information
 *
 * @param apiId API Id
 * @param organization organization
 * @return API Lifecycle state information
 */
private LifecycleStateDTO getLifecycleState(String apiId, String organization) {
    try {
        APIIdentifier apiIdentifier;
        if (ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiId) != null) {
            apiIdentifier = APIMappingUtil.getAPIInfoFromUUID(apiId, organization).getId();
        } else {
            apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
        }
        return PublisherCommonUtils.getLifecycleStateInformation(apiIdentifier, organization);
    } 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 deleting API : " + apiId, e, log);
        } else {
            String errorMessage = "Error while deleting API : " + apiId;
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

Example 5 with LifecycleStateDTO

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

the class ApiProductsApiServiceImpl method getLifecycleState.

private LifecycleStateDTO getLifecycleState(String apiProductId, String organization) {
    try {
        APIProductIdentifier productIdentifier = APIMappingUtil.getAPIProductIdentifierFromUUID(apiProductId, organization);
        return PublisherCommonUtils.getLifecycleStateInformation(productIdentifier, organization);
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving the lifecycle " + "state information of API Product with id : " + apiProductId, e, log);
        } else {
            String errorMessage = "Error while retrieving the lifecycle state information of the API Product with" + " " + "id : " + apiProductId;
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    return null;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

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