Search in sources :

Example 1 with ConstantPreparedStatementDataProvider

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));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) EParticipantMigrationDirection(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationDirection) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nullable(javax.annotation.Nullable)

Example 2 with ConstantPreparedStatementDataProvider

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) MutableLong(com.helger.commons.mutable.MutableLong) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nonnull(javax.annotation.Nonnull)

Example 3 with ConstantPreparedStatementDataProvider

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));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPRedirect(com.helger.phoss.smp.domain.redirect.SMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) X509Certificate(java.security.cert.X509Certificate) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nullable(javax.annotation.Nullable)

Example 4 with ConstantPreparedStatementDataProvider

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Wrapper(com.helger.commons.wrapper.Wrapper) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) IRegistrationHook(com.helger.phoss.smp.smlhook.IRegistrationHook) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 5 with ConstantPreparedStatementDataProvider

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);
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Wrapper(com.helger.commons.wrapper.Wrapper) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)33 Nonnull (javax.annotation.Nonnull)20 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)16 ESuccess (com.helger.commons.state.ESuccess)15 Nullable (javax.annotation.Nullable)15 Wrapper (com.helger.commons.wrapper.Wrapper)14 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)14 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)14 MutableBoolean (com.helger.commons.mutable.MutableBoolean)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)8 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)8 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)7 EChange (com.helger.commons.state.EChange)6 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)5 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)5 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)5 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)5 ValueEnforcer (com.helger.commons.ValueEnforcer)4 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4