Search in sources :

Example 36 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse 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 37 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse 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 38 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse 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 39 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse 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)

Example 40 with GeneralWorkflowResponse

use of org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse in project carbon-apimgt by wso2.

the class SubscriptionCreationWSWorkflowExecutor method execute.

/**
 * This method is used to execute the workflow without giving a workflow response back to the caller to execute
 * some other task after completing the workflow
 *
 * @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow.
 * @throws WorkflowException
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    try {
        String action = WorkflowConstants.CREATE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:SubscriptionApprovalWorkFlowProcessRequest " + "         xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" + "         <wor:apiName>$1</wor:apiName>\n" + "         <wor:apiVersion>$2</wor:apiVersion>\n" + "         <wor:apiContext>$3</wor:apiContext>\n" + "         <wor:apiProvider>$4</wor:apiProvider>\n" + "         <wor:subscriber>$5</wor:subscriber>\n" + "         <wor:applicationName>$6</wor:applicationName>\n" + "         <wor:tierName>$7</wor:tierName>\n" + "         <wor:workflowExternalRef>$8</wor:workflowExternalRef>\n" + "         <wor:callBackURL>$9</wor:callBackURL>\n" + "      </wor:SubscriptionApprovalWorkFlowProcessRequest>";
        SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
        String callBackURL = subsWorkflowDTO.getCallbackUrl();
        payload = payload.replace("$1", subsWorkflowDTO.getApiName());
        payload = payload.replace("$2", subsWorkflowDTO.getApiVersion());
        payload = payload.replace("$3", subsWorkflowDTO.getApiContext());
        payload = payload.replace("$4", subsWorkflowDTO.getApiProvider());
        payload = payload.replace("$5", subsWorkflowDTO.getSubscriber());
        payload = payload.replace("$6", subsWorkflowDTO.getApplicationName());
        payload = payload.replace("$7", subsWorkflowDTO.getTierName());
        payload = payload.replace("$8", subsWorkflowDTO.getExternalWorkflowReference());
        payload = payload.replace("$9", callBackURL != null ? callBackURL : "?");
        client.fireAndForget(AXIOMUtil.stringToOM(payload));
        super.execute(workflowDTO);
    } catch (AxisFault axisFault) {
        log.error("Error sending out message", axisFault);
        throw new WorkflowException("Error sending out message", axisFault);
    } catch (XMLStreamException e) {
        log.error("Error converting String to OMElement", e);
        throw new WorkflowException("Error converting String to OMElement", e);
    }
    return new GeneralWorkflowResponse();
}
Also used : AxisFault(org.apache.axis2.AxisFault) XMLStreamException(javax.xml.stream.XMLStreamException) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ServiceClient(org.apache.axis2.client.ServiceClient)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)19 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)19 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)15 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)9 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)8 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)7 Test (org.testng.annotations.Test)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 Application (org.wso2.carbon.apimgt.api.model.Application)5 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)5 Request (org.wso2.msf4j.Request)5 HashMap (java.util.HashMap)4 AxisFault (org.apache.axis2.AxisFault)4 ServiceClient (org.apache.axis2.client.ServiceClient)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)4 Application (org.wso2.carbon.apimgt.core.models.Application)4