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