From 8edb8ca78f2002b0f1e0cebd013d3f9505ec5f41 Mon Sep 17 00:00:00 2001 From: manuraf Date: Fri, 10 Nov 2023 15:29:32 +0100 Subject: [PATCH] code smell --- .../selfcare/onboarding/utils/PdfMapper.java | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java index c79b5be7b..d76566d58 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java @@ -16,6 +16,16 @@ public class PdfMapper { private static final String[] PLAN_LIST = {"C1", "C2", "C3", "C4", "C5", "C6", "C7"}; + public static final String INSTITUTION_REA = "institutionREA"; + public static final String INSTITUTION_NAME = "institutionName"; + public static final String INSTITUTION_SHARE_CAPITAL = "institutionShareCapital"; + public static final String INSTITUTION_BUSINESS_REGISTER_PLACE = "institutionBusinessRegisterPlace"; + public static final String PRICING_PLAN_PREMIUM = "pricingPlanPremium"; + public static final String PRICING_PLAN_PREMIUM_CHECKBOX = "pricingPlanPremiumCheckbox"; + public static final String PRICING_PLAN_FAST_CHECKBOX = "pricingPlanFastCheckbox"; + public static final String PRICING_PLAN_BASE_CHECKBOX = "pricingPlanBaseCheckbox"; + public static final String PRICING_PLAN = "pricingPlan"; + public static final String INSTITUTION_REGISTER_LABEL_VALUE = "institutionRegisterLabelValue"; public static Map setUpCommonData(UserResource validManager, List users, Institution institution, Billing billing, List geographicTaxonomies) { @@ -24,7 +34,7 @@ public static Map setUpCommonData(UserResource validManager, Lis //} Map map = new HashMap<>(); - map.put("institutionName", institution.getDescription()); + map.put(INSTITUTION_NAME, institution.getDescription()); map.put("address", institution.getAddress()); map.put("institutionTaxCode", institution.getTaxCode()); map.put("zipCode", institution.getZipCode()); @@ -90,9 +100,9 @@ public static void setupProdIOData(Onboarding onboarding, Map ma map.put("GPSmanagerSurname", InstitutionType.GSP == institutionType ? validManager.getFamilyName() : underscore); map.put("GPSmanagerTaxCode", InstitutionType.GSP == institutionType ? validManager.getFiscalCode() : underscore); - map.put("institutionREA", Optional.ofNullable(institution.getRea()).orElse(underscore)); - map.put("institutionShareCapital", Optional.ofNullable(institution.getShareCapital()).orElse(underscore)); - map.put("institutionBusinessRegisterPlace", Optional.ofNullable(institution.getBusinessRegisterPlace()).orElse(underscore)); + map.put(INSTITUTION_REA, Optional.ofNullable(institution.getRea()).orElse(underscore)); + map.put(INSTITUTION_SHARE_CAPITAL, Optional.ofNullable(institution.getShareCapital()).orElse(underscore)); + map.put(INSTITUTION_BUSINESS_REGISTER_PLACE, Optional.ofNullable(institution.getBusinessRegisterPlace()).orElse(underscore)); addPricingPlan(onboarding.getPricingPlan(), map); } @@ -100,9 +110,9 @@ public static void setupProdIOData(Onboarding onboarding, Map ma public static void setupSAProdInteropData(Map map, Institution institution) { String underscore = "_______________"; - map.put("institutionREA", Optional.ofNullable(institution.getRea()).orElse(underscore)); - map.put("institutionShareCapital", Optional.ofNullable(institution.getShareCapital()).orElse(underscore)); - map.put("institutionBusinessRegisterPlace", Optional.ofNullable(institution.getBusinessRegisterPlace()).orElse(underscore)); + map.put(INSTITUTION_REA, Optional.ofNullable(institution.getRea()).orElse(underscore)); + map.put(INSTITUTION_SHARE_CAPITAL, Optional.ofNullable(institution.getShareCapital()).orElse(underscore)); + map.put(INSTITUTION_BUSINESS_REGISTER_PLACE, Optional.ofNullable(institution.getBusinessRegisterPlace()).orElse(underscore)); //override originId to not fill ipa code in case of SA if(InstitutionType.SA.equals(institution.getInstitutionType())) map.put("originId", underscore); @@ -119,19 +129,19 @@ public static void setupProdPNData(Map map, Institution institut private static void addPricingPlan(String pricingPlan, Map map) { if (Objects.nonNull(pricingPlan) && Arrays.stream(PLAN_LIST).anyMatch(s -> s.equalsIgnoreCase(pricingPlan))) { - map.put("pricingPlanPremium", pricingPlan.replace("C", "")); - map.put("pricingPlanPremiumCheckbox", "X"); + map.put(PRICING_PLAN_PREMIUM, pricingPlan.replace("C", "")); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, "X"); } else { - map.put("pricingPlanPremium", ""); - map.put("pricingPlanPremiumCheckbox", ""); + map.put(PRICING_PLAN_PREMIUM, ""); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, ""); } map.put("pricingPlanPremiumBase", Optional.ofNullable(pricingPlan).orElse("")); if (Objects.nonNull(pricingPlan) && "C0".equalsIgnoreCase(pricingPlan)) { - map.put("pricingPlanPremiumBaseCheckbox", "X"); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, "X"); } else { - map.put("pricingPlanPremiumBaseCheckbox", ""); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, ""); } } @@ -139,30 +149,30 @@ private static void addInstitutionRegisterLabelValue(Institution institution, Ma if (institution.getPaymentServiceProvider() != null && Objects.nonNull(institution.getPaymentServiceProvider().getBusinessRegisterNumber())) { map.put("number", institution.getPaymentServiceProvider().getBusinessRegisterNumber()); - map.put("institutionRegisterLabelValue", "
  • codice di iscrizione all’Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) ${number}
  • \n"); + map.put(INSTITUTION_REGISTER_LABEL_VALUE, "
  • codice di iscrizione all’Indice delle Pubbliche Amministrazioni e dei gestori di pubblici servizi (I.P.A.) ${number}
  • \n"); } else { - map.put("institutionRegisterLabelValue", ""); + map.put(INSTITUTION_REGISTER_LABEL_VALUE, ""); } } private static void decodePricingPlan(String pricingPlan, String productId, Map map) { if (PricingPlan.FA.name().equals(pricingPlan)) { - map.put("pricingPlanFastCheckbox", "X"); - map.put("pricingPlanBaseCheckbox", ""); - map.put("pricingPlanPremiumCheckbox", ""); - map.put("pricingPlan", PricingPlan.FA.getValue()); + map.put(PRICING_PLAN_FAST_CHECKBOX, "X"); + map.put(PRICING_PLAN_BASE_CHECKBOX, ""); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, ""); + map.put(PRICING_PLAN, PricingPlan.FA.getValue()); return; } if (PROD_IO.getValue().equalsIgnoreCase(productId)) { - map.put("pricingPlanFastCheckbox", ""); - map.put("pricingPlanBaseCheckbox", "X"); - map.put("pricingPlanPremiumCheckbox", ""); - map.put("pricingPlan", PricingPlan.BASE.getValue()); + map.put(PRICING_PLAN_FAST_CHECKBOX, ""); + map.put(PRICING_PLAN_BASE_CHECKBOX, "X"); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, ""); + map.put(PRICING_PLAN, PricingPlan.BASE.getValue()); } else { - map.put("pricingPlanFastCheckbox", ""); - map.put("pricingPlanBaseCheckbox", ""); - map.put("pricingPlanPremiumCheckbox", "X"); - map.put("pricingPlan", PricingPlan.PREMIUM.getValue()); + map.put(PRICING_PLAN_FAST_CHECKBOX, ""); + map.put(PRICING_PLAN_BASE_CHECKBOX, ""); + map.put(PRICING_PLAN_PREMIUM_CHECKBOX, "X"); + map.put(PRICING_PLAN, PricingPlan.PREMIUM.getValue()); } }