use of com.helger.json.JsonArray in project peppol-commons by phax.
the class SMPJsonResponse method convert.
@Nonnull
public static IJsonObject convert(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final IDocumentTypeIdentifier aDocTypeID, @Nonnull final com.helger.xsds.peppol.smp1.ServiceMetadataType aSM) {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aDocTypeID, "DocTypeID");
ValueEnforcer.notNull(aSM, "SM");
final IJsonObject ret = new JsonObject();
ret.add(JSON_SMPTYPE, ESMPAPIType.PEPPOL.getID());
ret.add(JSON_PARTICIPANT_ID, aParticipantID.getURIEncoded());
ret.add(JSON_DOCUMENT_TYPE_ID, aDocTypeID.getURIEncoded());
final com.helger.xsds.peppol.smp1.RedirectType aRedirect = aSM.getRedirect();
if (aRedirect != null) {
final IJsonObject aJsonRedirect = new JsonObject().add(JSON_HREF, aRedirect.getHref()).add(JSON_CERTIFICATE_UID, aRedirect.getCertificateUID()).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aRedirect.getExtension()));
ret.addJson(JSON_REDIRECT, aJsonRedirect);
} else {
final com.helger.xsds.peppol.smp1.ServiceInformationType aSI = aSM.getServiceInformation();
final IJsonObject aJsonSI = new JsonObject();
{
final IJsonArray aJsonProcs = new JsonArray();
// For all processes
if (aSI.getProcessList() != null)
for (final com.helger.xsds.peppol.smp1.ProcessType aProcess : aSI.getProcessList().getProcess()) if (aProcess.getProcessIdentifier() != null) {
final IJsonObject aJsonProc = new JsonObject().add(JSON_PROCESS_ID, CIdentifier.getURIEncoded(aProcess.getProcessIdentifier()));
final IJsonArray aJsonEPs = new JsonArray();
// For all endpoints
if (aProcess.getServiceEndpointList() != null)
for (final com.helger.xsds.peppol.smp1.EndpointType aEndpoint : aProcess.getServiceEndpointList().getEndpoint()) {
aJsonEPs.add(convertEndpoint(aEndpoint));
}
aJsonProc.addJson(JSON_ENDPOINTS, aJsonEPs).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aProcess.getExtension()));
aJsonProcs.add(aJsonProc);
}
aJsonSI.addJson(JSON_PROCESSES, aJsonProcs).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aSI.getExtension()));
}
ret.addJson(JSON_SERVICEINFO, aJsonSI);
}
return ret;
}
Aggregations