Search in sources :

Example 91 with APIMgtDAOException

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

the class APIMgtAdminServiceImpl method updateBlockConditionStateByUUID.

@Override
public boolean updateBlockConditionStateByUUID(String uuid, Boolean state) throws APIManagementException {
    try {
        if (policyDAO.updateBlockConditionStateByUUID(uuid, state)) {
            BlockConditions blockConditions = getBlockConditionByUUID(uuid);
            apiGateway.updateBlockCondition(blockConditions);
            return true;
        } else {
            return false;
        }
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't update block condition with UUID: " + uuid + ", state: " + state;
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions)

Example 92 with APIMgtDAOException

use of org.wso2.carbon.apimgt.api.APIMgtDAOException 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 93 with APIMgtDAOException

use of org.wso2.carbon.apimgt.api.APIMgtDAOException 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 94 with APIMgtDAOException

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

Example 95 with APIMgtDAOException

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

the class APIMgtAdminServiceImpl method addApplicationPolicy.

@Override
public String addApplicationPolicy(ApplicationPolicy policy) throws APIManagementException {
    try {
        String policyUuid = policy.getUuid();
        if (policyUuid == null) {
            if (log.isDebugEnabled()) {
                log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
            }
            policyUuid = UUID.randomUUID().toString();
            policy.setUuid(policyUuid);
        }
        policyDAO.addApplicationPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
        apiGateway.addPolicy(policyValidationData);
        return policyUuid;
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add Application for uuid: " + policy.getUuid();
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)333 SQLException (java.sql.SQLException)192 Connection (java.sql.Connection)146 PreparedStatement (java.sql.PreparedStatement)129 Test (org.testng.annotations.Test)84 ResultSet (java.sql.ResultSet)72 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)72 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)57 API (org.wso2.carbon.apimgt.core.models.API)57 ArrayList (java.util.ArrayList)50 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)35 Application (org.wso2.carbon.apimgt.core.models.Application)24 HashMap (java.util.HashMap)23 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)22 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)21 BeforeTest (org.testng.annotations.BeforeTest)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)20 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)20 IOException (java.io.IOException)19 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)17