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);
}
}
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;
}
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;
}
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();
}
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;
}
Aggregations