jeudi 26 avril 2018

Create and fill very large autogenerated with cxf class

I have very large object generated with org.apache.cxf

This class look like this:

public class AcceptorBatchTransfer {

    @XmlElement(name = "Hdr", required = true)
    protected Header3 hdr;
    @XmlElement(name = "DataSet", required = true)
    protected List<CardPaymentDataSet1> dataSet;
    @XmlElement(name = "SctyTrlr", required = true)
    protected ContentInformationType1 sctyTrlr;

    getters and setters and not constructor

Header3 class look like this:

public class Header3 {

    @XmlElement(name = "DwnldTrf")
    protected boolean dwnldTrf;
    @XmlElement(name = "FrmtVrsn", required = true)
    protected String frmtVrsn;
    @XmlElement(name = "XchgId", required = true)
    protected String xchgId;
    @XmlElement(name = "CreDtTm", required = true)
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar creDtTm;
    @XmlElement(name = "InitgPty", required = true)
    protected GenericIdentification32 initgPty;
    @XmlElement(name = "RcptPty")
    protected GenericIdentification32 rcptPty;

    getters and setters and not constructor

And all nested classes look simular. I need create and fill this AcceptorBatchTransfer and I need write very very very much code((((((

It look like this

final AcceptorBatchTransferV01 acceptBTransfer = new AcceptorBatchTransferV01();
      request.setAccptrBtchTrf(acceptBTransfer);

      Header3 header = createHeader(paymentRequest.getInitgPty());
      acceptBTransfer.setHdr(header);

      final List<CardPaymentDataSet1> dataSets = acceptBTransfer.getDataSet();
      CardPaymentDataSet1 dataSet = createDataSet(paymentRequest);
      dataSets.add(dataSet);
...
private Header3 createHeader(String senderId) {
    final Header3 header = new Header3();
    header.setDwnldTrf(DWNLD_TRF);
    header.setFrmtVrsn(FRMT_VRSN);
    header.setXchgId(XCHG_ID);
    final XMLGregorianCalendar creDtTm = XMLGregorianCalendarConverter.asXMLGregorianCalendar(new Date());
    header.setCreDtTm(creDtTm);
    final GenericIdentification32 sender = new GenericIdentification32();
    sender.setId(senderId);//MEGAR
    header.setInitgPty(sender);
    return header;
  }

and 277 rows code for fill one object! I want simplify this process bu I do know how.

This classes was generatet with cxf and do not have constructors. Mabbe there are suitable design pattern? I can not create Builder because classes is autogenerated. Maybe I can create some wrapper....or somthing else?

Aucun commentaire:

Enregistrer un commentaire