@@ -89,12 +89,19 @@ private static Integration parseMapToIntegration(String featureName, Map<String,
8989
9090 loadBasicAttributes (integration , featureName , map , pricingManager );
9191
92+ String integrationType = "" ;
93+ try {
94+ integrationType = (String ) map .get ("integrationType" );
95+ } catch (NullPointerException e ) {
96+ throw new InvalidIntegrationTypeException ("The feature " + featureName + " is from type INTEGRATION but does not have an integrationType attribute" );
97+ }
98+
9299 try {
93- integration .setIntegrationType (IntegrationType .valueOf (( String ) map . get ( " integrationType" ) ));
100+ integration .setIntegrationType (IntegrationType .valueOf (integrationType ));
94101 } catch (NullPointerException | IllegalArgumentException e ) {
95102 throw new InvalidIntegrationTypeException (
96103 "The feature " + featureName + " does not have a supported integrationType (" + Arrays .toString (IntegrationType .values ()) + "). Current value: "
97- + ( String ) map . get ( " integrationType" ) );
104+ + integrationType );
98105 }
99106
100107 if (integration .getIntegrationType ().equals (IntegrationType .WEB_SAAS )) {
@@ -118,12 +125,19 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O
118125
119126 loadBasicAttributes (automation , featureName , map , pricingManager );
120127
128+ String automationType = "" ;
129+ try {
130+ automationType = (String ) map .get ("automationType" );
131+ } catch (NullPointerException e ) {
132+ throw new InvalidAutomationTypeException ("The feature " + featureName + " is from type AUTOMATION but does not have an automationType attribute" );
133+ }
134+
121135 try {
122- automation .setAutomationType (AutomationType .valueOf (( String ) map . get ( " automationType" ) ));
136+ automation .setAutomationType (AutomationType .valueOf (automationType ));
123137 } catch (IllegalArgumentException e ) {
124138 throw new InvalidAutomationTypeException (
125139 "The feature " + featureName + " does not have a supported automationType (" + Arrays .toString (AutomationType .values ()) + "). Current value: "
126- + ( String ) map . get ( " automationType" ) );
140+ + automationType );
127141 }
128142
129143 return automation ;
@@ -190,7 +204,7 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
190204 feature .setValueType (ValueType .valueOf ((String ) map .get ("valueType" )));
191205 } catch (IllegalArgumentException e ) {
192206 throw new PricingParsingException ("The feature " + featureName
193- + " does not have a supported valueType. Current valueType: " + (String ) map .get ("valueType" ));
207+ + " does not have a supported valueType (" + Arrays . toString ( ValueType . values ()) + ") . Current valueType: " + (String ) map .get ("valueType" ));
194208 }
195209 try {
196210 Object defaultValue = map .get ("defaultValue" );
@@ -204,6 +218,10 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
204218
205219 switch (feature .getValueType ()) {
206220 case NUMERIC :
221+ if (feature instanceof Payment ) {
222+ throw new InvalidDefaultValueException ("The feature " + featureName
223+ + " is from type PAYMENT but has a valueType of NUMERIC. It should be TEXT." );
224+ }
207225 feature .setDefaultValue (map .get ("defaultValue" ));
208226 if (!(feature .getDefaultValue () instanceof Integer || feature .getDefaultValue () instanceof Double
209227 || feature .getDefaultValue () instanceof Long )) {
@@ -251,18 +269,21 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
251269 }
252270
253271 private static void parsePaymentValue (Feature feature , String featureName , Map <String , Object > map ) {
254-
255- List <String > allowedPaymentTypes = (List <String >) map .get ("defaultValue" );
256- for (String type : allowedPaymentTypes ) {
272+ List <String > allowedPaymentTypes ;
273+ try {
274+ allowedPaymentTypes = (List <String >) map .get ("defaultValue" );
275+ } catch (ClassCastException e ) {
276+ throw new InvalidDefaultValueException ("The feature " + featureName
277+ + " is from type PAYMENT but has a valueType of TEXT. It should be a list of supported paymentType (" +Arrays .toString (PaymentType .values ())+"). To specify a list, use a dash (-) before each value. The defaultValue that generates the issue: " + map .get ("defaultValue" ));
278+ }
279+ for (String paymentType : allowedPaymentTypes ) {
257280 try {
258- PaymentType .valueOf (type );
281+ PaymentType .valueOf (paymentType );
259282 } catch (IllegalArgumentException e ) {
260283 throw new InvalidDefaultValueException ("The feature " + featureName
261- + " does not have a supported paymentType. PaymentType that generates the issue: " + type );
284+ + " does not have a valid defaultValue consisting on a list of supported paymentType (" + Arrays . toString ( PaymentType . values ())+ "). PaymentType that generates the issue: " + paymentType );
262285 }
263286 }
264-
265287 feature .setDefaultValue (allowedPaymentTypes );
266-
267288 }
268289}
0 commit comments