Search in sources :

Example 1 with SMPBusinessCard

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

the class SMPBusinessCardManagerMongoDB method toDomain.

@Nonnull
@ReturnsMutableCopy
public SMPBusinessCard toDomain(@Nonnull final Document aDoc) {
    final IParticipantIdentifier aParticipantID = m_aIdentifierFactory.parseParticipantIdentifier(aDoc.getString(BSON_SERVICE_GROUP_ID));
    final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
    final List<Document> aEntityList = aDoc.getList(BSON_ENTITIES, Document.class);
    if (aEntityList != null)
        for (final Document aItemDoc : aEntityList) aEntities.add(toBCEntity(aItemDoc));
    return new SMPBusinessCard(aParticipantID, aEntities);
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) Document(org.bson.Document) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with SMPBusinessCard

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

the class SMPBusinessCardManagerMongoDB method createOrUpdateSMPBusinessCard.

@Nonnull
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 ISMPBusinessCard aOldBusinessCard = getSMPBusinessCardOfID(aParticipantID);
    final SMPBusinessCard aNewBusinessCard = new SMPBusinessCard(aParticipantID, aEntities);
    if (aOldBusinessCard != null) {
        // Reuse old ID
        _updateSMPBusinessCard(aNewBusinessCard);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("createOrUpdateSMPBusinessCard update successful");
    } else {
        // Create new ID
        _createSMPBusinessCard(aNewBusinessCard);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("createOrUpdateSMPBusinessCard create successful");
    }
    // Invoke generic callbacks
    m_aCBs.forEach(x -> x.onSMPBusinessCardCreatedOrUpdated(aNewBusinessCard));
    return aNewBusinessCard;
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 3 with SMPBusinessCard

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

the class SMPBusinessCardManagerXML method createOrUpdateSMPBusinessCard.

@Nonnull
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 ISMPBusinessCard aOldBusinessCard = getSMPBusinessCardOfID(aParticipantID);
    final SMPBusinessCard aNewBusinessCard = new SMPBusinessCard(aParticipantID, aEntities);
    if (aOldBusinessCard != null) {
        // Reuse old ID
        _updateSMPBusinessCard(aNewBusinessCard);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("createOrUpdateSMPBusinessCard update successful");
    } else {
        // Create new ID
        _createSMPBusinessCard(aNewBusinessCard);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("createOrUpdateSMPBusinessCard create successful");
    }
    // Invoke generic callbacks
    m_aCBs.forEach(x -> x.onSMPBusinessCardCreatedOrUpdated(aNewBusinessCard));
    return aNewBusinessCard;
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 4 with SMPBusinessCard

use of com.helger.phoss.smp.domain.businesscard.SMPBusinessCard 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 5 with SMPBusinessCard

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

the class SMPBusinessCardManagerJDBC method getSMPBusinessCardOfID.

@Nullable
public ISMPBusinessCard getSMPBusinessCardOfID(@Nullable final IParticipantIdentifier aID) {
    if (aID == null)
        return null;
    final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT id, name, country, geoinfo, identifiers, websites, contacts, addon, regdate" + " FROM smp_bce" + " WHERE pid=?", new ConstantPreparedStatementDataProvider(aID.getURIEncoded()));
    if (aDBResult == null)
        return null;
    if (aDBResult.isEmpty())
        return null;
    final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
    for (final DBResultRow aRow : aDBResult) {
        final SMPBusinessCardEntity aEntity = new SMPBusinessCardEntity(aRow.getAsString(0));
        // Single name only
        aEntity.names().add(new SMPBusinessCardName(aRow.getAsString(1), null));
        aEntity.setCountryCode(aRow.getAsString(2));
        aEntity.setGeographicalInformation(aRow.getAsString(3));
        aEntity.identifiers().setAll(getJsonAsBCI(aRow.getAsString(4)));
        aEntity.websiteURIs().setAll(getJsonAsString(aRow.getAsString(5)));
        aEntity.contacts().setAll(getJsonAsBCC(aRow.getAsString(6)));
        aEntity.setAdditionalInformation(aRow.getAsString(7));
        aEntity.setRegistrationDate(aRow.get(8).getAsLocalDate());
        aEntities.add(aEntity);
    }
    return new SMPBusinessCard(aID, aEntities);
}
Also used : DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nullable(javax.annotation.Nullable)

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