Search in sources :

Example 21 with ESuccess

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nullable(javax.annotation.Nullable)

Example 22 with ESuccess

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

Example 23 with ESuccess

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;
}
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 24 with ESuccess

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 25 with ESuccess

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) LoggerFactory(org.slf4j.LoggerFactory) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) AbstractPhotonMapBasedWALDAO(com.helger.photon.app.dao.AbstractPhotonMapBasedWALDAO) CallbackList(com.helger.commons.callback.CallbackList) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) Nonempty(com.helger.commons.annotation.Nonempty) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) DAOException(com.helger.dao.DAOException) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) 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