use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method getAPIsByStatus.
/**
* @see ApiDAO#getAPIsByStatus(Set, List, List)
*/
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<API> getAPIsByStatus(Set<String> roles, List<String> statuses, List<String> labels) throws APIMgtDAOException {
// check for null at the beginning before constructing the query to retrieve APIs from database
if (roles == null || statuses == null) {
String errorMessage = "Role list or API status list should not be null to retrieve APIs.";
log.error(errorMessage);
throw new APIMgtDAOException(errorMessage);
}
// the below query will be used to retrieve the union of,
// published/prototyped APIs (statuses) with public visibility and
// published/prototyped APIs with restricted visibility where APIs are restricted based on roles of the user
String labelQuery = null;
if (labels.isEmpty()) {
labelQuery = "SELECT LABEL_ID FROM AM_LABELS WHERE TYPE_NAME='STORE'";
} else {
labelQuery = "SELECT LABEL_ID FROM AM_LABELS WHERE NAME IN ( " + DAOUtil.getParameterString(labels.size()) + ") AND TYPE_NAME='STORE'";
}
final String query = "Select UUID, PROVIDER, NAME, CONTEXT, VERSION, DESCRIPTION, CURRENT_LC_STATUS, " + "LIFECYCLE_INSTANCE_ID, LC_WORKFLOW_STATUS, SECURITY_SCHEME FROM (" + API_SUMMARY_SELECT + " WHERE " + "VISIBILITY = '" + API.Visibility.PUBLIC + "' " + "AND " + "CURRENT_LC_STATUS IN (" + DAOUtil.getParameterString(statuses.size()) + ") AND " + "API_TYPE_ID = (SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)" + "UNION " + API_SUMMARY_SELECT + " WHERE " + "VISIBILITY = '" + API.Visibility.RESTRICTED + "' " + "AND " + "UUID IN (SELECT API_ID FROM AM_API_VISIBLE_ROLES WHERE ROLE IN " + "(" + DAOUtil.getParameterString(roles.size()) + ")) " + " AND CURRENT_LC_STATUS IN (" + DAOUtil.getParameterString(statuses.size()) + ") AND " + " API_TYPE_ID = (SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)) A" + " JOIN AM_API_LABEL_MAPPING LM ON A.UUID=LM.API_ID WHERE LM.LABEL_ID IN (" + labelQuery + ")";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
int i = 0;
// put desired API status into the query (to get APIs with public visibility)
for (String status : statuses) {
statement.setString(++i, status);
}
statement.setString(++i, ApiType.STANDARD.toString());
// put desired roles into the query
for (String role : roles) {
statement.setString(++i, role);
}
// put desired API status into the query (to get APIs with restricted visibility)
for (String status : statuses) {
statement.setString(++i, status);
}
statement.setString(++i, ApiType.STANDARD.toString());
// Set the label names in the query
for (String label : labels) {
statement.setString(++i, label);
}
return constructAPISummaryList(connection, statement);
} catch (SQLException e) {
String errorMessage = "Error while retrieving API list in store.";
throw new APIMgtDAOException(errorMessage, e);
}
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateRating.
@Override
public void updateRating(String apiId, String ratingId, Rating rating) throws APIMgtDAOException {
final String updateRatingQuery = "UPDATE AM_API_RATINGS SET RATING = ? , UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE API_ID = ? AND UUID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(updateRatingQuery)) {
try {
connection.setAutoCommit(false);
statement.setInt(1, rating.getRating());
statement.setString(2, rating.getUsername());
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(4, apiId);
statement.setString(5, ratingId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "updating Rating for API: " + apiId + ", Rating: " + rating.getUuid();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "updating Rating for API: " + apiId + ", Rating: " + rating.getUuid();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method getRatingByUUID.
@Override
public Rating getRatingByUUID(String apiId, String ratingId) throws APIMgtDAOException {
final String query = "SELECT UUID, API_ID, RATING, USER_IDENTIFIER, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME " + "FROM AM_API_RATINGS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, ratingId);
statement.setString(2, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return constructRatingFromResultSet(rs);
}
}
} catch (SQLException e) {
String errorMessage = "getting Rating: " + ratingId + " for API: " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
} catch (SQLException e) {
String errorMessage = "getting Rating: " + ratingId + " for API: " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return null;
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructRatingFromResultSet.
/**
* Constructs a Rating object from a result set
*
* @param rs the result set retrieved from db
* @return Rating constructed from result set
* @throws APIMgtDAOException if result set access fails
*/
private Rating constructRatingFromResultSet(ResultSet rs) throws APIMgtDAOException {
Rating rating = new Rating();
try {
rating.setUuid(rs.getString("UUID"));
rating.setRating((int) Double.parseDouble(rs.getString("RATING")));
rating.setApiId(rs.getString("API_ID"));
rating.setUsername(rs.getString("USER_IDENTIFIER"));
rating.setCreatedUser(rs.getString("CREATED_BY"));
rating.setCreatedTime(rs.getTimestamp("CREATED_TIME").toLocalDateTime());
rating.setLastUpdatedUser(rs.getString("UPDATED_BY"));
rating.setLastUpdatedTime(rs.getTimestamp("LAST_UPDATED_TIME").toLocalDateTime());
} catch (SQLException e) {
String errorMessage = "constructing Rating from ResultSet";
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return rating;
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class PolicyDAOImpl method deletePolicy.
@Override
public void deletePolicy(APIMgtAdminService.PolicyLevel policyLevel, String policyName) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
if (APIMgtAdminService.PolicyLevel.application == policyLevel) {
deleteApplicationPolicy(policyName, connection);
} else if (APIMgtAdminService.PolicyLevel.subscription == policyLevel) {
deleteSubscriptionPolicy(policyName, connection);
} else if (APIMgtAdminService.PolicyLevel.api == policyLevel) {
deleteApiPolicy(policyName, connection);
}
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "Error in deleting throttling policy for level: " + policyLevel + ", policy name: " + policyName;
log.error(errorMessage, e);
throw new APIMgtDAOException(errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMsg = "Error in obtaining DB connection";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
Aggregations