Skip to content

Commit

Permalink
Merge pull request #88 from pagopa/PRDP-214-change-refNumber-value
Browse files Browse the repository at this point in the history
[PRDP-214] Change RefNumber's value & type mapping
  • Loading branch information
pasqualespica authored Nov 30, 2023
2 parents cedca24 + ee58305 commit d2e916d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {

private static final Map<String, String> brandLogoMap;
private static final Map<String, Object> pspMap;
public static final String MODEL_TYPE_IUV = "1";
public static final String MODEL_TYPE_NOTICE = "2";

static {
try {
Expand Down Expand Up @@ -241,19 +243,24 @@ private String getUserTaxCode(BizEvent event) throws TemplateDataMappingExceptio

private String getRefNumberType(BizEvent event) throws TemplateDataMappingException {
if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
if (event.getDebtorPosition().getModelType().equals("1")) {
return REF_TYPE_NOTICE;
}
if (event.getDebtorPosition().getModelType().equals("2")) {
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV)) {
return REF_TYPE_IUV;
}
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE)) {
return REF_TYPE_NOTICE;
}
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_TYPE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}

private String getRefNumberValue(BizEvent event) throws TemplateDataMappingException {
if (event.getDebtorPosition() != null && event.getDebtorPosition().getIuv() != null) {
return event.getDebtorPosition().getIuv();
if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV) && event.getDebtorPosition().getIuv() != null) {
return event.getDebtorPosition().getIuv();
}
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE) && event.getDebtorPosition().getNoticeNumber() != null) {
return event.getDebtorPosition().getNoticeNumber();
}
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ class BuildTemplateServiceImplTest {
public static final String PSP_PROVINCE = "province";
public static final String BRAND_ASSET_URL = "/asset";
private static final String IUV = "02119891614290410";
private static final String NOTICE_NUMBER = "valid notice number";
private static final String BIZ_EVENT_ID = "biz-event-id";
private static final String MODEL_TYPE_NOTICE_CODE = "1";
private static final String MODEL_TYPE_IUV_CODE = "2";
private static final String MODEL_TYPE_IUV_CODE = "1";
private static final String MODEL_TYPE_NOTICE_CODE = "2";
private static final String MODEL_TYPE_NOTICE_TEXT = "codiceAvviso";
private static final String MODEL_TYPE_IUV_TEXT = "IUV";
private static final String DATE_TIME_TIMESTAMP_FORMATTED = "14 novembre 2023, 19:31:55";
Expand Down Expand Up @@ -268,7 +269,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.noticeNumber(NOTICE_NUMBER)
.modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.creditor(Creditor.builder()
Expand Down Expand Up @@ -350,7 +351,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
assertEquals(MODEL_TYPE_NOTICE_TEXT, cart.getItems().get(0).getRefNumber().getType());
assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
assertEquals(NOTICE_NUMBER, cart.getItems().get(0).getRefNumber().getValue());
}

@Test
Expand Down Expand Up @@ -1116,7 +1117,7 @@ void mapTemplateNoCartItemRefNumberTypeError() {
}

@Test
void mapTemplateNoCartItemRefNumberValueError() {
void mapTemplateNoCartItemRefNumberValueIUVError() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
Expand All @@ -1142,6 +1143,34 @@ void mapTemplateNoCartItemRefNumberValueError() {
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
}

@Test
void mapTemplateWrongModelTypeError() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
.paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
.idPsp(ID_PSP)
.psp(PSP_NAME)
.build())
.payer(Payer.builder()
.fullName(PAYER_FULL_NAME)
.entityUniqueIdentifierValue(PAYER_VALID_CF)
.build())
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.build();
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build()));

assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
}

@Test
void mapTemplateNoCartItemDebtorTaxCodeValueError() {
BizEvent event = BizEvent.builder()
Expand Down

0 comments on commit d2e916d

Please sign in to comment.