Search in sources :

Example 86 with APIMgtDAOException

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

the class APIManagerFactory method newConsumer.

private APIStore newConsumer(String username) throws APIManagementException {
    // }
    try {
        APIStoreImpl userAwareAPIStore = new APIStoreImpl(username, getIdentityProvider(), getKeyManager(), DAOFactory.getApiDAO(), DAOFactory.getApplicationDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getPolicyDAO(), DAOFactory.getTagDAO(), DAOFactory.getLabelDAO(), DAOFactory.getWorkflowDAO(), new GatewaySourceGeneratorImpl(), new APIGatewayPublisherImpl());
        // Register all the observers which need to observe 'Store' component
        userAwareAPIStore.registerObserver(new EventLogger());
        userAwareAPIStore.registerObserver(new FunctionTrigger(DAOFactory.getFunctionDAO(), new RestCallUtilImpl()));
        return userAwareAPIStore;
    } catch (APIMgtDAOException e) {
        log.error("Couldn't Create API Consumer", e);
        throw new APIMgtDAOException("Couldn't Create API Consumer", ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 87 with APIMgtDAOException

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

the class APIManagerFactory method newProvider.

private APIPublisher newProvider(String username) throws APIManagementException {
    try {
        APIPublisherImpl apiPublisher = new APIPublisherImpl(username, getIdentityProvider(), getKeyManager(), DAOFactory.getApiDAO(), DAOFactory.getApplicationDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getPolicyDAO(), geApiLifecycleManager(), DAOFactory.getLabelDAO(), DAOFactory.getWorkflowDAO(), DAOFactory.getTagDAO(), DAOFactory.getThreatProtectionDAO(), new GatewaySourceGeneratorImpl(), new APIGatewayPublisherImpl());
        // Register all the observers which need to observe 'Publisher' component
        apiPublisher.registerObserver(new EventLogger());
        apiPublisher.registerObserver(new FunctionTrigger(DAOFactory.getFunctionDAO(), new RestCallUtilImpl()));
        return apiPublisher;
    } catch (APIMgtDAOException e) {
        log.error("Couldn't Create API Provider", e);
        throw new APIMgtDAOException("Couldn't Create API Provider", ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 88 with APIMgtDAOException

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

the class APIMgtAdminServiceImpl method getAPIsByGatewayLabel.

@Override
public List<API> getAPIsByGatewayLabel(List<String> gatewayLabels) throws APIManagementException {
    List<API> apiList;
    try {
        if (gatewayLabels != null) {
            apiList = apiDAO.getAPIsByGatewayLabel(gatewayLabels);
        } else {
            String msg = "Gateway labels cannot be null";
            log.error(msg);
            throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
        }
    } catch (APIMgtDAOException e) {
        String msg = "Error occurred while getting the API list in given gateway labels";
        log.error(msg, e);
        throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
    return apiList;
}
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 89 with APIMgtDAOException

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

the class APIMgtAdminServiceImpl method addApiPolicy.

@Override
public String addApiPolicy(APIPolicy 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.addApiPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
        apiGateway.addPolicy(policyValidationData);
        return policyUuid;
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add API policy 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)

Example 90 with APIMgtDAOException

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

the class APIMgtAdminServiceImpl method getAPIsByStatus.

@Override
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIManagementException {
    List<API> apiList;
    try {
        if (gatewayLabels != null && status != null) {
            apiList = apiDAO.getAPIsByStatus(gatewayLabels, status);
        } else {
            if (gatewayLabels == null) {
                String msg = "Gateway labels cannot be null";
                log.error(msg);
                throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
            } else {
                String msg = "Status cannot be null";
                log.error(msg);
                throw new APIManagementException(msg, ExceptionCodes.STATUS_CANNOT_BE_NULL);
            }
        }
    } catch (APIMgtDAOException e) {
        String msg = "Error occurred while getting the API list in given states";
        log.error(msg, e);
        throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
    return apiList;
}
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)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)333 SQLException (java.sql.SQLException)190 Connection (java.sql.Connection)144 PreparedStatement (java.sql.PreparedStatement)127 Test (org.testng.annotations.Test)84 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)72 ResultSet (java.sql.ResultSet)70 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)57 API (org.wso2.carbon.apimgt.core.models.API)57 ArrayList (java.util.ArrayList)49 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