use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class GatewaysApiServiceImpl method gatewaysRegisterPost.
/**
* Register gateway
*
* @param body RegistrationDTO
* @param contentType Content-Type header value
* @return Registration summary details
* @throws NotFoundException If failed to register gateway
*/
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
try {
LabelInfoDTO labelInfoDTO = body.getLabelInfo();
if (labelInfoDTO != null) {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
String overwriteLabels = labelInfoDTO.getOverwriteLabels();
List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
adminService.registerGatewayLabels(labels, overwriteLabels);
RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
} else {
String errorMessage = "Label information cannot be null";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while registering the gateway";
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.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.core.exception.APIMgtResourceNotFoundException 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.core.exception.APIMgtResourceNotFoundException 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.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Get all subscriptions.
* {@code <p/>}
* If apiId is specified this will return the subscribed applications of that api
* If application id is specified this will return the api subscriptions of that application
*
* @param apiId ID of the API
* @param applicationId ID of the Application
* @param offset offset value
* @param limit limit value
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return Subscription List
* @throws NotFoundException If failed to get the subscription
*/
@Override
public Response subscriptionsGet(String apiId, String applicationId, String apiType, Integer offset, Integer limit, String ifNoneMatch, Request request) throws NotFoundException {
List<Subscription> subscribedApiList = null;
SubscriptionListDTO subscriptionListDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
if (!StringUtils.isEmpty(apiId)) {
subscribedApiList = apiStore.getSubscriptionsByAPI(apiId);
subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscribedApiList, limit, offset);
} else if (!StringUtils.isEmpty(applicationId)) {
Application application = apiStore.getApplicationByUuid(applicationId);
if (application != null) {
if (!StringUtils.isEmpty(apiType)) {
ApiType apiTypeEnum = ApiType.fromString(apiType);
if (apiTypeEnum == null) {
throw new APIManagementException("API Type specified is invalid", ExceptionCodes.API_TYPE_INVALID);
}
subscribedApiList = apiStore.getAPISubscriptionsByApplication(application, apiTypeEnum);
} else {
subscribedApiList = apiStore.getAPISubscriptionsByApplication(application);
}
subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscribedApiList, limit, offset);
} else {
String errorMessage = "Application not found: " + applicationId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.APPLICATION_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} else {
// mandatory parameters not provided
String errorMessage = "Either applicationId or apiId should be provided";
ErrorHandler errorHandler = ExceptionCodes.PARAMETER_NOT_PROVIDED;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler);
log.error(errorMessage);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscriptions";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, applicationId);
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(subscriptionListDTO).build();
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdGet.
/**
* Retrives an existing application
*
* @param applicationId application Id
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Requested application detials as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsApplicationIdGet(String applicationId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
ApplicationDTO applicationDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
String existingFingerprint = applicationsApplicationIdGetFingerprint(applicationId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
Application application = apiConsumer.getApplication(applicationId, username);
if (application != null) {
applicationDTO = ApplicationMappingUtil.fromApplicationToDTO(application);
return Response.ok().entity(applicationDTO).header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").build();
} else {
String errorMessage = "Application not found: " + applicationId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.APPLICATION_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving application: " + applicationId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations