use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingAdvancedIdGet.
/**
* Get policy by id
* @param Id Uuid of the Advanced policy.
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingAdvancedIdGet(String Id, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.info("Received Advanced Policy Get request. Policy uuid: " + Id);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
APIPolicy policy = apiMgtAdminService.getApiPolicyByUuid(Id);
return Response.status(Response.Status.OK).entity(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(policy)).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting Advanced 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.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingCustomPost.
/**
* Add a Custom Policy.
*
* @param body DTO of new policy to be created
* @param request msf4j request object
* @return Created policy along with the location of it with Location header
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingCustomPost(CustomRuleDTO body, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Custom Policy POST request " + body);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
CustomPolicy customPolicy = CustomPolicyMappingUtil.fromCustomPolicyDTOToModel(body);
String uuid = apiMgtAdminService.addCustomRule(customPolicy);
return Response.status(Response.Status.CREATED).entity(CustomPolicyMappingUtil.fromCustomPolicyToDTO(apiMgtAdminService.getCustomRuleByUUID(uuid))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while adding custom policy, policy name: " + body.getPolicyName();
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.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingSubscriptionPost.
/**
* Add subscription level policy
*
* @param body DTO object including the Policy meta information
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingSubscriptionPost(SubscriptionThrottlePolicyDTO body, Request request) throws NotFoundException {
APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.subscription;
if (log.isDebugEnabled()) {
log.info("Received Subscription Policy POST request " + body + " with tierLevel = " + tierLevel);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
SubscriptionPolicy subscriptionPolicy = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyDTOToModel(body);
String policyId = apiMgtAdminService.addSubscriptionPolicy(subscriptionPolicy);
return Response.status(Response.Status.CREATED).entity(SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyToDTO(apiMgtAdminService.getSubscriptionPolicyByUuid(policyId))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while adding Subscription Policy. policy name: " + body.getPolicyName();
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.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingAdvancedPost.
/**
* Create Policy
*
* @param body DTO object including the Policy meta information
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingAdvancedPost(AdvancedThrottlePolicyDTO body, Request request) throws NotFoundException {
APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.api;
if (log.isDebugEnabled()) {
log.info("Received Advance Policy POST request " + body + " with tierLevel = " + tierLevel);
}
if (log.isDebugEnabled()) {
log.info("Received Advance Policy PUT request " + body + " with tierLevel = " + tierLevel);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
APIPolicy apiPolicy = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(body);
String policyId = apiMgtAdminService.addApiPolicy(apiPolicy);
return Response.status(Response.Status.CREATED).entity(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(apiMgtAdminService.getApiPolicyByUuid(policyId))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while adding Advanced Throttle Policy, policy name: " + body.getPolicyName();
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.api.model.policy.Policy in project carbon-apimgt by wso2.
the class ThreatProtectionMappingUtil method toThreatProtectionPolicyDTO.
/**
* Converts ThreatProtectionPolicy core model ThreatProtectionPolicyDTO rest api core model
* @param policy apimgt core model of ThreatProtectionPolicy
* @return ThreatProtectionPolicyDTO rest api core model
*/
public static ThreatProtectionPolicyDTO toThreatProtectionPolicyDTO(ThreatProtectionPolicy policy) {
if (policy == null)
return null;
ThreatProtectionPolicyDTO dto = new ThreatProtectionPolicyDTO();
dto.setUuid(policy.getUuid());
dto.setName(policy.getName());
dto.setType(policy.getType());
dto.setPolicy(policy.getPolicy());
return dto;
}
Aggregations