use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdDelete.
/**
* Delete a threat protection policy
*
* @param threatProtectionPolicyId ID of the threat protection policy
* @param request
* @return HTTP status 200, 500 if failed to delete the policy
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdDelete(String threatProtectionPolicyId, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
apiMgtAdminService.deleteThreatProtectionPolicy(threatProtectionPolicyId);
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.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesPost.
/**
* Add a new threat protection policy
*
* @param threatProtectionPolicy Threat protection policy
* @param request
* @return HTTP Status 200, 500 if there was an error adding policy
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesPost(ThreatProtectionPolicyDTO threatProtectionPolicy, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
apiMgtAdminService.addThreatProtectionPolicy(ThreatProtectionMappingUtil.toThreatProtectionPolicy(threatProtectionPolicy));
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.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : policyList) {
listDTO.addListItem(ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImpl method workflowsGet.
@Override
public Response workflowsGet(String ifNoneMatch, String ifModifiedSince, String workflowType, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<Workflow> workflowList;
if (workflowType == null) {
workflowList = apiMgtAdminService.retrieveUncompletedWorkflows();
} else {
workflowList = apiMgtAdminService.retrieveUncompletedWorkflowsByType(workflowType);
}
WorkflowListDTO workflowListDTO = WorkflowMappingUtil.toWorkflowListDTO(workflowList);
return Response.ok().entity(workflowListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving workflows list";
org.wso2.carbon.apimgt.rest.api.common.dto.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 WorkflowsApiServiceImpl method workflowsWorkflowReferenceIdPut.
@Override
public Response workflowsWorkflowReferenceIdPut(String workflowReferenceId, WorkflowRequestDTO body, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
Workflow workflow = apiMgtAdminService.retrieveWorkflow(workflowReferenceId);
if (workflow == null) {
String errorMessage = "Workflow entry not found for: " + workflowReferenceId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_NOT_FOUND);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
if (WorkflowStatus.APPROVED == workflow.getStatus()) {
String errorMessage = "Workflow is already in complete state";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_ALREADY_COMPLETED);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
WorkflowExecutor workflowExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(workflow.getWorkflowType());
if (body == null) {
RestApiUtil.handleBadRequest("Request payload is missing", log);
}
if (body.getDescription() != null) {
workflow.setWorkflowDescription(body.getDescription());
}
if (body.getStatus() == null) {
String errorMessage = "Workflow status is not defined";
APIManagementException e = new APIManagementException(errorMessage, ExceptionCodes.WORKFLOW_STATE_MISSING);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
workflow.setStatus(WorkflowStatus.valueOf(body.getStatus().toString()));
}
if (body.getAttributes() != null) {
Map<String, String> existingAttributs = workflow.getAttributes();
Map<String, String> newAttributes = body.getAttributes();
if (existingAttributs == null) {
workflow.setAttributes(newAttributes);
} else {
newAttributes.forEach(existingAttributs::putIfAbsent);
workflow.setAttributes(existingAttributs);
}
}
WorkflowResponse response = apiMgtAdminService.completeWorkflow(workflowExecutor, workflow);
WorkflowResponseDTO workflowResponseDTO = WorkflowMappingUtil.toWorkflowResponseDTO(response);
return Response.ok().entity(workflowResponseDTO).build();
}
}
} catch (APIManagementException e) {
String errorMessage = "Error while completing workflow for reference : " + workflowReferenceId + ". " + e.getMessage();
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations