use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method createAPIRevision.
/**
* Create a new API revision
*
* @param apiId UUID of the API
* @param apIRevisionDTO API object that needs to be added
* @param messageContext message context object
* @return response containing newly created APIRevision object
*/
@Override
public Response createAPIRevision(String apiId, APIRevisionDTO apIRevisionDTO, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate if api exists
APIInfo apiInfo = validateAPIExistence(apiId);
// validate whether the API is advertise only
APIDTO apiDto = getAPIByID(apiId, apiProvider, organization);
if (apiDto != null && apiDto.getAdvertiseInfo() != null && apiDto.getAdvertiseInfo().isAdvertised()) {
throw new APIManagementException("Creating API Revisions is not supported for third party APIs: " + apiId);
}
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(apiInfo.getStatus().toString());
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(apiId);
apiRevision.setDescription(apIRevisionDTO.getDescription());
// adding the api revision
String revisionId = apiProvider.addAPIRevision(apiRevision, organization);
// Retrieve the newly added APIRevision to send in the response payload
APIRevision createdApiRevision = apiProvider.getAPIRevision(revisionId);
APIRevisionDTO createdApiRevisionDTO = APIMappingUtil.fromAPIRevisiontoDTO(createdApiRevision);
// This URI used to set the location header of the POST response
URI createdApiUri = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + createdApiRevisionDTO.getApiInfo().getId() + "/" + RestApiConstants.RESOURCE_PATH_REVISIONS + "/" + createdApiRevisionDTO.getId());
return Response.created(createdApiUri).entity(createdApiRevisionDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while adding new API Revision for API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving created revision API location for API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAPIRevision.
/**
* Retrieve a revision of an API
*
* @param apiId UUID of the API
* @param revisionId Revision ID of the API
* @param messageContext message context object
* @return response containing APIRevision object
*/
@Override
public Response getAPIRevision(String apiId, String revisionId, MessageContext messageContext) {
// remove errorObject and add implementation code!
ErrorDTO errorObject = new ErrorDTO();
Response.Status status = Response.Status.NOT_IMPLEMENTED;
errorObject.setCode((long) status.getStatusCode());
errorObject.setMessage(status.toString());
errorObject.setDescription("The requested resource has not been implemented");
return Response.status(status).entity(errorObject).build();
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method getAPIProductRevisionDeployments.
@Override
public Response getAPIProductRevisionDeployments(String apiProductId, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
List<APIRevisionDeployment> apiRevisionDeploymentsList = new ArrayList<>();
List<APIRevision> apiRevisions = apiProvider.getAPIRevisions(apiProductId);
for (APIRevision apiRevision : apiRevisions) {
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(apiRevision.getRevisionUUID());
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentsList.add(apiRevisionDeployment);
}
}
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsList) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
return Response.ok().entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method getAPIProductLifecycleHistory.
@Override
public Response getAPIProductLifecycleHistory(String apiProductId, String ifNoneMatch, MessageContext messageContext) {
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIProduct product;
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiProductId);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
product = apiProvider.getAPIProductbyUUID(apiRevision.getApiUUID(), organization);
} else {
product = apiProvider.getAPIProductbyUUID(apiProductId, organization);
}
return Response.ok().entity(PublisherCommonUtils.getLifecycleHistoryDTO(product.getUuid(), apiProvider)).build();
} 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 history of the API Product with id : " + apiProductId, e, log);
} else {
String errorMessage = "Error while retrieving the lifecycle history of API Product with id : " + apiProductId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIRevision in project carbon-apimgt by wso2.
the class OASParserUtil method getAPIDefinition.
/**
* This method returns api definition json for given api
*
* @param apiIdentifier api identifier
* @param registry user registry
* @return api definition json as json string
* @throws APIManagementException
*/
public static String getAPIDefinition(Identifier apiIdentifier, Registry registry) throws APIManagementException {
String resourcePath = "";
if (apiIdentifier instanceof APIIdentifier) {
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiIdentifier.getUUID());
if (apiRevision != null && apiRevision.getApiUUID() != null) {
resourcePath = APIUtil.getRevisionPath(apiRevision.getApiUUID(), apiRevision.getId());
} else {
resourcePath = APIUtil.getOpenAPIDefinitionFilePath(apiIdentifier.getName(), apiIdentifier.getVersion(), apiIdentifier.getProviderName());
}
} else if (apiIdentifier instanceof APIProductIdentifier) {
resourcePath = APIUtil.getAPIProductOpenAPIDefinitionFilePath(apiIdentifier.getName(), apiIdentifier.getVersion(), apiIdentifier.getProviderName());
}
JSONParser parser = new JSONParser();
String apiDocContent = null;
try {
if (registry.resourceExists(resourcePath + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME)) {
Resource apiDocResource = registry.get(resourcePath + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME);
apiDocContent = new String((byte[]) apiDocResource.getContent(), Charset.defaultCharset());
parser.parse(apiDocContent);
} else {
if (log.isDebugEnabled()) {
log.debug("Resource " + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME + " not found at " + resourcePath);
}
}
} catch (RegistryException e) {
handleException("Error while retrieving OpenAPI v2.0 or v3.0.0 Definition for " + apiIdentifier.getName() + '-' + apiIdentifier.getVersion(), e);
} catch (ParseException e) {
handleException("Error while parsing OpenAPI v2.0 or v3.0.0 Definition for " + apiIdentifier.getName() + '-' + apiIdentifier.getVersion() + " in " + resourcePath, e);
}
return apiDocContent;
}
Aggregations