use of org.wso2.carbon.apimgt.core.workflow.ApplicationDeletionWorkflow in project carbon-apimgt by wso2.
the class APIStoreImpl method deleteApplication.
/**
* @see APIStore#deleteApplication(String)
*/
@Override
public WorkflowResponse deleteApplication(String appId) throws APIManagementException {
try {
if (appId == null) {
String message = "Application Id is not provided";
throw new APIManagementException(message, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
// get app info
Application application = getApplicationDAO().getApplication(appId);
if (application == null) {
String message = "Application cannot be found for id :" + appId;
throw new APIManagementException(message, ExceptionCodes.APPLICATION_NOT_FOUND);
}
// delete application creation pending tasks
cleanupPendingTaskForApplicationDeletion(application);
WorkflowExecutor removeApplicationWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION);
ApplicationDeletionWorkflow workflow = new ApplicationDeletionWorkflow(getApplicationDAO(), getWorkflowDAO(), getApiGateway());
workflow.setApplication(application);
workflow.setWorkflowType(APIMgtConstants.WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION);
workflow.setWorkflowReference(application.getId());
workflow.setExternalWorkflowReference(UUID.randomUUID().toString());
workflow.setCreatedTime(LocalDateTime.now());
String workflowDescription = "Application [ " + application.getName() + " ] deletion request from - " + application.getName();
workflow.setWorkflowDescription(workflowDescription);
WorkflowResponse response = removeApplicationWFExecutor.execute(workflow);
workflow.setStatus(response.getWorkflowStatus());
if (WorkflowStatus.CREATED != response.getWorkflowStatus()) {
completeWorkflow(removeApplicationWFExecutor, workflow);
} else {
// add entry to workflow table if it is only in pending state
addWorkflowEntries(workflow);
}
return response;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while deleting the application - " + appId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.workflow.ApplicationDeletionWorkflow in project carbon-apimgt by wso2.
the class WorkflowExecutorFactory method createWorkflow.
/**
* Create a DTO object related to a given workflow type.
*
* @param workflowType Type of the workflow.
* @return WorkFlow instance
*/
public Workflow createWorkflow(String workflowType) throws APIMgtDAOException {
Workflow workflow = null;
if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(workflowType)) {
workflow = new ApplicationCreationWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equals(workflowType)) {
workflow = new ApplicationDeletionWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflowType)) {
workflow = new SubscriptionCreationWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equals(workflowType)) {
workflow = new SubscriptionDeletionWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(workflowType)) {
workflow = new APIStateChangeWorkflow(DAOFactory.getApiDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().geApiLifecycleManager(), APIManagerFactory.getInstance().getApiGateway(), DAOFactory.getLabelDAO());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE.equals(workflowType)) {
workflow = new ApplicationUpdateWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else {
throw new APIMgtDAOException("Invalid workflow type: " + workflowType + " specified", ExceptionCodes.WORKFLOW_INVALID_WFTYPE);
}
return workflow;
}
Aggregations