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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations