Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing subscription policy parameter returning issue #4581

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ public List<SubscriptionPolicy> getSubscriptionPolicies() throws APIMgtDAOExcept
try {
List<SubscriptionPolicy> policyList = new ArrayList<>();
String sqlQuery = "SELECT UUID, NAME, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, "
+ "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED from AM_SUBSCRIPTION_POLICY";
+ "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED,RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, "
+ "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY";

try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
Expand All @@ -745,7 +746,8 @@ public List<SubscriptionPolicy> getSubscriptionPolicies() throws APIMgtDAOExcept
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 FROM AM_SUBSCRIPTION_POLICY WHERE NAME = ?";
+ "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);
Expand Down Expand Up @@ -1050,7 +1052,8 @@ public List<APIPolicy> getApiPolicies() throws APIMgtDAOException {
*/
private SubscriptionPolicy getSubscriptionPolicyById(String uuid) throws SQLException, APIMgtDAOException {
final String query = "SELECT NAME, UUID, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, "
+ "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED FROM AM_SUBSCRIPTION_POLICY WHERE UUID = ?";
+ "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED, RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, "
+ "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection();
PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, uuid);
Expand Down Expand Up @@ -1083,6 +1086,7 @@ private SubscriptionPolicy createSubscriptionPolicyFromResultSet(String identifi
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(rs.getString(APIMgtConstants.
ThrottlePolicyConstants.COLUMN_NAME));
setCommonPolicyDetails(subscriptionPolicy, rs);
setSubscriptionPolicyDetals(subscriptionPolicy, rs);
InputStream binary = rs.getBinaryStream(APIMgtConstants.ThrottlePolicyConstants.
COLUMN_CUSTOM_ATTRIB);
if (binary != null) {
Expand All @@ -1102,6 +1106,17 @@ private SubscriptionPolicy createSubscriptionPolicyFromResultSet(String identifi
return subscriptionPolicy;
}

private void setSubscriptionPolicyDetals(SubscriptionPolicy subscriptionPolicy, ResultSet rs) throws SQLException {

subscriptionPolicy.setBillingPlan(rs.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_BILLING_PLAN));
subscriptionPolicy
.setRateLimitCount(rs.getInt(APIMgtConstants.ThrottlePolicyConstants.COLUMN_RATE_LIMIT_COUNT));
subscriptionPolicy.setRateLimitTimeUnit(
rs.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_RATE_LIMIT_TIME_UNIT));
subscriptionPolicy
.setStopOnQuotaReach(rs.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_STOP_ON_QUOTA_REACH));
}

@Override
public String getLastUpdatedTimeOfThrottlingPolicy(APIMgtAdminService.PolicyLevel policyLevel, String policyName)
throws APIMgtDAOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public class SampleTestObjectCreator {
public static final String ACCESS_URL = "https://test.";
public static final String ORIGINAL_ENDPOINT_WEATHER = "http://www.webservicex.net/WeatherForecast.asmx";
public static final String ORIGINAL_ENDPOINT_STOCK_QUOTE = "http://www.webservicex.net/stockquote.asmx";
public static final String BUSINESS_PLAN_FREE = "FREE";

public static APIPolicy unlimitedApiPolicy = new APIPolicy(UUID.randomUUID().toString(), UNLIMITED_TIER);
public static APIPolicy goldApiPolicy = new APIPolicy(UUID.randomUUID().toString(), GOLD_TIER);
Expand Down Expand Up @@ -762,7 +763,7 @@ public static APIPolicy createDefaultAPIPolicy() {
apiPolicy.setDescription(SAMPLE_API_POLICY_DESCRIPTION);
apiPolicy.setUserLevel(APIMgtConstants.ThrottlePolicyConstants.API_LEVEL);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1000, 10000);
defaultQuotaPolicy.setLimit(requestCountLimit);
apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
Expand All @@ -780,7 +781,7 @@ public static APIPolicy updateAPIPolicy(APIPolicy apiPolicy) {
apiPolicy.setDisplayName(UPDATED_SAMPLE_API_POLICY);
apiPolicy.setDescription(UPDATED_SAMPLE_API_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
Expand Down Expand Up @@ -835,7 +836,7 @@ public static List<Pipeline> createDefaultPipelines() {
//pipeline 2 with request count as quota policy
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
QuotaPolicy quotaPolicy2 = new QuotaPolicy();
quotaPolicy2.setType(REQUEST_COUNT_TYPE);
quotaPolicy2.setType(PolicyConstants.REQUEST_COUNT_TYPE);
quotaPolicy2.setLimit(requestCountLimit);

Pipeline pipeline2 = new Pipeline();
Expand Down Expand Up @@ -897,7 +898,7 @@ public static ApplicationPolicy createDefaultApplicationPolicy() {
applicationPolicy.setDescription(SAMPLE_APP_POLICY_DESCRIPTION);
applicationPolicy.setCustomAttributes(SAMPLE_CUSTOM_ATTRIBUTE.getBytes());
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 10000, 1000);
defaultQuotaPolicy.setLimit(requestCountLimit);
applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
Expand All @@ -909,7 +910,7 @@ public static ApplicationPolicy updateApplicationPolicy(ApplicationPolicy applic
applicationPolicy.setDisplayName(UPDATED_SAMPLE_APP_POLICY);
applicationPolicy.setDescription(UPDATED_SAMPLE_APP_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 10, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
Expand All @@ -922,19 +923,41 @@ public static SubscriptionPolicy createDefaultSubscriptionPolicy() {
subscriptionPolicy.setDisplayName(SAMPLE_SUBSCRIPTION_POLICY);
subscriptionPolicy.setDescription(SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
subscriptionPolicy.setCustomAttributes(SAMPLE_CUSTOM_ATTRIBUTE.getBytes());
subscriptionPolicy.setDeployed(true);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(REQUEST_COUNT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 10000, 1000);
defaultQuotaPolicy.setLimit(requestCountLimit);
subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
subscriptionPolicy.setBillingPlan(BUSINESS_PLAN_FREE);
subscriptionPolicy.setRateLimitCount(100);
subscriptionPolicy.setRateLimitTimeUnit("s");
subscriptionPolicy.setStopOnQuotaReach(true);
return subscriptionPolicy;
}
public static SubscriptionPolicy createSubscriptionPolicyWithBandwithLimit() {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy("SubPolicyBandwith");
subscriptionPolicy.setUuid(UUID.randomUUID().toString());
subscriptionPolicy.setDisplayName(SAMPLE_SUBSCRIPTION_POLICY);
subscriptionPolicy.setDescription(SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
subscriptionPolicy.setCustomAttributes(SAMPLE_CUSTOM_ATTRIBUTE.getBytes());
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
subscriptionPolicy.setBillingPlan(BUSINESS_PLAN_FREE);
subscriptionPolicy.setRateLimitCount(100);
subscriptionPolicy.setRateLimitTimeUnit("s");
subscriptionPolicy.setStopOnQuotaReach(true);
return subscriptionPolicy;
}

public static SubscriptionPolicy updateSubscriptionPolicy(SubscriptionPolicy subscriptionPolicy) {
subscriptionPolicy.setDisplayName(UPDATED_SAMPLE_SUBSCRIPTION_POLICY);
subscriptionPolicy.setDescription(UPDATED_SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
Expand Down
Loading