Search in sources :

Example 1 with PDStoredMLName

use of com.helger.pd.indexer.storage.PDStoredMLName in project phoss-directory by phax.

the class AbstractPagePublicSearch method createParticipantDetails.

@Nonnull
protected HCNodeList createParticipantDetails(@Nonnull final Locale aDisplayLocale, @Nonnull final String sParticipantID, @Nonnull final IParticipantIdentifier aParticipantID, final boolean bIsLoggedInUserAdministrator) {
    final HCNodeList aDetails = new HCNodeList();
    // Search document matching participant ID
    final ICommonsList<PDStoredBusinessEntity> aResultDocs = PDMetaManager.getStorageMgr().getAllDocumentsOfParticipant(aParticipantID);
    // Group by participant ID
    final ICommonsMap<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aGroupedDocs = PDStorageManager.getGroupedByParticipantID(aResultDocs);
    if (aGroupedDocs.isEmpty())
        LOGGER.error("No stored document matches participant identifier '" + sParticipantID + "' - cannot show details");
    else {
        if (aGroupedDocs.size() > 1)
            LOGGER.warn("Found " + aGroupedDocs.size() + " entries for participant identifier '" + sParticipantID + "' - weird");
        // Get the first one
        final ICommonsList<PDStoredBusinessEntity> aStoredEntities = aGroupedDocs.getFirstValue();
        // Details header
        {
            IHCNode aDetailsHeader = null;
            final boolean bIsPeppolDefault = aParticipantID.hasScheme(PeppolIdentifierFactory.INSTANCE.getDefaultParticipantIdentifierScheme());
            if (bIsPeppolDefault) {
                final IParticipantIdentifierScheme aIIA = ParticipantIdentifierSchemeManager.getSchemeOfIdentifier(aParticipantID);
                if (aIIA != null) {
                    final HCH1 aH1 = h1("Details for: " + aParticipantID.getValue());
                    if (StringHelper.hasText(aIIA.getSchemeAgency()))
                        aH1.addChild(small(" (" + aIIA.getSchemeAgency() + ")"));
                    aDetailsHeader = new BootstrapPageHeader().addChild(aH1);
                }
            }
            if (aDetailsHeader == null) {
                // Fallback
                aDetailsHeader = BootstrapWebPageUIHandler.INSTANCE.createPageHeader("Details for " + sParticipantID);
            }
            aDetails.addChild(aDetailsHeader);
        }
        final BootstrapTabBox aTabBox = new BootstrapTabBox();
        // Business information
        {
            final HCNodeList aOL = new HCNodeList();
            int nIndex = 1;
            for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) {
                final BootstrapCard aCard = aOL.addAndReturnChild(new BootstrapCard());
                aCard.addClass(CSS_CLASS_RESULT_PANEL);
                if (aStoredEntities.size() > 1)
                    aCard.createAndAddHeader().addChild("Business information entity " + nIndex);
                final BootstrapViewForm aViewForm = PDCommonUI.showBusinessInfoDetails(aStoredEntity, aDisplayLocale);
                aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Full Peppol participant ID").setCtrl(code(sParticipantID)));
                if (GlobalDebug.isDebugMode() || bIsLoggedInUserAdministrator) {
                    aViewForm.addChild(new HCHR());
                    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Creation DT").setCtrl(PDTToString.getAsString(aStoredEntity.getMetaData().getCreationDT(), aDisplayLocale)));
                    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Owner ID").setCtrl(code(aStoredEntity.getMetaData().getOwnerID())));
                    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Requesting Host").setCtrl(code(aStoredEntity.getMetaData().getRequestingHost())));
                }
                aCard.createAndAddBody().addChild(aViewForm);
                ++nIndex;
            }
            // Add whole list or just the first item?
            final IHCNode aTabLabel = span("Business information ").addChild(badgePrimary(aStoredEntities.size()));
            aTabBox.addTab("businessinfo", aTabLabel, aOL, true);
        }
        // Document types
        {
            final HCNodeList aDocTypeCtrl = new HCNodeList();
            final ICommonsList<String> aNames = new CommonsArrayList<>();
            for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) aNames.addAllMapped(aStoredEntity.names(), PDStoredMLName::getName);
            aDocTypeCtrl.addChild(info("The following document types are supported by " + _getImplodedMapped(", ", " and ", aNames, x -> "'" + x + "'") + ":"));
            HCOL aDocTypeOL = null;
            final ICommonsList<IDocumentTypeIdentifier> aDocTypeIDs = aResultDocs.getFirst().documentTypeIDs().getSorted(IDocumentTypeIdentifier.comparator());
            for (final IDocumentTypeIdentifier aDocTypeID : aDocTypeIDs) {
                if (aDocTypeOL == null)
                    aDocTypeOL = aDocTypeCtrl.addAndReturnChild(new HCOL());
                final HCLI aLI = aDocTypeOL.addItem();
                aLI.addChild(NiceNameUI.getDocumentTypeID(aDocTypeID));
            }
            if (aDocTypeOL == null)
                aDocTypeCtrl.addChild(warn("This participant does not support any document types!"));
            aTabBox.addTab("doctypes", span("Supported document types ").addChild(badgePrimary(aDocTypeIDs.size())), aDocTypeCtrl, false);
        }
        aDetails.addChild(aTabBox);
    }
    return aDetails;
}
Also used : HCH1(com.helger.html.hc.html.sections.HCH1) HCOL(com.helger.html.hc.html.grouping.HCOL) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) BootstrapWebPageUIHandler(com.helger.photon.bootstrap4.pages.BootstrapWebPageUIHandler) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) Function(java.util.function.Function) NiceNameUI(com.helger.pd.publisher.nicename.NiceNameUI) PDCommonUI(com.helger.pd.publisher.ui.PDCommonUI) IHCNode(com.helger.html.hc.IHCNode) ParticipantIdentifierSchemeManager(com.helger.peppolid.peppol.pidscheme.ParticipantIdentifierSchemeManager) BootstrapPageHeader(com.helger.photon.bootstrap4.utils.BootstrapPageHeader) Nonempty(com.helger.commons.annotation.Nonempty) Locale(java.util.Locale) PDServerConfiguration(com.helger.pd.indexer.settings.PDServerConfiguration) IHasID(com.helger.commons.id.IHasID) EnumHelper(com.helger.commons.lang.EnumHelper) IParticipantIdentifierScheme(com.helger.peppolid.peppol.pidscheme.IParticipantIdentifierScheme) GlobalDebug(com.helger.commons.debug.GlobalDebug) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) HCNodeList(com.helger.html.hc.impl.HCNodeList) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) HCLI(com.helger.html.hc.html.grouping.HCLI) PDStorageManager(com.helger.pd.indexer.storage.PDStorageManager) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) PeppolIdentifierFactory(com.helger.peppolid.factory.PeppolIdentifierFactory) StringHelper(com.helger.commons.string.StringHelper) AbstractAppWebPage(com.helger.pd.publisher.ui.AbstractAppWebPage) Collection(java.util.Collection) ValueEnforcer(com.helger.commons.ValueEnforcer) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCHR(com.helger.html.hc.html.grouping.HCHR) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) DefaultCSSClassProvider(com.helger.html.css.DefaultCSSClassProvider) ICSSClassProvider(com.helger.html.css.ICSSClassProvider) ICommonsList(com.helger.commons.collection.impl.ICommonsList) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCHR(com.helger.html.hc.html.grouping.HCHR) HCH1(com.helger.html.hc.html.sections.HCH1) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) BootstrapPageHeader(com.helger.photon.bootstrap4.utils.BootstrapPageHeader) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) IParticipantIdentifierScheme(com.helger.peppolid.peppol.pidscheme.IParticipantIdentifierScheme) HCOL(com.helger.html.hc.html.grouping.HCOL) HCLI(com.helger.html.hc.html.grouping.HCLI) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) IHCNode(com.helger.html.hc.IHCNode) Nonnull(javax.annotation.Nonnull)

