Search in sources :

Example 96 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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 97 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class AbstractApplicationRegistrationWorkflowExecutor method dogenerateKeysForApplication.

public static void dogenerateKeysForApplication(ApplicationRegistrationWorkflowDTO workflowDTO) throws APIManagementException {
    log.debug("Registering Application and creating an Access Token... ");
    Application application = workflowDTO.getApplication();
    Subscriber subscriber = application.getSubscriber();
    ApiMgtDAO dao = ApiMgtDAO.getInstance();
    if (subscriber == null || workflowDTO.getAllowedDomains() == null) {
        dao.populateAppRegistrationWorkflowDTO(workflowDTO);
    }
    try {
        // get new key manager
        // Here the default flow is set expecting an ID as the keymanager as this flow only involves new applications
        String keyManagerId = workflowDTO.getKeyManager();
        KeyManagerConfigurationDTO km = dao.getKeyManagerConfigurationByUUID(keyManagerId);
        String tenantDomain = km.getOrganization();
        String keyManagerName = km.getName();
        KeyManager keyManager = KeyManagerHolder.getKeyManagerInstance(tenantDomain, keyManagerName);
        if (keyManager == null) {
            throw new APIManagementException("Key Manager " + keyManagerName + " not configured");
        }
        workflowDTO.getAppInfoDTO().getOAuthApplicationInfo().setClientName(application.getName());
        // set applications attributes to the oAuthApplicationInfo
        workflowDTO.getAppInfoDTO().getOAuthApplicationInfo().putAllAppAttributes(application.getApplicationAttributes());
        // createApplication on oAuthorization server.
        OAuthApplicationInfo oAuthApplication = keyManager.createApplication(workflowDTO.getAppInfoDTO());
        // update associateApplication
        ApplicationUtils.updateOAuthAppAssociation(application, workflowDTO.getKeyType(), oAuthApplication, keyManagerId);
        // change create application status in to completed.
        dao.updateApplicationRegistration(APIConstants.AppRegistrationStatus.REGISTRATION_COMPLETED, workflowDTO.getKeyType(), workflowDTO.getApplication().getId(), keyManagerId);
        workflowDTO.setApplicationInfo(oAuthApplication);
        AccessTokenInfo tokenInfo;
        Object enableTokenGeneration = keyManager.getKeyManagerConfiguration().getParameter(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION);
        if (enableTokenGeneration != null && (Boolean) enableTokenGeneration && oAuthApplication.getJsonString().contains(APIConstants.GRANT_TYPE_CLIENT_CREDENTIALS)) {
            AccessTokenRequest tokenRequest = ApplicationUtils.createAccessTokenRequest(keyManager, oAuthApplication, null);
            tokenInfo = keyManager.getNewApplicationAccessToken(tokenRequest);
        } else {
            tokenInfo = new AccessTokenInfo();
            tokenInfo.setAccessToken("");
            tokenInfo.setValidityPeriod(0L);
            String[] noScopes = new String[] { "N/A" };
            tokenInfo.setScope(noScopes);
            oAuthApplication.addParameter("tokenScope", Arrays.toString(noScopes));
        }
        workflowDTO.setAccessTokenInfo(tokenInfo);
    } catch (Exception e) {
        APIUtil.handleException("Error occurred while executing SubscriberKeyMgtClient.", e);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) AccessTokenRequest(org.wso2.carbon.apimgt.api.model.AccessTokenRequest) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager)

Example 98 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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 99 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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 100 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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

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