Search in sources :

Example 1 with HCUL

use of com.helger.html.hc.html.grouping.HCUL in project phoss-directory by phax.

the class PDCommonUI method showBusinessInfoDetails.

@Nonnull
public static BootstrapViewForm showBusinessInfoDetails(@Nonnull final PDStoredBusinessEntity aStoredDoc, @Nonnull final Locale aDisplayLocale) {
    final BootstrapViewForm aViewForm = new BootstrapViewForm();
    if (aStoredDoc.hasCountryCode()) {
        final HCNodeList aCountryCtrl = new HCNodeList();
        final String sCountryCode = aStoredDoc.getCountryCode();
        aCountryCtrl.addChild(getFlagNode(sCountryCode));
        final Locale aCountry = CountryCache.getInstance().getCountry(sCountryCode);
        if (aCountry != null)
            aCountryCtrl.addChild(" " + aCountry.getDisplayCountry(aDisplayLocale) + " [" + sCountryCode + "]");
        else
            aCountryCtrl.addChild(" " + sCountryCode);
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Country").setCtrl(aCountryCtrl));
    }
    if (aStoredDoc.names().isNotEmpty()) {
        final ICommonsList<PDStoredMLName> aNames = getUIFilteredNames(aStoredDoc.names(), aDisplayLocale);
        IHCNode aNameCtrl;
        if (aNames.size() == 1)
            aNameCtrl = getMLNameNode(aNames.getFirst(), aDisplayLocale);
        else {
            final HCUL aNameUL = new HCUL();
            aNames.forEach(x -> aNameUL.addItem(getMLNameNode(x, aDisplayLocale)));
            aNameCtrl = aNameUL;
        }
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Entity Name").setCtrl(aNameCtrl));
    }
    if (aStoredDoc.hasGeoInfo())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Geographical information").setCtrl(HCExtHelper.nl2divList(aStoredDoc.getGeoInfo())));
    if (aStoredDoc.identifiers().isNotEmpty()) {
        final BootstrapTable aIDTable = new BootstrapTable(HCCol.star(), HCCol.star()).setStriped(true).setBordered(true).setCondensed(true);
        aIDTable.addHeaderRow().addCells("Scheme", "Value");
        for (final PDStoredIdentifier aStoredID : aStoredDoc.identifiers()) aIDTable.addBodyRow().addCells(aStoredID.getScheme(), aStoredID.getValue());
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional identifiers").setCtrl(aIDTable));
    }
    if (aStoredDoc.websiteURIs().isNotEmpty()) {
        final HCOL aOL = new HCOL();
        for (final String sWebsiteURI : aStoredDoc.websiteURIs()) aOL.addItem(HCA.createLinkedWebsite(sWebsiteURI, HC_Target.BLANK));
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Website URIs").setCtrl(aOL));
    }
    if (aStoredDoc.contacts().isNotEmpty()) {
        final BootstrapTable aContactTable = new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star()).setStriped(true).setBordered(true);
        aContactTable.addHeaderRow().addCells("Type", "Name", "Phone Number", "Email");
        for (final PDStoredContact aStoredContact : aStoredDoc.contacts()) aContactTable.addBodyRow().addCells(aStoredContact.getType(), aStoredContact.getName(), aStoredContact.getPhone(), aStoredContact.getEmail());
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Contacts").setCtrl(aContactTable));
    }
    if (aStoredDoc.hasAdditionalInformation())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional information").setCtrl(HCExtHelper.nl2divList(aStoredDoc.getAdditionalInformation())));
    if (aStoredDoc.hasRegistrationDate())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Registration date").setCtrl(PDTToString.getAsString(aStoredDoc.getRegistrationDate(), aDisplayLocale)));
    return aViewForm;
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) PDTToString(com.helger.commons.datetime.PDTToString) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) HCOL(com.helger.html.hc.html.grouping.HCOL) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) IHCNode(com.helger.html.hc.IHCNode) Nonnull(javax.annotation.Nonnull)

Example 2 with HCUL

use of com.helger.html.hc.html.grouping.HCUL in project phoss-smp by phax.

the class PageSecureEndpointTree method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new Endpoint", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
    aToolbar.addButton("List view", aWPEC.getLinkToMenuItem(CMenuSecure.MENU_ENDPOINT_LIST), EDefaultIcon.MAGNIFIER);
    aNodeList.addChild(aToolbar);
    // Create list of service groups
    final ICommonsMap<ISMPServiceGroup, ICommonsList<ISMPServiceInformation>> aMap = new CommonsHashMap<>();
    aServiceInfoMgr.getAllSMPServiceInformation().forEach(x -> aMap.computeIfAbsent(x.getServiceGroup(), k -> new CommonsArrayList<>()).add(x));
    final HCUL aULSG = new HCUL();
    final ICommonsList<ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups().getSortedInline(ISMPServiceGroup.comparator());
    for (final ISMPServiceGroup aServiceGroup : aServiceGroups) {
        // Print service group
        final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
        final HCLI aLISG = aULSG.addAndReturnItem(new HCA(createViewURL(aWPEC, CMenuSecure.MENU_SERVICE_GROUPS, aServiceGroup)).addChild(aParticipantID.getURIEncoded()));
        final HCUL aULDT = new HCUL();
        final ICommonsList<ISMPServiceInformation> aServiceInfos = aMap.get(aServiceGroup);
        if (aServiceInfos != null) {
            for (final ISMPServiceInformation aServiceInfo : aServiceInfos.getSortedInline(ISMPServiceInformation.comparator())) {
                final HCUL aULP = new HCUL();
                final IDocumentTypeIdentifier aDocTypeID = aServiceInfo.getDocumentTypeIdentifier();
                final ICommonsList<ISMPProcess> aProcesses = aServiceInfo.getAllProcesses().getSortedInline(ISMPProcess.comparator());
                for (final ISMPProcess aProcess : aProcesses) {
                    final BootstrapTable aEPTable = new BootstrapTable(HCCol.perc(40), HCCol.perc(40), HCCol.perc(20)).setBordered(true);
                    final ICommonsList<ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints().getSortedInline(ISMPEndpoint.comparator());
                    for (final ISMPEndpoint aEndpoint : aEndpoints) {
                        final StringMap aParams = createParamMap(aServiceInfo, aProcess, aEndpoint);
                        final HCRow aBodyRow = aEPTable.addBodyRow();
                        final String sTransportProfile = aEndpoint.getTransportProfile();
                        final ISimpleURL aViewURL = createViewURL(aWPEC, aServiceInfo, aParams);
                        aBodyRow.addCell(new HCA(aViewURL).addChild(NiceNameUI.getTransportProfile(sTransportProfile, false)));
                        aBodyRow.addCell(aEndpoint.getEndpointReference());
                        final ISimpleURL aEditURL = createEditURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aCopyURL = createCopyURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aDeleteURL = createDeleteURL(aWPEC, aServiceInfo).addAll(aParams);
                        final ISimpleURL aPreviewURL = LinkHelper.getURLWithServerAndContext(aParticipantID.getURIPercentEncoded() + SMPRestFilter.PATH_SERVICES + aDocTypeID.getURIPercentEncoded());
                        aBodyRow.addAndReturnCell(new HCA(aViewURL).setTitle("View endpoint").addChild(EDefaultIcon.MAGNIFIER.getAsNode()), new HCTextNode(" "), new HCA(aEditURL).setTitle("Edit endpoint").addChild(EDefaultIcon.EDIT.getAsNode()), new HCTextNode(" "), new HCA(aCopyURL).setTitle("Copy endpoint").addChild(EDefaultIcon.COPY.getAsNode()), new HCTextNode(" "), new HCA(aDeleteURL).setTitle("Delete endpoint").addChild(EDefaultIcon.DELETE.getAsNode()), new HCTextNode(" "), new HCA(aPreviewURL).setTitle("Perform SMP query on endpoint").setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode())).addClass(CSS_CLASS_RIGHT);
                    }
                    // Show process + endpoints
                    final HCLI aLI = aULP.addItem();
                    final HCDiv aDiv = div(NiceNameUI.getProcessID(aDocTypeID, aProcess.getProcessIdentifier(), false));
                    aLI.addChild(aDiv);
                    if (aEndpoints.isEmpty()) {
                        aDiv.addChild(" ").addChild(new HCA(aWPEC.getSelfHref().addAll(createParamMap(aServiceInfo, aProcess, (ISMPEndpoint) null)).add(CPageParam.PARAM_ACTION, ACTION_DELETE_PROCESS)).setTitle("Delete process").addChild(EDefaultIcon.DELETE.getAsNode()));
                    } else
                        aLI.addChild(aEPTable);
                }
                // Show document types + children
                final HCLI aLI = aULDT.addItem();
                final HCDiv aDiv = div().addChild(NiceNameUI.getDocumentTypeID(aServiceInfo.getDocumentTypeIdentifier(), false)).addChild(" ").addChild(new HCA(LinkHelper.getURLWithServerAndContext(aParticipantID.getURIPercentEncoded() + SMPRestFilter.PATH_SERVICES + aDocTypeID.getURIPercentEncoded())).setTitle("Perform SMP query on document type ").setTargetBlank().addChild(EFamFamIcon.SCRIPT_GO.getAsNode()));
                aLI.addChild(aDiv);
                if (aProcesses.isEmpty()) {
                    aDiv.addChild(" ").addChild(new HCA(aWPEC.getSelfHref().addAll(createParamMap(aServiceInfo, (ISMPProcess) null, (ISMPEndpoint) null)).add(CPageParam.PARAM_ACTION, ACTION_DELETE_DOCUMENT_TYPE)).setTitle("Delete document type").addChild(EDefaultIcon.DELETE.getAsNode()));
                } else
                    aLI.addChild(aULP);
            }
        }
        if (aServiceInfos == null || aServiceInfos.isEmpty() || aULDT.hasNoChildren())
            aLISG.addChild(" ").addChild(badgeInfo("This service group has no assigned endpoints!"));
        else
            aLISG.addChild(aULDT);
    }
    aNodeList.addChild(aULSG);
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) StringMap(com.helger.commons.collection.attr.StringMap) HCNodeList(com.helger.html.hc.impl.HCNodeList) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HCRow(com.helger.html.hc.html.tabular.HCRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISimpleURL(com.helger.commons.url.ISimpleURL) HCLI(com.helger.html.hc.html.grouping.HCLI) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) HCTextNode(com.helger.html.hc.impl.HCTextNode) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 3 with HCUL

use of com.helger.html.hc.html.grouping.HCUL in project phoss-smp by phax.

the class PageSecureServiceGroupImport method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final ICommonsSet<String> aAllServiceGroupIDs = aServiceGroupMgr.getAllSMPServiceGroupIDs();
    final ICommonsSet<String> aAllBusinessCardIDs = aBusinessCardMgr.getAllSMPBusinessCardIDs();
    final FormErrorList aFormErrors = new FormErrorList();
    final HCUL aImportResultUL = new HCUL();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        // Start import
        final IFileItem aImportFile = aWPEC.params().getAsFileItem(FIELD_IMPORT_FILE);
        final boolean bOverwriteExisting = aWPEC.params().isCheckBoxChecked(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING);
        final String sDefaultOwnerID = aWPEC.params().getAsString(FIELD_DEFAULT_OWNER);
        final IUser aDefaultOwner = aUserMgr.getActiveUserOfID(sDefaultOwnerID);
        if (aImportFile == null || aImportFile.getSize() == 0)
            aFormErrors.addFieldError(FIELD_IMPORT_FILE, "A file to import must be selected!");
        if (StringHelper.hasNoText(sDefaultOwnerID))
            aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A default owner must be selected!");
        else if (aDefaultOwner == null)
            aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A valid default owner must be selected!");
        if (aFormErrors.isEmpty()) {
            final SAXReaderSettings aSRS = new SAXReaderSettings();
            final IMicroDocument aDoc = MicroReader.readMicroXML(aImportFile, aSRS);
            if (aDoc == null || aDoc.getDocumentElement() == null)
                aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file is not a valid XML file!");
            else {
                // Start interpreting
                final String sVersion = aDoc.getDocumentElement().getAttributeValue(CSMPExchange.ATTR_VERSION);
                if (CSMPExchange.VERSION_10.equals(sVersion)) {
                    // Version 1.0
                    final ICommonsList<ImportActionItem> aActionList = new CommonsArrayList<>();
                    final ImportSummary aImportSummary = new ImportSummary();
                    ServiceGroupImport.importXMLVer10(aDoc.getDocumentElement(), bOverwriteExisting, aDefaultOwner, aAllServiceGroupIDs, aAllBusinessCardIDs, aActionList, aImportSummary);
                    for (final ImportActionItem aAction : aActionList) {
                        final IErrorLevel aErrorLevel = aAction.getErrorLevel();
                        final EBootstrapBadgeType eBadgeType;
                        if (aErrorLevel.isGE(EErrorLevel.ERROR))
                            eBadgeType = EBootstrapBadgeType.DANGER;
                        else if (aErrorLevel.isGE(EErrorLevel.WARN))
                            eBadgeType = EBootstrapBadgeType.WARNING;
                        else if (aErrorLevel.isGE(EErrorLevel.INFO))
                            eBadgeType = EBootstrapBadgeType.INFO;
                        else
                            eBadgeType = EBootstrapBadgeType.SUCCESS;
                        // By default is is centered
                        aImportResultUL.addItem(new BootstrapBadge(eBadgeType).addChild((aAction.hasParticipantID() ? "[" + aAction.getParticipantID() + "] " : "") + aAction.getMessage()).addChild(SMPCommonUI.getTechnicalDetailsUI(aAction.getLinkedException())).addClass(CBootstrapCSS.TEXT_LEFT));
                    }
                } else {
                    // Unsupported or no version present
                    if (sVersion == null)
                        aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file cannot be imported because it has the wrong layout.");
                    else
                        aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file contains the unsupported version '" + sVersion + "'.");
                }
            }
        }
    }
    final boolean bHandleBusinessCards = aSettings.isDirectoryIntegrationEnabled();
    if (aImportResultUL.hasChildren()) {
        final BootstrapCard aPanel = new BootstrapCard();
        aPanel.createAndAddHeader().addChild("Import results");
        aPanel.createAndAddBody().addChild(aImportResultUL);
        aNodeList.addChild(aPanel);
    }
    aNodeList.addChild(info("Import service groups incl. all endpoints" + (bHandleBusinessCards ? " and business cards" : "") + " from a file."));
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("File to import").setCtrl(new BootstrapFileUpload(FIELD_IMPORT_FILE, aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_IMPORT_FILE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Overwrite existing elements").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING))).setHelpText("If this box is checked, all existing endpoints etc. of a service group are deleted and new endpoints are created! If the " + SMPWebAppConfiguration.getDirectoryName() + " integration is enabled, existing business cards contained in the import are also overwritten!").setErrorList(aFormErrors.getListOfField(FIELD_OVERWRITE_EXISTING)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Owner of the new service groups").setCtrl(new HCUserSelect(new RequestField(FIELD_DEFAULT_OWNER), aDisplayLocale)).setHelpText("This owner is only selected, if the owner contained in the import file is unknown.").setErrorList(aFormErrors.getListOfField(FIELD_DEFAULT_OWNER)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addChild(new BootstrapSubmitButton().addChild("Import Service Groups").setIcon(EDefaultIcon.ADD));
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) IUserManager(com.helger.photon.security.user.IUserManager) ImportSummary(com.helger.phoss.smp.exchange.ImportSummary) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) FormErrorList(com.helger.photon.core.form.FormErrorList) ImportActionItem(com.helger.phoss.smp.exchange.ImportActionItem) SAXReaderSettings(com.helger.xml.serialize.read.SAXReaderSettings) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) IFileItem(com.helger.web.fileupload.IFileItem) IUser(com.helger.photon.security.user.IUser) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) RequestField(com.helger.photon.core.form.RequestField) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) BootstrapBadge(com.helger.photon.bootstrap4.badge.BootstrapBadge) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCUserSelect(com.helger.phoss.smp.ui.secure.hc.HCUserSelect) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCUL(com.helger.html.hc.html.grouping.HCUL) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) EBootstrapBadgeType(com.helger.photon.bootstrap4.badge.EBootstrapBadgeType) IErrorLevel(com.helger.commons.error.level.IErrorLevel) IMicroDocument(com.helger.xml.microdom.IMicroDocument) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 4 with HCUL

use of com.helger.html.hc.html.grouping.HCUL in project phoss-directory by phax.

the class PagePublicSearchSimple method _showResultList.

private void _showResultList(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull @Nonempty final String sQuery, @Nonnegative final int nMaxResults) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
    final PDStorageManager aStorageMgr = PDMetaManager.getStorageMgr();
    // Search all documents
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Searching generically for '" + sQuery + "'");
    // Build Lucene query
    Query aLuceneQuery = PDQueryManager.convertQueryStringToLuceneQuery(PDMetaManager.getLucene(), CPDStorage.FIELD_ALL_FIELDS, sQuery);
    aLuceneQuery = EQueryMode.NON_DELETED_ONLY.getEffectiveQuery(aLuceneQuery);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Created query for '" + sQuery + "' is <" + aLuceneQuery + ">");
    PDSessionSingleton.getInstance().setLastQuery(aLuceneQuery);
    // Search all documents
    final ICommonsList<PDStoredBusinessEntity> aResultBEs = aStorageMgr.getAllDocuments(aLuceneQuery, nMaxResults);
    // Also get the total hit count for UI display. May be < 0 in case of
    // error
    final int nTotalBEs = aStorageMgr.getCount(aLuceneQuery);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("  Result for <" + aLuceneQuery + "> (max=" + nMaxResults + ") " + (aResultBEs.size() == 1 ? "is 1 document" : "are " + aResultBEs.size() + " documents") + "." + (nTotalBEs >= 0 ? " " + nTotalBEs + " total hits are available." : ""));
    // Group by participant ID
    final ICommonsMap<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aGroupedBEs = PDStorageManager.getGroupedByParticipantID(aResultBEs);
    // Display results
    if (aGroupedBEs.isEmpty()) {
        aNodeList.addChild(info("No search results found for query '" + sQuery + "'"));
    } else {
        aNodeList.addChild(div(badgeSuccess("Found " + (aGroupedBEs.size() == 1 ? "1 entity" : aGroupedBEs.size() + " entities") + " matching '" + sQuery + "'")));
        if (nTotalBEs > nMaxResults) {
            aNodeList.addChild(div(badgeWarn("Found more entities than displayed (" + nTotalBEs + " entries exist). Try to be more specific.")));
        }
        // Show basic information
        final HCOL aOL = new HCOL().setStart(1);
        for (final Map.Entry<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aEntry : aGroupedBEs.entrySet()) {
            final IParticipantIdentifier aDocParticipantID = aEntry.getKey();
            final ICommonsList<PDStoredBusinessEntity> aDocs = aEntry.getValue();
            // Start result document
            final HCDiv aResultItem = div().addClass(CSS_CLASS_RESULT_DOC);
            final HCDiv aHeadRow = aResultItem.addAndReturnChild(new HCDiv());
            {
                final boolean bIsPeppolDefault = aDocParticipantID.hasScheme(PEPPOL_DEFAULT_SCHEME);
                IHCNode aParticipantNode = null;
                if (bIsPeppolDefault) {
                    final IParticipantIdentifierScheme aScheme = ParticipantIdentifierSchemeManager.getSchemeOfIdentifier(aDocParticipantID);
                    if (aScheme != null) {
                        aParticipantNode = new HCNodeList().addChild(aDocParticipantID.getValue());
                        if (StringHelper.hasText(aScheme.getSchemeAgency()))
                            ((HCNodeList) aParticipantNode).addChild(" (" + aScheme.getSchemeAgency() + ")");
                    }
                }
                if (aParticipantNode == null) {
                    // Fallback
                    aParticipantNode = code(aDocParticipantID.getURIEncoded());
                }
                aHeadRow.addChild("Participant ID: ").addChild(aParticipantNode);
            }
            if (aDocs.size() > 1)
                aHeadRow.addChild(" (" + aDocs.size() + " entities)");
            // Show all entities of the stored document
            final HCUL aUL = aResultItem.addAndReturnChild(new HCUL());
            for (final PDStoredBusinessEntity aStoredDoc : aEntry.getValue()) {
                final BootstrapTable aTable = new BootstrapTable(HCCol.perc(20), HCCol.star());
                aTable.setCondensed(true);
                if (aStoredDoc.hasCountryCode()) {
                    // Add country flag (if available)
                    final String sCountryCode = aStoredDoc.getCountryCode();
                    final Locale aCountry = CountryCache.getInstance().getCountry(sCountryCode);
                    aTable.addBodyRow().addCell("Country:").addCell(new HCNodeList().addChild(PDCommonUI.getFlagNode(sCountryCode)).addChild(" ").addChild(span(aCountry != null ? aCountry.getDisplayCountry(aDisplayLocale) + " (" + sCountryCode + ")" : sCountryCode).addClass(CSS_CLASS_RESULT_DOC_COUNTRY_CODE)));
                }
                if (aStoredDoc.names().isNotEmpty()) {
                    // TODO add locale filter here
                    final ICommonsList<PDStoredMLName> aNames = PDCommonUI.getUIFilteredNames(aStoredDoc.names(), aDisplayLocale);
                    IHCNode aNameCtrl;
                    if (aNames.size() == 1)
                        aNameCtrl = PDCommonUI.getMLNameNode(aNames.getFirst(), aDisplayLocale);
                    else {
                        final HCUL aNameUL = new HCUL();
                        aNames.forEach(x -> aNameUL.addItem(PDCommonUI.getMLNameNode(x, aDisplayLocale)));
                        aNameCtrl = aNameUL;
                    }
                    aTable.addBodyRow().addCell("Entity Name:").addCell(span(aNameCtrl).addClass(CSS_CLASS_RESULT_DOC_NAME));
                }
                if (aStoredDoc.hasGeoInfo())
                    aTable.addBodyRow().addCell("Geographical information:").addCell(div(HCExtHelper.nl2divList(aStoredDoc.getGeoInfo())).addClass(CSS_CLASS_RESULT_DOC_GEOINFO));
                if (aStoredDoc.hasAdditionalInformation())
                    aTable.addBodyRow().addCell("Additional information:").addCell(div(HCExtHelper.nl2divList(aStoredDoc.getAdditionalInformation())).addClass(CSS_CLASS_RESULT_DOC_FREETEXT));
                aUL.addAndReturnItem(aTable).addClass(CSS_CLASS_RESULT_DOC_HEADER);
            }
            final BootstrapButton aShowDetailsBtn = new BootstrapButton(EBootstrapButtonType.SUCCESS, EBootstrapButtonSize.DEFAULT).addChild("Show details").setIcon(EDefaultIcon.MAGNIFIER).addClass(CSS_CLASS_RESULT_DOC_SDBUTTON).setOnClick(aWPEC.getSelfHref().add(FIELD_QUERY, sQuery).add(CPageParam.PARAM_ACTION, CPageParam.ACTION_VIEW).add(FIELD_PARTICIPANT_ID, aDocParticipantID.getURIEncoded()));
            aResultItem.addChild(div(aShowDetailsBtn));
            aOL.addItem(aResultItem);
            // Is the max result limit reached?
            if (aOL.getChildCount() >= nMaxResults)
                break;
        }
        aNodeList.addChild(aOL);
        aNodeList.addChild(div(new BootstrapButton().setOnClick(AJAX_EXPORT_LAST.getInvocationURL(aRequestScope)).addChild("Download results as XML").setIcon(EDefaultIcon.SAVE_ALL)));
    }
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) Query(org.apache.lucene.search.Query) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) IParticipantIdentifierScheme(com.helger.peppolid.peppol.pidscheme.IParticipantIdentifierScheme) HCOL(com.helger.html.hc.html.grouping.HCOL) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) PDStorageManager(com.helger.pd.indexer.storage.PDStorageManager) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) IHCNode(com.helger.html.hc.IHCNode)

Example 5 with HCUL

use of com.helger.html.hc.html.grouping.HCUL in project phoss-directory by phax.

the class PageSecureIndexImport method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final FormErrorList aFormErrors = new FormErrorList();
    {
        final IPDBusinessCardProvider aBCProv = PDMetaManager.getBusinessCardProvider();
        if (aBCProv instanceof SMPBusinessCardProvider) {
            final SMPBusinessCardProvider aSMPBCProv = (SMPBusinessCardProvider) aBCProv;
            if (aSMPBCProv.isFixedSMP()) {
                aNodeList.addChild(info("Fixed SMP URI " + aSMPBCProv.getFixedSMPURI() + " is used."));
            } else {
                aNodeList.addChild(info("The following SMLs are crawled for entries: " + StringHelper.getImplodedMapped(", ", aSMPBCProv.getAllSMLsToUse(), ISMLInfo::getDisplayName)));
            }
        }
    }
    final boolean bIsFormSubmitted = aWPEC.hasAction(CPageParam.ACTION_PERFORM);
    if (bIsFormSubmitted) {
        final IFileItem aFile = aWPEC.params().getAsFileItem(FIELD_FILE);
        if (aFile == null || StringHelper.hasNoText(aFile.getName()))
            aFormErrors.addFieldError(FIELD_FILE, "No file was selected");
        if (aFormErrors.isEmpty()) {
            final HCNodeList aResultNL = new HCNodeList();
            final SAXReaderSettings aSettings = new SAXReaderSettings();
            aSettings.setFeatureValues(EXMLParserFeature.AVOID_DOS_SETTINGS);
            final CollectingSAXErrorHandler aErrorHandler = new CollectingSAXErrorHandler();
            aSettings.setErrorHandler(aErrorHandler);
            final ICommonsList<IParticipantIdentifier> aQueued = new CommonsArrayList<>();
            final ICommonsList<IParticipantIdentifier> aNotQueued = new CommonsArrayList<>();
            aSettings.setContentHandler(new DefaultHandler() {

                @Override
                public void startElement(final String sURI, final String sLocalName, final String sQName, final Attributes aAttributes) throws SAXException {
                    if (sQName.equals("participant")) {
                        final String sScheme = aAttributes.getValue("scheme");
                        final String sValue = aAttributes.getValue("value");
                        final IParticipantIdentifier aParticipantID = aIdentifierFactory.createParticipantIdentifier(sScheme, sValue);
                        if (aParticipantID != null) {
                            if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, "import-triggered", PDIndexerManager.HOST_LOCALHOST).isChanged()) {
                                aQueued.add(aParticipantID);
                            } else {
                                aNotQueued.add(aParticipantID);
                            }
                        } else
                            LOGGER.error("Failed to convert '" + sScheme + "' and '" + sValue + "' to a participant identifier");
                    }
                }
            });
            LOGGER.info("Importing participant IDs from '" + aFile.getNameSecure() + "'");
            final ESuccess eSuccess = SAXReader.readXMLSAX(new FileItemResource(aFile), aSettings);
            LOGGER.info("Finished reading XML file. Queued " + aQueued.size() + "; not queued: " + aNotQueued.size() + "; errors: " + aErrorHandler.getErrorList().size());
            // Some things may have been queued even in case of error
            if (aQueued.isNotEmpty()) {
                final HCUL aUL = new HCUL();
                for (final IParticipantIdentifier aPI : aQueued) aUL.addItem(aPI.getURIEncoded());
                aResultNL.addChild(success(div("The following identifiers were successfully queued for indexing:")).addChild(aUL));
            }
            if (aNotQueued.isNotEmpty()) {
                final HCUL aUL = new HCUL();
                for (final IParticipantIdentifier aPI : aNotQueued) aUL.addItem(aPI.getURIEncoded());
                aResultNL.addChild(warn(div("The following identifiers could not be queued (because they are already in the queue):")).addChild(aUL));
            }
            if (eSuccess.isFailure()) {
                final HCUL aUL = new HCUL();
                for (final IError aError : aErrorHandler.getErrorList()) {
                    final String sMsg = aError.getAsString(AppCommonUI.DEFAULT_LOCALE);
                    LOGGER.error("  " + sMsg);
                    aUL.addItem(sMsg);
                }
                aResultNL.addChild(error(div("Error parsing provided XML:")).addChild(aUL));
            }
            aWPEC.postRedirectGetInternal(aResultNL);
        }
    }
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC, bIsFormSubmitted));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Import file").setCtrl(new BootstrapFileUpload(FIELD_FILE, aDisplayLocale)).setHelpText("Select a file that was created from a full XML export to index of all them manually.").setErrorList(aFormErrors.getListOfField(FIELD_FILE)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addSubmitButton("Import all", EDefaultIcon.YES);
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) CollectingSAXErrorHandler(com.helger.xml.sax.CollectingSAXErrorHandler) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) Attributes(org.xml.sax.Attributes) SAXReaderSettings(com.helger.xml.serialize.read.SAXReaderSettings) SAXException(org.xml.sax.SAXException) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) IFileItem(com.helger.web.fileupload.IFileItem) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SMPBusinessCardProvider(com.helger.pd.indexer.businesscard.SMPBusinessCardProvider) ESuccess(com.helger.commons.state.ESuccess) IError(com.helger.commons.error.IError) FileItemResource(com.helger.web.fileupload.FileItemResource) DefaultHandler(org.xml.sax.helpers.DefaultHandler) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

HCUL (com.helger.html.hc.html.grouping.HCUL)10 HCNodeList (com.helger.html.hc.impl.HCNodeList)8 Locale (java.util.Locale)7 Nonnull (javax.annotation.Nonnull)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 HCOL (com.helger.html.hc.html.grouping.HCOL)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 ISimpleURL (com.helger.commons.url.ISimpleURL)2 IHCNode (com.helger.html.hc.IHCNode)2 HCDiv (com.helger.html.hc.html.grouping.HCDiv)2 HCA (com.helger.html.hc.html.textlevel.HCA)2 HCCode (com.helger.html.hc.html.textlevel.HCCode)2 PDStoredMLName (com.helger.pd.indexer.storage.PDStoredMLName)2 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)2 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)2 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)2 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)2 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)2