Search in sources :

Example 1 with Workflow

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

the class ApiDAOImpl method updateAPIWorkflowStatus.

/**
 * Update an existing API workflow state
 *
 * @param apiID          The {@link String} of the API that needs to be updated
 * @param workflowStatus workflow status
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void updateAPIWorkflowStatus(String apiID, APILCWorkflowStatus workflowStatus) throws APIMgtDAOException {
    final String query = "UPDATE AM_API SET LAST_UPDATED_TIME = ?, LC_WORKFLOW_STATUS=? WHERE UUID = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        try {
            connection.setAutoCommit(false);
            statement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
            statement.setString(2, workflowStatus.toString());
            statement.setString(3, apiID);
            statement.execute();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Workflow

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

the class APIPublisherImpl method removePendingLifecycleWorkflowTaskForAPI.

/**
 * {@inheritDoc}
 */
@Override
public void removePendingLifecycleWorkflowTaskForAPI(String apiId) throws APIManagementException {
    try {
        API api = getApiDAO().getAPI(apiId);
        if (APILCWorkflowStatus.PENDING.toString().equals(api.getWorkflowStatus())) {
            // change the state back
            getApiDAO().updateAPIWorkflowStatus(apiId, APILCWorkflowStatus.APPROVED);
            // call executor's cleanup task
            cleanupPendingTaskForAPIStateChange(apiId);
        } else {
            String msg = "API does not have a pending lifecycle state change.";
            log.error(msg);
            throw new APIManagementException(msg, ExceptionCodes.WORKFLOW_NO_PENDING_TASK);
        }
    } catch (APIMgtDAOException e) {
        String msg = "Error occurred while changing api lifecycle workflow status";
        log.error(msg, e);
        throw new APIManagementException(msg, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) API(org.wso2.carbon.apimgt.core.models.API)

Example 3 with Workflow

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

the class WorkflowDAOImpl method retrieveUncompleteWorkflowsFromDB.

private List<Workflow> retrieveUncompleteWorkflowsFromDB() throws APIMgtDAOException, SQLException, ParseException {
    final String getworkflowQuery = "SELECT * FROM AM_WORKFLOWS WHERE WF_STATUS=?";
    List<Workflow> workflow;
    try (Connection conn = DAOUtil.getConnection();
        PreparedStatement ps = conn.prepareStatement(getworkflowQuery)) {
        ps.setString(1, WorkflowStatus.CREATED.toString());
        try (ResultSet rs = ps.executeQuery()) {
            workflow = this.createWorkflowsFromResultSet(rs);
        }
    }
    return workflow;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) PreparedStatement(java.sql.PreparedStatement)

Example 4 with Workflow

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

the class WorkflowDAOImpl method createWorkflowsFromResultSet.

private List<Workflow> createWorkflowsFromResultSet(ResultSet rs) throws SQLException, APIMgtDAOException, ParseException {
    List<Workflow> workflows = new ArrayList<>();
    while (rs.next()) {
        String wfType = rs.getString("WF_TYPE");
        Workflow workflow = WorkflowExecutorFactory.getInstance().createWorkflow(wfType);
        workflow.setStatus(WorkflowStatus.valueOf(rs.getString("WF_STATUS")));
        workflow.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
        workflow.setWorkflowReference(rs.getString("WF_REFERENCE"));
        workflow.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").toLocalDateTime());
        workflow.setUpdatedTime(rs.getTimestamp("WF_UPDATED_TIME").toLocalDateTime());
        workflow.setWorkflowReference(rs.getString("WF_REFERENCE"));
        workflow.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
        workflow.setAttributes(WorkflowUtils.jsonStringToMap(rs.getString("WF_ATTRIBUTES")));
        workflows.add(workflow);
    }
    return workflows;
}
Also used : ArrayList(java.util.ArrayList) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow)

Example 5 with Workflow

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

the class WorkflowDAOImpl method createWorkflowFromResultSet.

private Workflow createWorkflowFromResultSet(ResultSet rs) throws SQLException, APIMgtDAOException, ParseException {
    Workflow workflow = null;
    if (rs.next()) {
        String wfType = rs.getString("WF_TYPE");
        workflow = WorkflowExecutorFactory.getInstance().createWorkflow(wfType);
        workflow.setStatus(WorkflowStatus.valueOf(rs.getString("WF_STATUS")));
        workflow.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
        workflow.setWorkflowReference(rs.getString("WF_REFERENCE"));
        workflow.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").toLocalDateTime());
        workflow.setUpdatedTime(rs.getTimestamp("WF_UPDATED_TIME").toLocalDateTime());
        workflow.setWorkflowReference(rs.getString("WF_REFERENCE"));
        workflow.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
        workflow.setAttributes(WorkflowUtils.jsonStringToMap(rs.getString("WF_ATTRIBUTES")));
    }
    return workflow;
}
Also used : Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow)

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