Skip to content

Commit 974264d

Browse files
authored
Merge pull request #43 from isa-group/fix/pricing-parser
fix: parsing exceptions
2 parents ed9d8d3 + 3cba1fd commit 974264d

4 files changed

Lines changed: 71 additions & 9 deletions

File tree

src/main/java/io/github/isagroup/services/parsing/AddOnParser.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ private static void setAddOnFeatures(String addOnName, Map<String, Object> addOn
169169

170170
Feature addOnFeature = Feature.cloneFeature(globalFeaturesMap.get(addOnFeatureName));
171171

172+
Object value = addOnFeatureMap.get("value");
173+
boolean isValueNull = (value == null);
174+
175+
if (isValueNull){
176+
throw new InvalidDefaultValueException("The feature " + addOnFeature.getName()
177+
+ " does not have a valid value. Current valueType: "
178+
+ addOnFeature.getValueType().toString() + "; Current value in addOn " + addOn.getName() + " is null");
179+
}
180+
172181
switch (addOnFeature.getValueType()) {
173182
case NUMERIC:
174183
addOnFeature.setValue(addOnFeatureMap.get("value"));
@@ -230,17 +239,26 @@ private static void setAddOnUsageLimits(String addOnName, Map<String, Object> ad
230239

231240
if (!globalUsageLimitsMap.containsKey(addOnUsageLimitName)) {
232241
throw new FeatureNotFoundException(
233-
"The feature " + addOnUsageLimitName + " is not defined in the global features");
242+
"The usageLimit " + addOnUsageLimitName + " is not defined in the global features");
234243
}
235244

236245
UsageLimit addOnUsageLimit = UsageLimit.cloneUsageLimit(globalUsageLimitsMap.get(addOnUsageLimitName));
237246

247+
Object value = addOnUsageLimitMap.get("value");
248+
boolean isValueNull = (value == null);
249+
250+
if (isValueNull){
251+
throw new InvalidDefaultValueException("The usageLimit " + addOnUsageLimit.getName()
252+
+ " does not have a valid value. Current valueType: "
253+
+ addOnUsageLimit.getValueType().toString() + "; Current value in addOn " + addOn.getName() + " is null");
254+
}
255+
238256
switch (addOnUsageLimit.getValueType()) {
239257
case NUMERIC:
240258
addOnUsageLimit.setValue(addOnUsageLimitMap.get("value"));
241259
if (!(addOnUsageLimit.getValue() instanceof Integer || addOnUsageLimit.getValue() instanceof Double
242260
|| addOnUsageLimit.getValue() instanceof Long)) {
243-
throw new InvalidDefaultValueException("The feature " + addOnUsageLimitName
261+
throw new InvalidDefaultValueException("The usageLimit " + addOnUsageLimitName
244262
+ " does not have a valid value. Current valueType:"
245263
+ addOnUsageLimit.getValueType().toString() + "; Current defaultValue: "
246264
+ addOnUsageLimitMap.get("value").toString());

src/main/java/io/github/isagroup/services/parsing/FeatureParser.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.isagroup.services.parsing;
22

3+
import java.util.Arrays;
34
import java.util.List;
45
import java.util.Map;
56
import java.util.NoSuchElementException;
@@ -69,7 +70,7 @@ public static Feature parseMapToFeature(String featureName, Map<String, Object>
6970
}
7071
} catch (IllegalArgumentException e) {
7172
throw new IllegalArgumentException("The feature " + featureName
72-
+ " does not have a supported feature type. Current value: " + (String) featureMap.get("type"));
73+
+ " does not have a supported feature type (" + Arrays.toString(FeatureType.values()) + "). Current value: " + (String) featureMap.get("type"));
7374
}
7475
}
7576

@@ -92,7 +93,7 @@ private static Integration parseMapToIntegration(String featureName, Map<String,
9293
integration.setIntegrationType(IntegrationType.valueOf((String) map.get("integrationType")));
9394
} catch (NullPointerException | IllegalArgumentException e) {
9495
throw new InvalidIntegrationTypeException(
95-
"The feature " + featureName + " does not have a supported integrationType. Current value: "
96+
"The feature " + featureName + " does not have a supported integrationType (" + Arrays.toString(IntegrationType.values()) + "). Current value: "
9697
+ (String) map.get("integrationType"));
9798
}
9899

@@ -121,7 +122,7 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O
121122
automation.setAutomationType(AutomationType.valueOf((String) map.get("automationType")));
122123
} catch (IllegalArgumentException e) {
123124
throw new InvalidAutomationTypeException(
124-
"The feature " + featureName + " does not have a supported automationType. Current value: "
125+
"The feature " + featureName + " does not have a supported automationType (" + Arrays.toString(AutomationType.values()) + "). Current value: "
125126
+ (String) map.get("automationType"));
126127
}
127128

@@ -192,6 +193,15 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
192193
+ " does not have a supported valueType. Current valueType: " + (String) map.get("valueType"));
193194
}
194195
try {
196+
Object defaultValue = map.get("defaultValue");
197+
boolean isValueNull = (defaultValue == null);
198+
199+
if (isValueNull){
200+
throw new InvalidDefaultValueException("The feature " + feature.getName()
201+
+ " does not have a valid defaultValue. Current valueType: "
202+
+ feature.getValueType().toString() + "; Current defaultValue is null");
203+
}
204+
195205
switch (feature.getValueType()) {
196206
case NUMERIC:
197207
feature.setDefaultValue(map.get("defaultValue"));

src/main/java/io/github/isagroup/services/parsing/PlanParser.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.isagroup.services.parsing;
22

3+
import java.util.Arrays;
34
import java.util.LinkedHashMap;
45
import java.util.List;
56
import java.util.Map;
@@ -109,6 +110,15 @@ private static void setFeaturesToPlan(String planName, Map<String, Object> map,
109110
"The feature " + planFeatureName + " is not defined in the global features");
110111
} else {
111112
Feature feature = plan.getFeatures().get(planFeatureName);
113+
114+
Object value = planFeatureMap.get("value");
115+
boolean isValueNull = (value == null);
116+
117+
if (isValueNull){
118+
throw new InvalidDefaultValueException("The feature " + feature.getName()
119+
+ " does not have a valid value. Current valueType: "
120+
+ feature.getValueType().toString() + "; Current value in plan " + plan.getName() + " is null");
121+
}
112122

113123
switch (feature.getValueType()) {
114124
case NUMERIC:
@@ -186,6 +196,15 @@ private static void setUsageLimitsToPlan(String planName, Map<String, Object> ma
186196
} else {
187197
UsageLimit usageLimit = plan.getUsageLimits().get(planUsageLimitName);
188198

199+
Object value = planUsageLimitMap.get("value");
200+
boolean isValueNull = (value == null);
201+
202+
if (isValueNull){
203+
throw new InvalidDefaultValueException("The usageLimit " + usageLimit.getName()
204+
+ " does not have a valid value. Current valueType: "
205+
+ usageLimit.getValueType().toString() + "; Current value in plan " + plan.getName() + " is null");
206+
}
207+
189208
switch (usageLimit.getValueType()) {
190209
case NUMERIC:
191210
usageLimit.setValue(planUsageLimitMap.get("value"));
@@ -222,16 +241,21 @@ public static void parsePaymentValue(Feature feature, String featureName, Map<St
222241
Object paymentValue = map.get("value");
223242
if (paymentValue instanceof String) {
224243
throw new PricingParsingException(
225-
"\"" + featureName + "\"" + "should be a list of supported payment types");
244+
"Invalid value for \"" + featureName + "\": expected a list of supported payment types ("
245+
+ Arrays.toString(PaymentType.values()) + "), but found a string. "
246+
+ "To specify a list, use a dash (-) before each value. "
247+
+ "Problematic value: \"" + paymentValue + "\".");
226248
}
227249

228250
List<String> allowedPaymentTypes = (List<String>) paymentValue;
229251
for (String type : allowedPaymentTypes) {
230252
try {
231253
PaymentType.valueOf(type);
232254
} catch (IllegalArgumentException e) {
233-
throw new InvalidDefaultValueException("The feature " + featureName
234-
+ " does not have a supported paymentType. PaymentType that generates the issue: " + type);
255+
throw new InvalidDefaultValueException(
256+
"Invalid payment type for feature \"" + featureName + "\": \"" + type + "\" is not a supported payment type. "
257+
+ "Supported types are: " + Arrays.toString(PaymentType.values()) + ". "
258+
);
235259
}
236260
}
237261

src/main/java/io/github/isagroup/services/parsing/UsageLimitParser.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.isagroup.services.parsing;
22

3+
import java.util.Arrays;
34
import java.util.List;
45
import java.util.Map;
56
import java.util.Set;
@@ -48,7 +49,7 @@ public static UsageLimit parseMapToUsageLimit(String limitName, Map<String, Obje
4849
}
4950
} catch (IllegalArgumentException e) {
5051
throw new IllegalArgumentException("The usage limit " + limitName
51-
+ " does not have a supported type. Current type value: " + (String) limitMap.get("type"));
52+
+ " does not have a supported type (" + Arrays.toString(UsageLimitType.values()) + "). Current type value: " + (String) limitMap.get("type"));
5253
}
5354
}
5455

@@ -100,6 +101,15 @@ private static void loadBasicAttributes(UsageLimit limit, String limitName, Map<
100101
+ " does not have a supported valueType. Current valueType: " + (String) map.get("valueType"));
101102
}
102103
try {
104+
Object defaultValue = map.get("defaultValue");
105+
boolean isValueNull = (defaultValue == null);
106+
107+
if (isValueNull){
108+
throw new InvalidDefaultValueException("The usageLimit " + limit.getName()
109+
+ " does not have a valid defaultValue. Current valueType: "
110+
+ limit.getValueType().toString() + "; Current defaultValue is null");
111+
}
112+
103113
switch (limit.getValueType()) {
104114
case NUMERIC:
105115
limit.setDefaultValue(map.get("defaultValue"));

0 commit comments

Comments
 (0)