use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method getParticipantMigrationOfID.
@Nullable
public SMPParticipantMigration getParticipantMigrationOfID(@Nullable final String sID) {
if (StringHelper.hasNoText(sID))
return null;
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
newExecutor().querySingle("SELECT direction, state, pid, initdt, migkey FROM smp_pmigration WHERE id=?", new ConstantPreparedStatementDataProvider(sID), aDBResult::set);
if (aDBResult.isNotSet())
return null;
final DBResultRow aRow = aDBResult.get();
final EParticipantMigrationDirection eDirection = EParticipantMigrationDirection.getFromIDOrNull(aRow.getAsString(0));
final EParticipantMigrationState eState = EParticipantMigrationState.getFromIDOrNull(aRow.getAsString(1));
final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().parseParticipantIdentifier(aRow.getAsString(2));
return new SMPParticipantMigration(sID, eDirection, eState, aPI, aRow.getAsLocalDateTime(3), aRow.getAsString(4));
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method setParticipantMigrationState.
@Nonnull
public EChange setParticipantMigrationState(@Nullable final String sParticipantMigrationID, @Nonnull final EParticipantMigrationState eNewState) {
ValueEnforcer.notNull(eNewState, "NewState");
final MutableLong aUpdated = new MutableLong(-1);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_pmigration SET state=? WHERE id=?", new ConstantPreparedStatementDataProvider(eNewState.getID(), sParticipantMigrationID));
aUpdated.set(nUpdated);
});
if (eSuccess.isFailure()) {
// DB error
AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState, "database-error");
return EChange.UNCHANGED;
}
if (aUpdated.is0()) {
// No such participant migration ID
AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditModifySuccess(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState);
return EChange.CHANGED;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method getSMPRedirectOfServiceGroupAndDocumentType.
@Nullable
public ISMPRedirect getSMPRedirectOfServiceGroupAndDocumentType(@Nullable final ISMPServiceGroup aServiceGroup, @Nullable final IDocumentTypeIdentifier aDocTypeID) {
if (aServiceGroup == null)
return null;
if (aDocTypeID == null)
return null;
final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
newExecutor().querySingle("SELECT redirectionUrl, certificateUID, certificate, extension" + " FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? and documentIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()), aDBResult::set);
if (aDBResult.isNotSet())
return null;
final DBResultRow aRow = aDBResult.get();
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(aRow.getAsString(2));
return new SMPRedirect(aServiceGroup, aDocTypeID, aRow.getAsString(0), aRow.getAsString(1), aCertificate, aRow.getAsString(3));
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPServiceGroupManagerJDBC method createSMPServiceGroup.
@Nonnull
public SMPServiceGroup createSMPServiceGroup(@Nonnull @Nonempty final String sOwnerID, @Nonnull final IParticipantIdentifier aParticipantID, @Nullable final String sExtension, final boolean bCreateInSML) throws SMPServerException {
ValueEnforcer.notEmpty(sOwnerID, "OwnerID");
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup (" + sOwnerID + ", " + aParticipantID.getURIEncoded() + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ", " + bCreateInSML + ")");
final MutableBoolean aCreatedSGHook = new MutableBoolean(false);
final MutableBoolean aCreatedSGDB = new MutableBoolean(false);
final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
final Wrapper<Exception> aCaughtException = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Check if the passed service group ID is already in use
final SMPServiceGroup aDBServiceGroup = getSMPServiceGroupOfID(aParticipantID);
if (aDBServiceGroup != null)
throw new IllegalStateException("The service group with ID " + aParticipantID.getURIEncoded() + " already exists!");
if (bCreateInSML) {
// It's a new service group - Create in SML and remember that
// Throws exception in case of an error
aHook.createServiceGroup(aParticipantID);
aCreatedSGHook.set(true);
}
// Did not exist. Create it.
if (aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_service_group (businessIdentifierScheme, businessIdentifier, extension) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sExtension)) > 0) {
aCreatedSGDB.set(true);
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_ownership (businessIdentifierScheme, businessIdentifier, username) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sOwnerID));
}
}, aCaughtException::set);
if (aCreatedSGHook.booleanValue() && !aCreatedSGDB.booleanValue()) {
// Undo creation in SML again
try {
aHook.undoCreateServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
LOGGER.error("Failed to undoCreateServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
}
}
if (eSuccess.isFailure() || aCaughtException.isSet() || !aCreatedSGDB.booleanValue()) {
AuditHelper.onAuditCreateFailure(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
// Propagate contained exception
final Exception ex = aCaughtException.get();
if (ex instanceof SMPServerException)
throw (SMPServerException) ex;
if (ex instanceof RegistrationHookException)
throw new SMPSMLException("Failed to create '" + aParticipantID.getURIEncoded() + "' in SML", ex);
throw new SMPInternalErrorException("Error creating ServiceGroup '" + aParticipantID.getURIEncoded() + "'", ex);
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup succeeded");
AuditHelper.onAuditCreateSuccess(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
final SMPServiceGroup aServiceGroup = new SMPServiceGroup(sOwnerID, aParticipantID, sExtension);
if (m_aCache != null)
m_aCache.put(aParticipantID.getURIEncoded(), aServiceGroup);
m_aCBs.forEach(x -> x.onSMPServiceGroupCreated(aServiceGroup, bCreateInSML));
return aServiceGroup;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteSMPProcess.
@Nonnull
public EChange deleteSMPProcess(@Nullable final ISMPServiceInformation aSMPServiceInformation, @Nullable final ISMPProcess aProcess) {
if (aSMPServiceInformation == null || aProcess == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc));
});
if (eSuccess.isFailure())
return EChange.UNCHANGED;
return EChange.valueOf(ret.get().longValue() > 0);
}
Aggregations