use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class APIStateChangeWSWorkflowExecutor method cleanUpPendingTask.
/**
* Handle cleanup task for api state change workflow ws executor. This queries the BPMN process related to the given
* workflow reference id and delete that process
*/
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Starting cleanup task for APIStateChangeWSWorkflowExecutor for :" + workflowExtRef);
}
String errorMsg;
if (serviceEndpoint == null) {
// set the bps endpoint from the global configurations
WorkflowProperties workflowProperties = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration().getWorkflowProperties();
serviceEndpoint = workflowProperties.getServerUrl();
}
URL serviceEndpointURL = new URL(serviceEndpoint);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
// get the basic auth header value to connect to the bpmn process
String authHeader = getBasicAuthHeader();
JSONParser parser = new JSONParser();
HttpGet httpGet = null;
HttpDelete httpDelete = null;
try {
// Get the process instance details related to the given workflow reference id. If there is a process that
// is already started with the given wf reference as the businesskey, that process needes to be deleted
httpGet = new HttpGet(serviceEndpoint + RUNTIME_INSTANCE_RESOURCE_PATH + "?businessKey=" + workflowExtRef);
httpGet.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String processId = null;
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// already exists a process related to the given workflow reference
String responseStr = EntityUtils.toString(entity);
if (log.isDebugEnabled()) {
log.debug("Process instance details for ref : " + workflowExtRef + ": " + responseStr);
}
JSONObject obj = (JSONObject) parser.parse(responseStr);
JSONArray data = (JSONArray) obj.get(PayloadConstants.DATA);
if (data != null) {
JSONObject instanceDetails = (JSONObject) data.get(0);
// extract the id related to that process. this id is used to delete the process
processId = (String) instanceDetails.get(PayloadConstants.ID);
}
if (processId != null) {
// delete the process using the id
httpDelete = new HttpDelete(serviceEndpoint + RUNTIME_INSTANCE_RESOURCE_PATH + "/" + processId);
httpDelete.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
response = httpClient.execute(httpDelete);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
errorMsg = "Error while deleting process instance details for " + workflowExtRef + " code: " + response.getStatusLine().getStatusCode();
log.error(errorMsg);
throw new WorkflowException(errorMsg);
}
if (log.isDebugEnabled()) {
log.debug("Successfully deleted process instance for : " + workflowExtRef);
}
// remove entry from the db
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
apiMgtDAO.removeWorkflowEntry(workflowExtRef, WorkflowConstants.WF_TYPE_AM_API_STATE.toString());
}
} else {
errorMsg = "Error while getting process instance details for " + workflowExtRef + " code: " + response.getStatusLine().getStatusCode();
log.error(errorMsg);
throw new WorkflowException(errorMsg);
}
} catch (ClientProtocolException e) {
log.error("Error while creating the http client", e);
throw new WorkflowException("Error while creating the http client", e);
} catch (IOException e) {
log.error("Error while connecting to the BPMN process server from the WorkflowExecutor.", e);
throw new WorkflowException("Error while connecting to the external service", e);
} catch (ParseException e) {
log.error("Error while parsing response from BPS server", e);
throw new WorkflowException("Error while parsing response from BPS server", e);
} catch (APIManagementException e) {
log.error("Error removing the workflow entry", e);
throw new WorkflowException("Error removing the workflow entry", e);
} finally {
if (httpGet != null) {
httpGet.reset();
}
if (httpDelete != null) {
httpDelete.reset();
}
}
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class AbstractApplicationRegistrationWorkflowExecutor method execute.
public WorkflowResponse execute(WorkflowDTO workFlowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing AbstractApplicationRegistrationWorkflowExecutor...");
}
ApiMgtDAO dao = ApiMgtDAO.getInstance();
try {
// dao.createApplicationRegistrationEntry((ApplicationRegistrationWorkflowDTO) workFlowDTO, false);
ApplicationRegistrationWorkflowDTO appRegDTO;
if (workFlowDTO instanceof ApplicationRegistrationWorkflowDTO) {
appRegDTO = (ApplicationRegistrationWorkflowDTO) workFlowDTO;
} else {
String message = "Invalid workflow type found";
log.error(message);
throw new WorkflowException(message);
}
dao.createApplicationRegistrationEntry(appRegDTO, false);
// appRegDTO.getAppInfoDTO().saveDTO();
super.execute(workFlowDTO);
} catch (APIManagementException e) {
log.error("Error while creating Application Registration entry.", e);
throw new WorkflowException("Error while creating Application Registration entry.", e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationDeletionSimpleWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
ApplicationWorkflowDTO applicationWorkflowDTO = (ApplicationWorkflowDTO) workflowDTO;
Application application = applicationWorkflowDTO.getApplication();
String errorMsg = null;
try {
apiMgtDAO.deleteApplication(application);
} catch (APIManagementException e) {
if (e.getMessage() == null) {
errorMsg = "Couldn't complete simple application deletion workflow for application: " + application.getName();
} else {
errorMsg = e.getMessage();
}
throw new WorkflowException(errorMsg, e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationCreationApprovalWorkflowExecutor method complete.
/**
* Complete the Application creation approval workflow peocess.
*
* @param workFlowDTO
*/
@Override
public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException {
workFlowDTO.setUpdatedTime(System.currentTimeMillis());
ApiMgtDAO dao = ApiMgtDAO.getInstance();
try {
if (dao.getApplicationById(Integer.parseInt(workFlowDTO.getWorkflowReference())) != null) {
super.complete(workFlowDTO);
if (log.isDebugEnabled()) {
String logMessage = "Application Creation [Complete] Workflow Invoked. Workflow ID : " + workFlowDTO.getExternalWorkflowReference() + " Workflow State : " + workFlowDTO.getStatus();
log.debug(logMessage);
}
String status = null;
if (WorkflowStatus.CREATED.equals(workFlowDTO.getStatus())) {
status = APIConstants.ApplicationStatus.APPLICATION_CREATED;
} else if (WorkflowStatus.REJECTED.equals(workFlowDTO.getStatus())) {
status = APIConstants.ApplicationStatus.APPLICATION_REJECTED;
} else if (WorkflowStatus.APPROVED.equals(workFlowDTO.getStatus())) {
status = APIConstants.ApplicationStatus.APPLICATION_APPROVED;
}
try {
dao.updateApplicationStatus(Integer.parseInt(workFlowDTO.getWorkflowReference()), status);
} catch (APIManagementException e) {
String msg = "Error occurred when updating the status of the Application creation process";
log.error(msg, e);
throw new WorkflowException(msg, e);
}
} else {
String msg = "Application does not exist";
throw new WorkflowException(msg);
}
} catch (APIManagementException e) {
String msg = "Error occurred when retrieving the Application creation with workflow ID :" + workFlowDTO.getWorkflowReference();
log.error(msg, e);
throw new WorkflowException(msg, e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationRegistrationApprovalWorkflowExecutor method execute.
/**
* Execute the Application Creation workflow approval process.
*
* @param workflowDTO
*/
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing Application registration Workflow..");
}
ApplicationRegistrationWorkflowDTO appRegDTO = (ApplicationRegistrationWorkflowDTO) workflowDTO;
Application application = appRegDTO.getApplication();
String message = "Approve request to create " + appRegDTO.getKeyType() + " keys for " + application.getName() + " from application creator - " + appRegDTO.getUserName() + " with throttling tier - " + application.getTier();
workflowDTO.setWorkflowDescription(message);
workflowDTO.setProperties("keyType", appRegDTO.getKeyType());
workflowDTO.setProperties("applicationName", application.getName());
workflowDTO.setProperties("userName", appRegDTO.getUserName());
workflowDTO.setProperties("applicationTier", application.getTier());
super.execute(workflowDTO);
return new GeneralWorkflowResponse();
}
Aggregations