Search in sources :

Example 16 with WorkflowDTO

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

the class ApplicationDeletionSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
    ApplicationWorkflowDTO applicationWorkflowDTO = (ApplicationWorkflowDTO) workflowDTO;
    Application application = applicationWorkflowDTO.getApplication();
    String errorMsg = null;
    try {
        apiMgtDAO.deleteApplication(application);
    } catch (APIManagementException e) {
        if (e.getMessage() == null) {
            errorMsg = "Couldn't complete simple application deletion workflow for application: " + application.getName();
        } else {
            errorMsg = e.getMessage();
        }
        throw new WorkflowException(errorMsg, e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 17 with WorkflowDTO

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

the class SubscriptionCreationApprovalWorkflowExecutor 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 Creation 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());
    super.execute(workflowDTO);
    return new GeneralWorkflowResponse();
}
Also used : SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)

Example 18 with WorkflowDTO

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

the class SubscriptionCreationWSWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setUpdatedTime(System.currentTimeMillis());
    super.complete(workflowDTO);
    log.info("Subscription Creation [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 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 19 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.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 20 with WorkflowDTO

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

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