use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerJDBC method getAllSMPServiceGroups.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceGroup> getAllSMPServiceGroups() {
if (LOGGER.isDebugEnabled())
LOGGER.debug("getAllSMPServiceGroups()");
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sg.businessIdentifierScheme, sg.businessIdentifier, sg.extension, so.username" + " FROM smp_service_group sg, smp_ownership so" + " WHERE so.businessIdentifierScheme=sg.businessIdentifierScheme AND so.businessIdentifier=sg.businessIdentifier");
final ICommonsList<ISMPServiceGroup> ret = new CommonsArrayList<>();
if (aDBResult != null)
for (final DBResultRow aRow : aDBResult) ret.add(new SMPServiceGroup(aRow.getAsString(3), new SimpleParticipantIdentifier(aRow.getAsString(0), aRow.getAsString(1)), aRow.getAsString(2)));
return ret;
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method getAllSMPServiceInformationOfServiceGroup.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceInformation> getAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
final ICommonsList<ISMPServiceInformation> ret = new CommonsArrayList<>();
if (aServiceGroup != null) {
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT 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" + " WHERE sm.businessIdentifierScheme=? AND sm.businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
if (aDBResult != null) {
final ICommonsMap<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aGrouping = new CommonsHashMap<>();
for (final DBResultRow aDBRow : aDBResult) {
// Document type ID and extension
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(aDBRow.getAsString(0), aDBRow.getAsString(1));
final String sServiceInformationExtension = aDBRow.getAsString(2);
// Process without endpoints
final SMPProcess aProcess = new SMPProcess(new SimpleProcessIdentifier(aDBRow.getAsString(3), aDBRow.getAsString(4)), null, aDBRow.getAsString(5));
// Don't add endpoint to process, because that impacts
// SMPProcess.equals/hashcode
final SMPEndpoint aEndpoint = new SMPEndpoint(aDBRow.getAsString(6), aDBRow.getAsString(7), aDBRow.getAsBoolean(8, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE), aDBRow.getAsString(9), aDBRow.getAsXMLOffsetDateTime(10), aDBRow.getAsXMLOffsetDateTime(11), aDBRow.getAsString(12), aDBRow.getAsString(13), aDBRow.getAsString(14), aDBRow.getAsString(15), aDBRow.getAsString(16));
aGrouping.computeIfAbsent(new DocTypeAndExtension(aDocTypeID, sServiceInformationExtension), k -> new CommonsHashMap<>()).computeIfAbsent(aProcess, k -> new CommonsArrayList<>()).add(aEndpoint);
}
for (final Map.Entry<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aEntry : aGrouping.entrySet()) {
// Flatten list
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final Map.Entry<SMPProcess, ICommonsList<SMPEndpoint>> aEntry2 : aEntry.getValue().entrySet()) {
final SMPProcess aProcess = aEntry2.getKey();
aProcess.addEndpoints(aEntry2.getValue());
aProcesses.add(aProcess);
}
final DocTypeAndExtension aDE = aEntry.getKey();
ret.add(new SMPServiceInformation(aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
}
}
}
return ret;
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteAllSMPServiceInformationOfServiceGroup.
@Nonnull
public EChange deleteAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
if (aServiceGroup == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final Wrapper<ICommonsList<ISMPServiceInformation>> aAllDeleted = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// get the old ones first
aAllDeleted.set(getAllSMPServiceInformationOfServiceGroup(aServiceGroup));
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
});
if (eSuccess.isFailure() || ret.get().longValue() <= 0) {
AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, "no-such-id", aServiceGroup.getID());
return EChange.UNCHANGED;
}
// Callback outside of transaction
if (aAllDeleted.isSet())
for (final ISMPServiceInformation aSMPServiceInformation : aAllDeleted.get()) {
AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID());
m_aCBs.forEach(x -> x.onSMPServiceInformationDeleted(aSMPServiceInformation));
}
return EChange.CHANGED;
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerMongoDB method deleteSMPServiceGroup.
@Nonnull
public EChange deleteSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, final boolean bDeleteInSML) throws SMPServerException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup (" + aParticipantID.getURIEncoded() + ", " + bDeleteInSML + ")");
// Check first in memory, to avoid unnecessary deletion
final ISMPServiceGroup aServiceGroup = getSMPServiceGroupOfID(aParticipantID);
if (aServiceGroup == null)
return EChange.UNCHANGED;
final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
if (bDeleteInSML) {
// Delete in SML - throws exception in case of error
try {
aHook.deleteServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
throw new SMPSMLException("Failed to delete '" + aParticipantID.getURIEncoded() + "' in SML", ex);
}
}
// Delete all redirects (must be done before the SG is deleted)
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aServiceGroup);
// Delete all service information (must be done before the SG is deleted)
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aServiceGroup);
final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
final DeleteResult aDR = getCollection().deleteOne(new Document(BSON_ID, sServiceGroupID));
if (!aDR.wasAcknowledged() || aDR.getDeletedCount() == 0) {
AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aParticipantID, "no-such-id");
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup - failure");
// restore in SML
if (bDeleteInSML) {
// Undo deletion in SML!
try {
aHook.undoDeleteServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
}
}
throw new SMPNotFoundException("No such service group '" + aParticipantID.getURIEncoded() + "'");
}
AuditHelper.onAuditDeleteSuccess(SMPServiceGroup.OT, aParticipantID, Boolean.valueOf(bDeleteInSML));
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup - success");
m_aCBs.forEach(x -> x.onSMPServiceGroupDeleted(aParticipantID, bDeleteInSML));
return EChange.CHANGED;
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPRedirectManagerMongoDBTest method testConversion.
@Test
public void testConversion() throws SMPServerException {
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "doctype4711");
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup("blub", aPI, null, true);
assertNotNull(aSG);
try {
_testConversion(new SMPRedirect(aSG, aDocTypeID, "target href", "what ever", null, null));
_testConversion(new SMPRedirect(aSG, aDocTypeID, "target href", "what ever", null, "<ext/>"));
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
Aggregations