Skip to content

Commit

Permalink
Removed the need for ISMPServiceInformation to know its owning
Browse files Browse the repository at this point in the history
ISMPServiceGroup
  • Loading branch information
phax committed Jan 9, 2025
1 parent b66e95e commit 7a10a2e
Show file tree
Hide file tree
Showing 27 changed files with 206 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ISMPRedirectManager createRedirectMgr (@Nonnull final IIdentifierFactory
public ISMPServiceInformationManager createServiceInformationMgr (@Nonnull final IIdentifierFactory aIdentifierFactory,
@Nonnull final ISMPServiceGroupManager aServiceGroupMgr)
{
return new SMPServiceInformationManagerMongoDB (aIdentifierFactory, aServiceGroupMgr);
return new SMPServiceInformationManagerMongoDB (aIdentifierFactory);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
import com.helger.commons.typeconvert.TypeConverter;
import com.helger.peppol.smp.ISMPTransportProfile;
import com.helger.peppolid.IDocumentTypeIdentifier;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.IProcessIdentifier;
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager;
import com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint;
import com.helger.phoss.smp.domain.serviceinfo.ISMPProcess;
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation;
Expand Down Expand Up @@ -87,15 +87,12 @@ public final class SMPServiceInformationManagerMongoDB extends AbstractManagerMo
private static final String BSON_TECHINFOURL = "techinfourl";

private final IIdentifierFactory m_aIdentifierFactory;
private final ISMPServiceGroupManager m_aServiceGroupMgr;
private final CallbackList <ISMPServiceInformationCallback> m_aCBs = new CallbackList <> ();

public SMPServiceInformationManagerMongoDB (@Nonnull final IIdentifierFactory aIdentifierFactory,
@Nonnull final ISMPServiceGroupManager aServiceGroupMgr)
public SMPServiceInformationManagerMongoDB (@Nonnull final IIdentifierFactory aIdentifierFactory)
{
super ("smp-serviceinfo");
m_aIdentifierFactory = aIdentifierFactory;
m_aServiceGroupMgr = aServiceGroupMgr;
}

@Nonnull
Expand Down Expand Up @@ -213,7 +210,7 @@ public static Document toBson (@Nonnull final ISMPServiceInformation aValue)
@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 IParticipantIdentifier aParticipantID = 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)
Expand All @@ -226,7 +223,7 @@ public SMPServiceInformation toServiceInformation (@Nonnull final Document aDoc,
final String sExtension = aDoc.getString (BSON_EXTENSIONS);

// The ID itself is derived from ServiceGroupID and DocTypeID
return new SMPServiceInformation (aServiceGroup, aDocTypeID, aProcesses, sExtension);
return new SMPServiceInformation (aParticipantID, aDocTypeID, aProcesses, sExtension);
}

@Nullable
Expand All @@ -235,7 +232,7 @@ public ISMPServiceInformation findServiceInformation (@Nullable final ISMPServic
@Nullable final IProcessIdentifier aProcessID,
@Nullable final ISMPTransportProfile aTransportProfile)
{
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup,
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup.getParticipantIdentifier (),
aDocTypeID);
if (aServiceInfo != null)
{
Expand All @@ -261,7 +258,7 @@ public ESuccess mergeSMPServiceInformation (@Nonnull final ISMPServiceInformatio

// Check for an update
boolean bChangedExisting = false;
final ISMPServiceInformation aOldInformation = getSMPServiceInformationOfServiceGroupAndDocumentType (aSMPServiceInformation.getServiceGroup (),
final ISMPServiceInformation aOldInformation = getSMPServiceInformationOfServiceGroupAndDocumentType (aSMPServiceInformation.getServiceGroupParticipantIdentifier (),
aSMPServiceInformation.getDocumentTypeIdentifier ());
if (aOldInformation != null)
{
Expand Down Expand Up @@ -473,26 +470,26 @@ public ICommonsList <IDocumentTypeIdentifier> getAllSMPDocumentTypesOfServiceGro
}

@Nullable
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final ISMPServiceGroup aServiceGroup,
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final IParticipantIdentifier aParticipantIdentifier,
@Nullable final IDocumentTypeIdentifier aDocumentTypeIdentifier)
{
if (aServiceGroup == null)
if (aParticipantIdentifier == 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 ()),
getCollection ().find (Filters.and (new Document (BSON_SERVICE_GROUP_ID, aParticipantIdentifier.getURIEncoded ()),
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 () +
aParticipantIdentifier.getURIEncoded () +
"' and document type '" +
aDocumentTypeIdentifier.getValue () +
aDocumentTypeIdentifier.getURIEncoded () +
"'. This seems to be a bug! Using the first one.");
return ret.getFirstOrNull ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public ISMPRedirectManager createRedirectMgr (@Nonnull final IIdentifierFactory
public ISMPServiceInformationManager createServiceInformationMgr (@Nonnull final IIdentifierFactory aIdentifierFactory,
@Nonnull final ISMPServiceGroupManager aServiceGroupMgr)
{
return new SMPServiceInformationManagerJDBC (SMPDBExecutor::new, aServiceGroupMgr);
return new SMPServiceInformationManagerJDBC (SMPDBExecutor::new);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import com.helger.peppolid.simple.participant.SimpleParticipantIdentifier;
import com.helger.peppolid.simple.process.SimpleProcessIdentifier;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager;
import com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint;
import com.helger.phoss.smp.domain.serviceinfo.ISMPProcess;
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation;
Expand Down Expand Up @@ -104,7 +103,6 @@ public int hashCode ()
}
}

private final ISMPServiceGroupManager m_aServiceGroupMgr;
private final CallbackList <ISMPServiceInformationCallback> m_aCBs = new CallbackList <> ();

/**
Expand All @@ -113,14 +111,10 @@ public int hashCode ()
* @param aDBExecSupplier
* The supplier for {@link DBExecutor} objects. May not be
* <code>null</code>.
* @param aServiceGroupMgr
* The service group manager to use. May not be <code>null</code>.
*/
public SMPServiceInformationManagerJDBC (@Nonnull final Supplier <? extends DBExecutor> aDBExecSupplier,
@Nonnull final ISMPServiceGroupManager aServiceGroupMgr)
public SMPServiceInformationManagerJDBC (@Nonnull final Supplier <? extends DBExecutor> aDBExecSupplier)
{
super (aDBExecSupplier);
m_aServiceGroupMgr = aServiceGroupMgr;
}

@Nonnull
Expand All @@ -144,7 +138,7 @@ public ESuccess mergeSMPServiceInformation (@Nonnull final ISMPServiceInformatio
aUpdated.set (eDeleted.isChanged ());

// Insert new processes
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup ().getParticipantIdentifier ();
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroupParticipantIdentifier ();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier ();

aExecutor.insertOrUpdateOrDelete ("INSERT INTO smp_service_metadata (businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, extension) VALUES (?, ?, ?, ?, ?)",
Expand Down Expand Up @@ -230,7 +224,7 @@ public ISMPServiceInformation findServiceInformation (@Nullable final ISMPServic
@Nullable final IProcessIdentifier aProcessID,
@Nullable final ISMPTransportProfile aTransportProfile)
{
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup,
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup.getParticipantIdentifier (),
aDocTypeID);
if (aServiceInfo != null)
{
Expand All @@ -251,7 +245,7 @@ private EChange _deleteSMPServiceInformationNoCallback (@Nonnull final ISMPServi
final Wrapper <Long> ret = new Wrapper <> (Long.valueOf (-1));
final DBExecutor aExecutor = newExecutor ();
final ESuccess eSuccess = aExecutor.performInTransaction ( () -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup ().getParticipantIdentifier ();
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroupParticipantIdentifier ();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier ();
final long nCountEP = aExecutor.insertOrUpdateOrDelete ("DELETE FROM smp_endpoint" +
" WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?",
Expand Down Expand Up @@ -354,7 +348,7 @@ public EChange deleteSMPProcess (@Nullable final ISMPServiceInformation aSMPServ
final Wrapper <Long> ret = new Wrapper <> (Long.valueOf (0));
final DBExecutor aExecutor = newExecutor ();
final ESuccess eSuccess = aExecutor.performInTransaction ( () -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup ().getParticipantIdentifier ();
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroupParticipantIdentifier ();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier ();
final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier ();
final long nCountEP = aExecutor.insertOrUpdateOrDelete ("DELETE FROM smp_endpoint" +
Expand Down Expand Up @@ -446,11 +440,7 @@ public void forEachSMPServiceInformation (@Nonnull final Consumer <? super ISMPS
// 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 () +
"'");
final IParticipantIdentifier aParticipantID = aEntry.getKey ();

// Per document type ID
for (final Map.Entry <DocTypeAndExtension, ICommonsMap <SMPProcess, ICommonsList <SMPEndpoint>>> aEntry2 : aEntry.getValue ()
Expand All @@ -466,7 +456,7 @@ public void forEachSMPServiceInformation (@Nonnull final Consumer <? super ISMPS
}

final DocTypeAndExtension aDE = aEntry2.getKey ();
aConsumer.accept (new SMPServiceInformation (aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
aConsumer.accept (new SMPServiceInformation (aParticipantID, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
}
}
}
Expand Down Expand Up @@ -547,7 +537,10 @@ public ICommonsList <ISMPServiceInformation> getAllSMPServiceInformationOfServic
}

final DocTypeAndExtension aDE = aEntry.getKey ();
ret.add (new SMPServiceInformation (aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
ret.add (new SMPServiceInformation (aServiceGroup.getParticipantIdentifier (),
aDE.m_aDocTypeID,
aProcesses,
aDE.m_sExt));
}
}
}
Expand Down Expand Up @@ -575,15 +568,14 @@ public ICommonsList <IDocumentTypeIdentifier> getAllSMPDocumentTypesOfServiceGro
}

@Nullable
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final ISMPServiceGroup aServiceGroup,
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final IParticipantIdentifier aParticipantID,
@Nullable final IDocumentTypeIdentifier aDocTypeID)
{
if (aServiceGroup == null)
if (aParticipantID == 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," +
Expand All @@ -598,8 +590,8 @@ public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentT
" 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 (),
new ConstantPreparedStatementDataProvider (aParticipantID.getScheme (),
aParticipantID.getValue (),
aDocTypeID.getScheme (),
aDocTypeID.getValue ()));
if (aDBResult != null && aDBResult.isNotEmpty ())
Expand Down Expand Up @@ -637,7 +629,7 @@ public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentT
aProcess.addEndpoints (aEntry.getValue ());
aProcesses.add (aProcess);
}
return new SMPServiceInformation (aServiceGroup, aDocTypeID, aProcesses, sServiceInformationExtension);
return new SMPServiceInformation (aParticipantID, aDocTypeID, aProcesses, sServiceInformationExtension);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.helger.dao.DAOException;
import com.helger.peppol.smp.ISMPTransportProfile;
import com.helger.peppolid.IDocumentTypeIdentifier;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.peppolid.IProcessIdentifier;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup;
import com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint;
Expand Down Expand Up @@ -82,7 +83,7 @@ public ISMPServiceInformation findServiceInformation (@Nullable final ISMPServic
@Nullable final IProcessIdentifier aProcessID,
@Nullable final ISMPTransportProfile aTransportProfile)
{
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup,
final ISMPServiceInformation aServiceInfo = getSMPServiceInformationOfServiceGroupAndDocumentType (aServiceGroup.getParticipantIdentifier (),
aDocTypeID);
if (aServiceInfo != null)
{
Expand All @@ -108,7 +109,7 @@ public ESuccess mergeSMPServiceInformation (@Nonnull final ISMPServiceInformatio

// Check for an update
boolean bChangeExisting = false;
final SMPServiceInformation aOldInformation = (SMPServiceInformation) getSMPServiceInformationOfServiceGroupAndDocumentType (aSMPServiceInformation.getServiceGroup (),
final SMPServiceInformation aOldInformation = (SMPServiceInformation) getSMPServiceInformationOfServiceGroupAndDocumentType (aSMPServiceInformation.getServiceGroupParticipantIdentifier (),
aSMPServiceInformation.getDocumentTypeIdentifier ());
if (aOldInformation != null)
{
Expand Down Expand Up @@ -342,15 +343,15 @@ public ICommonsList <IDocumentTypeIdentifier> getAllSMPDocumentTypesOfServiceGro
}

@Nullable
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final ISMPServiceGroup aServiceGroup,
public ISMPServiceInformation getSMPServiceInformationOfServiceGroupAndDocumentType (@Nullable final IParticipantIdentifier aParticipantID,
@Nullable final IDocumentTypeIdentifier aDocumentTypeIdentifier)
{
if (aServiceGroup == null)
if (aParticipantID == null)
return null;
if (aDocumentTypeIdentifier == null)
return null;

final String sServiceGroupID = aServiceGroup.getID ();
final String sServiceGroupID = aParticipantID.getURIEncoded ();
final ICommonsList <ISMPServiceInformation> ret = getAll (aSI -> aSI.getServiceGroupID ()
.equals (sServiceGroupID) &&
aSI.getDocumentTypeIdentifier ()
Expand Down
Loading

0 comments on commit 7a10a2e

Please sign in to comment.