use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class LabelsApiServiceImpl method labelsLabelIdPut.
/**
* Update the label
* @param body The body of the label with fields to be modified
* @param contentType The content type of the body
* @param request The ms4j request object
* @return 200 OK response.
* @throws NotFoundException
*/
@Override
public Response labelsLabelIdPut(String labelId, LabelDTO body, String contentType, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
body.labelUUID(labelId);
Label updatedLabel = apiMgtAdminService.updateLabel(LabelMappingUtil.fromDTOTLabel(body));
return Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelToDTO(updatedLabel)).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while adding label, label name: " + body.getName();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class LabelsApiServiceImpl method labelsLabelIdDelete.
/**
* Delete label by label id
*
* @param labelId Id of the label
* @param request msf4j request object
* @return 200 OK if the operation is successful
* @throws NotFoundException If failed to find the particular resource
*/
@Override
public Response labelsLabelIdDelete(String labelId, Request request) throws NotFoundException {
try {
if (labelId != null) {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
apiMgtAdminService.deleteLabel(labelId);
} else {
// mandatory parameters not provided
String errorMessage = "Label Id parameter 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 occurred while deleting the label [labelId] " + labelId;
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.status(Response.Status.NO_CONTENT).build();
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class LabelsApiServiceImpl method labelsGet.
/**
* Gets all labels
* @param accept Accept header value
* @param request ms4j request object
* @return a list of label objects
* @throws NotFoundException
*/
@Override
public Response labelsGet(String labelId, String accept, Request request) throws NotFoundException {
List<Label> labels = new ArrayList<>();
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
// get all labels
if (labelId == null) {
labels = apiMgtAdminService.getLabels();
} else {
Label label = apiMgtAdminService.getLabelByID(labelId);
labels.add(label);
}
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving all labels";
ErrorHandler errorHandler = ExceptionCodes.LABEL_EXCEPTION;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler);
log.error(errorMessage, e);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
return Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build();
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdGet.
/**
* Returns a matching Application policy for the given policy id @{policyId}
*
* @param id Uuid of the Application policy
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object Response with matching {@link ApplicationThrottlePolicyDTO} object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingApplicationIdGet(String id, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.info("Received Application Policy Get request. Policy uuid: " + id);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
Policy applicationPolicy = apiMgtAdminService.getApplicationPolicyByUuid(id);
return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(applicationPolicy)).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting Application Policy. policy uuid: " + id;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingCustomRuleIdPut.
/**
* Updates a given Global level policy/custom rule specified by uuid.
*
* @param ruleId uuid of the policy
* @param body DTO of policy to be updated
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Updated policy
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingCustomRuleIdPut(String ruleId, CustomRuleDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Custom Policy PUT request " + body + " with rule ID = " + ruleId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
CustomPolicy customPolicy = CustomPolicyMappingUtil.fromCustomPolicyDTOToModel(body);
customPolicy.setUuid(ruleId);
apiMgtAdminService.updateCustomRule(customPolicy);
return Response.status(Response.Status.OK).entity(CustomPolicyMappingUtil.fromCustomPolicyToDTO(apiMgtAdminService.getCustomRuleByUUID(ruleId))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while updating Custom Policy. policy ID: " + ruleId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations