use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromListAPIRevisiontoDTO.
public static APIRevisionListDTO fromListAPIRevisiontoDTO(List<APIRevision> apiRevisionList) throws APIManagementException {
APIRevisionListDTO apiRevisionListDTO = new APIRevisionListDTO();
List<APIRevisionDTO> apiRevisionDTOS = new ArrayList<>();
for (APIRevision apiRevision : apiRevisionList) {
apiRevisionDTOS.add(fromAPIRevisiontoDTO(apiRevision));
}
apiRevisionListDTO.setCount(apiRevisionList.size());
apiRevisionListDTO.setList(apiRevisionDTOS);
return apiRevisionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method createAPIProductRevision.
@Override
public Response createAPIProductRevision(String apiProductId, APIRevisionDTO apIRevisionDTO, MessageContext messageContext) throws APIManagementException {
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(apiProductId);
apiRevision.setDescription(apIRevisionDTO.getDescription());
// adding the api revision
String revisionId = apiProvider.addAPIProductRevision(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_API_PRODUCTS + "/" + 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 Product: " + apiProductId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving created revision API location for API Product: " + apiProductId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDTO 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.rest.api.publisher.v1.dto.APIRevisionDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIRevisiontoDTO.
public static APIRevisionDTO fromAPIRevisiontoDTO(APIRevision model) throws APIManagementException {
APIRevisionDTO apiRevisionDTO = new APIRevisionDTO();
apiRevisionDTO.setId(model.getRevisionUUID());
String key = "Revision " + model.getId();
apiRevisionDTO.setDisplayName(key);
apiRevisionDTO.setDescription(model.getDescription());
if (model.getCreatedTime() != null) {
try {
apiRevisionDTO.setCreatedTime(parseStringToDate(model.getCreatedTime()));
} catch (java.text.ParseException e) {
throw new APIManagementException("Error while parsing the created time:" + model.getCreatedTime(), e);
}
}
APIRevisionAPIInfoDTO apiRevisionAPIInfoDTO = new APIRevisionAPIInfoDTO();
apiRevisionAPIInfoDTO.setId(model.getApiUUID());
apiRevisionDTO.setApiInfo(apiRevisionAPIInfoDTO);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
if (model.getApiRevisionDeploymentList() != null) {
for (APIRevisionDeployment apiRevisionDeployment : model.getApiRevisionDeploymentList()) {
apiRevisionDeploymentDTOS.add(fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
}
apiRevisionDTO.setDeploymentInfo(apiRevisionDeploymentDTOS);
return apiRevisionDTO;
}
Aggregations