use of org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisPost.
@Override
public Response compositeApisPost(CompositeAPIDTO body, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
CompositeAPI.Builder apiBuilder = CompositeAPIMappingUtil.toAPI(body);
APIStore apiStore = RestApiUtil.getConsumer(username);
Application app = apiStore.getApplicationByUuid(apiBuilder.getApplicationId());
// One application can only have one Composite API in default implementation
if (apiStore.getAPISubscriptionsByApplication(app, ApiType.COMPOSITE).size() > 0) {
String errorMessage = "A Composite API already exists for application : " + app.getId();
APIMgtResourceAlreadyExistsException e = new APIMgtResourceAlreadyExistsException(errorMessage, ExceptionCodes.COMPOSITE_API_ALREADY_EXISTS);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, app.getId());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
apiStore.addCompositeApi(apiBuilder);
CompositeAPI returnAPI = apiStore.getCompositeAPIbyId(apiBuilder.build().getId());
return Response.status(Response.Status.CREATED).entity(CompositeAPIMappingUtil.toCompositeAPIDTO(returnAPI)).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, body.getName());
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, body.getVersion());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations