Skip to content

Commit

Permalink
[NOD-781] feat: aligned some classes wrongly merged
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Mar 26, 2024
1 parent 0bd3f2f commit c93be74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import it.gov.digitpa.schemas._2011.pagamenti.CtRichiestaPagamentoTelematico;
import it.gov.pagopa.wispconverter.entity.Primitive;
import it.gov.pagopa.wispconverter.entity.RPTRequestEntity;
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.exception.conversion.ConversionException;
import it.gov.pagopa.wispconverter.model.client.gpd.MultiplePaymentPosition;
import it.gov.pagopa.wispconverter.model.client.gpd.PaymentPosition;
Expand Down Expand Up @@ -138,7 +139,7 @@ private RPTRequest extractRPTRequest(RPTRequestEntity rptRequestEntity) throws C
default ->
throw new ConversionException(String.format("Unable to unmarshall RPT header or body. No valid parsing process was defined for the primitive [%s].", primitive));
}
} catch (IOException e) {
} catch (IOException | AppException e) {
throw new ConversionException("Unable to unmarshall Envelope content. ", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
import it.gov.pagopa.wispconverter.exception.conversion.ConversionException;
import it.gov.pagopa.wispconverter.model.client.iuvgenerator.IUVGeneratorRequest;
import it.gov.pagopa.wispconverter.model.client.iuvgenerator.IUVGeneratorResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class NAVGeneratorService {

private final IUVGeneratorClient iuvGeneratorClient;

@Value("${wisp-converter.aux-digit}")
private String auxDigit;
private final String auxDigit;

@Value("${wisp-converter.segregation-code}")
private String segregationCode;
private final String segregationCode;

public NAVGeneratorService(@Autowired IUVGeneratorClient iuvGeneratorClient,
@Value("${wisp-converter.aux-digit}") String auxDigit,
@Value("${wisp-converter.segregation-code}") String segregationCode) {
this.iuvGeneratorClient = iuvGeneratorClient;
this.auxDigit = auxDigit;
this.segregationCode = segregationCode;
}

public String getNAVCodeFromIUVGenerator(String creditorInstitutionCode) throws ConversionException {
// generating request body
Expand Down

This file was deleted.

31 changes: 13 additions & 18 deletions src/main/java/it/gov/pagopa/wispconverter/util/JaxbElementUtil.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package it.gov.pagopa.wispconverter.util;

;
import it.gov.pagopa.wispconverter.entity.Primitive;
import it.gov.pagopa.wispconverter.exception.AppError;
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.exception.conversion.ConversionException;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
Expand All @@ -21,13 +18,11 @@
import org.xmlsoap.schemas.soap.envelope.Envelope;
import org.xmlsoap.schemas.soap.envelope.Header;

import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.util.Arrays;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;

@Slf4j
Expand All @@ -42,7 +37,7 @@ public class JaxbElementUtil {
private static final String RPT_NAMESPACE_URI = "http://www.digitpa.gov.it/schemas/2011/Pagamenti/";
private static final String RPT_LOCAL_NAME = "RPT";

private final DocumentBuilderFactory documentBuilderFactory;
private final DocumentBuilderFactory documentBuilderFactory;

private Element convertToElement(InputSource is, String nameSpaceUri, String localName) {
try {
Expand All @@ -52,8 +47,7 @@ private Element convertToElement(InputSource is, String nameSpaceUri, String loc
if (nodeList.getLength() == 0) {
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, "NodeList is empty");
}
Element element = (Element) nodeList.item(0);
return element;
return (Element) nodeList.item(0);
} catch (ParserConfigurationException | IOException | SAXException e) {
log.error("Errore durante il parsing", e);
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, e, e.getMessage());
Expand All @@ -73,36 +67,37 @@ public <T> T convertToBean(Element element, Class<T> targetType) {
}


public Element convertToEnvelopeElement(byte[] source){
public Element convertToEnvelopeElement(byte[] source) {
return convertToElement(new InputSource(new ByteArrayInputStream(source)), ENVELOPE_NAMESPACE_URI, ENVELOPE_LOCAL_NAME);
}
public Element convertToRPTElement(byte[] source){

public Element convertToRPTElement(byte[] source) {
return convertToElement(new InputSource(new ByteArrayInputStream(source)), RPT_NAMESPACE_URI, RPT_LOCAL_NAME);
}


public <T> T getSoapHeader(Envelope envelope, Class<T> targetType){
public <T> T getSoapHeader(Envelope envelope, Class<T> targetType) {
Header header = envelope.getHeader();
if(header == null){
if (header == null) {
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, "header is null");
}

List<Object> list = header.getAny();
if(list == null || list.isEmpty()){
if (list == null || list.isEmpty()) {
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, "headerValue is null or is empty");
}
Element element = (Element) list.get(0);
return convertToBean(element, targetType);
}

public <T> T getSoapBody(Envelope envelope, Class<T> targetType){
public <T> T getSoapBody(Envelope envelope, Class<T> targetType) {
Body body = envelope.getBody();
if(body == null){
if (body == null) {
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, "body is null");
}

List<Object> list = body.getAny();
if(list == null || list.isEmpty()){
if (list == null || list.isEmpty()) {
throw new AppException(AppError.PAYLOAD_CONVERSION_ERROR, "bodyValue is null or is empty");
}
Element element = (Element) list.get(0);
Expand Down

0 comments on commit c93be74

Please sign in to comment.