Search in sources :

Example 21 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation 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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) MustImplementEqualsAndHashcode(com.helger.commons.annotation.MustImplementEqualsAndHashcode) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) Supplier(java.util.function.Supplier) CallbackList(com.helger.commons.callback.CallbackList) DBValueHelper(com.helger.db.api.helper.DBValueHelper) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) HashCodeGenerator(com.helger.commons.hashcode.HashCodeGenerator) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) StringHelper(com.helger.commons.string.StringHelper) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Wrapper(com.helger.commons.wrapper.Wrapper) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) Map(java.util.Map) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 22 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation 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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) MustImplementEqualsAndHashcode(com.helger.commons.annotation.MustImplementEqualsAndHashcode) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) Supplier(java.util.function.Supplier) CallbackList(com.helger.commons.callback.CallbackList) DBValueHelper(com.helger.db.api.helper.DBValueHelper) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) HashCodeGenerator(com.helger.commons.hashcode.HashCodeGenerator) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) StringHelper(com.helger.commons.string.StringHelper) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Wrapper(com.helger.commons.wrapper.Wrapper) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Map(java.util.Map) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nullable(javax.annotation.Nullable)

Example 23 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation 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();
}
Also used : Document(org.bson.Document) ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) CallbackList(com.helger.commons.callback.CallbackList) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) Filters(com.mongodb.client.model.Filters) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) Consumer(java.util.function.Consumer) AuditHelper(com.helger.photon.audit.AuditHelper) List(java.util.List) TypeConverter(com.helger.commons.typeconvert.TypeConverter) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) DeleteResult(com.mongodb.client.result.DeleteResult) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Document(org.bson.Document) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nullable(javax.annotation.Nullable)

Example 24 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerMongoDB method deleteSMPProcess.

@Nonnull
public EChange deleteSMPProcess(@Nullable final ISMPServiceInformation aSMPServiceInformation, @Nullable final ISMPProcess aProcess) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPProcess (" + aSMPServiceInformation + ", " + aProcess + ")");
    if (aSMPServiceInformation == null || aProcess == null) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPProcess - failure");
        return EChange.UNCHANGED;
    }
    // Find implementation object
    final SMPServiceInformation aRealServiceInformation = getCollection().find(new Document(BSON_ID, aSMPServiceInformation.getID())).map(x -> toServiceInformation(x, true)).first();
    if (aRealServiceInformation == null) {
        AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aSMPServiceInformation.getID(), "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPProcess - failure");
        return EChange.UNCHANGED;
    }
    // Main deletion in write lock
    if (aRealServiceInformation.deleteProcess(aProcess).isUnchanged()) {
        AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aProcess.getProcessIdentifier().getURIEncoded(), "no-such-process");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPProcess - failure");
        return EChange.UNCHANGED;
    }
    // Save new one
    getCollection().replaceOne(new Document(BSON_ID, aSMPServiceInformation.getID()), toBson(aRealServiceInformation));
    AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aProcess.getProcessIdentifier().getURIEncoded());
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPProcess - success");
    return EChange.CHANGED;
}
Also used : Document(org.bson.Document) ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) CallbackList(com.helger.commons.callback.CallbackList) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) Filters(com.mongodb.client.model.Filters) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) Consumer(java.util.function.Consumer) AuditHelper(com.helger.photon.audit.AuditHelper) List(java.util.List) TypeConverter(com.helger.commons.typeconvert.TypeConverter) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) DeleteResult(com.mongodb.client.result.DeleteResult) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Document(org.bson.Document) Nonnull(javax.annotation.Nonnull)

Example 25 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceGroupManagerXML 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 + ")");
    final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
    final SMPServiceGroup aSMPServiceGroup = getOfID(sServiceGroupID);
    if (aSMPServiceGroup == null) {
        AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aParticipantID, "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPServiceGroup - failure");
        throw new SMPNotFoundException("No such service group '" + aParticipantID.getURIEncoded() + "'");
    }
    // Delete in SML - throws exception in case of error
    final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
    if (bDeleteInSML)
        try {
            aHook.deleteServiceGroup(aParticipantID);
        } catch (final RegistrationHookException ex) {
            throw new SMPSMLException("Failed to delete '" + aParticipantID.getURIEncoded() + "' in SML", ex);
        }
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    ICommonsList<ISMPRedirect> aOldRedirects = null;
    ICommonsList<ISMPServiceInformation> aOldServiceInformation = null;
    m_aRWLock.writeLock().lock();
    try {
        if (internalDeleteItem(aSMPServiceGroup.getID()) == null) {
            AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aSMPServiceGroup.getID(), "no-such-id");
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("deleteSMPServiceGroup - failure");
            // Restore in SML again
            if (bDeleteInSML) {
                try {
                    aHook.undoDeleteServiceGroup(aParticipantID);
                } catch (final RegistrationHookException ex2) {
                    LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex2);
                }
            }
            return EChange.UNCHANGED;
        }
        // Remember all redirects (in case of an error) and delete them
        aOldRedirects = aRedirectMgr.getAllSMPRedirectsOfServiceGroup(aSMPServiceGroup);
        aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSMPServiceGroup);
        // Remember all service information (in case of an error) and delete them
        aOldServiceInformation = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aSMPServiceGroup);
        aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aSMPServiceGroup);
    } catch (final RuntimeException ex) {
        // Try to rollback the actions
        if (!containsWithID(aSMPServiceGroup.getID()))
            internalCreateItem(aSMPServiceGroup);
        // Restore redirects (if any)
        if (aOldRedirects != null)
            for (final ISMPRedirect aOldRedirect : aOldRedirects) {
                // ignore return value - we cannot do anything anyway
                aRedirectMgr.createOrUpdateSMPRedirect(aSMPServiceGroup, aOldRedirect.getDocumentTypeIdentifier(), aOldRedirect.getTargetHref(), aOldRedirect.getSubjectUniqueIdentifier(), aOldRedirect.getCertificate(), aOldRedirect.getExtensionsAsString());
            }
        // Restore service information (if any)
        if (aOldServiceInformation != null)
            for (final ISMPServiceInformation aOldServiceInfo : aOldServiceInformation) {
                // ignore return value - we cannot do anything anyway
                aServiceInfoMgr.mergeSMPServiceInformation(aOldServiceInfo);
            }
        // An error occurred - restore in SML again
        try {
            aHook.undoDeleteServiceGroup(aParticipantID);
        } catch (final RegistrationHookException ex2) {
            LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex2);
        }
        throw ex;
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditDeleteSuccess(SMPServiceGroup.OT, aSMPServiceGroup.getID(), Boolean.valueOf(bDeleteInSML));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceGroup - success");
    m_aCBs.forEach(x -> x.onSMPServiceGroupDeleted(aParticipantID, bDeleteInSML));
    return EChange.CHANGED;
}
Also used : RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) IRegistrationHook(com.helger.phoss.smp.smlhook.IRegistrationHook) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)31 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)27 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)27 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)20 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)20 Nonnull (javax.annotation.Nonnull)20 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)17 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)16 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)15 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)14 ICommonsList (com.helger.commons.collection.impl.ICommonsList)13 SMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation)12 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)11 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)11 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)11 EChange (com.helger.commons.state.EChange)10 ValueEnforcer (com.helger.commons.ValueEnforcer)9 StringHelper (com.helger.commons.string.StringHelper)9 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)9 ISMPServiceInformationCallback (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback)9