use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPRedirectTest method testBasic.
@Test
public void testBasic() {
final IParticipantIdentifier aPI = new SimpleParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
// Create new one
final ISMPRedirect aRedirect = new SMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect/>");
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("target", aRedirect.getTargetHref());
assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertFalse(aRedirect.hasCertificate());
assertEquals("[{\"Any\":\"<extredirect />\"}]", aRedirect.getExtensionsAsString());
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationTest method testMinimal.
@Test
public void testMinimal() {
final IParticipantIdentifier aPI = new SimpleParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
final ISMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, (String) null, (XMLOffsetDateTime) null, (XMLOffsetDateTime) null, "cert", "sd", "tc", (String) null, (String) null);
assertEquals("tp", aEP.getTransportProfile());
assertEquals("http://localhost/as2", aEP.getEndpointReference());
assertFalse(aEP.isRequireBusinessLevelSignature());
assertNull(aEP.getMinimumAuthenticationLevel());
assertNull(aEP.getServiceActivationDateTime());
assertNull(aEP.getServiceExpirationDateTime());
assertEquals("cert", aEP.getCertificate());
assertEquals("sd", aEP.getServiceDescription());
assertEquals("tc", aEP.getTechnicalContactUrl());
assertNull(aEP.getTechnicalInformationUrl());
assertNull(aEP.getExtensionsAsString());
final IProcessIdentifier aProcessID = new SimpleProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
final SMPProcess aProcess = new SMPProcess(aProcessID, CollectionHelper.newList(aEP), (String) null);
assertEquals(aProcessID, aProcess.getProcessIdentifier());
assertEquals(1, aProcess.getAllEndpoints().size());
assertNull(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), (String) null);
assertSame(aSG, aSI.getServiceGroup());
assertEquals(aDocTypeID, aSI.getDocumentTypeIdentifier());
assertEquals(1, aSI.getAllProcesses().size());
assertNull(aSI.getExtensionsAsString());
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method deleteSMPRedirect.
@Nonnull
public EChange deleteSMPRedirect(@Nullable final ISMPRedirect aSMPRedirect) {
if (aSMPRedirect == null)
return EChange.UNCHANGED;
final IParticipantIdentifier aParticipantID = aSMPRedirect.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPRedirect.getDocumentTypeIdentifier();
final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? and documentIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (nDeleted == 0) {
AuditHelper.onAuditDeleteFailure(SMPRedirect.OT, aSMPRedirect.getID(), "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditDeleteSuccess(SMPRedirect.OT, aSMPRedirect.getID(), aSMPRedirect.getServiceGroupID(), aSMPRedirect.getDocumentTypeIdentifier().getURIEncoded());
m_aCallbacks.forEach(x -> x.onSMPRedirectDeleted(aSMPRedirect));
return EChange.CHANGED;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method mergeSMPServiceInformation.
@Nonnull
public ESuccess mergeSMPServiceInformation(@Nonnull final ISMPServiceInformation aSMPServiceInformation) {
ValueEnforcer.notNull(aSMPServiceInformation, "ServiceInformation");
final MutableBoolean aUpdated = new MutableBoolean(false);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Simply delete the old one
final EChange eDeleted = _deleteSMPServiceInformationNoCallback(aSMPServiceInformation);
aUpdated.set(eDeleted.isChanged());
// Insert new processes
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_service_metadata (businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, extension) VALUES (?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aSMPServiceInformation.getExtensionsAsString()));
for (final ISMPProcess aProcess : aSMPServiceInformation.getAllProcesses()) {
final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier();
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_process (businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, processIdentifierType, processIdentifier, extension) VALUES (?, ?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue(), aProcess.getExtensionsAsString()));
// Insert new endpoints
for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_endpoint (businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, processIdentifierType, processIdentifier," + " certificate, endpointReference, minimumAuthenticationLevel, requireBusinessLevelSignature, serviceActivationDate, serviceDescription, serviceExpirationDate, technicalContactUrl, technicalInformationUrl, transportProfile," + " extension) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue(), aEndpoint.getCertificate(), aEndpoint.getEndpointReference(), aEndpoint.getMinimumAuthenticationLevel(), Boolean.valueOf(aEndpoint.isRequireBusinessLevelSignature()), DBValueHelper.toTimestamp(aEndpoint.getServiceActivationDateTime()), aEndpoint.getServiceDescription(), DBValueHelper.toTimestamp(aEndpoint.getServiceExpirationDateTime()), aEndpoint.getTechnicalContactUrl(), aEndpoint.getTechnicalInformationUrl(), aEndpoint.getTransportProfile(), aEndpoint.getExtensionsAsString()));
}
}
});
if (eSuccess.isFailure())
return ESuccess.FAILURE;
// Callback outside of transaction
if (aUpdated.booleanValue()) {
AuditHelper.onAuditModifySuccess(SMPServiceInformation.OT, "set-all", aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
} else {
AuditHelper.onAuditCreateSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
m_aCBs.forEach(x -> x.onSMPServiceInformationCreated(aSMPServiceInformation));
}
return ESuccess.SUCCESS;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method getAllSMPServiceInformation.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceInformation> getAllSMPServiceInformation() {
final ICommonsList<ISMPServiceInformation> ret = new CommonsArrayList<>();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sm.businessIdentifierScheme, sm.businessIdentifier, sm.documentIdentifierScheme, sm.documentIdentifier, sm.extension," + " sp.processIdentifierType, sp.processIdentifier, sp.extension," + " se.transportProfile, se.endpointReference, se.requireBusinessLevelSignature, se.minimumAuthenticationLevel," + " se.serviceActivationDate, se.serviceExpirationDate, se.certificate, se.serviceDescription," + " se.technicalContactUrl, se.technicalInformationUrl, se.extension" + " FROM smp_service_metadata AS sm" + " INNER JOIN smp_process AS sp" + " ON sm.businessIdentifierScheme=sp.businessIdentifierScheme AND sm.businessIdentifier=sp.businessIdentifier" + " AND sm.documentIdentifierScheme=sp.documentIdentifierScheme AND sm.documentIdentifier=sp.documentIdentifier" + " INNER JOIN smp_endpoint AS se" + " ON sp.businessIdentifierScheme=se.businessIdentifierScheme AND sp.businessIdentifier=se.businessIdentifier" + " AND sp.documentIdentifierScheme=se.documentIdentifierScheme AND sp.documentIdentifier=se.documentIdentifier" + " AND sp.processIdentifierType=se.processIdentifierType AND sp.processIdentifier=se.processIdentifier");
final ICommonsMap<IParticipantIdentifier, ICommonsMap<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>>> aGrouping = new CommonsHashMap<>();
if (aDBResult != null)
for (final DBResultRow aDBRow : aDBResult) {
// Participant ID
final IParticipantIdentifier aParticipantID = new SimpleParticipantIdentifier(aDBRow.getAsString(0), aDBRow.getAsString(1));
// Document type ID and extension
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(aDBRow.getAsString(2), aDBRow.getAsString(3));
final String sServiceInformationExtension = aDBRow.getAsString(4);
// Process without endpoints
final SMPProcess aProcess = new SMPProcess(new SimpleProcessIdentifier(aDBRow.getAsString(5), aDBRow.getAsString(6)), null, aDBRow.getAsString(7));
// Don't add endpoint to process, because that impacts
// SMPProcess.equals/hashcode
final SMPEndpoint aEndpoint = new SMPEndpoint(aDBRow.getAsString(8), aDBRow.getAsString(9), aDBRow.getAsBoolean(10, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE), aDBRow.getAsString(11), aDBRow.getAsXMLOffsetDateTime(12), aDBRow.getAsXMLOffsetDateTime(13), aDBRow.getAsString(14), aDBRow.getAsString(15), aDBRow.getAsString(16), aDBRow.getAsString(17), aDBRow.getAsString(18));
aGrouping.computeIfAbsent(aParticipantID, k -> new CommonsHashMap<>()).computeIfAbsent(new DocTypeAndExtension(aDocTypeID, sServiceInformationExtension), k -> new CommonsHashMap<>()).computeIfAbsent(aProcess, k -> new CommonsArrayList<>()).add(aEndpoint);
}
// Per participant ID
for (final Map.Entry<IParticipantIdentifier, ICommonsMap<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>>> aEntry : aGrouping.entrySet()) {
final ISMPServiceGroup aServiceGroup = m_aServiceGroupMgr.getSMPServiceGroupOfID(aEntry.getKey());
if (aServiceGroup == null)
throw new IllegalStateException("Failed to resolve service group for participant ID '" + aEntry.getKey().getURIEncoded() + "'");
// Per document type ID
for (final Map.Entry<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aEntry2 : aEntry.getValue().entrySet()) {
// Flatten list
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final Map.Entry<SMPProcess, ICommonsList<SMPEndpoint>> aEntry3 : aEntry2.getValue().entrySet()) {
final SMPProcess aProcess = aEntry3.getKey();
aProcess.addEndpoints(aEntry3.getValue());
aProcesses.add(aProcess);
}
final DocTypeAndExtension aDE = aEntry2.getKey();
ret.add(new SMPServiceInformation(aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
}
}
return ret;
}
Aggregations