Search in sources :

Example 16 with WorkflowDTO

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

the class SubscriptionUpdateWSWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setUpdatedTime(System.currentTimeMillis());
    super.complete(workflowDTO);
    log.info("Subscription Update [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
    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 update workflow", e);
            throw new WorkflowException("Could not complete subscription update 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 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) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)

Example 17 with WorkflowDTO

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

the class ApiMgtDAO method populateAppRegistrationWorkflowDTO.

public void populateAppRegistrationWorkflowDTO(ApplicationRegistrationWorkflowDTO workflowDTO) throws APIManagementException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    Application application = null;
    Subscriber subscriber = null;
    String registrationEntry = SQLConstants.GET_APPLICATION_REGISTRATION_ENTRY_BY_SUBSCRIBER_SQL;
    try {
        conn = APIMgtDBUtil.getConnection();
        ps = conn.prepareStatement(registrationEntry);
        ps.setString(1, workflowDTO.getExternalWorkflowReference());
        rs = ps.executeQuery();
        while (rs.next()) {
            subscriber = new Subscriber(rs.getString("USER_ID"));
            subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
            application = new Application(rs.getString("NAME"), subscriber);
            application.setId(rs.getInt("APPLICATION_ID"));
            application.setUUID(rs.getString("UUID"));
            application.setTokenType(rs.getString("APP_TYPE"));
            application.setApplicationWorkFlowStatus(rs.getString("APPLICATION_STATUS"));
            application.setCallbackUrl(rs.getString("CALLBACK_URL"));
            application.setDescription(rs.getString("DESCRIPTION"));
            application.setTier(rs.getString("APPLICATION_TIER"));
            workflowDTO.setApplication(application);
            workflowDTO.setKeyType(rs.getString("TOKEN_TYPE"));
            workflowDTO.setUserName(subscriber.getName());
            workflowDTO.setDomainList(rs.getString("ALLOWED_DOMAINS"));
            workflowDTO.setValidityTime(rs.getLong("VALIDITY_PERIOD"));
            String tenantDomain = MultitenantUtils.getTenantDomain(subscriber.getName());
            String keyManagerUUID = rs.getString("KEY_MANAGER");
            workflowDTO.setKeyManager(keyManagerUUID);
            KeyManagerConfigurationDTO keyManagerConfigurationByUUID = getKeyManagerConfigurationByUUID(conn, keyManagerUUID);
            if (keyManagerConfigurationByUUID != null) {
                OAuthAppRequest request = ApplicationUtils.createOauthAppRequest(application.getName(), null, application.getCallbackUrl(), rs.getString("TOKEN_SCOPE"), rs.getString("INPUTS"), application.getTokenType(), keyManagerConfigurationByUUID.getOrganization(), keyManagerConfigurationByUUID.getName());
                request.setMappingId(workflowDTO.getWorkflowReference());
                request.getOAuthApplicationInfo().setApplicationUUID(application.getUUID());
                workflowDTO.setAppInfoDTO(request);
            } else {
                throw new APIManagementException("Error occured while finding the KeyManager from uuid " + keyManagerUUID + ".", ExceptionCodes.KEY_MANAGER_NOT_REGISTERED);
            }
        }
    } catch (SQLException | IOException e) {
        handleException("Error occurred while retrieving an " + "Application Registration Entry for Workflow : " + workflowDTO.getExternalWorkflowReference(), e);
    } finally {
        APIMgtDBUtil.closeAllConnections(ps, conn, rs);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 18 with WorkflowDTO

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

the class ApiMgtDAO method retrieveWorkflowFromInternalReference.

/**
 * Returns a workflow object for a given internal workflow reference and the workflow type.
 *
 * @param workflowReference
 * @param workflowType
 * @return
 * @throws APIManagementException
 */
public WorkflowDTO retrieveWorkflowFromInternalReference(String workflowReference, String workflowType) throws APIManagementException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    WorkflowDTO workflowDTO = null;
    String query = SQLConstants.GET_ALL_WORKFLOW_ENTRY_FROM_INTERNAL_REF_SQL;
    try {
        connection = APIMgtDBUtil.getConnection();
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, workflowReference);
        prepStmt.setString(2, workflowType);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            workflowDTO = WorkflowExecutorFactory.getInstance().createWorkflowDTO(rs.getString("WF_TYPE"));
            workflowDTO.setStatus(WorkflowStatus.valueOf(rs.getString("WF_STATUS")));
            workflowDTO.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
            workflowDTO.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").getTime());
            workflowDTO.setWorkflowReference(rs.getString("WF_REFERENCE"));
            workflowDTO.setTenantDomain(rs.getString("TENANT_DOMAIN"));
            workflowDTO.setTenantId(rs.getInt("TENANT_ID"));
            workflowDTO.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
        }
    } catch (SQLException e) {
        handleException("Error while retrieving workflow details for " + workflowReference, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
    }
    return workflowDTO;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with WorkflowDTO

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

the class UserSignUpWSWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    // workflowDTO.setStatus(workflowDTO.getStatus());
    workflowDTO.setUpdatedTime(System.currentTimeMillis());
    if (log.isDebugEnabled()) {
        log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
    }
    super.complete(workflowDTO);
    String tenantDomain = workflowDTO.getTenantDomain();
    try {
        UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
        if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
            try {
                updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
            } catch (Exception e) {
                // updateRolesOfUser throws generic Exception. Therefore generic Exception is caught
                throw new WorkflowException("Error while assigning role to user", e);
            }
        } else {
            try {
                /* Remove created user */
                deleteUser(tenantDomain, tenantAwareUserName);
            } catch (Exception e) {
                throw new WorkflowException("Error while deleting the user", e);
            }
        }
    } catch (APIManagementException e1) {
        throw new WorkflowException("Error while accessing signup configuration", e1);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 20 with WorkflowDTO

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

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