Search in sources :

Example 1 with SMPBusinessCardName

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

the class PageSecureBusinessCard method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPBusinessCard aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bEdit = eFormAction.isEdit();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    final String sServiceGroupID = bEdit ? aSelectedObject.getID() : aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
    ISMPServiceGroup aServiceGroup = null;
    final ICommonsList<SMPBusinessCardEntity> aSMPEntities = new CommonsArrayList<>();
    // validations
    if (StringHelper.hasNoText(sServiceGroupID))
        aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A Service Group must be selected!");
    else {
        aServiceGroup = aServiceGroupManager.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
        if (aServiceGroup == null)
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided Service Group does not exist!");
        else if (!bEdit) {
            final ISMPBusinessCard aExistingBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroup.getParticipantIdentifier());
            if (aExistingBusinessCard != null)
                aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The selected Service Group already has a Business Card assigned!");
        }
    }
    final IRequestParamMap aEntities = aWPEC.getRequestParamMap().getMap(PREFIX_ENTITY);
    if (aEntities != null)
        for (final String sEntityRowID : aEntities.keySet()) {
            final ICommonsMap<String, String> aEntityRow = aEntities.getValueMap(sEntityRowID);
            final int nErrors = aFormErrors.size();
            // Entity name
            final String sFieldName = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_NAME);
            final String sEntityName = aEntityRow.get(SUFFIX_NAME);
            if (StringHelper.hasNoText(sEntityName))
                aFormErrors.addFieldError(sFieldName, "The Name of the Entity must be provided!");
            // Entity country code
            final String sFieldCountryCode = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_COUNTRY_CODE);
            final String sCountryCode = aEntityRow.get(SUFFIX_COUNTRY_CODE);
            if (StringHelper.hasNoText(sCountryCode))
                aFormErrors.addFieldError(sFieldCountryCode, "The Country Code of the Entity must be provided!");
            // Entity Geographical Information
            final String sGeoInfo = aEntityRow.get(SUFFIX_GEO_INFO);
            // Entity Identifiers
            final ICommonsList<SMPBusinessCardIdentifier> aSMPIdentifiers = new CommonsArrayList<>();
            final IRequestParamMap aIdentifiers = aEntities.getMap(sEntityRowID, PREFIX_IDENTIFIER);
            if (aIdentifiers != null)
                for (final String sIdentifierRowID : aIdentifiers.keySet()) {
                    final ICommonsMap<String, String> aIdentifierRow = aIdentifiers.getValueMap(sIdentifierRowID);
                    final int nErrors2 = aFormErrors.size();
                    // Scheme
                    final String sFieldScheme = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_SCHEME);
                    final String sScheme = aIdentifierRow.get(SUFFIX_SCHEME);
                    if (StringHelper.hasNoText(sScheme))
                        aFormErrors.addFieldError(sFieldScheme, "The Scheme of the Identifier must be provided!");
                    // Value
                    final String sFieldValue = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_VALUE);
                    final String sValue = aIdentifierRow.get(SUFFIX_VALUE);
                    if (StringHelper.hasNoText(sValue))
                        aFormErrors.addFieldError(sFieldValue, "The Value of the Identifier must be provided!");
                    if (aFormErrors.size() == nErrors2) {
                        final boolean bIsNewIdentifier = sIdentifierRowID.startsWith(TMP_ID_PREFIX);
                        aSMPIdentifiers.add(bIsNewIdentifier ? new SMPBusinessCardIdentifier(sScheme, sValue) : new SMPBusinessCardIdentifier(sIdentifierRowID, sScheme, sValue));
                    }
                }
            aSMPIdentifiers.sort((o1, o2) -> {
                int ret = o1.getScheme().compareToIgnoreCase(o2.getScheme());
                if (ret == 0)
                    ret = o1.getValue().compareToIgnoreCase(o2.getValue());
                return ret;
            });
            // Entity Website URIs
            final String sFieldWebsiteURIs = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_WEBSITE_URIS);
            final String sWebsiteURIs = aEntityRow.get(SUFFIX_WEBSITE_URIS);
            final ICommonsList<String> aWebsiteURIs = new CommonsArrayList<>();
            for (final String sWebsiteURI : RegExHelper.getSplitToArray(sWebsiteURIs, "\\n")) {
                final String sRealWebsiteURI = sWebsiteURI.trim();
                if (sRealWebsiteURI.length() > 0)
                    if (URLValidator.isValid(sRealWebsiteURI))
                        aWebsiteURIs.add(sRealWebsiteURI);
                    else
                        aFormErrors.addFieldError(sFieldWebsiteURIs, "The website URI '" + sRealWebsiteURI + "' is invalid!");
            }
            // Entity Contacts
            final ICommonsList<SMPBusinessCardContact> aSMPContacts = new CommonsArrayList<>();
            final IRequestParamMap aContacts = aEntities.getMap(sEntityRowID, PREFIX_CONTACT);
            if (aContacts != null)
                for (final String sContactRowID : aContacts.keySet()) {
                    final ICommonsMap<String, String> aContactRow = aContacts.getValueMap(sContactRowID);
                    final int nErrors2 = aFormErrors.size();
                    final String sType = aContactRow.get(SUFFIX_TYPE);
                    final String sName = aContactRow.get(SUFFIX_NAME);
                    final String sPhoneNumber = aContactRow.get(SUFFIX_PHONE);
                    final String sFieldEmail = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_CONTACT, sContactRowID, SUFFIX_EMAIL);
                    final String sEmail = aContactRow.get(SUFFIX_EMAIL);
                    if (StringHelper.hasText(sEmail))
                        if (!EmailAddressValidator.isValid(sEmail))
                            aFormErrors.addFieldError(sFieldEmail, "The provided email address is invalid!");
                    final boolean bIsAnySet = StringHelper.hasText(sType) || StringHelper.hasText(sName) || StringHelper.hasText(sPhoneNumber) || StringHelper.hasText(sEmail);
                    if (aFormErrors.size() == nErrors2 && bIsAnySet) {
                        final boolean bIsNewContact = sContactRowID.startsWith(TMP_ID_PREFIX);
                        aSMPContacts.add(bIsNewContact ? new SMPBusinessCardContact(sType, sName, sPhoneNumber, sEmail) : new SMPBusinessCardContact(sContactRowID, sType, sName, sPhoneNumber, sEmail));
                    }
                }
            aSMPContacts.sort((o1, o2) -> {
                int ret = CompareHelper.compareIgnoreCase(o1.getType(), o2.getType());
                if (ret == 0) {
                    ret = CompareHelper.compareIgnoreCase(o1.getName(), o2.getName());
                    if (ret == 0) {
                        ret = CompareHelper.compareIgnoreCase(o1.getPhoneNumber(), o2.getPhoneNumber());
                        if (ret == 0)
                            ret = CompareHelper.compareIgnoreCase(o1.getEmail(), o2.getEmail());
                    }
                }
                return ret;
            });
            // Entity Additional Information
            final String sAdditionalInfo = aEntityRow.get(SUFFIX_ADDITIONAL_INFO);
            // Entity Registration Date
            final String sFieldRegDate = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_REG_DATE);
            final String sRegDate = aEntityRow.get(SUFFIX_REG_DATE);
            final LocalDate aRegDate = PDTFromString.getLocalDateFromString(sRegDate, aDisplayLocale);
            if (aRegDate == null && StringHelper.hasText(sRegDate))
                aFormErrors.addFieldError(sFieldRegDate, "The entered registration date is invalid!");
            if (aFormErrors.size() == nErrors) {
                // Add to list
                final boolean bIsNewEntity = sEntityRowID.startsWith(TMP_ID_PREFIX);
                final SMPBusinessCardEntity aEntity = bIsNewEntity ? new SMPBusinessCardEntity() : new SMPBusinessCardEntity(sEntityRowID);
                aEntity.names().add(new SMPBusinessCardName(sEntityName, null));
                aEntity.setCountryCode(sCountryCode);
                aEntity.setGeographicalInformation(sGeoInfo);
                aEntity.identifiers().setAll(aSMPIdentifiers);
                aEntity.websiteURIs().setAll(aWebsiteURIs);
                aEntity.contacts().setAll(aSMPContacts);
                aEntity.setAdditionalInformation(sAdditionalInfo);
                aEntity.setRegistrationDate(aRegDate);
                aSMPEntities.add(aEntity);
            }
        }
    if (aSMPEntities.isEmpty())
        if (aFormErrors.isEmpty())
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "At least one entity must be provided.");
    if (aFormErrors.isEmpty()) {
        // Store in a consistent manner
        aSMPEntities.sort((o1, o2) -> o1.names().getFirst().getName().compareToIgnoreCase(o2.names().getFirst().getName()));
        if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aSMPEntities) != null) {
            final ISMPSettings aSettings = SMPMetaManager.getSettings();
            aWPEC.postRedirectGetInternal(success("The Business Card for Service Group '" + aServiceGroup.getID() + "' was successfully saved." + (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate() ? " " + SMPWebAppConfiguration.getDirectoryName() + " server should have been updated." : "")));
        } else
            aWPEC.postRedirectGetInternal(error("Error creating the Business Card for Service Group '" + aServiceGroup.getID() + "'"));
    }
}
Also used : Locale(java.util.Locale) GlobalIDFactory(com.helger.commons.id.factory.GlobalIDFactory) ILayoutExecutionContext(com.helger.photon.core.execcontext.ILayoutExecutionContext) PDClientProvider(com.helger.phoss.smp.app.PDClientProvider) EWithDeprecated(com.helger.photon.uicore.html.select.HCCountrySelect.EWithDeprecated) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) Nonempty(com.helger.commons.annotation.Nonempty) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) HCA(com.helger.html.hc.html.textlevel.HCA) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) CPageParam(com.helger.photon.uicore.css.CPageParam) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) IHCCell(com.helger.html.hc.html.tabular.IHCCell) HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCTextNode(com.helger.html.hc.impl.HCTextNode) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCExtHelper(com.helger.html.hc.ext.HCExtHelper) RegExHelper(com.helger.commons.regex.RegExHelper) IValidityIndicator(com.helger.commons.state.IValidityIndicator) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) RequestParamMap(com.helger.servlet.request.RequestParamMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) JSJQueryHelper(com.helger.photon.uicore.js.JSJQueryHelper) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) DataTables(com.helger.photon.uictrls.datatables.DataTables) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) LinkHelper(com.helger.photon.app.url.LinkHelper) JSAssocArray(com.helger.html.jscode.JSAssocArray) BootstrapDateTimePicker(com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker) PDTFromString(com.helger.commons.datetime.PDTFromString) HCEdit(com.helger.html.hc.html.forms.HCEdit) IHCNode(com.helger.html.hc.IHCNode) JQuery(com.helger.html.jquery.JQuery) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) Nullable(javax.annotation.Nullable) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) StringHelper(com.helger.commons.string.StringHelper) WorkInProgress(com.helger.commons.annotation.WorkInProgress) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) BootstrapFormHelper(com.helger.photon.bootstrap4.form.BootstrapFormHelper) CAjax(com.helger.phoss.smp.ui.ajax.CAjax) HCA_MailTo(com.helger.html.hc.ext.HCA_MailTo) HCCol(com.helger.html.hc.html.tabular.HCCol) RequestField(com.helger.photon.core.form.RequestField) AbstractBootstrapWebPageActionHandler(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandler) ESortOrder(com.helger.commons.compare.ESortOrder) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) JSVar(com.helger.html.jscode.JSVar) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) BootstrapSuccessBox(com.helger.photon.bootstrap4.alert.BootstrapSuccessBox) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) EmailAddressValidator(com.helger.smtp.util.EmailAddressValidator) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) BootstrapErrorBox(com.helger.photon.bootstrap4.alert.BootstrapErrorBox) HCCountrySelect(com.helger.photon.uicore.html.select.HCCountrySelect) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) IAjaxFunctionDeclaration(com.helger.photon.ajax.decl.IAjaxFunctionDeclaration) PDClient(com.helger.pd.client.PDClient) CountryCache(com.helger.commons.locale.country.CountryCache) EFamFamIcon(com.helger.photon.uictrls.famfam.EFamFamIcon) LocalDate(java.time.LocalDate) SMPWebAppConfiguration(com.helger.phoss.smp.app.SMPWebAppConfiguration) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ESuccess(com.helger.commons.state.ESuccess) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) PhotonUnifiedResponse(com.helger.photon.app.PhotonUnifiedResponse) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) CompareHelper(com.helger.commons.compare.CompareHelper) URLValidator(com.helger.commons.url.URLValidator) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) CBootstrapCSS(com.helger.photon.bootstrap4.CBootstrapCSS) HCTable(com.helger.html.hc.html.tabular.HCTable) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) EBootstrapButtonSize(com.helger.photon.bootstrap4.button.EBootstrapButtonSize) EShowList(com.helger.photon.uicore.page.EShowList) EFamFamFlagIcon(com.helger.photon.uictrls.famfam.EFamFamFlagIcon) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) JSPackage(com.helger.html.jscode.JSPackage) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) LocalDate(java.time.LocalDate) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 2 with SMPBusinessCardName

