use of org.wso2.carbon.apimgt.api.BlockConditionNotFoundException in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistConditionIdPut.
/**
* Update blacklist/block condition statues
*
* @param conditionId uuid of the blacklist condition
* @param body body of the blacklist status to be updated
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-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 blacklistConditionIdPut(String conditionId, BlockingConditionDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received BlockCondition GET request with id: " + conditionId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
Boolean status = apiMgtAdminService.updateBlockConditionStateByUUID(conditionId, body.getStatus());
BlockingConditionDTO dto = null;
if (status) {
BlockConditions blockCondition = apiMgtAdminService.getBlockConditionByUUID(conditionId);
dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(blockCondition);
}
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting blacklist condition with UUID " + conditionId;
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.BlockConditionNotFoundException in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistConditionIdGet.
/**
* Get blacklist condition by ID.
*
* @param conditionId ID of the blacklist condition to be retrieved
* @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 blacklistConditionIdGet(String conditionId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received BlockCondition GET request with id: " + conditionId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
BlockConditions blockCondition = apiMgtAdminService.getBlockConditionByUUID(conditionId);
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(blockCondition);
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting blacklist condition with UUID " + conditionId;
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.BlockConditionNotFoundException in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdGet.
/**
* Get a specific Block condition by its id
*
* @param conditionId Id of the block condition
* @return Matched block condition for the given Id
*/
@Override
public Response throttlingDenyPolicyConditionIdGet(String conditionId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
BlockConditionsDTO blockCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, blockCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(blockCondition);
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while retrieving Block Condition. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
} catch (ParseException e) {
String errorMessage = "Error while retrieving Blocking Conditions";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.BlockConditionNotFoundException in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdDelete.
/**
* Delete a block condition specified by the condition Id
*
* @param conditionId Id of the block condition
* @return 200 OK response if successfully deleted the block condition
*/
@Override
public Response throttlingDenyPolicyConditionIdDelete(String conditionId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
BlockConditionsDTO existingCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, existingCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
apiProvider.deleteBlockConditionByUUID(conditionId);
return Response.ok().build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while deleting Block Condition. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.BlockConditionNotFoundException in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingDenyPolicyConditionIdPatch.
/**
* Updates an existing condition status of a blocking condition
*
* @param conditionId Id of the block condition
* @param body content to update
* @param contentType Content-Type header
* @return 200 response if successful
*/
@Override
public Response throttlingDenyPolicyConditionIdPatch(String conditionId, String contentType, BlockingConditionStatusDTO body, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give BlockConditionNotFoundException if there's no block condition exists with UUID
BlockConditionsDTO existingCondition = apiProvider.getBlockConditionByUUID(conditionId);
if (!RestApiAdminUtils.isBlockConditionAccessibleToUser(username, existingCondition)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, log);
}
// update the status
apiProvider.updateBlockConditionByUUID(conditionId, String.valueOf(body.isConditionStatus()));
// retrieve the new blocking condition and send back as the response
BlockConditionsDTO newBlockingCondition = apiProvider.getBlockConditionByUUID(conditionId);
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(newBlockingCondition);
return Response.ok().entity(dto).build();
} catch (APIManagementException | ParseException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_BLOCK_CONDITION, conditionId, e, log);
} else {
String errorMessage = "Error while updating Block Condition Status. Id : " + conditionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
Aggregations