Search in sources :

Example 1 with PModePayloadService

use of com.helger.phase4.model.pmode.PModePayloadService in project phase4 by phax.

the class PeppolCompatibilityValidator method validatePMode.

@Override
public void validatePMode(@Nonnull final IPMode aPMode, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.isTrue(aErrorList.isEmpty(), () -> "Errors in global PMode validation: " + aErrorList.toString());
    try {
        MetaAS4Manager.getPModeMgr().validatePMode(aPMode);
    } catch (final PModeValidationException ex) {
        aErrorList.add(_createError(ex.getMessage()));
    }
    final EMEP eMEP = aPMode.getMEP();
    final EMEPBinding eMEPBinding = aPMode.getMEPBinding();
    if (eMEP == EMEP.ONE_WAY && eMEPBinding == EMEPBinding.PUSH) {
    // Valid
    } else {
        aErrorList.add(_createError("An invalid combination of PMode MEP (" + eMEP + ") and MEP binding (" + eMEPBinding + ") was specified, only one-way/push is valid."));
    }
    // Leg1 must be present
    final PModeLeg aPModeLeg1 = aPMode.getLeg1();
    if (aPModeLeg1 == null) {
        aErrorList.add(_createError("PMode.Leg[1] is missing"));
    } else {
        _checkIfLegIsValid(aErrorList, aPModeLeg1, "PMode.Leg[1].");
    }
    if (aPMode.getLeg2() != null) {
        aErrorList.add(_createError("PMode.Leg[2] must not be present"));
    }
    // Compression application/gzip ONLY
    // other possible states are absent or "" (No input)
    final PModePayloadService aPayloadService = aPMode.getPayloadService();
    if (aPayloadService != null) {
        final EAS4CompressionMode eCompressionMode = aPayloadService.getCompressionMode();
        if (eCompressionMode != null) {
            if (!eCompressionMode.equals(EAS4CompressionMode.GZIP))
                aErrorList.add(_createError("PMode.PayloadService.CompressionMode must be " + EAS4CompressionMode.GZIP + " instead of " + eCompressionMode));
        }
    }
}
Also used : PModeValidationException(com.helger.phase4.model.pmode.PModeValidationException) EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) PModePayloadService(com.helger.phase4.model.pmode.PModePayloadService)

Example 2 with PModePayloadService

use of com.helger.phase4.model.pmode.PModePayloadService in project phase4 by phax.

the class PeppolPMode method createPeppolPMode.

/**
 * One-Way Version of the PEPPOL pmode uses one-way push
 *
 * @param sInitiatorID
 *        Initiator ID. May neither be <code>null</code> nor empty.
 * @param sResponderID
 *        Responder ID. May neither be <code>null</code> nor empty.
 * @param sAddress
 *        Endpoint address URL. May be <code>null</code>.
 * @param aPModeIDProvider
 *        PMode ID provider. May not be <code>null</code>.
 * @param bPersist
 *        <code>true</code> to persist the PMode in the PModeManager,
 *        <code>false</code> to have it only in memory.
 * @return New PMode and never <code>null</code>.
 */
@Nonnull
public static PMode createPeppolPMode(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
    final PModeParty aInitiator = createParty(sInitiatorID, CAS4.DEFAULT_INITIATOR_URL);
    final PModeParty aResponder = createParty(sResponderID, CAS4.DEFAULT_RESPONDER_URL);
    final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.ONE_WAY, EMEPBinding.PUSH, generatePModeLeg(sAddress), (PModeLeg) null, (PModePayloadService) null, generatePModeReceptionAwareness());
    if (bPersist) {
        // Ensure it is stored
        MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
    }
    return aPMode;
}
Also used : PModeParty(com.helger.phase4.model.pmode.PModeParty) PMode(com.helger.phase4.model.pmode.PMode) Nonnull(javax.annotation.Nonnull)

Example 3 with PModePayloadService

use of com.helger.phase4.model.pmode.PModePayloadService in project phase4 by phax.

the class CEFCompatibilityValidator method validatePMode.

