Search in sources :

Example 26 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class ExternallyDeployedApiNotifier method process.

/**
 * Process API lifecycle notifier events related to APIs deployed in external gateway
 *
 * @param event related to deployments
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    APIEvent apiEvent;
    apiEvent = (APIEvent) event;
    if (APIConstants.EventType.API_LIFECYCLE_CHANGE.name().equals(event.getType())) {
        // Handle API retiring life cycle change in external gateway
        undeployApiWhenRetiring(apiEvent);
    } else if (APIConstants.EventType.API_DELETE.name().equals(event.getType())) {
        // Handle API deletion in external gateway
        undeployWhenDeleting(apiEvent);
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent)

Example 27 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle 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 28 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle 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 29 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle 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 30 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle 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)

Aggregations

Test (org.testng.annotations.Test)20 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)20 API (org.wso2.carbon.apimgt.core.models.API)20 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)19 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)10 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)10 LifecycleException (org.wso2.carbon.lcm.core.exception.LifecycleException)10 JSONObject (org.json.simple.JSONObject)8 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7 List (java.util.List)6 IOException (java.io.IOException)5 Map (java.util.Map)5 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)4