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);
}
}
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());
}
}
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;
}
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;
}
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;
}
Aggregations