Search in sources :

Example 1 with SMPTransportProfile

use of com.helger.peppol.smp.SMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerJDBC method getSMPTransportProfileOfID.

@Nullable
public ISMPTransportProfile getSMPTransportProfileOfID(@Nullable final String sID) {
    if (StringHelper.hasNoText(sID))
        return null;
    final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
    newExecutor().querySingle("SELECT name, deprecated FROM smp_tprofile WHERE id=?", new ConstantPreparedStatementDataProvider(sID), aDBResult::set);
    if (aDBResult.isNotSet())
        return null;
    final DBResultRow aRow = aDBResult.get();
    return new SMPTransportProfile(sID, aRow.getAsString(0), aRow.getAsBoolean(1, SMPTransportProfile.DEFAULT_DEPRECATED));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 2 with SMPTransportProfile

use of com.helger.peppol.smp.SMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerXML method createSMPTransportProfile.

@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    // Double ID needs to be taken care of
    if (containsWithID(sID))
        return null;
    final SMPTransportProfile aSMPTransportProfile = new SMPTransportProfile(sID, sName, bIsDeprecated);
    m_aRWLock.writeLocked(() -> {
        internalCreateItem(aSMPTransportProfile);
    });
    AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
    return aSMPTransportProfile;
}
Also used : ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 3 with SMPTransportProfile

use of com.helger.peppol.smp.SMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerMongoDB method createSMPTransportProfile.

@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    // Double ID needs to be taken care of
    if (containsSMPTransportProfileWithID(sID))
        return null;
    final SMPTransportProfile aSMPTransportProfile = new SMPTransportProfile(sID, sName, bIsDeprecated);
    if (!getCollection().insertOne(toBson(aSMPTransportProfile)).wasAcknowledged())
        throw new IllegalStateException("Failed to insert into MongoDB Collection");
    AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
    return aSMPTransportProfile;
}
Also used : ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 4 with SMPTransportProfile

use of com.helger.peppol.smp.SMPTransportProfile 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 5 with SMPTransportProfile

use of com.helger.peppol.smp.SMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerXML method updateSMPTransportProfile.

@Nonnull
public EChange updateSMPTransportProfile(@Nullable final String sSMPTransportProfileID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    final SMPTransportProfile aSMPTransportProfile = getOfID(sSMPTransportProfileID);
    if (aSMPTransportProfile == null) {
        AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "set-all", sSMPTransportProfileID, "no-such-id");
        return EChange.UNCHANGED;
    }
    m_aRWLock.writeLock().lock();
    try {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aSMPTransportProfile.setName(sName));
        eChange = eChange.or(aSMPTransportProfile.setDeprecated(bIsDeprecated));
        if (eChange.isUnchanged())
            return EChange.UNCHANGED;
        internalUpdateItem(aSMPTransportProfile);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditModifySuccess(SMPTransportProfile.OT, "set-all", sSMPTransportProfileID, sName, Boolean.valueOf(bIsDeprecated));
    return EChange.CHANGED;
}
Also used : EChange(com.helger.commons.state.EChange) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)6 SMPTransportProfile (com.helger.peppol.smp.SMPTransportProfile)6 Nullable (javax.annotation.Nullable)4 ESMPTransportProfile (com.helger.peppol.smp.ESMPTransportProfile)3 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)2 Nonnull (javax.annotation.Nonnull)2 EChange (com.helger.commons.state.EChange)1 ESuccess (com.helger.commons.state.ESuccess)1 Wrapper (com.helger.commons.wrapper.Wrapper)1 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)1 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)1