Search in sources :

Example 1 with XMLOffsetDateTime

use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.

the class SMPServiceInformationManagerMongoDB method toEndpoint.

@Nonnull
@ReturnsMutableCopy
public static SMPEndpoint toEndpoint(@Nonnull final Document aDoc) {
    final String sTransportProfile = aDoc.getString(BSON_TRANSPORT_PROFILE);
    final String sEndpointReference = aDoc.getString(BSON_ENDPOINT_REFERENCE);
    final boolean bRequireBusinessLevelSignature = aDoc.getBoolean(BSON_BUSINESSLEVELSIG, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
    final String sMinimumAuthenticationLevel = aDoc.getString(BSON_MINIMUM_AUTHENTICATION_LEVEL);
    final XMLOffsetDateTime aServiceActivationDT = TypeConverter.convert(aDoc.getDate(BSON_SERVICEACTIVATION), XMLOffsetDateTime.class);
    final XMLOffsetDateTime aServiceExpirationDT = TypeConverter.convert(aDoc.getDate(BSON_SERVICEEXPIRATION), XMLOffsetDateTime.class);
    final String sCertificate = aDoc.getString(BSON_CERTIFICATE);
    final String sServiceDescription = aDoc.getString(BSON_SERVICE_DESCRIPTION);
    final String sTechnicalContactUrl = aDoc.getString(BSON_TECHCONTACTURL);
    final String sTechnicalInformationUrl = aDoc.getString(BSON_TECHINFOURL);
    final String sExtension = aDoc.getString(BSON_EXTENSIONS);
    return new SMPEndpoint(sTransportProfile, sEndpointReference, bRequireBusinessLevelSignature, sMinimumAuthenticationLevel, aServiceActivationDT, aServiceExpirationDT, sCertificate, sServiceDescription, sTechnicalContactUrl, sTechnicalInformationUrl, sExtension);
}
Also used : XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with XMLOffsetDateTime

use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.

the class SMPEndpointMicroTypeConverter method convertToNative.

@Nonnull
@ContainsSoftMigration
public SMPEndpoint convertToNative(@Nonnull final IMicroElement aElement) {
    final String sTransportProfile = aElement.getAttributeValue(ATTR_TRANSPORT_PROFILE);
    final String sEndpointReference = aElement.getAttributeValue(ATTR_ENDPOINT_REFERENCE);
    final String sRequireBusinessLevelSignature = aElement.getAttributeValue(ATTR_REQUIRE_BUSINESS_LEVEL_SIGNATURE);
    final boolean bRequireBusinessLevelSignature = StringParser.parseBool(sRequireBusinessLevelSignature, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
    final String sMinimumAuthenticationLevel = aElement.getAttributeValue(ATTR_MINIMUM_AUTHENTICATION_LEVEL);
    XMLOffsetDateTime aServiceActivationDate = aElement.getAttributeValueWithConversion(ATTR_SERVICE_ACTIVATION_DATE, XMLOffsetDateTime.class);
    if (aServiceActivationDate == null) {
        final LocalDateTime aServiceActivationDateLDT = aElement.getAttributeValueWithConversion(ATTR_SERVICE_ACTIVATION_DATE, LocalDateTime.class);
        if (aServiceActivationDateLDT != null)
            aServiceActivationDate = XMLOffsetDateTime.of(aServiceActivationDateLDT, null);
    }
    XMLOffsetDateTime aServiceExpirationDate = aElement.getAttributeValueWithConversion(ATTR_SERVICE_EXPIRATION_DATE, XMLOffsetDateTime.class);
    if (aServiceExpirationDate == null) {
        final LocalDateTime aServiceExpirationDateLDT = aElement.getAttributeValueWithConversion(ATTR_SERVICE_EXPIRATION_DATE, LocalDateTime.class);
        if (aServiceExpirationDateLDT != null)
            aServiceExpirationDate = XMLOffsetDateTime.of(aServiceExpirationDateLDT, null);
    }
    final String sCertificate = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_CERTIFICATE);
    final String sServiceDescription = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_SERVICE_DESCRIPTION);
    final String sTechnicalContactUrl = aElement.getAttributeValue(ATTR_TECHNICAL_CONTACT_URL);
    final String sTechnicalInformationUrl = aElement.getAttributeValue(ATTR_TECHNICAL_INFORMATION_URL);
    final String sExtension = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_EXTENSION);
    return new SMPEndpoint(sTransportProfile, sEndpointReference, bRequireBusinessLevelSignature, sMinimumAuthenticationLevel, aServiceActivationDate, aServiceExpirationDate, sCertificate, sServiceDescription, sTechnicalContactUrl, sTechnicalInformationUrl, sExtension);
}
Also used : LocalDateTime(java.time.LocalDateTime) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) Nonnull(javax.annotation.Nonnull) ContainsSoftMigration(com.helger.commons.annotation.ContainsSoftMigration)

