use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method getDedicatedGateway.
/**
* @see ApiDAO#getDedicatedGateway(String)
*/
@Override
public DedicatedGateway getDedicatedGateway(String apiId) throws APIMgtDAOException {
final String query = "SELECT HAS_OWN_GATEWAY FROM AM_API WHERE UUID = ?";
DedicatedGateway dedicatedGateway;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(rs.getBoolean(ContainerBasedGatewayConstants.IS_DEDICATED_GATEWAY_ENABLED));
return dedicatedGateway;
} else {
throw new APIMgtDAOException("Couldn't Find Dedicated Gateway details ", ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
}
}
} catch (SQLException e) {
String errorMessage = "Error while retrieving dedicated gateway details of API : " + apiId;
throw new APIMgtDAOException(errorMessage, e);
}
} catch (SQLException e) {
String message = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(message, e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method isAPIVersionsExist.
@Override
public boolean isAPIVersionsExist(String apiName) throws APIMgtDAOException {
final String query = "SELECT COUNT (NAME) FROM AM_API WHERE NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiName);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next() && rs.getInt(1) > 1) {
return true;
} else {
return false;
}
}
} catch (SQLException e) {
String errorMessage = "getting existence of versioned API: " + apiName;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method getAPIsByStatus.
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIMgtDAOException {
final String query = "SELECT DISTINCT UUID, PROVIDER, A.NAME, CONTEXT, VERSION, DESCRIPTION, CURRENT_LC_STATUS," + " LIFECYCLE_INSTANCE_ID, LC_WORKFLOW_STATUS, SECURITY_SCHEME FROM AM_API A INNER JOIN " + " AM_API_LABEL_MAPPING M ON A.UUID" + " = M.API_ID INNER JOIN AM_LABELS L ON L.LABEL_ID = M.LABEL_ID WHERE L.TYPE_NAME='GATEWAY' " + "AND L.NAME" + " " + "IN" + " " + "(" + DAOUtil.getParameterString(gatewayLabels.size()) + ") AND A" + ".CURRENT_LC_STATUS=?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
int i = 0;
for (String label : gatewayLabels) {
statement.setString(++i, label);
}
statement.setString(++i, status);
return constructAPISummaryList(connection, statement);
} catch (SQLException e) {
String msg = "getting APIs for given gateway labels: " + gatewayLabels.toString() + " with status: " + status;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId) throws APIMgtDAOException {
final String deleteCommentQuery = "DELETE FROM AM_API_COMMENTS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(deleteCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, commentId);
statement.setString(2, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method addDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void addDocumentInfo(String apiId, DocumentInfo documentInfo) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
ApiResourceDAO.addResourceWithoutValue(connection, apiId, documentInfo.getId(), ResourceCategory.DOC);
DocMetaDataDAO.addDocumentInfo(connection, documentInfo);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
Aggregations