Skip to content

Commit

Permalink
More Json; #40
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 20, 2020
1 parent fd96fd5 commit 7f5b71e
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ private PModeLegBusinessInformationJsonConverter ()
public static IJsonObject convertToJson (@Nonnull final PModeLegBusinessInformation aValue)
{
final IJsonObject ret = new JsonObject ();
ret.add (SERVICE, aValue.getService ());
ret.add (SERVICE_TYPE, aValue.getServiceType ());
ret.add (ACTION, aValue.getAction ());
ret.addJson (PROPERTIES,
new JsonArray ().addAllMapped (aValue.properties ().values (),
PModePropertyJsonConverter::convertToJson));
ret.addJson (PAYLOAD_PROFILE,
new JsonArray ().addAllMapped (aValue.payloadProfiles ().values (),
PModePayloadProfileJsonConverter::convertToJson));
if (aValue.hasService ())
ret.add (SERVICE, aValue.getService ());
if (aValue.hasServiceType ())
ret.add (SERVICE_TYPE, aValue.getServiceType ());
if (aValue.hasAction ())
ret.add (ACTION, aValue.getAction ());
if (aValue.properties ().isNotEmpty ())
ret.addJson (PROPERTIES,
new JsonArray ().addAllMapped (aValue.properties ().values (),
PModePropertyJsonConverter::convertToJson));
if (aValue.payloadProfiles ().isNotEmpty ())
ret.addJson (PAYLOAD_PROFILE,
new JsonArray ().addAllMapped (aValue.payloadProfiles ().values (),
PModePayloadProfileJsonConverter::convertToJson));
if (aValue.hasPayloadProfileMaxKB ())
ret.add (PAYLOAD_PROFILE_MAX_KB, aValue.getPayloadProfileMaxKB ().longValue ());
ret.add (MPCID, aValue.getMPCID ());
if (aValue.hasMPCID ())
ret.add (MPCID, aValue.getMPCID ());
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,55 @@
@Immutable
public final class PModeLegErrorHandlingJsonConverter
{
private static final String ELEMENT_REPORT_SENDER_ERRORS_TO = "ReportSenderErrorsTo";
private static final String ELEMENT_REPORT_RECEIVER_ERRORS_TO = "ReportReceiverErrorsTo";
private static final String ATTR_REPORT_AS_RESPONSE = "ReportAsResponse";
private static final String ATTR_REPORT_PROCESS_ERROR_NOTFIY_CONSUMER = "ReportProcessErrorNotifyConsumer";
private static final String ATTR_REPORT_PROCESS_ERROR_NOTFIY_PRODUCER = "ReportProcessErrorNotifyProducer";
private static final String ATTR_REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER = "ReportDeliveryFailuresNotifyProducer";
private static final String REPORT_SENDER_ERRORS_TO = "ReportSenderErrorsTo";
private static final String REPORT_RECEIVER_ERRORS_TO = "ReportReceiverErrorsTo";
private static final String REPORT_AS_RESPONSE = "ReportAsResponse";
private static final String REPORT_PROCESS_ERROR_NOTFIY_CONSUMER = "ReportProcessErrorNotifyConsumer";
private static final String REPORT_PROCESS_ERROR_NOTFIY_PRODUCER = "ReportProcessErrorNotifyProducer";
private static final String REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER = "ReportDeliveryFailuresNotifyProducer";

private PModeLegErrorHandlingJsonConverter ()
{}

@Nonnull
public final IJsonObject convertToJson (@Nonnull final PModeLegErrorHandling aValue)
public static IJsonObject convertToJson (@Nonnull final PModeLegErrorHandling aValue)
{
final IJsonObject ret = new JsonObject ();
if (aValue.hasReportSenderErrorsTo ())
ret.addJson (ELEMENT_REPORT_SENDER_ERRORS_TO,
ret.addJson (REPORT_SENDER_ERRORS_TO,
PModeAddressListJsonConverter.convertToJson (aValue.getReportSenderErrorsTo ()));
if (aValue.hasReportReceiverErrorsTo ())
ret.addJson (ELEMENT_REPORT_RECEIVER_ERRORS_TO,
ret.addJson (REPORT_RECEIVER_ERRORS_TO,
PModeAddressListJsonConverter.convertToJson (aValue.getReportReceiverErrorsTo ()));
if (aValue.isReportAsResponseDefined ())
ret.add (ATTR_REPORT_AS_RESPONSE, aValue.isReportAsResponse ());
ret.add (REPORT_AS_RESPONSE, aValue.isReportAsResponse ());
if (aValue.isReportProcessErrorNotifyConsumerDefined ())
ret.add (ATTR_REPORT_PROCESS_ERROR_NOTFIY_CONSUMER, aValue.isReportProcessErrorNotifyConsumer ());
ret.add (REPORT_PROCESS_ERROR_NOTFIY_CONSUMER, aValue.isReportProcessErrorNotifyConsumer ());
if (aValue.isReportProcessErrorNotifyProducerDefined ())
ret.add (ATTR_REPORT_PROCESS_ERROR_NOTFIY_PRODUCER, aValue.isReportProcessErrorNotifyProducer ());
ret.add (REPORT_PROCESS_ERROR_NOTFIY_PRODUCER, aValue.isReportProcessErrorNotifyProducer ());
if (aValue.isReportDeliveryFailuresNotifyProducerDefined ())
ret.add (ATTR_REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER, aValue.isReportDeliveryFailuresNotifyProducer ());
ret.add (REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER, aValue.isReportDeliveryFailuresNotifyProducer ());
return ret;
}

@Nonnull
public static PModeLegErrorHandling convertToNative (@Nonnull final IJsonObject aElement)
{
final IJsonArray aSender = aElement.getAsArray (ELEMENT_REPORT_SENDER_ERRORS_TO);
final IJsonArray aSender = aElement.getAsArray (REPORT_SENDER_ERRORS_TO);
final PModeAddressList aSenderAddresses = aSender == null ? null
: PModeAddressListJsonConverter.convertToNative (aSender);

final IJsonArray aReceiver = aElement.getAsArray (ELEMENT_REPORT_RECEIVER_ERRORS_TO);
final IJsonArray aReceiver = aElement.getAsArray (REPORT_RECEIVER_ERRORS_TO);
final PModeAddressList aReceiverAddresses = aReceiver == null ? null
: PModeAddressListJsonConverter.convertToNative (aReceiver);

final ETriState eReportAsResponse = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (ATTR_REPORT_AS_RESPONSE),
final ETriState eReportAsResponse = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (REPORT_AS_RESPONSE),
PModeLegSecurity.DEFAULT_PMODE_AUTHORIZE);
final ETriState eReportProcessErrorNotifyConsumer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (ATTR_REPORT_PROCESS_ERROR_NOTFIY_CONSUMER),
final ETriState eReportProcessErrorNotifyConsumer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (REPORT_PROCESS_ERROR_NOTFIY_CONSUMER),
PModeLegSecurity.DEFAULT_USERNAME_TOKEN_CREATED);
final ETriState eReportProcessErrorNotifyProducer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (ATTR_REPORT_PROCESS_ERROR_NOTFIY_PRODUCER),
final ETriState eReportProcessErrorNotifyProducer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (REPORT_PROCESS_ERROR_NOTFIY_PRODUCER),
PModeLegSecurity.DEFAULT_USERNAME_TOKEN_DIGEST);
final ETriState eReportDeliveryFailuresNotifyProducer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (ATTR_REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER),
final ETriState eReportDeliveryFailuresNotifyProducer = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (REPORT_DELIVERY_FAILURE_NOTFIY_PRODUCER),
PModeLegSecurity.DEFAULT_SEND_RECEIPT);
return new PModeLegErrorHandling (aSenderAddresses,
aReceiverAddresses,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (C) 2015-2020 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.phase4.model.pmode.leg;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

import com.helger.json.IJsonObject;
import com.helger.json.JsonObject;

/**
* JSON converter for {@link PModeLeg}.
*
* @author Philip Helger
* @since 0.12.0
*/
@Immutable
public final class PModeLegJsonConverter
{
private static final String ELEMENT_PROTOCOL = "Protocol";
private static final String ELEMENT_BUSINESS_INFORMATION = "BusinessInfo";
private static final String ELEMENT_ERROR_HANDLING = "ErrorHandling";
private static final String ELEMENT_RELIABILITY = "Reliability";
private static final String ELEMENT_SECURITY = "Security";

private PModeLegJsonConverter ()
{}

@Nonnull
public static IJsonObject convertToJson (@Nonnull final PModeLeg aValue)
{
final IJsonObject ret = new JsonObject ();
if (aValue.hasProtocol ())
ret.addJson (ELEMENT_PROTOCOL, PModeLegProtocolJsonConverter.convertToJson (aValue.getProtocol ()));
if (aValue.hasBusinessInfo ())
ret.addJson (ELEMENT_BUSINESS_INFORMATION,
PModeLegBusinessInformationJsonConverter.convertToJson (aValue.getBusinessInfo ()));
if (aValue.hasErrorHandling ())
ret.addJson (ELEMENT_ERROR_HANDLING,
PModeLegErrorHandlingJsonConverter.convertToJson (aValue.getErrorHandling ()));
if (aValue.hasReliability ())
ret.addJson (ELEMENT_RELIABILITY, PModeLegReliabilityJsonConverter.convertToJson (aValue.getReliability ()));
if (aValue.hasSecurity ())
ret.addJson (ELEMENT_SECURITY, PModeLegSecurityJsonConverter.convertToJson (aValue.getSecurity ()));
return ret;
}

@Nonnull
public static PModeLeg convertToNative (@Nonnull final IJsonObject aElement)
{
final IJsonObject aProt = aElement.getAsObject (ELEMENT_PROTOCOL);
final PModeLegProtocol aProtocol = aProt == null ? null : PModeLegProtocolJsonConverter.convertToNative (aProt);

final IJsonObject aBI = aElement.getAsObject (ELEMENT_BUSINESS_INFORMATION);
final PModeLegBusinessInformation aBusinessInformation = aBI == null ? null
: PModeLegBusinessInformationJsonConverter.convertToNative (aBI);

final IJsonObject aEH = aElement.getAsObject (ELEMENT_ERROR_HANDLING);
final PModeLegErrorHandling aErrorHandling = aEH == null ? null
: PModeLegErrorHandlingJsonConverter.convertToNative (aEH);

final IJsonObject aR = aElement.getAsObject (ELEMENT_RELIABILITY);
final PModeLegReliability aReliability = aR == null ? null : PModeLegReliabilityJsonConverter.convertToNative (aR);

final IJsonObject aS = aElement.getAsObject (ELEMENT_SECURITY);
final PModeLegSecurity aSecurity = aS == null ? null : PModeLegSecurityJsonConverter.convertToNative (aS);

return new PModeLeg (aProtocol, aBusinessInformation, aErrorHandling, aReliability, aSecurity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.helger.commons.equals.EqualsHelper;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.state.EChange;
import com.helger.commons.string.StringHelper;
import com.helger.commons.string.ToStringGenerator;
import com.helger.commons.url.URLHelper;
import com.helger.phase4.soap.ESoapVersion;
Expand Down Expand Up @@ -73,6 +74,11 @@ public final String getAddress ()
return m_sAddress;
}

public final boolean hasAddress ()
{
return StringHelper.hasText (m_sAddress);
}

@Nullable
public final String getAddressProtocol ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ private PModeLegProtocolJsonConverter ()
@Nonnull
public static IJsonObject convertToJson (@Nonnull final PModeLegProtocol aValue)
{
return new JsonObject ().add (ADDRESS, aValue.getAddress ())
.add (SOAP_VERSION, aValue.getSoapVersion ().getVersion ());
final IJsonObject ret = new JsonObject ();
if (aValue.hasAddress ())
ret.add (ADDRESS, aValue.getAddress ());
ret.add (SOAP_VERSION, aValue.getSoapVersion ().getVersion ());
return ret;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.state.EChange;
import com.helger.commons.state.ETriState;
import com.helger.commons.string.StringHelper;
import com.helger.commons.string.ToStringGenerator;

/**
Expand Down Expand Up @@ -232,6 +233,11 @@ public final String getAtLeastOnceContractAcksTo ()
return m_sAtLeastOnceContractAcksTo;
}

public final boolean hasAtLeastOnceContractAcksTo ()
{
return StringHelper.hasText (m_sAtLeastOnceContractAcksTo);
}

@Nonnull
public final EChange setAtLeastOnceContractAcksTo (@Nullable final String sAtLeastOnceContractAcksTo)
{
Expand Down Expand Up @@ -273,6 +279,11 @@ public final String getAtLeastOnceReplyPattern ()
return m_sAtLeastOnceReplyPattern;
}

public final boolean hasAtLeastOnceReplyPattern ()
{
return StringHelper.hasText (m_sAtLeastOnceReplyPattern);
}

@Nonnull
public final EChange setAtLeastOnceReplyPattern (@Nullable final String sAtLeastOnceReplyPattern)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ public static IJsonObject convertToJson (@Nonnull final PModeLegReliability aVal
ret.add (AT_LEAST_ONCE_CONTRACT, aValue.isAtLeastOnceContract ());
if (aValue.isAtLeastOnceAckOnDeliveryDefined ())
ret.add (AT_LEAST_ONCE_ACK_ON_DELIVERY, aValue.isAtLeastOnceAckOnDelivery ());
ret.add (AT_LEAST_ONCE_CONTRACT_ACK_TO, aValue.getAtLeastOnceContractAcksTo ());
if (aValue.hasAtLeastOnceContractAcksTo ())
ret.add (AT_LEAST_ONCE_CONTRACT_ACK_TO, aValue.getAtLeastOnceContractAcksTo ());
if (aValue.isAtLeastOnceContractAckResponseDefined ())
ret.add (AT_LEAST_ONCE_CONTRACT_ACK_RESPONSE, aValue.isAtLeastOnceContractAckResponse ());
ret.add (AT_LEAST_ONCE_REPLY_PATTERN, aValue.getAtLeastOnceReplyPattern ());
if (aValue.hasAtLeastOnceReplyPattern ())
ret.add (AT_LEAST_ONCE_REPLY_PATTERN, aValue.getAtLeastOnceReplyPattern ());
if (aValue.isAtMostOnceContractDefined ())
ret.add (AT_MOST_ONCE_CONTRACT, aValue.isAtMostOnceContract ());
if (aValue.isInOrderContractDefined ())
Expand Down Expand Up @@ -95,8 +97,8 @@ public static PModeLegReliability convertToNative (@Nonnull final IJsonObject aE
PModeLegReliability.DEFAULT_IN_ORDER_CONTACT);
final ETriState eStartGroup = AbstractPModeMicroTypeConverter.getTriState (aElement.getAsString (START_GROUP),
PModeLegReliability.DEFAULT_START_GROUP);
final IJsonArray aCorrelation = aElement.getAsArray (CORRELATION);
final ICommonsList <String> aCorrelationStrings = new CommonsArrayList <> ();
final IJsonArray aCorrelation = aElement.getAsArray (CORRELATION);
if (aCorrelation != null)
for (final IJsonValue aCorrelationElement : aCorrelation.iteratorValues ())
aCorrelationStrings.add (aCorrelationElement.getAsString ());
Expand Down
Loading

0 comments on commit 7f5b71e

Please sign in to comment.