Search in sources :

Example 11 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class WorkflowExecutorFactory method createWorkflowDTO.

/**
 * Create a DTO object related to a given workflow type.
 * @param wfType Type of the workflow.
 */
public WorkflowDTO createWorkflowDTO(String wfType) {
    WorkflowDTO workflowDTO = null;
    if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(wfType)) {
        workflowDTO = new ApplicationWorkflowDTO();
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION.equals(wfType)) {
        workflowDTO = new ApplicationRegistrationWorkflowDTO();
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION);
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_SANDBOX.equals(wfType)) {
        workflowDTO = new ApplicationRegistrationWorkflowDTO();
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setKeyType(APIConstants.API_KEY_TYPE_SANDBOX);
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(wfType)) {
        workflowDTO = new SubscriptionWorkflowDTO();
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_UPDATE.equals(wfType)) {
        workflowDTO = new SubscriptionWorkflowDTO();
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_USER_SIGNUP.equals(wfType)) {
        workflowDTO = new WorkflowDTO();
        workflowDTO.setWorkflowType(wfType);
    } else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(wfType) || WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE.equals(wfType)) {
        workflowDTO = new APIStateWorkflowDTO();
        workflowDTO.setWorkflowType(wfType);
    }
    return workflowDTO;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)

Example 12 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 13 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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();
}
Also used : ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 14 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationRegistrationWSWorkflowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing Application registration Workflow..");
    }
    try {
        String action = WorkflowConstants.CREATE_REGISTRATION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:ApplicationRegistrationWorkFlowProcessRequest xmlns:wor=\"http://workflow.application.apimgt.carbon.wso2.org\">\n" + "        <wor:applicationName>$1</wor:applicationName>\n" + "        <wor:applicationTier>$2</wor:applicationTier>\n" + "        <wor:applicationCallbackUrl>$3</wor:applicationCallbackUrl>\n" + "        <wor:applicationDescription>$4</wor:applicationDescription>\n" + "        <wor:tenantDomain>$5</wor:tenantDomain>\n" + "        <wor:userName>$6</wor:userName>\n" + "        <wor:workflowExternalRef>$7</wor:workflowExternalRef>\n" + "        <wor:callBackURL>$8</wor:callBackURL>\n" + "        <wor:keyType>$9</wor:keyType>\n" + "      </wor:ApplicationRegistrationWorkFlowProcessRequest>";
        ApplicationRegistrationWorkflowDTO appRegDTO = (ApplicationRegistrationWorkflowDTO) workflowDTO;
        Application application = appRegDTO.getApplication();
        String callBackURL = appRegDTO.getCallbackUrl();
        String applicationCallbackUrl = application.getCallbackUrl();
        String applicationDescription = application.getDescription();
        payload = payload.replace("$1", application.getName());
        payload = payload.replace("$2", application.getTier());
        payload = payload.replace("$3", applicationCallbackUrl != null ? applicationCallbackUrl : "?");
        payload = payload.replace("$4", applicationDescription != null ? applicationDescription : "?");
        payload = payload.replace("$5", appRegDTO.getTenantDomain());
        payload = payload.replace("$6", appRegDTO.getUserName());
        payload = payload.replace("$7", appRegDTO.getExternalWorkflowReference());
        payload = payload.replace("$8", callBackURL != null ? callBackURL : "?");
        payload = payload.replace("$9", appRegDTO.getKeyType());
        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) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) XMLStreamException(javax.xml.stream.XMLStreamException) ServiceClient(org.apache.axis2.client.ServiceClient) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 15 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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();
}
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)

Aggregations

Test (org.junit.Test)51 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)51 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)49 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)46 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)33 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)31 Application (org.wso2.carbon.apimgt.api.model.Application)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)19 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)17 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)14 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)11 XMLStreamException (javax.xml.stream.XMLStreamException)10 JSONObject (org.json.simple.JSONObject)10 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)10 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)10 HashMap (java.util.HashMap)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 ServiceClient (org.apache.axis2.client.ServiceClient)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)7