Example 2 with PDStoredMLName

use of com.helger.pd.indexer.storage.PDStoredMLName 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 3 with PDStoredMLName

use of com.helger.pd.indexer.storage.PDStoredMLName 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 4 with PDStoredMLName

use of com.helger.pd.indexer.storage.PDStoredMLName in project phoss-directory by phax.

the class ExportAllManager method queryAllContainedBusinessCardsAsCSV.

public static void queryAllContainedBusinessCardsAsCSV(@Nonnull final EQueryMode eQueryMode, @Nonnull @WillNotClose final CSVWriter aCSVWriter) throws IOException {
    _unify(aCSVWriter);
    final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
    aCSVWriter.writeNext("Participant ID", "Names (per-row)", "Country code", "Geo info", "Identifier schemes", "Identifier values", "Websites", "Contact type", "Contact name", "Contact phone", "Contact email", "Additional info", "Registration date", "Document types");
    final Consumer<? super PDStoredBusinessEntity> aConsumer = aEntity -> {
        aCSVWriter.writeNext(aEntity.getParticipantID().getURIEncoded(), StringHelper.getImplodedMapped("\n", aEntity.names(), PDStoredMLName::getNameAndLanguageCode), aEntity.getCountryCode(), aEntity.getGeoInfo(), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getScheme), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getValue), StringHelper.getImploded("\n", aEntity.websiteURIs()), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getType), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getName), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getPhone), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getEmail), aEntity.getAdditionalInformation(), aEntity.getRegistrationDate() == null ? "" : aEntity.getRegistrationDate().toString(), StringHelper.getImplodedMapped("\n", aEntity.documentTypeIDs(), IDocumentTypeIdentifier::getURIEncoded));
    };
    PDMetaManager.getStorageMgr().searchAllDocuments(aQuery, -1, aConsumer);
    aCSVWriter.flush();
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact)

