use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method getAllApplications.
@Override
public List<Application> getAllApplications() throws APIMgtDAOException {
List<Application> applicationList = new ArrayList<>();
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(GET_APPS_QUERY)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String createdUser = rs.getString("CREATED_BY");
Application application = new Application(rs.getString("NAME"), createdUser);
application.setId(rs.getString("UUID"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setPolicy(new ApplicationPolicy(rs.getString("APPLICATION_POLICY_ID"), ""));
applicationList.add(application);
}
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting all applications", ex);
}
return applicationList;
}
use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method createApplicationFromResultSet.
private Application createApplicationFromResultSet(ResultSet rs) throws APIMgtDAOException, SQLException {
Application application = null;
if (rs.next()) {
String createdUser = rs.getString("CREATED_BY");
application = new Application(rs.getString("NAME"), createdUser);
application.setId(rs.getString("UUID"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setCreatedTime(rs.getTimestamp("CREATED_TIME").toLocalDateTime());
application.setUpdatedUser(rs.getString("UPDATED_BY"));
application.setUpdatedTime(rs.getTimestamp("LAST_UPDATED_TIME").toLocalDateTime());
application.setPolicy(new ApplicationPolicy(rs.getString("APPLICATION_POLICY_NAME")));
}
return application;
}
use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImpl method addApplicationPolicy.
/**
* Adds an Application Policy
*
* @param policy {@link ApplicationPolicy} instance
* @param connection DB Connection instance
* @throws SQLException if an error occurs while adding an Application Policy
*/
private static void addApplicationPolicy(ApplicationPolicy policy, Connection connection) throws SQLException {
final String query = "INSERT INTO AM_APPLICATION_POLICY (UUID, NAME, DISPLAY_NAME, " + "DESCRIPTION, QUOTA_TYPE, QUOTA, QUOTA_UNIT, UNIT_TIME, TIME_UNIT, IS_DEPLOYED, CUSTOM_ATTRIBUTES) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)";
Limit limit = policy.getDefaultQuotaPolicy().getLimit();
try (PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, policy.getUuid());
statement.setString(2, policy.getPolicyName());
statement.setString(3, policy.getDisplayName());
statement.setString(4, policy.getDescription());
statement.setString(5, policy.getDefaultQuotaPolicy().getType());
setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement);
statement.setInt(8, policy.getDefaultQuotaPolicy().getLimit().getUnitTime());
statement.setString(9, policy.getDefaultQuotaPolicy().getLimit().getTimeUnit());
statement.setBoolean(10, policy.isDeployed());
statement.setBytes(11, policy.getCustomAttributes());
statement.execute();
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImpl method addApplicationPolicy.
@Override
public void addApplicationPolicy(ApplicationPolicy policy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
addApplicationPolicy(policy, connection);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "Error in adding Application policy, policy name: " + policy.getPolicyName();
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);
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApplicationPolicy.
@Override
public String addApplicationPolicy(ApplicationPolicy 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.addApplicationPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add Application for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
Aggregations