Search in sources :

Example 6 with SMPBusinessCard

use of com.helger.phoss.smp.domain.businesscard.SMPBusinessCard in project phoss-smp by phax.

the class SMPBusinessCardManagerJDBC method getAllSMPBusinessCards.

@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPBusinessCard> getAllSMPBusinessCards() {
    final ICommonsList<ISMPBusinessCard> ret = new CommonsArrayList<>();
    final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT id, pid, name, country, geoinfo, identifiers, websites, contacts, addon, regdate" + " FROM smp_bce");
    if (aDBResult != null) {
        final IIdentifierFactory aIF = SMPMetaManager.getIdentifierFactory();
        // Group by ID
        final ICommonsMap<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntityMap = new CommonsHashMap<>();
        for (final DBResultRow aRow : aDBResult) {
            final SMPBusinessCardEntity aEntity = new SMPBusinessCardEntity(aRow.getAsString(0));
            // Single name only
            aEntity.names().add(new SMPBusinessCardName(aRow.getAsString(2), null));
            aEntity.setCountryCode(aRow.getAsString(3));
            aEntity.setGeographicalInformation(aRow.getAsString(4));
            aEntity.identifiers().setAll(getJsonAsBCI(aRow.getAsString(5)));
            aEntity.websiteURIs().setAll(getJsonAsString(aRow.getAsString(6)));
            aEntity.contacts().setAll(getJsonAsBCC(aRow.getAsString(7)));
            aEntity.setAdditionalInformation(aRow.getAsString(8));
            aEntity.setRegistrationDate(aRow.get(9).getAsLocalDate());
            aEntityMap.computeIfAbsent(aIF.parseParticipantIdentifier(aRow.getAsString(1)), k -> new CommonsArrayList<>()).add(aEntity);
        }
        // Convert
        for (final Map.Entry<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntry : aEntityMap.entrySet()) {
            final IParticipantIdentifier aPID = aEntry.getKey();
            ret.add(new SMPBusinessCard(aPID, aEntry.getValue()));
        }
    }
    return ret;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) LoggerFactory(org.slf4j.LoggerFactory) IJsonObject(com.helger.json.IJsonObject) EChange(com.helger.commons.state.EChange) IJsonWriterSettings(com.helger.json.serialize.IJsonWriterSettings) Supplier(java.util.function.Supplier) JsonWriterSettings(com.helger.json.serialize.JsonWriterSettings) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) CallbackList(com.helger.commons.callback.CallbackList) JsonArray(com.helger.json.JsonArray) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) JsonReader(com.helger.json.serialize.JsonReader) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) Collection(java.util.Collection) JsonObject(com.helger.json.JsonObject) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) List(java.util.List) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJson(com.helger.json.IJson) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Map(java.util.Map) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 7 with SMPBusinessCard

use of com.helger.phoss.smp.domain.businesscard.SMPBusinessCard in project phoss-smp by phax.

the class SMPBusinessCardManagerXML method deleteSMPBusinessCard.

@Nonnull
public EChange deleteSMPBusinessCard(@Nullable final ISMPBusinessCard aSMPBusinessCard) {
    if (aSMPBusinessCard == null)
        return EChange.UNCHANGED;
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPBusinessCard (" + aSMPBusinessCard.getID() + ")");
    m_aRWLock.writeLock().lock();
    try {
        final SMPBusinessCard aRealBusinessCard = internalDeleteItem(aSMPBusinessCard.getID());
        if (aRealBusinessCard == null) {
            AuditHelper.onAuditDeleteFailure(SMPBusinessCard.OT, aSMPBusinessCard.getID(), "no-such-id");
            return EChange.UNCHANGED;
        }
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditDeleteSuccess(SMPBusinessCard.OT, aSMPBusinessCard.getID(), Integer.valueOf(aSMPBusinessCard.getEntityCount()));
    // Invoke generic callbacks
    m_aCBs.forEach(x -> x.onSMPBusinessCardDeleted(aSMPBusinessCard));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPBusinessCard successful");
    return EChange.CHANGED;
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)7 SMPBusinessCard (com.helger.phoss.smp.domain.businesscard.SMPBusinessCard)7 Nonnull (javax.annotation.Nonnull)5 SMPBusinessCardEntity (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)3 Nullable (javax.annotation.Nullable)3 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 MutableBoolean (com.helger.commons.mutable.MutableBoolean)2 ESuccess (com.helger.commons.state.ESuccess)2 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)2 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 SMPBusinessCardName (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)1 CallbackList (com.helger.commons.callback.CallbackList)1 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)1 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)1 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1