Search in sources :

Example 41 with GeneralWorkflowResponse

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

the class SubscriptionUpdateApprovalWorkflowExecutor 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 Subscription Update Webservice Workflow.. ");
    }
    SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
    String message = "Approve API " + subsWorkflowDTO.getApiName() + " - " + subsWorkflowDTO.getApiVersion() + " subscription creation request from subscriber - " + subsWorkflowDTO.getSubscriber() + " for the application - " + subsWorkflowDTO.getApplicationName();
    workflowDTO.setWorkflowDescription(message);
    workflowDTO.setProperties("apiName", subsWorkflowDTO.getApiName());
    workflowDTO.setProperties("apiVersion", subsWorkflowDTO.getApiVersion());
    workflowDTO.setProperties("subscriber", subsWorkflowDTO.getSubscriber());
    workflowDTO.setProperties("applicationName", subsWorkflowDTO.getApplicationName());
    workflowDTO.setProperties("currentTier", subsWorkflowDTO.getTierName());
    workflowDTO.setProperties("requestedTier", subsWorkflowDTO.getRequestedTierName());
    super.execute(workflowDTO);
    return new GeneralWorkflowResponse();
}
Also used : SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)

Example 42 with GeneralWorkflowResponse

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

the class ApplicationCreationWSWorkflowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing Application creation Workflow.");
    }
    super.execute(workflowDTO);
    try {
        String action = WorkflowConstants.CREATE_APPLICATION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:ApplicationApprovalWorkFlowProcessRequest 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:ApplicationApprovalWorkFlowProcessRequest>";
        ApplicationWorkflowDTO appWorkFlowDTO = (ApplicationWorkflowDTO) workflowDTO;
        Application application = appWorkFlowDTO.getApplication();
        String callBackURL = appWorkFlowDTO.getCallbackUrl();
        payload = payload.replace("$1", application.getName());
        payload = payload.replace("$2", application.getTier());
        payload = payload.replace("$3", application.getCallbackUrl() == null ? "" : application.getCallbackUrl());
        payload = payload.replace("$4", application.getDescription() == null ? "" : application.getDescription());
        payload = payload.replace("$5", appWorkFlowDTO.getTenantDomain());
        payload = payload.replace("$6", appWorkFlowDTO.getUserName());
        payload = payload.replace("$7", appWorkFlowDTO.getExternalWorkflowReference());
        payload = payload.replace("$8", callBackURL != null ? callBackURL : "?");
        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } 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) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ServiceClient(org.apache.axis2.client.ServiceClient) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 43 with GeneralWorkflowResponse

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

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

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

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