use of com.helger.commons.state.ESuccess in project phoss-smp by phax.
the class SMPBusinessCardManagerJDBC method createOrUpdateSMPBusinessCard.
@Nullable
public ISMPBusinessCard createOrUpdateSMPBusinessCard(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final Collection<SMPBusinessCardEntity> aEntities) {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aEntities, "Entities");
if (LOGGER.isDebugEnabled())
LOGGER.debug("createOrUpdateSMPBusinessCard (" + aParticipantID.getURIEncoded() + ", " + aEntities.size() + " entities" + ")");
final MutableBoolean aUpdated = new MutableBoolean(false);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSucces = aExecutor.performInTransaction(() -> {
// Delete all existing entities
final String sPID = aParticipantID.getURIEncoded();
final long nDeleted = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_bce" + " WHERE pid=?", new ConstantPreparedStatementDataProvider(sPID));
if (nDeleted > 0) {
aUpdated.set(true);
if (LOGGER.isDebugEnabled())
LOGGER.info("Deleted " + nDeleted + " existing DBBusinessCardEntity rows");
}
for (final SMPBusinessCardEntity aEntity : aEntities) {
// Single name only
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_bce (id, pid, name, country, geoinfo, identifiers, websites, contacts, addon, regdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aEntity.getID(), sPID, aEntity.names().getFirst().getName(), aEntity.getCountryCode(), aEntity.getGeographicalInformation(), getBCIAsJson(aEntity.identifiers()).getAsJsonString(JWS), getStringAsJson(aEntity.websiteURIs()).getAsJsonString(JWS), getBCCAsJson(aEntity.contacts()).getAsJsonString(JWS), aEntity.getAdditionalInformation(), aEntity.getRegistrationDate()));
}
});
if (eSucces.isFailure()) {
if (aUpdated.booleanValue())
AuditHelper.onAuditModifyFailure(SMPBusinessCard.OT, "set-all", aParticipantID.getURIEncoded());
else
AuditHelper.onAuditCreateFailure(SMPBusinessCard.OT, aParticipantID.getURIEncoded());
return null;
}
final SMPBusinessCard aNewBusinessCard = new SMPBusinessCard(aParticipantID, aEntities);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Finished createOrUpdateSMPBusinessCard");
if (aUpdated.booleanValue())
AuditHelper.onAuditModifySuccess(SMPBusinessCard.OT, "set-all", aParticipantID.getURIEncoded(), Integer.valueOf(aEntities.size()));
else
AuditHelper.onAuditCreateSuccess(SMPBusinessCard.OT, aParticipantID.getURIEncoded(), Integer.valueOf(aEntities.size()));
// Invoke generic callbacks
m_aCBs.forEach(x -> x.onSMPBusinessCardCreatedOrUpdated(aNewBusinessCard));
return aNewBusinessCard;
}
use of com.helger.commons.state.ESuccess in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method _createParticipantMigration.
@Nullable
private ISMPParticipantMigration _createParticipantMigration(@Nonnull final SMPParticipantMigration aSMPParticipantMigration) {
ValueEnforcer.notNull(aSMPParticipantMigration, "SMPParticipantMigration");
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Create new
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_pmigration (id, direction, state, pid, initdt, migkey)" + " VALUES (?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection().getID(), aSMPParticipantMigration.getState().getID(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), DBValueHelper.toTimestamp(aSMPParticipantMigration.getInitiationDateTime()), aSMPParticipantMigration.getMigrationKey()));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
});
if (eSuccess.isFailure()) {
AuditHelper.onAuditCreateFailure(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), "database-error");
return null;
}
AuditHelper.onAuditCreateSuccess(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), aSMPParticipantMigration.getInitiationDateTime(), aSMPParticipantMigration.getMigrationKey());
return aSMPParticipantMigration;
}
use of com.helger.commons.state.ESuccess in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method updateSMPTransportProfile.
@Nonnull
public EChange updateSMPTransportProfile(@Nullable final String sSMPTransportProfileID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final MutableLong aUpdated = new MutableLong(-1);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_tprofile SET name=?, deprecated=? WHERE id=?", new ConstantPreparedStatementDataProvider(sName, Boolean.valueOf(bIsDeprecated), sSMPTransportProfileID));
aUpdated.set(nUpdated);
});
if (eSuccess.isFailure()) {
// DB error
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "database-error");
return EChange.UNCHANGED;
}
if (aUpdated.is0()) {
// No such transport profile ID
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditModifySuccess(SMPTransportProfile.OT, "update", sSMPTransportProfileID, sName, Boolean.valueOf(bIsDeprecated));
return EChange.CHANGED;
}
use of com.helger.commons.state.ESuccess in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method createSMPTransportProfile.
@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final ISMPTransportProfile ret = new SMPTransportProfile(sID, sName, bIsDeprecated);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Create new
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_tprofile (id, name, deprecated) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(ret.getID(), 45), ret.getName(), Boolean.valueOf(ret.isDeprecated())));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
});
if (eSuccess.isFailure()) {
AuditHelper.onAuditCreateFailure(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated), "database-error");
return null;
}
AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
return ret;
}
use of com.helger.commons.state.ESuccess in project phoss-smp by phax.
the class SMPServiceInformationManagerXML method mergeSMPServiceInformation.
@Nonnull
public ESuccess mergeSMPServiceInformation(@Nonnull final ISMPServiceInformation aSMPServiceInformationObj) {
final SMPServiceInformation aSMPServiceInformation = (SMPServiceInformation) aSMPServiceInformationObj;
ValueEnforcer.notNull(aSMPServiceInformation, "ServiceInformation");
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation (" + aSMPServiceInformationObj + ")");
// Check for an update
boolean bChangeExisting = false;
final SMPServiceInformation aOldInformation = (SMPServiceInformation) getSMPServiceInformationOfServiceGroupAndDocumentType(aSMPServiceInformation.getServiceGroup(), aSMPServiceInformation.getDocumentTypeIdentifier());
if (aOldInformation != null) {
// This is not true for the REST API
if (EqualsHelper.identityEqual(aOldInformation, aSMPServiceInformation))
bChangeExisting = true;
}
if (bChangeExisting) {
// Edit existing
m_aRWLock.writeLocked(() -> {
internalUpdateItem(aOldInformation);
});
AuditHelper.onAuditModifySuccess(SMPServiceInformation.OT, "set-all", aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded(), aOldInformation.getAllProcesses(), aOldInformation.getExtensionsAsString());
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation - success - updated");
m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
} else {
// (Optionally delete the old one and) create the new one
boolean bRemovedOld = false;
m_aRWLock.writeLock().lock();
try {
if (aOldInformation != null) {
// Delete only if present
final SMPServiceInformation aDeletedInformation = internalDeleteItem(aOldInformation.getID());
bRemovedOld = EqualsHelper.identityEqual(aDeletedInformation, aOldInformation);
}
internalCreateItem(aSMPServiceInformation);
} finally {
m_aRWLock.writeLock().unlock();
}
if (bRemovedOld) {
AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
} else if (aOldInformation != null) {
AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
}
AuditHelper.onAuditCreateSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation - success - created");
if (aOldInformation != null)
m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
else
m_aCBs.forEach(x -> x.onSMPServiceInformationCreated(aSMPServiceInformation));
}
return ESuccess.SUCCESS;
}
Aggregations