Search in sources :

Example 61 with Workflow

use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.

the class WorkflowsApiServiceImpl method workflowsExternalWorkflowRefGet.

/**
 * This is used to get the workflow pending request according to ExternalWorkflowReference
 *
 * @param externalWorkflowRef is the unique identifier for workflow request
 * @return
 */
@Override
public Response workflowsExternalWorkflowRefGet(String externalWorkflowRef, MessageContext messageContext) throws APIManagementException {
    WorkflowInfoDTO workflowinfoDTO;
    try {
        Workflow workflow;
        String status = "CREATED";
        String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        APIAdmin apiAdmin = new APIAdminImpl();
        workflow = apiAdmin.getworkflowReferenceByExternalWorkflowReferenceID(externalWorkflowRef, status, tenantDomain);
        workflowinfoDTO = WorkflowMappingUtil.fromWorkflowsToInfoDTO(workflow);
        return Response.ok().entity(workflowinfoDTO).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving workflow request by the " + "external workflow reference. ", e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WorkflowInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowInfoDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Workflow(org.wso2.carbon.apimgt.api.model.Workflow) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 62 with Workflow

use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.

the class WorkflowMappingUtil method fromWorkflowsToInfoDTO.

public static WorkflowInfoDTO fromWorkflowsToInfoDTO(Workflow workflow) {
    WorkflowInfoDTO workflowInfoDTO = new WorkflowInfoDTO();
    if (workflow.getWorkflowType().equals("AM_APPLICATION_CREATION")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.APPLICATION_CREATION);
    } else if (workflow.getWorkflowType().equals("AM_SUBSCRIPTION_CREATION")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.SUBSCRIPTION_CREATION);
    } else if (workflow.getWorkflowType().equals("AM_USER_SIGNUP")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.USER_SIGNUP);
    } else if (workflow.getWorkflowType().equals("AM_APPLICATION_REGISTRATION_PRODUCTION")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.APPLICATION_REGISTRATION_PRODUCTION);
    } else if (workflow.getWorkflowType().equals("AM_APPLICATION_REGISTRATION_SANDBOX")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.APPLICATION_REGISTRATION_SANDBOX);
    } else if (workflow.getWorkflowType().equals("AM_API_STATE")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.API_STATE);
    } else if (workflow.getWorkflowType().equals("AM_API_PRODUCT_STATE")) {
        workflowInfoDTO.setWorkflowType(WorkflowInfoDTO.WorkflowTypeEnum.API_PRODUCT_STATE);
    }
    workflowInfoDTO.setWorkflowStatus(WorkflowInfoDTO.WorkflowStatusEnum.valueOf(workflow.getStatus().toString()));
    workflowInfoDTO.setCreatedTime(workflow.getCreatedTime());
    workflowInfoDTO.setUpdatedTime(workflow.getUpdatedTime());
    workflowInfoDTO.setReferenceId(workflow.getExternalWorkflowReference());
    workflowInfoDTO.setDescription(workflow.getWorkflowDescription());
    workflowInfoDTO.setProperties(workflow.getProperties());
    return workflowInfoDTO;
}
Also used : WorkflowInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.WorkflowInfoDTO)

Example 63 with Workflow

use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.

the class ApiMgtDAO method getworkflowReferenceByExternalWorkflowReferenceID.

/**
 * Get the Pending workflow Request using ExternalWorkflowReference for a particular tenant
 *
 * @param externelWorkflowRef of pending workflow request
 * @param status              workflow status of workflow pending process
 * @param tenantDomain        tenant domain of user
 * @return workflow pending request
 */
public Workflow getworkflowReferenceByExternalWorkflowReferenceID(String externelWorkflowRef, String status, String tenantDomain) throws APIManagementException {
    ResultSet rs = null;
    Workflow workflow = new Workflow();
    String sqlQuery = SQLConstants.GET_ALL_WORKFLOW_DETAILS_BY_EXTERNAL_WORKFLOW_REFERENCE;
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement prepStmt = connection.prepareStatement(sqlQuery)) {
        try {
            prepStmt.setString(1, externelWorkflowRef);
            prepStmt.setString(2, status);
            prepStmt.setString(3, tenantDomain);
            rs = prepStmt.executeQuery();
            while (rs.next()) {
                workflow.setWorkflowId(rs.getInt("WF_ID"));
                workflow.setWorkflowReference(rs.getString("WF_REFERENCE"));
                workflow.setWorkflowType(rs.getString("WF_TYPE"));
                String workflowstatus = rs.getString("WF_STATUS");
                workflow.setStatus(org.wso2.carbon.apimgt.api.WorkflowStatus.valueOf(workflowstatus));
                workflow.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").toString());
                workflow.setUpdatedTime(rs.getTimestamp("WF_UPDATED_TIME").toString());
                workflow.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
                workflow.setTenantId(rs.getInt("TENANT_ID"));
                workflow.setTenantDomain(rs.getString("TENANT_DOMAIN"));
                workflow.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
                InputStream targetStream = rs.getBinaryStream("WF_METADATA");
                InputStream propertiesTargetStream = rs.getBinaryStream("WF_PROPERTIES");
                if (targetStream != null) {
                    String metadata = APIMgtDBUtil.getStringFromInputStream(targetStream);
                    Gson metadataGson = new Gson();
                    JSONObject metadataJson = metadataGson.fromJson(metadata, JSONObject.class);
                    workflow.setMetadata(metadataJson);
                } else {
                    JSONObject metadataJson = new JSONObject();
                    workflow.setMetadata(metadataJson);
                }
                if (propertiesTargetStream != null) {
                    String properties = APIMgtDBUtil.getStringFromInputStream(propertiesTargetStream);
                    Gson propertiesGson = new Gson();
                    JSONObject propertiesJson = propertiesGson.fromJson(properties, JSONObject.class);
                    workflow.setProperties(propertiesJson);
                } else {
                    JSONObject propertiesJson = new JSONObject();
                    workflow.setProperties(propertiesJson);
                }
            }
        } catch (SQLException e) {
            handleException("Error when retriving the workflow details. ", e);
        } finally {
            APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
        }
    } catch (SQLException e) {
        handleException("Error when retriving the workflow details. ", e);
    }
    return workflow;
}
Also used : JSONObject(org.json.simple.JSONObject) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) Workflow(org.wso2.carbon.apimgt.api.model.Workflow) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement)

Example 64 with Workflow

use of org.wso2.carbon.apimgt.api.model.Workflow 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 65 with Workflow

use of org.wso2.carbon.apimgt.api.model.Workflow 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

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 Test (org.junit.Test)35 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)28 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)26 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)25 Test (org.testng.annotations.Test)24 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)22 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)21 HashMap (java.util.HashMap)20 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)20 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)19 JSONObject (org.json.simple.JSONObject)17 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)17 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)16 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)15 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)15 Application (org.wso2.carbon.apimgt.api.model.Application)14 ArrayList (java.util.ArrayList)12 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)11