Search in sources :

Example 1 with InternalWorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException in project carbon-identity-framework by wso2.

the class WorkflowDAO method listWorkflows.

/**
 * Retrieve all the Workflows for a tenant
 *
 * @param tenantId Tenant ID
 * @return List<Workflow>
 * @throws InternalWorkflowException
 */
public List<Workflow> listWorkflows(int tenantId) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection(false);
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<Workflow> workflowList = new ArrayList<>();
    String query = SQLConstants.LIST_WORKFLOWS_QUERY;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setInt(1, tenantId);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            String id = rs.getString(SQLConstants.ID_COLUMN);
            String name = rs.getString(SQLConstants.WF_NAME_COLUMN);
            String description = rs.getString(SQLConstants.DESCRIPTION_COLUMN);
            String templateId = rs.getString(SQLConstants.TEMPLATE_ID_COLUMN);
            String templateImplId = rs.getString(SQLConstants.TEMPLATE_IMPL_ID_COLUMN);
            Workflow workflowDTO = new Workflow();
            workflowDTO.setWorkflowId(id);
            workflowDTO.setWorkflowName(name);
            workflowDTO.setWorkflowDescription(description);
            workflowDTO.setTemplateId(templateId);
            workflowDTO.setWorkflowImplId(templateImplId);
            workflowList.add(workflowDTO);
        }
    } catch (SQLException e) {
        throw new InternalWorkflowException(errorMessage, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
    return workflowList;
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) PreparedStatement(java.sql.PreparedStatement)

Example 2 with InternalWorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException in project carbon-identity-framework by wso2.

the class WorkflowDAO method removeWorkflowParams.

/**
 * Clear all the parameters that stored under workflow Id
 *
 * @param workflowId WorkflowId
 * @throws InternalWorkflowException
 */
public void removeWorkflowParams(String workflowId) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.DELETE_WORKFLOW_PARAMS_QUERY;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, workflowId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException(errorMessage, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 3 with InternalWorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException in project carbon-identity-framework by wso2.

the class WorkflowDAO method removeWorkflows.

/**
 * Remove all workflows of a given tenant id.
 *
 * @param tenantId The id of the tenant.
 * @throws InternalWorkflowException throws when an error occurs in removing workflows.
 */
public void removeWorkflows(int tenantId) throws InternalWorkflowException {
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
        try (PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.DELETE_WORKFLOW_BY_TENANT_ID_QUERY)) {
            prepStmt.setInt(1, tenantId);
            prepStmt.executeUpdate();
            IdentityDatabaseUtil.commitTransaction(connection);
        } catch (SQLException e) {
            throw new InternalWorkflowException(errorMessage, e);
        }
    } catch (SQLException e) {
        throw new InternalWorkflowException(errorMessage, e);
    }
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 4 with InternalWorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException in project carbon-identity-framework by wso2.

the class WorkflowDAO method removeWorkflow.

/**
 * Remove Workflow from the DB
 *
 * @param workflowId workflow Id
 * @throws InternalWorkflowException
 */
public void removeWorkflow(String workflowId) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.DELETE_WORKFLOW_QUERY;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, workflowId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException(errorMessage, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 5 with InternalWorkflowException

use of org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException in project carbon-identity-framework by wso2.

the class WorkflowRequestAssociationDAO method updateStatusOfRelationshipsOfPendingRequest.

/**
 * Update state of workflow of a request
 *
 * @param requestId requestId to update relationships of.
 * @throws InternalWorkflowException
 */
public void updateStatusOfRelationshipsOfPendingRequest(String requestId, String status) throws InternalWorkflowException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.UPDATE_STATUS_OF_RELATIONSHIPS_OF_REQUEST;
    try {
        Timestamp updatedDateStamp = new Timestamp(System.currentTimeMillis());
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, status);
        prepStmt.setTimestamp(2, updatedDateStamp);
        prepStmt.setString(3, requestId);
        prepStmt.setString(4, WFConstant.HT_STATE_PENDING);
        prepStmt.execute();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Aggregations

InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)44 Connection (java.sql.Connection)39 PreparedStatement (java.sql.PreparedStatement)39 SQLException (java.sql.SQLException)39 ResultSet (java.sql.ResultSet)21 ArrayList (java.util.ArrayList)13 Timestamp (java.sql.Timestamp)6 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)6 IOException (java.io.IOException)5 Association (org.wso2.carbon.identity.workflow.mgt.dto.Association)4 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)4 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)3 Workflow (org.wso2.carbon.identity.workflow.mgt.bean.Workflow)3 WorkflowRequest (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)3 WorkflowAssociation (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation)2 WorkflowRequestAssociation (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequestAssociation)2 WorkflowRequestDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO)2 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard)2 AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)2 XPath (javax.xml.xpath.XPath)1