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