Search in sources :

Example 41 with Complete

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

the class APIStateChangeWSWorkflowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing API State change Workflow.");
        log.debug("Execute workflowDTO " + workflowDTO.toString());
    }
    if (stateList != null) {
        Map<String, List<String>> stateActionMap = getSelectedStatesToApprove();
        APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO;
        if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) && stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()).contains(apiStateWorkFlowDTO.getApiLCAction())) {
            // set the auth application related info. This will be used to call the callback service
            setOAuthApplicationInfo(apiStateWorkFlowDTO);
            // build request payload
            String jsonPayload = buildPayloadForBPMNProcess(apiStateWorkFlowDTO);
            if (log.isDebugEnabled()) {
                log.debug("APIStateChange payload: " + jsonPayload);
            }
            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());
            HttpPost httpPost = new HttpPost(serviceEndpoint + RUNTIME_INSTANCE_RESOURCE_PATH);
            // Generate the basic auth header using provided user credentials
            String authHeader = getBasicAuthHeader();
            httpPost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
            StringEntity requestEntity = new StringEntity(jsonPayload, ContentType.APPLICATION_JSON);
            httpPost.setEntity(requestEntity);
            try {
                HttpResponse response = httpClient.execute(httpPost);
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
                    String error = "Error while starting the process:  " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase();
                    log.error(error);
                    throw new WorkflowException(error);
                }
            } catch (ClientProtocolException e) {
                String errorMsg = "Error while creating the http client";
                log.error(errorMsg, e);
                throw new WorkflowException(errorMsg, e);
            } catch (IOException e) {
                String errorMsg = "Error while connecting to the BPMN process server from the WorkflowExecutor.";
                log.error(errorMsg, e);
                throw new WorkflowException(errorMsg, e);
            } finally {
                httpPost.reset();
            }
            super.execute(workflowDTO);
        } else {
            // For any other states, act as simpleworkflow executor.
            workflowDTO.setStatus(WorkflowStatus.APPROVED);
            // calling super.complete() instead of complete() to act as the simpleworkflow executor
            super.complete(workflowDTO);
        }
    } else {
        String msg = "State change list is not provided. Please check <stateList> element in ";
        log.error(msg);
        throw new WorkflowException(msg);
    }
    return new GeneralWorkflowResponse();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) WorkflowProperties(org.wso2.carbon.apimgt.impl.dto.WorkflowProperties) URL(org.apache.axis2.util.URL) ClientProtocolException(org.apache.http.client.ClientProtocolException) StringEntity(org.apache.http.entity.StringEntity) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with Complete

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

the class AbstractApplicationRegistrationWorkflowExecutor method complete.

public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Completing AbstractApplicationRegistrationWorkflowExecutor...");
    }
    super.complete(workFlowDTO);
    ApiMgtDAO dao = ApiMgtDAO.getInstance();
    try {
        String status = null;
        if ("CREATED".equals(workFlowDTO.getStatus().toString())) {
            status = APIConstants.AppRegistrationStatus.REGISTRATION_CREATED;
        } else if ("REJECTED".equals(workFlowDTO.getStatus().toString())) {
            status = APIConstants.AppRegistrationStatus.REGISTRATION_REJECTED;
        } else if ("APPROVED".equals(workFlowDTO.getStatus().toString())) {
            status = APIConstants.AppRegistrationStatus.REGISTRATION_APPROVED;
        }
        ApplicationRegistrationWorkflowDTO regWorkFlowDTO;
        if (workFlowDTO instanceof ApplicationRegistrationWorkflowDTO) {
            regWorkFlowDTO = (ApplicationRegistrationWorkflowDTO) workFlowDTO;
        } else {
            String message = "Invalid workflow type found";
            log.error(message);
            throw new WorkflowException(message);
        }
        dao.populateAppRegistrationWorkflowDTO(regWorkFlowDTO);
        dao.updateApplicationRegistration(status, regWorkFlowDTO.getKeyType(), regWorkFlowDTO.getApplication().getId(), regWorkFlowDTO.getKeyManager());
    } catch (APIManagementException e) {
        log.error("Error while completing Application Registration entry.", e);
        throw new WorkflowException("Error while completing Application Registration entry.", e);
    }
    return new GeneralWorkflowResponse();
}
Also used : ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 43 with Complete

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

the class ApplicationCreationSimpleWorkflowExecutor method complete.

/**
 * Complete the external process status
 * Based on the workflow status we will update the status column of the
 * Application table
 *
 * @param workFlowDTO - WorkflowDTO
 */
public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.info("Complete  Application creation Workflow..");
    }
    String status = null;
    if ("CREATED".equals(workFlowDTO.getStatus().toString())) {
        status = APIConstants.ApplicationStatus.APPLICATION_CREATED;
    } else if ("REJECTED".equals(workFlowDTO.getStatus().toString())) {
        status = APIConstants.ApplicationStatus.APPLICATION_REJECTED;
    } else if ("APPROVED".equals(workFlowDTO.getStatus().toString())) {
        status = APIConstants.ApplicationStatus.APPLICATION_APPROVED;
    }
    ApiMgtDAO dao = ApiMgtDAO.getInstance();
    try {
        dao.updateApplicationStatus(Integer.parseInt(workFlowDTO.getWorkflowReference()), status);
    } catch (APIManagementException e) {
        String msg = "Error occured when updating the status of the Application creation process";
        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 44 with Complete

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

the class ApplicationRegistrationSimpleWorkflowExecutor method complete.

/**
 * Complete the external process status
 * Based on the workflow status we will update the status column of the
 * Application table
 *
 * @param workFlowDTO - WorkflowDTO
 */
public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.info("Complete  Application Registration Workflow..");
    }
    ApplicationRegistrationWorkflowDTO regWFDTO = (ApplicationRegistrationWorkflowDTO) workFlowDTO;
    ApiMgtDAO dao = ApiMgtDAO.getInstance();
    try {
        dao.createApplicationRegistrationEntry((ApplicationRegistrationWorkflowDTO) workFlowDTO, false);
        generateKeysForApplication(regWFDTO);
    } catch (APIManagementException e) {
        String msg = "Error occurred when updating the status of the Application creation process";
        log.error(msg, e);
        throw new WorkflowException(e.getMessage(), e);
    }
    return new GeneralWorkflowResponse();
}
Also used : ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 45 with Complete

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

the class SubscriptionCreationApprovalWorkflowExecutor method complete.

/**
 * Complete the Approval workflow executor for Subscription creation.
 *
 * @param workflowDTO
 */
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setUpdatedTime(System.currentTimeMillis());
    super.complete(workflowDTO);
    if (log.isDebugEnabled()) {
        String logMessage = "Subscription Creation [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + " Workflow State : " + workflowDTO.getStatus();
        log.debug(logMessage);
    }
    if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
        ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
        try {
            apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
        } catch (APIManagementException e) {
            log.error("Could not complete subscription creation workflow", e);
            throw new WorkflowException("Could not complete subscription creation workflow", e);
        }
    } else if (WorkflowStatus.REJECTED.equals(workflowDTO.getStatus())) {
        ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
        try {
            apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
        } catch (APIManagementException e) {
            log.error("Could not complete subscription creation workflow", e);
            throw new WorkflowException("Could not complete subscription creation workflow", e);
        }
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

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