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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations