Search in sources :

Example 1 with EChange

use of com.helger.commons.state.EChange 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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) 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) Wrapper(com.helger.commons.wrapper.Wrapper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 2 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

the class SMPSettingsManagerMongoDB method updateSettings.

@Nonnull
public EChange updateSettings(final boolean bRESTWritableAPIDisabled, final boolean bDirectoryIntegrationEnabled, final boolean bDirectoryIntegrationRequired, final boolean bDirectoryIntegrationAutoUpdate, @Nullable final String sDirectoryHostName, final boolean bSMLEnabled, final boolean bSMLRequired, @Nullable final String sSMLInfoID) {
    EChange eChange = EChange.UNCHANGED;
    eChange = eChange.or(m_aSettings.setRESTWritableAPIDisabled(bRESTWritableAPIDisabled));
    eChange = eChange.or(m_aSettings.setDirectoryIntegrationEnabled(bDirectoryIntegrationEnabled));
    eChange = eChange.or(m_aSettings.setDirectoryIntegrationRequired(bDirectoryIntegrationRequired));
    eChange = eChange.or(m_aSettings.setDirectoryIntegrationAutoUpdate(bDirectoryIntegrationAutoUpdate));
    eChange = eChange.or(m_aSettings.setDirectoryHostName(sDirectoryHostName));
    eChange = eChange.or(m_aSettings.setSMLEnabled(bSMLEnabled));
    eChange = eChange.or(m_aSettings.setSMLRequired(bSMLRequired));
    eChange = eChange.or(m_aSettings.setSMLInfoID(sSMLInfoID));
    if (eChange.isChanged()) {
        final Document aDoc = toBson(m_aSettings);
        if (m_aInsertDocument.getAndSet(false)) {
            if (!getCollection().insertOne(aDoc).wasAcknowledged())
                throw new IllegalStateException("Failed to insert into MongoDB Collection");
        } else {
            if (!getCollection().replaceOne(new Document(BSON_ID, ID_SETTINGS), aDoc).wasAcknowledged())
                throw new IllegalStateException("Failed to replace in MongoDB Collection");
        }
        // Invoke callbacks
        m_aCallbacks.forEach(x -> x.onSMPSettingsChanged(m_aSettings));
    }
    return eChange;
}
Also used : EChange(com.helger.commons.state.EChange) Document(org.bson.Document) Nonnull(javax.annotation.Nonnull)

Example 3 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

the class SMPParticipantMigrationManagerMongoDB method setParticipantMigrationState.

@Nonnull
public EChange setParticipantMigrationState(@Nullable final String sParticipantMigrationID, @Nonnull final EParticipantMigrationState eNewState) {
    ValueEnforcer.notNull(eNewState, "NewState");
    final SMPParticipantMigration aPM = getParticipantMigrationOfID(sParticipantMigrationID);
    if (aPM == null) {
        AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, "no-such-id");
        return EChange.UNCHANGED;
    }
    {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aPM.setState(eNewState));
        if (eChange.isUnchanged())
            return EChange.UNCHANGED;
        getCollection().findOneAndReplace(new Document(BSON_ID, sParticipantMigrationID), toBson(aPM));
    }
    AuditHelper.onAuditModifySuccess(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState);
    return EChange.CHANGED;
}
Also used : SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) EChange(com.helger.commons.state.EChange) Document(org.bson.Document) Nonnull(javax.annotation.Nonnull)

Example 4 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

the class SMPServiceGroupManagerXML method updateSMPServiceGroup.

@Nonnull
public EChange updateSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull @Nonempty final String sNewOwnerID, @Nullable final String sExtension) throws SMPServerException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    ValueEnforcer.notEmpty(sNewOwnerID, "NewOwnerID");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("updateSMPServiceGroup (" + aParticipantID.getURIEncoded() + ", " + sNewOwnerID + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ")");
    final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
    final SMPServiceGroup aSMPServiceGroup = getOfID(sServiceGroupID);
    if (aSMPServiceGroup == null) {
        AuditHelper.onAuditModifyFailure(SMPServiceGroup.OT, "set-all", sServiceGroupID, "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("updateSMPServiceGroup - failure");
        throw new SMPNotFoundException("No such service group '" + sServiceGroupID + "'");
    }
    m_aRWLock.writeLock().lock();
    try {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aSMPServiceGroup.setOwnerID(sNewOwnerID));
        eChange = eChange.or(aSMPServiceGroup.setExtensionAsString(sExtension));
        if (eChange.isUnchanged()) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("updateSMPServiceGroup - unchanged");
            return EChange.UNCHANGED;
        }
        internalUpdateItem(aSMPServiceGroup);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditModifySuccess(SMPServiceGroup.OT, "set-all", sServiceGroupID, sNewOwnerID, sExtension);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("updateSMPServiceGroup - success");
    m_aCBs.forEach(x -> x.onSMPServiceGroupUpdated(aParticipantID));
    return EChange.CHANGED;
}
Also used : SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 5 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

the class SMPParticipantMigrationManagerXML method setParticipantMigrationState.

@Nonnull
public EChange setParticipantMigrationState(@Nullable final String sParticipantMigrationID, @Nonnull final EParticipantMigrationState eNewState) {
    ValueEnforcer.notNull(eNewState, "NewState");
    final SMPParticipantMigration aPM = getOfID(sParticipantMigrationID);
    if (aPM == null) {
        AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, "no-such-id");
        return EChange.UNCHANGED;
    }
    m_aRWLock.writeLock().lock();
    try {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aPM.setState(eNewState));
        if (eChange.isUnchanged())
            return EChange.UNCHANGED;
        internalUpdateItem(aPM);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditModifySuccess(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState);
    return EChange.CHANGED;
}
Also used : EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Aggregations

EChange (com.helger.commons.state.EChange)27 Nonnull (javax.annotation.Nonnull)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)9 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)7 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)7 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)6 ESuccess (com.helger.commons.state.ESuccess)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)5 IUser (com.helger.photon.security.user.IUser)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)4 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)4 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)4 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)4