@Override
public void validatePMode(@Nonnull final IPMode aPMode, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.isTrue(aErrorList.isEmpty(), () -> "Errors in global PMode validation: " + aErrorList.toString());
    try {
        MetaAS4Manager.getPModeMgr().validatePMode(aPMode);
    } catch (final PModeValidationException ex) {
        aErrorList.add(_createError(ex.getMessage()));
    }
    final EMEP eMEP = aPMode.getMEP();
    final EMEPBinding eMEPBinding = aPMode.getMEPBinding();
    if ((eMEP == EMEP.ONE_WAY && eMEPBinding == EMEPBinding.PUSH) || (eMEP == EMEP.TWO_WAY && eMEPBinding == EMEPBinding.PUSH_PUSH)) {
    // Valid
    } else {
        aErrorList.add(_createError("An invalid combination of PMode MEP (" + eMEP + ") and MEP binding (" + eMEPBinding + ") was specified, valid are only one-way/push and two-way/push-push."));
    }
    // Leg1 must be present
    final PModeLeg aPModeLeg1 = aPMode.getLeg1();
    if (aPModeLeg1 == null) {
        aErrorList.add(_createError("PMode.Leg[1] is missing"));
    } else {
        _checkIfLegIsValid(aErrorList, aPModeLeg1, "PMode.Leg[1].");
    }
    if (eMEP.isTwoWay()) {
        final PModeLeg aPModeLeg2 = aPMode.getLeg2();
        if (aPModeLeg2 == null) {
            aErrorList.add(_createError("PMode.Leg[2] is missing as it specified as TWO-WAY"));
        } else {
            _checkIfLegIsValid(aErrorList, aPModeLeg2, "PMode.Leg[2].");
        }
    }
    // Compression application/gzip ONLY
    // other possible states are absent or "" (No input)
    final PModePayloadService aPayloadService = aPMode.getPayloadService();
    if (aPayloadService != null) {
        final EAS4CompressionMode eCompressionMode = aPayloadService.getCompressionMode();
        if (eCompressionMode != null) {
            if (!eCompressionMode.equals(EAS4CompressionMode.GZIP))
                aErrorList.add(_createError("PMode.PayloadService.CompressionMode must be " + EAS4CompressionMode.GZIP + " instead of " + eCompressionMode));
        }
    }
}
Also used : PModeValidationException(com.helger.phase4.model.pmode.PModeValidationException) EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) PModePayloadService(com.helger.phase4.model.pmode.PModePayloadService)

Example 4 with PModePayloadService

use of com.helger.phase4.model.pmode.PModePayloadService in project phase4 by phax.

the class CEFPMode method createCEFPModeTwoWay.

/**
 * Two-Way Version of the CEF pmode uses two-way push-push
 *
 * @param sInitiatorID
 *        Initiator ID
 * @param sResponderID
 *        Responder ID
 * @param sResponderAddress
 *        Responder URL
 * @param aPModeIDProvider
 *        PMode ID provider
 * @param bPersist
 *        <code>true</code> to persist the PMode <code>false</code> to have it
 *        only in memory.
 * @return New PMode
 */
@Nonnull
public static PMode createCEFPModeTwoWay(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sResponderAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
    final PModeParty aInitiator = PModeParty.createSimple(sInitiatorID, CAS4.DEFAULT_INITIATOR_URL);
    final PModeParty aResponder = PModeParty.createSimple(sResponderID, CAS4.DEFAULT_RESPONDER_URL);
    final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.TWO_WAY, EMEPBinding.PUSH_PUSH, generatePModeLeg(sResponderAddress), generatePModeLeg(sResponderAddress), (PModePayloadService) null, PModeReceptionAwareness.createDefault());
    if (bPersist) {
        // Ensure it is stored
        MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
    }
    return aPMode;
}
Also used : PModeParty(com.helger.phase4.model.pmode.PModeParty) PMode(com.helger.phase4.model.pmode.PMode) Nonnull(javax.annotation.Nonnull)

Example 5 with PModePayloadService

use of com.helger.phase4.model.pmode.PModePayloadService 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)

Aggregations

Nonnull (javax.annotation.Nonnull)7 EAS4CompressionMode (com.helger.phase4.attachment.EAS4CompressionMode)5 EMEP (com.helger.phase4.model.EMEP)5 EMEPBinding (com.helger.phase4.model.EMEPBinding)5 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)5 PMode (com.helger.phase4.model.pmode.PMode)3 PModeParty (com.helger.phase4.model.pmode.PModeParty)3 PModePayloadService (com.helger.phase4.model.pmode.PModePayloadService)3 PModeValidationException (com.helger.phase4.model.pmode.PModeValidationException)3 IJsonObject (com.helger.json.IJsonObject)1