Search in sources :

Example 26 with IJsonObject

use of com.helger.json.IJsonObject in project phase4 by phax.

the class PModeJsonConverter method convertToNative.

@Nonnull
public static PMode convertToNative(@Nonnull final IJsonObject aElement) {
    final IJsonObject aInit = aElement.getAsObject(ELEMENT_INITIATOR);
    final PModeParty aInitiator = aInit == null ? null : PModePartyJsonConverter.convertToNative(aInit);
    final IJsonObject aResp = aElement.getAsObject(ELEMENT_RESPONDER);
    final PModeParty aResponder = aResp == null ? null : PModePartyJsonConverter.convertToNative(aResp);
    final String sAgreement = aElement.getAsString(ATTR_AGREEMENT);
    final String sMEP = aElement.getAsString(ATTR_MEP);
    final EMEP eMEP = EMEP.getFromIDOrNull(sMEP);
    if (eMEP == null)
        throw new IllegalStateException("Failed to resolve MEP '" + sMEP + "'");
    final String sMEPBinding = aElement.getAsString(ATTR_MEP_BINDING);
    final EMEPBinding eMEPBinding = EMEPBinding.getFromIDOrNull(sMEPBinding);
    if (eMEPBinding == null)
        throw new IllegalStateException("Failed to resolve MEPBinding '" + sMEPBinding + "'");
    final IJsonObject aL1 = aElement.getAsObject(ELEMENT_LEG1);
    final PModeLeg aLeg1 = aL1 == null ? null : PModeLegJsonConverter.convertToNative(aL1);
    final IJsonObject aL2 = aElement.getAsObject(ELEMENT_LEG2);
    final PModeLeg aLeg2 = aL2 == null ? null : PModeLegJsonConverter.convertToNative(aL2);
    final IJsonObject aPS = aElement.getAsObject(ELEMENT_PAYLOADSERVICE);
    final PModePayloadService aPayloadService = aPS == null ? null : PModePayloadServiceJsonConverter.convertToNative(aPS);
    final IJsonObject aRA = aElement.getAsObject(ELEMENT_RECEPETIONAWARENESS);
    final PModeReceptionAwareness aReceptionAwareness = aRA == null ? null : PModeReceptionAwarenessJsonConverter.convertToNative(aRA);
    return new PMode(getStubObject(aElement), aInitiator, aResponder, sAgreement, eMEP, eMEPBinding, aLeg1, aLeg2, aPayloadService, aReceptionAwareness);
}
Also used : EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IJsonObject(com.helger.json.IJsonObject) Nonnull(javax.annotation.Nonnull)

Example 27 with IJsonObject

use of com.helger.json.IJsonObject in project phase4 by phax.

the class PModeJsonConverter method setObjectFields.

public static void setObjectFields(@Nonnull final IBusinessObject aValue, @Nonnull final IJsonObject aElement) {
    aElement.add(ATTR_ID, aValue.getID());
    if (aValue.hasCreationDateTime())
        aElement.add(ATTR_CREATIONLDT, PDTWebDateHelper.getAsStringXSD(aValue.getCreationDateTime()));
    if (aValue.hasCreationUserID())
        aElement.add(ATTR_CREATIONUSERID, aValue.getCreationUserID());
    if (aValue.hasLastModificationDateTime())
        aElement.add(ATTR_LASTMODLDT, PDTWebDateHelper.getAsStringXSD(aValue.getLastModificationDateTime()));
    if (aValue.hasLastModificationUserID())
        aElement.add(ATTR_LASTMODUSERID, aValue.getLastModificationUserID());
    if (aValue.hasDeletionDateTime())
        aElement.add(ATTR_DELETIONLDT, PDTWebDateHelper.getAsStringXSD(aValue.getDeletionDateTime()));
    if (aValue.hasDeletionUserID())
        aElement.add(ATTR_DELETIONUSERID, aValue.getDeletionUserID());
    if (aValue.attrs().isNotEmpty()) {
        final IJsonArray aCustomArray = new JsonArray();
        for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(aValue.attrs()).entrySet()) {
            final IJsonObject eCustom = new JsonObject();
            eCustom.add(ATTR_ID, aEntry.getKey());
            if (aEntry.getValue() != null)
                eCustom.add(VALUE, aEntry.getValue());
            aCustomArray.add(eCustom);
        }
        aElement.addJson(ELEMENT_CUSTOM, aCustomArray);
    }
}
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) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) Map(java.util.Map) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap)

Example 28 with IJsonObject

use of com.helger.json.IJsonObject in project phase4 by phax.

the class PModeJsonConverter method getStubObject.

@Nonnull
public static StubObject getStubObject(@Nonnull final IJsonObject aElement) {
    // ID
    final String sID = aElement.getAsString(ATTR_ID);
    // Creation
    final LocalDateTime aCreationLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_CREATIONLDT));
    final String sCreationUserID = aElement.getAsString(ATTR_CREATIONUSERID);
    // Last modification
    final LocalDateTime aLastModificationLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_LASTMODLDT));
    final String sLastModificationUserID = aElement.getAsString(ATTR_LASTMODUSERID);
    // Deletion
    final LocalDateTime aDeletionLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_DELETIONLDT));
    final String sDeletionUserID = aElement.getAsString(ATTR_DELETIONUSERID);
    final ICommonsOrderedMap<String, String> aCustomAttrs = new CommonsLinkedHashMap<>();
    final IJsonArray aCustom = aElement.getAsArray(ELEMENT_CUSTOM);
    if (aCustom != null)
        for (final IJsonObject eCustom : aCustom.iteratorObjects()) aCustomAttrs.put(eCustom.getAsString(ATTR_ID), eCustom.getAsString(VALUE));
    return new StubObject(sID, aCreationLDT, sCreationUserID, aLastModificationLDT, sLastModificationUserID, aDeletionLDT, sDeletionUserID, aCustomAttrs);
}
Also used : LocalDateTime(java.time.LocalDateTime) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) IJsonObject(com.helger.json.IJsonObject) IJsonArray(com.helger.json.IJsonArray) StubObject(com.helger.photon.security.object.StubObject) Nonnull(javax.annotation.Nonnull)

Example 29 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDBusinessCard method getAsJson.

@Nonnull
public IJsonObject getAsJson() {
    final IJsonObject ret = new JsonObject();
    ret.addJson("participant", m_aParticipantIdentifier.getAsJson());
    ret.addJson("entity", new JsonArray().addAllMapped(m_aBusinessEntities, PDBusinessEntity::getAsJson));
    return ret;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 30 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDContact method getAsJson.

@Nonnull
public IJsonObject getAsJson() {
    final IJsonObject ret = new JsonObject();
    ret.add("type", m_sType);
    ret.add("name", m_sName);
    ret.add("phonenumber", m_sPhoneNumber);
    ret.add("email", m_sEmail);
    return ret;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)67 JsonObject (com.helger.json.JsonObject)38 Nonnull (javax.annotation.Nonnull)34 IJsonArray (com.helger.json.IJsonArray)16 JsonArray (com.helger.json.JsonArray)16 Test (org.junit.Test)15 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)6 StopWatch (com.helger.commons.timing.StopWatch)5 IJson (com.helger.json.IJson)5 JsonWriter (com.helger.json.serialize.JsonWriter)5 Map (java.util.Map)5 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)4 ZonedDateTime (java.time.ZonedDateTime)4 Nullable (javax.annotation.Nullable)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 SimpleLocation (com.helger.commons.location.SimpleLocation)3