use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method getSMPServiceInformationOfServiceGroupAndDocumentType.
@Nullable
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType(@Nullable final ISMPServiceGroup aServiceGroup, @Nullable final IDocumentTypeIdentifier aDocTypeID) {
if (aServiceGroup == null)
return null;
if (aDocTypeID == null)
return null;
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT 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" + " WHERE sm.businessIdentifierScheme=? AND sm.businessIdentifier=? AND sm.documentIdentifierScheme=? AND sm.documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (aDBResult != null && aDBResult.isNotEmpty()) {
final String sServiceInformationExtension = aDBResult.getFirst().getAsString(0);
final ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>> aEndpoints = new CommonsHashMap<>();
for (final DBResultRow aDBRow : aDBResult) {
// Process without endpoints as key
final SMPProcess aProcess = new SMPProcess(new SimpleProcessIdentifier(aDBRow.getAsString(1), aDBRow.getAsString(2)), null, aDBRow.getAsString(3));
final SMPEndpoint aEndpoint = new SMPEndpoint(aDBRow.getAsString(4), aDBRow.getAsString(5), aDBRow.getAsBoolean(6, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE), aDBRow.getAsString(7), aDBRow.getAsXMLOffsetDateTime(8), aDBRow.getAsXMLOffsetDateTime(9), aDBRow.getAsString(10), aDBRow.getAsString(11), aDBRow.getAsString(12), aDBRow.getAsString(13), aDBRow.getAsString(14));
aEndpoints.computeIfAbsent(aProcess, k -> new CommonsArrayList<>()).add(aEndpoint);
}
// Flatten list
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final Map.Entry<SMPProcess, ICommonsList<SMPEndpoint>> aEntry : aEndpoints.entrySet()) {
final SMPProcess aProcess = aEntry.getKey();
aProcess.addEndpoints(aEntry.getValue());
aProcesses.add(aProcess);
}
return new SMPServiceInformation(aServiceGroup, aDocTypeID, aProcesses, sServiceInformationExtension);
}
return null;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerMongoDB method getSMPServiceInformationOfServiceGroupAndDocumentType.
@Nullable
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType(@Nullable final ISMPServiceGroup aServiceGroup, @Nullable final IDocumentTypeIdentifier aDocumentTypeIdentifier) {
if (aServiceGroup == null)
return null;
if (aDocumentTypeIdentifier == null)
return null;
final ICommonsList<ISMPServiceInformation> ret = new CommonsArrayList<>();
getCollection().find(Filters.and(new Document(BSON_SERVICE_GROUP_ID, aServiceGroup.getID()), new Document(BSON_DOCTYPE_ID, toBson(aDocumentTypeIdentifier)))).forEach((Consumer<Document>) x -> ret.add(toServiceInformation(x, true)));
if (ret.isEmpty())
return null;
if (ret.size() > 1)
LOGGER.warn("Found more than one entry for service group '" + aServiceGroup.getID() + "' and document type '" + aDocumentTypeIdentifier.getValue() + "'. This seems to be a bug! Using the first one.");
return ret.getFirst();
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerMongoDB method toServiceInformation.
@Nonnull
@ReturnsMutableCopy
public SMPServiceInformation toServiceInformation(@Nonnull final Document aDoc, final boolean bNeedProcesses) {
final ISMPServiceGroup aServiceGroup = m_aServiceGroupMgr.getSMPServiceGroupOfID(m_aIdentifierFactory.parseParticipantIdentifier(aDoc.getString(BSON_SERVICE_GROUP_ID)));
final IDocumentTypeIdentifier aDocTypeID = toDocumentTypeID(aDoc.get(BSON_DOCTYPE_ID, Document.class));
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
if (bNeedProcesses)
for (final Document aDocP : aDoc.getList(BSON_PROCESSES, Document.class)) {
final SMPProcess aProcess = toProcess(aDocP);
if (aProcess != null)
aProcesses.add(aProcess);
}
final String sExtension = aDoc.getString(BSON_EXTENSIONS);
// The ID itself is derived from ServiceGroupID and DocTypeID
return new SMPServiceInformation(aServiceGroup, aDocTypeID, aProcesses, sExtension);
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPRedirectManagerMongoDB method toDomain.
@Nonnull
@ReturnsMutableCopy
public static SMPRedirect toDomain(@Nonnull final IIdentifierFactory aIdentifierFactory, @Nonnull final ISMPServiceGroupManager aServiceGroupMgr, @Nonnull final Document aDoc) {
// The ID itself is derived from ServiceGroupID and DocTypeID
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(aDoc.getString(BSON_SERVICE_GROUP_ID)));
final IDocumentTypeIdentifier aDocTypeID = toDocumentTypeID(aDoc.get(BSON_DOCTYPE_ID, Document.class));
final X509Certificate aCert = CertificateHelper.convertStringToCertficateOrNull(aDoc.getString(BSON_TARGET_CERTIFICATE));
return new SMPRedirect(aServiceGroup, aDocTypeID, aDoc.getString(BSON_TARGET_HREF), aDoc.getString(BSON_TARGET_SUBJECT_CN), aCert, aDoc.getString(BSON_EXTENSIONS));
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPRedirectManagerMongoDBTest method testRedirectBasic.
@Test
public void testRedirectBasic() throws SMPServerException {
// Ensure the user is present
final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
assertNotNull(aTestUser);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
assertEquals(0, aRedirectMgr.getSMPRedirectCount());
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
assertNotNull(aSG);
try {
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "doctype4711");
final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("bla", aRedirect.getTargetHref());
assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
Aggregations