Example 3 with XMLOffsetDateTime

use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.

the class ISMPServiceInformationManagerFuncTest method testAll.

@Test
public void testAll() throws SMPServerException {
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
    final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("junit::testdoc#ext:1.0");
    final IProcessIdentifier aProcessID = PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("junit-proc");
    final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
    if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
        // Failed to get DB connection. E.g. MySQL down or misconfigured.
        return;
    }
    aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
    final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
    assertNotNull(aSG);
    try {
        final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
        final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
        final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
        final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc/>");
        final SMPServiceInformation aServiceInformation = new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi/>");
        assertTrue(aServiceInfoMgr.mergeSMPServiceInformation(aServiceInformation).isSuccess());
    } finally {
        // Don't care about the result
        aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 4 with XMLOffsetDateTime

use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.

the class SMPServiceInformationTest method testBasic.

@Test
public void testBasic() {
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:dummy");
    final ISMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
    final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
    final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
    final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep/>");
    assertEquals("tp", aEP.getTransportProfile());
    assertEquals("http://localhost/as2", aEP.getEndpointReference());
    assertFalse(aEP.isRequireBusinessLevelSignature());
    assertEquals("minauth", aEP.getMinimumAuthenticationLevel());
    assertEquals(aStartDT, aEP.getServiceActivationDateTime());
    assertEquals(aEndDT, aEP.getServiceExpirationDateTime());
    assertEquals("cert", aEP.getCertificate());
    assertEquals("sd", aEP.getServiceDescription());
    assertEquals("tc", aEP.getTechnicalContactUrl());
    assertEquals("ti", aEP.getTechnicalInformationUrl());
    assertEquals("[{\"Any\":\"<extep />\"}]", aEP.getExtensionsAsString());
    final IProcessIdentifier aProcessID = new SimpleProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
    final SMPProcess aProcess = new SMPProcess(aProcessID, CollectionHelper.newList(aEP), "<extproc/>");
    assertEquals(aProcessID, aProcess.getProcessIdentifier());
    assertEquals(1, aProcess.getAllEndpoints().size());
    assertEquals("[{\"Any\":\"<extproc />\"}]", aProcess.getExtensionsAsString());
    final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
    final SMPServiceInformation aSI = new SMPServiceInformation(aSG, aDocTypeID, CollectionHelper.newList(aProcess), "<extsi/>");
    assertSame(aSG, aSI.getServiceGroup());
    assertEquals(aDocTypeID, aSI.getDocumentTypeIdentifier());
    assertEquals(1, aSI.getAllProcesses().size());
    assertEquals("[{\"Any\":\"<extsi />\"}]", aSI.getExtensionsAsString());
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 5 with XMLOffsetDateTime

use of com.helger.commons.datetime.XMLOffsetDateTime in project peppol-commons by phax.

the class PeppolSBDHDocumentReaderTest method testReadGoodAsBad2.

@Test
public void testReadGoodAsBad2() {
    // Always fails
    final PeppolSBDHDocumentReader aReader = new PeppolSBDHDocumentReader(SimpleIdentifierFactory.INSTANCE) {

        @Override
        protected boolean isValidCreationDateTime(@Nonnull final XMLOffsetDateTime aCreationDateTime) {
            // Should fail
            return aCreationDateTime.isAfter(PDTFactory.getCurrentXMLOffsetDateTime());
        }
    };
    for (final ClassPathResource aRes : PeppolSBDHTestFiles.getAllGoodCases()) {
        assertTrue(aRes.getPath(), aRes.exists());
        try {
            aReader.extractData(DOMReader.readXMLDOM(aRes));
            fail();
        } catch (final PeppolSBDHDocumentReadException ex) {
            // check for expected error code
            LOGGER.info(ex.toString());
        }
    }
}
Also used : Nonnull(javax.annotation.Nonnull) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Aggregations

XMLOffsetDateTime (com.helger.commons.datetime.XMLOffsetDateTime)7 Nonnull (javax.annotation.Nonnull)4 Test (org.junit.Test)4 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)3 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)3 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)2 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)2 ContainsSoftMigration (com.helger.commons.annotation.ContainsSoftMigration)1 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)1 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)1 SimpleProcessIdentifier (com.helger.peppolid.simple.process.SimpleProcessIdentifier)1 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)1 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)1 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)1