Search in sources :

Example 46 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutor method complete.

/**
 * Complete the external process status.
 * Based on the workflow , we will update the status column of the
 * Application table
 *
 * @param workFlowDTO object
 */
@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);
            log.info("Application Creation [Complete] Workflow Invoked. Workflow ID : " + workFlowDTO.getExternalWorkflowReference() + "Workflow State : " + workFlowDTO.getStatus());
            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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 47 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionCreationSimpleWorkflowExecutor method execute.

/**
 * This method executes subscription creation simple workflow and return workflow response back to the caller
 *
 * @param workflowDTO The WorkflowDTO which contains workflow contextual information related to the workflow
 * @return workflow response back to the caller
 * @throws WorkflowException Thrown when the workflow execution was not fully performed
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Example 48 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionDeletionSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
    SubscriptionWorkflowDTO subWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
    String errorMsg = null;
    try {
        APIIdentifier identifier = new APIIdentifier(subWorkflowDTO.getApiProvider(), subWorkflowDTO.getApiName(), subWorkflowDTO.getApiVersion());
        identifier.setId(Integer.parseInt(subWorkflowDTO.getMetadata(WorkflowConstants.PayloadConstants.API_ID)));
        apiMgtDAO.removeSubscription(identifier, ((SubscriptionWorkflowDTO) workflowDTO).getApplicationId());
    } catch (APIManagementException e) {
        errorMsg = "Could not complete subscription deletion workflow for api: " + subWorkflowDTO.getApiName();
        throw new WorkflowException(errorMsg, e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

Example 49 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionUpdateSimpleWorkflowExecutor method complete.

/**
 * This method completes subscription update simple workflow and return workflow response back to the caller
 *
 * @param workflowDTO The WorkflowDTO which contains workflow contextual information related to the workflow
 * @return workflow response back to the caller
 * @throws WorkflowException
 */
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
    SubscriptionWorkflowDTO subscriptionWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
    try {
        if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.APPROVED) {
            apiMgtDAO.updateSubscriptionStatusAndTier(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
        } else if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.CREATED || subscriptionWorkflowDTO.getStatus() == WorkflowStatus.REGISTERED) {
            apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.TIER_UPDATE_PENDING);
        } else if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.REJECTED) {
            apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
        }
    } catch (APIManagementException e) {
        log.error("Could not complete subscription update workflow", e);
        throw new WorkflowException("Could not complete subscription update workflow", e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 50 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionUpdateSimpleWorkflowExecutor method execute.

/**
 * This method executes subscription update simple workflow and return workflow response back to the caller
 *
 * @param workflowDTO The WorkflowDTO which contains workflow contextual information related to the workflow
 * @return workflow response back to the caller
 * @throws WorkflowException Thrown when the workflow execution was not fully performed
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)5 List (java.util.List)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 RepositoryService (org.activiti.engine.RepositoryService)2 Element (org.w3c.dom.Element)2