use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method createSubscriptionWithApiAndAppInformation.
private Subscription createSubscriptionWithApiAndAppInformation(ResultSet rs) throws APIMgtDAOException {
Subscription subscription = null;
try {
if (rs.next()) {
String subscriptionId = rs.getString("SUBS_UUID");
String subscriptionTier = rs.getString("SUBS_POLICY");
String subscriptionPolicyId = rs.getString("SUBS_POLICY_ID");
API.APIBuilder apiBuilder = new API.APIBuilder(rs.getString("API_PROVIDER"), rs.getString("API_NAME"), rs.getString("API_VERSION"));
apiBuilder.id(rs.getString("API_ID"));
apiBuilder.context(rs.getString("API_CONTEXT"));
API api = apiBuilder.build();
Application app = new Application(rs.getString("APP_NAME"), rs.getString("APP_OWNER"));
app.setId(rs.getString("APP_ID"));
app.setStatus(rs.getString("APP_STATUS"));
subscription = new Subscription(subscriptionId, app, api, new SubscriptionPolicy(subscriptionPolicyId, subscriptionTier));
subscription.setStatus(APIMgtConstants.SubscriptionStatus.valueOf(rs.getString("SUB_STATUS")));
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "creating subscriptions api and app information", e);
}
return subscription;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method createSubscriptionsWithAppInformationOnly.
private List<Subscription> createSubscriptionsWithAppInformationOnly(ResultSet rs) throws APIMgtDAOException {
List<Subscription> subscriptionList = new ArrayList<>();
try {
Subscription subscription;
while (rs.next()) {
String subscriptionId = rs.getString("SUBS_UUID");
String subscriptionTier = rs.getString("SUBS_POLICY");
Application app = new Application(rs.getString("APP_NAME"), rs.getString("APP_OWNER"));
app.setId(rs.getString("APP_ID"));
app.setStatus(rs.getString("APP_STATUS"));
subscription = new Subscription(subscriptionId, app, null, new SubscriptionPolicy(subscriptionTier));
subscription.setStatus(APIMgtConstants.SubscriptionStatus.valueOf(rs.getString("SUB_STATUS")));
subscriptionList.add(subscription);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "creating subscriptions app information", e);
}
return subscriptionList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy in project carbon-apimgt by wso2.
the class ApiDAOImpl method getSubscripitonPolciesByAPIId.
private Set<Policy> getSubscripitonPolciesByAPIId(Connection connection, String apiId) throws SQLException {
final String query = "SELECT amPolcySub.NAME FROM AM_API_SUBS_POLICY_MAPPING apimsubmapping," + "AM_SUBSCRIPTION_POLICY amPolcySub where apimsubmapping.SUBSCRIPTION_POLICY_ID=amPolcySub.UUID " + "AND apimsubmapping.API_ID = ?";
Set<Policy> policies = new HashSet<>();
try (PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
policies.add(new SubscriptionPolicy(rs.getString("NAME")));
}
}
}
return policies;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getSubscriptionPolicy.
@Override
public SubscriptionPolicy getSubscriptionPolicy(String policyName) throws APIMgtDAOException {
try {
final String query = "SELECT UUID, NAME, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, " + "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED, RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, " + "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY WHERE NAME = ?";
try (Connection conn = DAOUtil.getConnection();
PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, policyName);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return createSubscriptionPolicyFromResultSet(policyName, rs);
} else {
// not found
String msg = "Subscription Policy not found for name: " + policyName;
log.warn(msg);
throw new APIMgtDAOException(msg, ExceptionCodes.POLICY_NOT_FOUND);
}
}
}
} catch (SQLException e) {
String errorMsg = "Error in retrieving Subscription policy for name: " + policyName;
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method updateSubscriptionPolicy.
@Override
public void updateSubscriptionPolicy(SubscriptionPolicy policy) throws APIManagementException {
try {
policyDAO.updateSubscriptionPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policy.getUuid(), policy.getPolicyName(), policy.isStopOnQuotaReach());
apiGateway.updatePolicy(policyValidationData);
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't update Subscription policy for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
Aggregations