use of com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName 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)

Example 3 with SMPBusinessCardName

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

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

the class SMPBusinessCardManagerMongoDB method toBson.

@Nonnull
@ReturnsMutableCopy
public static Document toBson(@Nonnull final SMPBusinessCardEntity aValue) {
    final Document ret = new Document().append(BSON_ID, aValue.getID());
    // Mandatory fields
    {
        final ICommonsList<Document> aNames = new CommonsArrayList<>();
        for (final SMPBusinessCardName aName : aValue.names()) aNames.add(toBson(aName));
        ret.append(BSON_NAMES, aNames);
    }
    ret.append(BSON_COUNTRYCODE, aValue.getCountryCode());
    // Optional fields
    if (aValue.hasGeographicalInformation())
        ret.append(BSON_GEOINFO, aValue.getGeographicalInformation());
    {
        final ICommonsList<Document> aIDs = new CommonsArrayList<>();
        for (final SMPBusinessCardIdentifier aID : aValue.identifiers()) aIDs.add(toBson(aID));
        if (aIDs.isNotEmpty())
            ret.append(BSON_IDS, aIDs);
    }
    if (aValue.websiteURIs().isNotEmpty())
        ret.append(BSON_WEBSITES, aValue.websiteURIs());
    {
        final ICommonsList<Document> aContacts = new CommonsArrayList<>();
        for (final SMPBusinessCardContact aContact : aValue.contacts()) aContacts.add(toBson(aContact));
        if (aContacts.isNotEmpty())
            ret.append(BSON_CONTACTS, aContacts);
    }
    if (aValue.hasAdditionalInformation())
        ret.append(BSON_ADDITIONAL, aValue.getAdditionalInformation());
    if (aValue.hasRegistrationDate())
        ret.append(BSON_REGDATE, TypeConverter.convert(aValue.getRegistrationDate(), Date.class));
    return ret;
}
Also used : SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) Document(org.bson.Document) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Aggregations

CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 SMPBusinessCardName (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName)3 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)2 ESuccess (com.helger.commons.state.ESuccess)2 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)2 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)2 ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)2 SMPBusinessCard (com.helger.phoss.smp.domain.businesscard.SMPBusinessCard)2 SMPBusinessCardContact (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact)2 SMPBusinessCardEntity (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity)2 SMPBusinessCardIdentifier (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)1