use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class APIStateChangeWSWorkflowExecutor method complete.
/**
* Complete the API state change workflow process.
*/
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Completing API State change Workflow..");
log.debug("response: " + workflowDTO.toString());
}
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
String action = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_API_LC_ACTION);
String apiName = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_APINAME);
String providerName = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_APIPROVIDER);
String version = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_APIVERSION);
String invoker = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_INVOKER);
String currentStatus = workflowDTO.getAttributes().get(PayloadConstants.VARIABLE_APISTATE);
int tenantId = workflowDTO.getTenantId();
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
// tenant flow is already started from the rest api service impl. no need to start from here
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(invoker);
Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceUserRegistry(invoker, tenantId);
APIIdentifier apiIdentifier = new APIIdentifier(providerName, apiName, version);
GenericArtifact apiArtifact = APIUtil.getAPIArtifact(apiIdentifier, registry);
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
String targetStatus;
apiArtifact.invokeAction(action, APIConstants.API_LIFE_CYCLE);
targetStatus = apiArtifact.getLifecycleState();
if (!currentStatus.equals(targetStatus)) {
apiMgtDAO.recordAPILifeCycleEvent(apiArtifact.getId(), currentStatus.toUpperCase(), targetStatus.toUpperCase(), invoker, tenantId);
}
if (log.isDebugEnabled()) {
String logMessage = "API Status changed successfully. API Name: " + apiIdentifier.getApiName() + ", API Version " + apiIdentifier.getVersion() + ", New Status : " + targetStatus;
log.debug(logMessage);
}
}
} catch (RegistryException e) {
String errorMsg = "Could not complete api state change workflow";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
} catch (APIManagementException e) {
String errorMsg = "Could not complete api state change workflow";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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.dto.WorkflowDTO 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.dto.WorkflowDTO 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.dto.WorkflowDTO 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