use of com.helger.json.IJsonObject in project phase4 by phax.
the class PModeLegProtocolJsonConverter method convertToJson.
@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModeLegProtocol aValue) {
final IJsonObject ret = new JsonObject();
if (aValue.hasAddress())
ret.add(ADDRESS, aValue.getAddress());
ret.add(SOAP_VERSION, aValue.getSoapVersion().getVersion());
return ret;
}
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);
}
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);
}
}
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);
}
use of com.helger.json.IJsonObject in project ph-commons by phax.
the class SettingsPersistenceJson method writeSettings.
@Nonnull
public ESuccess writeSettings(@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS) {
ValueEnforcer.notNull(aOS, "OutputStream");
try {
final IJsonObject aProps = new JsonObject();
for (final Map.Entry<String, Object> aEntry : CollectionHelper.getSorted(aSettings.entrySet(), Comparator.comparing(Map.Entry::getKey))) {
final String sName = aEntry.getKey();
final Object aValue = aEntry.getValue();
final String sValue = TypeConverter.convert(aValue, String.class);
aProps.add(sName, sValue);
}
final JsonWriterSettings aJWS = new JsonWriterSettings();
aJWS.setIndentEnabled(true);
aJWS.setQuoteNames(false);
// Does not close the output stream!
new JsonWriter(aJWS).writeToWriterAndClose(aProps, StreamHelper.createWriter(aOS, m_aCharset));
return ESuccess.SUCCESS;
} catch (final IOException ex) {
LOGGER.error("Failed to write settings to JSON file", ex);
return ESuccess.FAILURE;
} finally {
StreamHelper.close(aOS);
}
}
Aggregations