Search in sources :

Example 6 with ESuccess

use of com.helger.commons.state.ESuccess 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 7 with ESuccess

use of com.helger.commons.state.ESuccess 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 8 with ESuccess

use of com.helger.commons.state.ESuccess 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)

Example 9 with ESuccess

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

the class SMPServiceInformationManagerJDBC method _deleteSMPServiceInformationNoCallback.

@Nonnull
private EChange _deleteSMPServiceInformationNoCallback(@Nonnull final ISMPServiceInformation aSMPServiceInformation) {
    final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(-1));
    final DBExecutor aExecutor = newExecutor();
    final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
        final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
        final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
        final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
        final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
        final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
        ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
    });
    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) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 10 with ESuccess

use of com.helger.commons.state.ESuccess 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)

Aggregations

ESuccess (com.helger.commons.state.ESuccess)27 Nonnull (javax.annotation.Nonnull)15 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)13 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)13 Nullable (javax.annotation.Nullable)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 MutableBoolean (com.helger.commons.mutable.MutableBoolean)7 Wrapper (com.helger.commons.wrapper.Wrapper)7 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)6 EChange (com.helger.commons.state.EChange)6 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)6 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)6 ValueEnforcer (com.helger.commons.ValueEnforcer)5 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)5 StringHelper (com.helger.commons.string.StringHelper)5 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)5 Document (org.w3c.dom.Document)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4