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