Example 5 with PDStoredMLName

use of com.helger.pd.indexer.storage.PDStoredMLName in project phoss-directory by phax.

the class ExportAllManager method queryAllContainedBusinessCardsAsExcel.

@Nonnull
public static WorkbookCreationHelper queryAllContainedBusinessCardsAsExcel(@Nonnull final EQueryMode eQueryMode, final boolean bIncludeDocTypes) throws IOException {
    final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
    final ExcelStyle ES_DATE = new ExcelStyle().setDataFormat("yyyy-mm-dd");
    final ExcelStyle ES_WRAP = new ExcelStyle().setWrapText(true);
    @WillNotClose final WorkbookCreationHelper aWBCH = new WorkbookCreationHelper(EExcelVersion.XLSX);
    aWBCH.createNewSheet();
    aWBCH.addRow();
    aWBCH.addCell("Participant ID");
    aWBCH.addCell("Names (per-row)");
    aWBCH.addCell("Country code");
    aWBCH.addCell("Geo info");
    aWBCH.addCell("Identifier schemes");
    aWBCH.addCell("Identifier values");
    aWBCH.addCell("Websites");
    aWBCH.addCell("Contact type");
    aWBCH.addCell("Contact name");
    aWBCH.addCell("Contact phone");
    aWBCH.addCell("Contact email");
    aWBCH.addCell("Additional info");
    aWBCH.addCell("Registration date");
    if (bIncludeDocTypes)
        aWBCH.addCell("Document types");
    final Consumer<? super PDStoredBusinessEntity> aConsumer = aEntity -> {
        aWBCH.addRow();
        aWBCH.addCell(aEntity.getParticipantID().getURIEncoded());
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.names(), PDStoredMLName::getNameAndLanguageCode));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(aEntity.getCountryCode());
        aWBCH.addCell(aEntity.getGeoInfo());
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getScheme));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getValue));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImploded("\n", aEntity.websiteURIs()));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getType));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getName));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getPhone));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getEmail));
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(aEntity.getAdditionalInformation());
        aWBCH.addCellStyle(ES_WRAP);
        aWBCH.addCell(aEntity.getRegistrationDate());
        aWBCH.addCellStyle(ES_DATE);
        if (bIncludeDocTypes) {
            aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.documentTypeIDs(), IDocumentTypeIdentifier::getURIEncoded));
            aWBCH.addCellStyle(ES_WRAP);
        }
    };
    // Query all and group by participant ID
    PDMetaManager.getStorageMgr().searchAllDocuments(aQuery, -1, aConsumer);
    aWBCH.autoSizeAllColumns();
    aWBCH.autoFilterAllColumns();
    return aWBCH;
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WillNotClose(javax.annotation.WillNotClose) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Nonnull(javax.annotation.Nonnull)

Aggregations

PDStoredMLName (com.helger.pd.indexer.storage.PDStoredMLName)6 Nonnull (javax.annotation.Nonnull)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 PDStoredBusinessEntity (com.helger.pd.indexer.storage.PDStoredBusinessEntity)4 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 StringHelper (com.helger.commons.string.StringHelper)3 PDMetaManager (com.helger.pd.indexer.mgr.PDMetaManager)3 PDStoredContact (com.helger.pd.indexer.storage.PDStoredContact)3 PDStoredIdentifier (com.helger.pd.indexer.storage.PDStoredIdentifier)3 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 Query (org.apache.lucene.search.Query)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)2 CommonsTreeSet (com.helger.commons.collection.impl.CommonsTreeSet)2 ICommonsOrderedMap (com.helger.commons.collection.impl.ICommonsOrderedMap)2 ICommonsSortedSet (com.helger.commons.collection.impl.ICommonsSortedSet)2 SimpleReadWriteLock (com.helger.commons.concurrent.SimpleReadWriteLock)2 CSVWriter (com.helger.commons.csv.CSVWriter)2 PDTFactory (com.helger.commons.datetime.PDTFactory)2 PDTToString (com.helger.commons.datetime.PDTToString)2