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);
}
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);
}
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);
}
}
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());
}
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());
}
}
}
Aggregations