use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdImplementationPut.
@Override
public Response compositeApisApiIdImplementationPut(String apiId, InputStream apiImplementationInputStream, FileInfo apiImplementationDetail, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdImplementationGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && ifMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
apiStore.updateCompositeApiImplementation(apiId, apiImplementationInputStream);
String uriString = RestApiConstants.RESOURCE_PATH_IMPLEMENTATION.replace(RestApiConstants.APIID_PARAM, apiId);
FileInfoDTO infoDTO = new FileInfoDTO();
infoDTO.setRelativePath(uriString);
infoDTO.setMediaType(MediaType.APPLICATION_OCTET_STREAM);
String newFingerprint = compositeApisApiIdImplementationGetFingerprint(apiId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(infoDTO).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdDedicatedGatewayGet.
/**
* Retrieve Dedicated Gateway of an API
*
* @param apiId UUID of API
* @param ifNoneMatch ifNoneMatch header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return 200 OK if the operation was successful
* @throws NotFoundException when the particular resource does not exist
*/
@Override
public Response compositeApisApiIdDedicatedGatewayGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
if (!apiStore.isCompositeAPIExist(apiId)) {
String errorMessage = "API not found : " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.API_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = compositeApisApiIdGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
DedicatedGateway dedicatedGateway = apiStore.getDedicatedGateway(apiId);
if (dedicatedGateway != null) {
DedicatedGatewayDTO dedicatedGatewayDTO = DedicatedGatewayMappingUtil.toDedicatedGatewayDTO(dedicatedGateway);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(dedicatedGatewayDTO).build();
} else {
String msg = "Dedicated Gateway not found for " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(msg, ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving dedicated gateway of the API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO 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();
}
}
use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdDedicatedGatewayPut.
/**
* Add or update Dedicated Gateway of an API
*
* @param apiId UUID of API
* @param body DedicatedGatewayDTO
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 OK if the operation was successful
* @throws NotFoundException when the particular resource does not exist
*/
@Override
public Response compositeApisApiIdDedicatedGatewayPut(String apiId, DedicatedGatewayDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
if (!apiStore.isCompositeAPIExist(apiId)) {
String errorMessage = "API not found : " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.API_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = compositeApisApiIdGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
DedicatedGateway dedicatedGateway = DedicatedGatewayMappingUtil.fromDTOtoDedicatedGateway(body, apiId, username);
apiStore.updateDedicatedGateway(dedicatedGateway);
DedicatedGateway updatedDedicatedGateway = apiStore.getDedicatedGateway(apiId);
String newFingerprint = compositeApisApiIdGetFingerprint(apiId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(DedicatedGatewayMappingUtil.toDedicatedGatewayDTO(updatedDedicatedGateway)).build();
} catch (APIManagementException e) {
String errorMessage = "Error while updating dedicated gateway of the composite API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdPut.
/**
* Updates an API by UUID
*
* @param apiId UUID of API
* @param body Updated API details
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Updated API
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response compositeApisApiIdPut(String apiId, CompositeAPIDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
CompositeAPI.Builder api = CompositeAPIMappingUtil.toAPI(body).id(apiId);
apiStore.updateCompositeApi(api);
String newFingerprint = compositeApisApiIdGetFingerprint(apiId, null, null, request);
CompositeAPIDTO apidto = CompositeAPIMappingUtil.toCompositeAPIDTO(apiStore.getCompositeAPIbyId(apiId));
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(apidto).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations