Search in sources :

Example 1 with ISMPBusinessCard

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

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

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

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

the class PageSecureServiceGroup method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bShowExtensionDetails = SMPWebAppConfiguration.isServiceGroupsExtensionsShow();
    final boolean bShowBusinessCardName = CSMP.ENABLE_ISSUE_56 && aSettings.isDirectoryIntegrationEnabled();
    final ICommonsList<ISMPServiceGroup> aAllServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Service group", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    if (aSettings.isSMLRequired() || aSettings.isSMLEnabled()) {
        // Disable button if no SML URL is configured
        // Disable button if no service group is present
        aToolbar.addAndReturnButton("Check DNS state", aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_CHECK_DNS), EDefaultIcon.MAGNIFIER).setDisabled(aSettings.getSMLDNSZone() == null || aAllServiceGroups.isEmpty() || !aSettings.isSMLEnabled());
    }
    aNodeList.addChild(aToolbar);
    final boolean bShowDetails = aAllServiceGroups.size() <= 1000;
    final HCTable aTable = new HCTable(new DTCol("Participant ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Owner"), bShowBusinessCardName ? new DTCol("Business Card Name") : null, new DTCol(span(bShowExtensionDetails ? "Ext" : "Ext?").setTitle("Is an Extension present?")), bShowDetails ? new DTCol(span("Docs").setTitle("Number of assigned document types")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("Procs").setTitle("Number of assigned processes")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, bShowDetails ? new DTCol(span("EPs").setTitle("Number of assigned endpoints")).setDisplayType(EDTColType.INT, aDisplayLocale) : null, new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMPServiceGroup aCurObject : aAllServiceGroups) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final String sDisplayName = aCurObject.getParticipantIdentifier().getURIEncoded();
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(sDisplayName));
        aRow.addCell(SMPCommonUI.getOwnerName(aCurObject.getOwnerID()));
        if (bShowBusinessCardName) {
            IHCNode aName = null;
            final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup(aCurObject);
            if (aBC != null) {
                final SMPBusinessCardEntity aEntity = aBC.getEntityAtIndex(0);
                if (aEntity != null && aEntity.names().isNotEmpty())
                    aName = HCTextNode.createOnDemand(aEntity.names().getFirst().getName());
            }
            aRow.addCell(aName);
        }
        if (bShowExtensionDetails) {
            if (aCurObject.extensions().isNotEmpty())
                aRow.addCell(new HCCode().addChildren(HCExtHelper.nl2divList(aCurObject.getFirstExtensionXML())));
            else
                aRow.addCell();
        } else {
            aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.extensions().isNotEmpty(), aDisplayLocale));
        }
        if (bShowDetails) {
            int nProcesses = 0;
            int nEndpoints = 0;
            final ICommonsList<ISMPServiceInformation> aSIs = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aCurObject);
            for (final ISMPServiceInformation aSI : aSIs) {
                nProcesses += aSI.getProcessCount();
                nEndpoints += aSI.getTotalEndpointCount();
            }
            aRow.addCell(Integer.toString(aSIs.size()));
            aRow.addCell(Integer.toString(nProcesses));
            aRow.addCell(Integer.toString(nEndpoints));
        }
        final HCNodeList aActions = new HCNodeList();
        aActions.addChildren(createEditLink(aWPEC, aCurObject, "Edit " + sDisplayName), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + sDisplayName), new HCTextNode(" "), createDeleteLink(aWPEC, aCurObject, "Delete " + sDisplayName), new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext(aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
        if (eRESTType.isCompleteServiceGroupSupported()) {
            aActions.addChildren(new HCTextNode(" "), new HCA(LinkHelper.getURLWithServerAndContext("complete/" + aCurObject.getParticipantIdentifier().getURIPercentEncoded())).setTitle("Perform complete SMP query on " + sDisplayName).setTargetBlank().addChild(EFamFamIcon.SCRIPT_LINK.getAsNode()));
        }
        aRow.addCell(aActions);
    }
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aTable).addChild(aDataTables);
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCRow(com.helger.html.hc.html.tabular.HCRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCCode(com.helger.html.hc.html.textlevel.HCCode) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCTable(com.helger.html.hc.html.tabular.HCTable) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode)

Example 5 with ISMPBusinessCard

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

the class PageSecureServiceGroup method showSelectedObject.

@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final ISMPServiceGroup aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final boolean bShowBusinessCard = CSMP.ENABLE_ISSUE_56 && aSettings.isDirectoryIntegrationEnabled();
    aNodeList.addChild(getUIHandler().createActionHeader("Show details of service group '" + aSelectedObject.getID() + "'"));
    final BootstrapViewForm aForm = new BootstrapViewForm();
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Participant ID").setCtrl(aSelectedObject.getParticipantIdentifier().getURIEncoded()));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Owning user").setCtrl(SMPCommonUI.getOwnerName(aSelectedObject.getOwnerID())));
    if (aSelectedObject.extensions().isNotEmpty())
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(SMPCommonUI.getExtensionDisplay(aSelectedObject)));
    if (bShowBusinessCard) {
        aForm.addChild(getUIHandler().createDataGroupHeader("Business Card Details"));
        final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
        final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup(aSelectedObject);
        if (aBC != null) {
            int nIndex = 0;
            for (final SMPBusinessCardEntity aEntity : aBC.getAllEntities()) {
                ++nIndex;
                aForm.addChild(PageSecureBusinessCard.showBusinessCardEntity(aEntity, nIndex, aDisplayLocale));
            }
        }
    }
    aNodeList.addChild(aForm);
}
Also used : Locale(java.util.Locale) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup)

Aggregations

ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)19 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)14 Nonnull (javax.annotation.Nonnull)10 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 SMPBusinessCardEntity (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity)8 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)8 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)6 SMPBusinessCard (com.helger.phoss.smp.domain.businesscard.SMPBusinessCard)6 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)6 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)6 HCNodeList (com.helger.html.hc.impl.HCNodeList)5 SMPMetaManager (com.helger.phoss.smp.domain.SMPMetaManager)5 Nullable (javax.annotation.Nullable)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)4 ISimpleURL (com.helger.commons.url.ISimpleURL)4 HCRow (com.helger.html.hc.html.tabular.HCRow)4 HCTable (com.helger.html.hc.html.tabular.HCTable)4 HCA (com.helger.html.hc.html.textlevel.HCA)4 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)4