Search in sources :

Example 16 with JsonArray

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;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IJsonArray(com.helger.json.IJsonArray) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)16 JsonArray (com.helger.json.JsonArray)16 JsonObject (com.helger.json.JsonObject)16 IJsonArray (com.helger.json.IJsonArray)13 Nonnull (javax.annotation.Nonnull)11 Map (java.util.Map)5 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 Nonempty (com.helger.commons.annotation.Nonempty)2 IError (com.helger.commons.error.IError)2 JsonWriterSettings (com.helger.json.serialize.JsonWriterSettings)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 MicroDocument (com.helger.xml.microdom.MicroDocument)2 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)2 ZonedDateTime (java.time.ZonedDateTime)2 Query (org.apache.lucene.search.Query)2