Search in sources :

Example 31 with APIMgtDAOException

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

the class ApiDAOImpl method addDocumentFileContent.

/**
 * @see ApiDAO#addDocumentFileContent(String, InputStream, String, String)
 */
@Override
public void addDocumentFileContent(String resourceID, InputStream content, String dataType, String updatedBy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            if (ApiResourceDAO.updateBinaryResource(connection, resourceID, content, dataType, updatedBy) == 0) {
                String msg = "Cannot add file content for non existing document: " + resourceID + ", updated by: " + updatedBy;
                throw new APIMgtDAOException(msg, ExceptionCodes.DOCUMENT_NOT_FOUND);
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "adding document file content for document: " + resourceID + ", updatedBy: " + updatedBy;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "adding document file content for document: " + resourceID + ", updatedBy: " + updatedBy;
        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)

Example 32 with APIMgtDAOException

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

the class ApiDAOImpl method deleteEndpoint.

/**
 * Delete an Endpoint
 *
 * @param endpointId UUID of the endpoint.
 * @return Success of the delete operation.
 * @throws APIMgtDAOException If failed to delete endpoint.
 */
@Override
public boolean deleteEndpoint(String endpointId) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            deleteEndpoint(connection, endpointId);
            connection.commit();
            return true;
        } catch (SQLException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 33 with APIMgtDAOException

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

the class ApiDAOImpl method updateDocumentInfo.

/**
 * Add artifact resource meta data to an API
 *
 * @param apiId        UUID of API
 * @param documentInfo {@link DocumentInfo}
 * @param updatedBy    user who performs the action
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
        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)

Example 34 with APIMgtDAOException

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

the class ApiDAOImpl method updateApiDefinition.

@Override
public void updateApiDefinition(String apiID, String apiDefinition, String updatedBy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            updateAPIDefinition(connection, apiID, apiDefinition, updatedBy);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 35 with APIMgtDAOException

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

the class ApiDAOImpl method getResourcesOfApi.

/**
 * @see org.wso2.carbon.apimgt.core.dao.ApiDAO#getResourcesOfApi(String, String)
 */
@Override
public List<UriTemplate> getResourcesOfApi(String apiContext, String apiVersion) throws APIMgtDAOException {
    final String query = "SELECT operationMapping.OPERATION_ID AS OPERATION_ID,operationMapping.HTTP_METHOD AS " + "HTTP_METHOD,operationMapping.URL_PATTERN AS URL_PATTERN,operationMapping.AUTH_SCHEME AS AUTH_SCHEME," + "operationMapping.API_POLICY_ID AS API_POLICY_ID FROM AM_API_OPERATION_MAPPING operationMapping," + "AM_API api WHERE operationMapping.API_ID = api.UUID AND api.CONTEXT = ? AND api.VERSION = ?";
    List<UriTemplate> uriTemplates = new ArrayList<>();
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setString(1, apiContext);
        preparedStatement.setString(2, apiVersion);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                UriTemplate uriTemplate = new UriTemplate.UriTemplateBuilder().uriTemplate(resultSet.getString("URL_PATTERN")).authType(resultSet.getString("AUTH_SCHEME")).httpVerb(resultSet.getString("HTTP_METHOD")).policy(new APIPolicy(resultSet.getString("API_POLICY_ID"), "")).templateId(resultSet.getString("OPERATION_ID")).build();
                uriTemplates.add(uriTemplate);
            }
        }
    } catch (SQLException e) {
        String msg = "getting API resources for Context: " + apiContext + ", Version: " + apiVersion;
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
    return uriTemplates;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

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