Skip to content

Commit 9800748

Browse files
author
rathnapandi
committed
- Fix issue #499
1 parent 5aa928d commit 9800748

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- Importing SOAP API with different endpoints (for import and for runtime calls) (See issue [#501](https://github.com/Axway-API-Management-Plus/apim-cli/issues/501))
1010
- -returnCodeMapping option does not work on apim-cli org import (See issue [#496](https://github.com/Axway-API-Management-Plus/apim-cli/issues/496))
1111
- The output of command 'apim api get' is not containing the complete list of client applications (array) of the api (See issue [#495](https://github.com/Axway-API-Management-Plus/apim-cli/issues/495))
12+
- Update API with Assigned Quota (See issue [#499](https://github.com/Axway-API-Management-Plus/apim-cli/issues/499))
13+
1214
### Added
1315
- Force APIM-cli to download the latest Trusted Certificates in a Frontend API (See issue [#494](https://github.com/Axway-API-Management-Plus/apim-cli/issues/494))
1416

modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/QuotaRestrictionSerializer.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@ public class QuotaRestrictionSerializer extends StdSerializer<QuotaRestriction>
1515
public static final String METHOD = "method";
1616

1717
public QuotaRestrictionSerializer() {
18-
this(null);
19-
}
20-
21-
public QuotaRestrictionSerializer(Class<QuotaRestriction> t) {
22-
super(t);
23-
}
24-
25-
@Override
26-
public void serialize(QuotaRestriction quotaRestriction, JsonGenerator jgen, SerializerProvider provider) throws IOException {
27-
jgen.writeStartObject();
28-
if(quotaRestriction.getRestrictedAPI()==null) {
29-
jgen.writeObjectField("api", "*");
30-
jgen.writeObjectField(METHOD, "*");
31-
} else { // API-Specific quota
32-
// Don't write the API-Name as it's confusing it is ignored during import when the API-Path is given.
33-
jgen.writeObjectField("apiPath", quotaRestriction.getRestrictedAPI().getPath());
34-
if(quotaRestriction.getRestrictedAPI().getVhost()!=null) {
35-
jgen.writeObjectField("vhost", quotaRestriction.getRestrictedAPI().getVhost());
36-
}
37-
if(quotaRestriction.getRestrictedAPI().getApiRoutingKey()!=null) {
38-
jgen.writeObjectField("apiRoutingKey", quotaRestriction.getRestrictedAPI().getApiRoutingKey());
39-
}
40-
if(quotaRestriction.getMethod()==null || "*".equals(quotaRestriction.getMethod())) {
41-
jgen.writeObjectField(METHOD, "*");
42-
} else {
43-
APIMethod method = APIManagerAdapter.getInstance().getMethodAdapter().getMethodForId(quotaRestriction.getApiId(), quotaRestriction.getMethod());
44-
jgen.writeObjectField(METHOD, method.getName());
45-
}
46-
}
47-
jgen.writePOJOField("type",quotaRestriction.getType());
48-
jgen.writePOJOField("config",quotaRestriction.getConfig());
49-
jgen.writeEndObject();
50-
}
51-
52-
@Override
53-
public Class<QuotaRestriction> handledType() {
54-
return QuotaRestriction.class;
55-
}
18+
this(null);
19+
}
20+
21+
public QuotaRestrictionSerializer(Class<QuotaRestriction> t) {
22+
super(t);
23+
}
24+
25+
@Override
26+
public void serialize(QuotaRestriction quotaRestriction, JsonGenerator jgen, SerializerProvider provider) throws IOException {
27+
jgen.writeStartObject();
28+
if (quotaRestriction.getRestrictedAPI() == null) {
29+
jgen.writeObjectField("api", "*");
30+
jgen.writeObjectField(METHOD, "*");
31+
} else { // API-Specific quota
32+
// Don't write the API-Name as it's confusing it is ignored during import when the API-Path is given.
33+
jgen.writeObjectField("apiPath", quotaRestriction.getRestrictedAPI().getPath());
34+
if (quotaRestriction.getRestrictedAPI().getVhost() != null) {
35+
jgen.writeObjectField("vhost", quotaRestriction.getRestrictedAPI().getVhost());
36+
}
37+
if (quotaRestriction.getRestrictedAPI().getApiRoutingKey() != null) {
38+
jgen.writeObjectField("apiRoutingKey", quotaRestriction.getRestrictedAPI().getApiRoutingKey());
39+
}
40+
if (quotaRestriction.getMethod() == null || "*".equals(quotaRestriction.getMethod())) {
41+
jgen.writeObjectField(METHOD, "*");
42+
} else {
43+
APIMethod method = APIManagerAdapter.getInstance().getMethodAdapter().getMethodForId(quotaRestriction.getApiId(), quotaRestriction.getMethod());
44+
jgen.writeObjectField(METHOD, method.getName());
45+
}
46+
}
47+
jgen.writePOJOField("type", quotaRestriction.getType());
48+
jgen.writePOJOField("config", quotaRestriction.getConfig());
49+
jgen.writeEndObject();
50+
}
51+
52+
@Override
53+
public Class<QuotaRestriction> handledType() {
54+
return QuotaRestriction.class;
55+
}
5656
}

modules/apis/src/main/java/com/axway/apim/apiimport/actions/APIQuotaManager.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,14 @@ public void updateRestrictions(List<QuotaRestriction> actualRestrictions, List<Q
6262
LOG.info("{} quota for API: {} Nothing to do.", type.getFriendlyName(), createdAPI.getName());
6363
return;
6464
}
65-
APIManagerAPIMethodAdapter methodAdapter = APIManagerAdapter.getInstance().getMethodAdapter();
6665
APIManagerQuotaAdapter quotaManager = APIManagerAdapter.getInstance().getQuotaAdapter();
6766
LOG.info("Updating {} quota for API: {}", type.getFriendlyName(), createdAPI.getName());
6867
LOG.debug("{}-Restrictions: Desired: {}, Actual: {}", type.getFriendlyName(), desiredRestrictions, actualRestrictions);
69-
// In order to compare/merge the restrictions, we must translate the desired API-Method-Names, if not a "*", into the methodId of the createdAPI
70-
if (desiredRestrictions != null) {
71-
for (QuotaRestriction desiredRestriction : desiredRestrictions) {
72-
if ("*".equals(desiredRestriction.getMethod()))
73-
continue;
74-
desiredRestriction.setMethod(methodAdapter.getMethodForName(createdAPI.getId(), desiredRestriction.getMethod()).getId());
75-
}
76-
}
7768
// Load the entire current default quota
7869
APIQuota currentDefaultQuota = quotaManager.getDefaultQuota(type);
7970
LOG.debug("Current Default Quota : {}", currentDefaultQuota);
8071
List<QuotaRestriction> mergedRestrictions = addOrMergeRestriction(actualRestrictions, desiredRestrictions);
72+
LOG.debug("Merged Quota : {}", mergedRestrictions);
8173
populateMethodId(createdAPI, mergedRestrictions);
8274
// If there is an actual API, remove the restrictions for the current actual API
8375
if (actualState != null) {
@@ -132,7 +124,7 @@ public void populateMethodId(API createdAPI, List<QuotaRestriction> mergedRestri
132124
// Additionally, we have to change the methodId
133125
// Load the method for actualAPI to get the name of the method to which the existing quota is applied to
134126
if (actualState != null) {
135-
APIMethod actualMethod = methodAdapter.getMethodForId(actualState.getId(), restriction.getMethod());
127+
APIMethod actualMethod = methodAdapter.getMethodForName(actualState.getId(), restriction.getMethod());
136128
if (actualMethod != null) {
137129
// Now load the new method based on the name for the createdAPI
138130
APIMethod newMethod = methodAdapter.getMethodForName(createdAPI.getId(), actualMethod.getName());
@@ -141,6 +133,10 @@ public void populateMethodId(API createdAPI, List<QuotaRestriction> mergedRestri
141133
} else {
142134
LOG.warn("API Method Name : {} not found in specification", restriction.getMethod());
143135
}
136+
}else {
137+
// For new api creation
138+
APIMethod newMethod = methodAdapter.getMethodForName(createdAPI.getId(), restriction.getMethod());
139+
restriction.setMethod(newMethod.getId());
144140
}
145141
}
146142
}

0 commit comments

Comments
 (0)