use of org.wso2.carbon.registry.api.Resource in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdThreatProtectionPoliciesDelete.
/**
* Delete a threat protection policy from an API
* @param apiId APIID
* @param policyId Threat protection policy id
* @param request MSF4J Request
* @return HTTP status 200 if success, 500 otherwise
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdThreatProtectionPoliciesDelete(String apiId, String policyId, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (!apiPublisher.isAPIExists(apiId)) {
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setCode(404l);
errorDTO.setDescription("Specified API was not found");
return Response.status(404).entity(errorDTO).build();
}
apiPublisher.deleteThreatProtectionPolicy(apiId, policyId);
return Response.ok().build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
return Response.status(500).entity("Internal Server Error.").build();
}
}
use of org.wso2.carbon.registry.api.Resource in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<DocumentInfo> documentInfos = apiPublisher.getAllDocumentation(apiId, offset, limit);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
return Response.status(Response.Status.OK).entity(documentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting list of documents" + 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.registry.api.Resource in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdPut.
/**
* 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 apisApiIdPut(String apiId, APIDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = apisApiIdGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
API.APIBuilder api = MappingUtil.toAPI(body).id(apiId);
apiPublisher.updateAPI(api);
String newFingerprint = apisApiIdGetFingerprint(apiId, null, null, request);
APIDTO apidto = MappingUtil.toAPIDto(apiPublisher.getAPIbyUUID(apiId));
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(apidto).build();
} catch (APIManagementException e) {
String errorMessage = "Error while updating 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();
} catch (JsonProcessingException e) {
String errorMessage = "Error while updating API : " + apiId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while updating API : " + apiId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.carbon.registry.api.Resource in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisCopyApiPost.
/**
* Creates a new version of an API
*
* @param newVersion new version
* @param apiId UUID of API
* @param request msf4j request object
* @return created new API
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisCopyApiPost(String newVersion, String apiId, Request request) throws NotFoundException {
APIDTO newVersionedApi;
String apiName, newApiVersion;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String newAPIVersionId = apiPublisher.createNewAPIVersion(apiId, newVersion);
newVersionedApi = MappingUtil.toAPIDto(apiPublisher.getAPIbyUUID(newAPIVersionId));
return Response.status(Response.Status.CREATED).entity(newVersionedApi).build();
} catch (APIManagementException e) {
String errorMessage = "Error while create new API version " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, newVersion);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while create new API version " + apiId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.carbon.registry.api.Resource in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsDocumentIdDelete.
/**
* Delete an API's document
*
* @param apiId UUID of API
* @param documentId UUID of the document
* @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 apisApiIdDocumentsDocumentIdDelete(String apiId, String documentId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
String existingFingerprint = apisApiIdDocumentsDocumentIdGetFingerprint(apiId, documentId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
apiPublisher.removeDocumentation(documentId);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error while deleting document" + documentId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
paramList.put(APIMgtConstants.ExceptionsConstants.DOC_ID, documentId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations