I have to create an mscons export of energy values. I created a bit of code from some examples I found, but now I stuck. MSCONS needs an UNB and an UNH header. I can add the UNB header to the UNEdifactInterchange41 object, but I don't find a method to attach the UNH header.
Here's my code so far:
import org.milyn.SmooksException;
import org.milyn.edi.unedifact.d16b.D16BInterchangeFactory;
import org.milyn.edi.unedifact.d16b.MSCONS.*;
import org.milyn.smooks.edi.unedifact.model.r41.*;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.StringWriter;
import org.milyn.smooks.edi.unedifact.model.r41.types.MessageIdentifier;
import org.milyn.smooks.edi.unedifact.model.r41.types.Party;
import org.milyn.smooks.edi.unedifact.model.r41.types.SyntaxIdentifier;
public class EDI {
public static void main(String[] args) throws IOException, SAXException, SmooksException {
D16BInterchangeFactory factory = D16BInterchangeFactory.getInstance();
UNEdifactInterchange41 edi = new UNEdifactInterchange41();
Mscons mscons = new Mscons();
/*UNB*/
UNB41 unb = new UNB41();
unb.setSender(null);
Party sender = new Party();
sender.setInternalId(getSenderInternalId());
sender.setCodeQualifier(getSenderCodeQualifier());
sender.setId(getSenderId());
SyntaxIdentifier si=new SyntaxIdentifier();
si.setVersionNum("3");
si.setId("UNOC");
unb.setSyntaxIdentifier(si);
unb.setSender(sender);
edi.setInterchangeHeader(unb);
/*UNH*/
UNH41 unh = new UNH41();
MessageIdentifier mi=new MessageIdentifier();
mi.setTypeSubFunctionId("MSCONS");
mi.setControllingAgencyCode("UN");
mi.setAssociationAssignedCode("2.2h");
String refno=createRefNo();
unh.setMessageIdentifier(mi);
/* How to attach UNH? */
}
}
Sounds like you got it almost right, you need to attach the UNH to message and not the opposite:
mi.setMessageIdentifier(unh);
You have an example there if you need: https://github.com/ClaudePlos/VOrders/blob/master/src/main/java/pl/vo/integration/edifact/EdifactExportPricat.java