use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdSwaggerPut.
/**
* Updates the swagger defnition of an API
*
* @param apiId UUID of API
* @param apiDefinition updated swagger defintion
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Updated swagger definition
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response compositeApisApiIdSwaggerPut(String apiId, String apiDefinition, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdSwaggerGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiStore.updateCompositeApiDefinition(apiId, apiDefinition);
String apiSwagger = apiStore.getCompositeApiDefinition(apiId);
String newFingerprint = compositeApisApiIdSwaggerGetFingerprint(apiId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(apiSwagger).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.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdDelete.
/**
* Deletes a particular API
*
* @param apiId UUID of API
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 OK if the opration was successful
* @throws NotFoundException when the particular resource does not exist
*/
@Override
public Response compositeApisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdDeleteFingerprint(apiId, ifMatch, ifUnmodifiedSince, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiStore.deleteCompositeApi(apiId);
return Response.ok().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.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdSwaggerGet.
/**
* Retrieves the swagger definition of an API
*
* @param apiId UUID of API
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return swagger definition of an API
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response compositeApisApiIdSwaggerGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdSwaggerGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
String swagger = apiStore.getCompositeApiDefinition(apiId);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(swagger).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.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesTierLevelGet.
/**
* Retrieve a list of tiers for a particular tier level
*
* @param tierLevel Tier level
* @param limit maximum number of tiers to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-Non-Match header value
* @param request msf4j request object
* @return A list of qualifying tiers
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response policiesTierLevelGet(String tierLevel, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
TierListDTO tierListDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<Policy> tierList = apiStore.getPolicies(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum(tierLevel));
tierListDTO = TierMappingUtil.fromTierListToDTO(tierList, tierLevel, limit, offset);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving tiers";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.TIER_LEVEL, tierLevel);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(tierListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsSubscriptionIdDelete.
/**
* Delete a subscription
*
* @param subscriptionId Id of the subscription
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 OK response if the deletion was successful
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsSubscriptionIdDelete(String subscriptionId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = subscriptionsSubscriptionIdGetFingerprint(subscriptionId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiStore.deleteAPISubscription(subscriptionId);
} catch (GatewayException e) {
String errorMessage = "Failed to remove subscription :" + subscriptionId + " from gateway";
log.error(errorMessage, e);
return Response.status(Response.Status.ACCEPTED).build();
} catch (APIManagementException e) {
String errorMessage = "Error while deleting subscription";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, subscriptionId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().build();
}
Aggregations