Search in sources :

Example 6 with HCOL

use of com.helger.html.hc.html.grouping.HCOL 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 7 with HCOL

use of com.helger.html.hc.html.grouping.HCOL 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
    final Query aLuceneQuery = PDQueryManager.convertQueryStringToLuceneQuery(PDMetaManager.getLucene(), CPDStorage.FIELD_ALL_FIELDS, sQuery);
    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 8 with HCOL

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

the class PageSecureServiceGroupMigrationOutbound method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    {
        final HCOL aOL = new HCOL();
        aOL.addItem("The migration is initiated on this SMP, and the SML is informed about the upcoming migration");
        aOL.addItem("The other SMP, that is taking over the Service Group, must acknowledge the migration by providing the same migration code (created by this SMP) to the SML");
        aOL.addItem("If the migration was successful, the Service Group must be deleted from this SMP, ideally a temporary redirect to the new SMP is created. If the migration was cancelled no action is needed.");
        aNodeList.addChild(info().addChild(div("The process of migrating a Service Group to another SMP consists of multiple steps:")).addChild(aOL).addChild(div("Therefore each open Migration must either be finished (deleting the Service Group) or cancelled (no action taken)." + " If a Migration is cancelled, it can be retried later.")));
    }
    EValidity eCanStartMigration = EValidity.VALID;
    if (aSettings.getSMLInfo() == null) {
        final BootstrapWarnBox aWarn = aNodeList.addAndReturnChild(warn().addChild(div("No valid SML Configuration is selected hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Select SML Configuration in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
        if (aSettings.isSMLEnabled() || aSettings.isSMLRequired()) {
            aWarn.addChild(div(new BootstrapButton().addChild("Create a new SML Configuration").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SML_CONFIGURATION)).setIcon(EDefaultIcon.YES)));
        }
        eCanStartMigration = EValidity.INVALID;
    } else if (!aSettings.isSMLEnabled()) {
        aNodeList.addChild(warn().addChild(div("SML Connection is not enabled hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Enable SML in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
        eCanStartMigration = EValidity.INVALID;
    } else {
        if (aServiceGroupManager.getSMPServiceGroupCount() <= 0) {
            aNodeList.addChild(warn("No Service Group is present! At least one Service Group must be present to migrate it."));
            // Note: makes no to allow to create a new Service Group here and than
            // directly migrate it away
            eCanStartMigration = EValidity.INVALID;
        }
    }
    {
        final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aToolbar.addChild(new BootstrapButton().addChild("Start Participant Migration").setOnClick(createCreateURL(aWPEC)).setDisabled(eCanStartMigration.isInvalid()).setIcon(EDefaultIcon.NEW));
        aNodeList.addChild(aToolbar);
    }
    final BootstrapTabBox aTabBox = aNodeList.addAndReturnChild(new BootstrapTabBox());
    final ICommonsList<ISMPParticipantMigration> aAllMigs = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(null);
    for (final EParticipantMigrationState eState : EParticipantMigrationState.values()) if (eState.isOutboundState()) {
        final ICommonsList<ISMPParticipantMigration> aMatchingMigs = aAllMigs.getAll(x -> x.getState() == eState);
        aTabBox.addTab(eState.getID(), eState.getDisplayName() + " (" + aMatchingMigs.size() + ")", _createTable(aWPEC, aMatchingMigs, eState));
    }
}
Also used : HCOL(com.helger.html.hc.html.grouping.HCOL) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) LoggerFactory(org.slf4j.LoggerFactory) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ICommonsIterable(com.helger.commons.collection.impl.ICommonsIterable) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) Nonempty(com.helger.commons.annotation.Nonempty) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) HCA(com.helger.html.hc.html.textlevel.HCA) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) CPageParam(com.helger.photon.uicore.css.CPageParam) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) IHCCell(com.helger.html.hc.html.tabular.IHCCell) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ICommonsList(com.helger.commons.collection.impl.ICommonsList) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) DataTables(com.helger.photon.uictrls.datatables.DataTables) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) IHCNode(com.helger.html.hc.IHCNode) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPKeyManager(com.helger.phoss.smp.security.SMPKeyManager) EDTColType(com.helger.photon.uictrls.datatables.column.EDTColType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapWarnBox(com.helger.photon.bootstrap4.alert.BootstrapWarnBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) Logger(org.slf4j.Logger) StringHelper(com.helger.commons.string.StringHelper) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) HCTable(com.helger.html.hc.html.tabular.HCTable) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) RequestField(com.helger.photon.core.form.RequestField) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) SMPServerConfiguration(com.helger.phoss.smp.SMPServerConfiguration) ESortOrder(com.helger.commons.compare.ESortOrder) AbstractBootstrapWebPageActionHandlerWithQuery(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerWithQuery) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) EValidity(com.helger.commons.state.EValidity) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) BootstrapWarnBox(com.helger.photon.bootstrap4.alert.BootstrapWarnBox) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) HCOL(com.helger.html.hc.html.grouping.HCOL) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)

Example 9 with HCOL

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

the class PageSecureTasksProblems method _iterateTrustStore.

private void _iterateTrustStore(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final HCOL aOL, @Nonnull final OffsetDateTime aNowDT, @Nonnull final OffsetDateTime aNowPlusDT, @Nonnull final KeyStore aTrustStore) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCOL aTrustStoreOL = new HCOL();
    boolean bHasError = false;
    try {
        for (final String sAlias : CollectionHelper.newList(aTrustStore.aliases())) {
            final Certificate aCert = aTrustStore.getCertificate(sAlias);
            if (aCert instanceof X509Certificate) {
                final X509Certificate aX509Cert = (X509Certificate) aCert;
                final String sLogPrefix = "The provided certificate with subject '" + aX509Cert.getSubjectX500Principal().getName() + "' ";
                final OffsetDateTime aNotBefore = PDTFactory.createOffsetDateTime(aX509Cert.getNotBefore());
                if (aNowDT.isBefore(aNotBefore)) {
                    aTrustStoreOL.addItem(_createError(sLogPrefix + " is not yet valid."), div("It will be valid from " + PDTToString.getAsString(aNotBefore, aDisplayLocale)));
                    bHasError = true;
                }
                final OffsetDateTime aNotAfter = PDTFactory.createOffsetDateTime(aX509Cert.getNotAfter());
                if (aNowDT.isAfter(aNotAfter)) {
                    aTrustStoreOL.addItem(_createError(sLogPrefix + " is already expired."), div("It was valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale)));
                    bHasError = true;
                } else if (aNowPlusDT.isAfter(aNotAfter))
                    aTrustStoreOL.addItem(_createWarning(sLogPrefix + " will expire soon."), div("It is only valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale)));
            } else
                aTrustStoreOL.addItem(_createWarning("The certificate is not an X.509 certificate! It is internally a " + ClassHelper.getClassName(aCert)));
        }
    } catch (final GeneralSecurityException ex) {
        aTrustStoreOL.addItem(_createError("Error iterating trust store."), div(SMPCommonUI.getTechnicalDetailsUI(ex)));
        bHasError = true;
    }
    if (aTrustStoreOL.hasChildren())
        aOL.addItem(bHasError ? _createError("Trust store issues") : _createWarning("Trust store issues"), aTrustStoreOL);
}
Also used : Locale(java.util.Locale) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) OffsetDateTime(java.time.OffsetDateTime) GeneralSecurityException(java.security.GeneralSecurityException) HCOL(com.helger.html.hc.html.grouping.HCOL) PDTToString(com.helger.commons.datetime.PDTToString) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 10 with HCOL

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

the class PageSecureTasksProblems method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final OffsetDateTime aNowDT = PDTFactory.getCurrentOffsetDateTime();
    final OffsetDateTime aNowPlusDT = aNowDT.plusMonths(3);
    aNodeList.addChild(info("This page tries to identify upcoming tasks and potential problems in the SMP configuration. It is meant to highlight immediate and upcoming action items as well as potential misconfiguration."));
    final HCOL aOL = new HCOL();
    // Check for default password
    if (PhotonSecurityManager.getUserMgr().areUserIDAndPasswordValid(CSecurity.USER_ADMINISTRATOR_ID, CSecurity.USER_ADMINISTRATOR_PASSWORD)) {
        aOL.addItem(_createError("Please change the password of the default user " + CSecurity.USER_ADMINISTRATOR_EMAIL + "!"), div("This is a severe security risk"));
    }
    _checkSettings(aOL);
    // check keystore configuration
    _checkKeyStore(aWPEC, aOL, aNowDT, aNowPlusDT);
    // Check truststore configuration
    _checkTrustStore(aWPEC, aOL, aNowDT, aNowPlusDT);
    // Check SML configuration
    _checkSMLConfiguration(aOL);
    // Check Directory configuration
    _checkDirectoryConfig(aWPEC, aOL, aNowDT, aNowPlusDT);
    // check service groups and redirects
    {
        final ICommonsList<ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
        if (aServiceGroups.isEmpty()) {
            aOL.addItem(_createWarning("No service group is configured. This SMP is currently empty."));
        } else {
            // For all service groups
            for (final ISMPServiceGroup aServiceGroup : CollectionHelper.getSorted(aServiceGroups, ISMPServiceGroup.comparator())) {
                final HCUL aULPerSG = new HCUL();
                final ICommonsList<ISMPServiceInformation> aServiceInfos = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup);
                if (aServiceInfos.isEmpty()) {
                    // This is merely a warning or an error
                    aULPerSG.addItem(_createInfo("No endpoint is configured for this service group."));
                } else {
                    for (final ISMPServiceInformation aServiceInfo : aServiceInfos) {
                        final HCUL aULPerDocType = new HCUL();
                        final ICommonsList<ISMPProcess> aProcesses = aServiceInfo.getAllProcesses();
                        for (final ISMPProcess aProcess : aProcesses) {
                            final HCUL aULPerProcess = new HCUL();
                            final ICommonsList<ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints();
                            for (final ISMPEndpoint aEndpoint : aEndpoints) {
                                final HCUL aULPerEndpoint = new HCUL();
                                final ESMPTransportProfile eTransportProfile = ESMPTransportProfile.getFromIDOrNull(aEndpoint.getTransportProfile());
                                if (eTransportProfile == null)
                                    aULPerEndpoint.addItem(_createWarning("The endpoint uses the non-standard transport profile '" + aEndpoint.getTransportProfile() + "'."));
                                if (aEndpoint.getServiceActivationDateTime() != null) {
                                    if (aEndpoint.getServiceActivationDateTime().isAfter(XMLOffsetDateTime.of(aNowDT)))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint is not yet active."), div("It will be active from " + PDTToString.getAsString(aEndpoint.getServiceActivationDateTime(), aDisplayLocale) + "."));
                                }
                                if (aEndpoint.getServiceExpirationDateTime() != null) {
                                    if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowDT)))
                                        aULPerEndpoint.addItem(_createError("The endpoint is no longer active."), div("It was valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
                                    else if (aEndpoint.getServiceExpirationDateTime().isBefore(XMLOffsetDateTime.of(aNowPlusDT)))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint will be inactive soon."), div("It is only valid until " + PDTToString.getAsString(aEndpoint.getServiceExpirationDateTime(), aDisplayLocale) + "."));
                                }
                                X509Certificate aX509Cert = null;
                                try {
                                    aX509Cert = CertificateHelper.convertStringToCertficate(aEndpoint.getCertificate());
                                } catch (final CertificateException ex) {
                                // Ignore
                                }
                                if (aX509Cert == null)
                                    aULPerEndpoint.addItem(_createError("The X.509 certificate configured at the endpoint is invalid and could not be interpreted as a certificate."));
                                else {
                                    final OffsetDateTime aNotBefore = PDTFactory.createOffsetDateTime(aX509Cert.getNotBefore());
                                    if (aNowDT.isBefore(aNotBefore))
                                        aULPerEndpoint.addItem(_createError("The endpoint certificate is not yet active."), div("It will be valid from " + PDTToString.getAsString(aNotBefore, aDisplayLocale) + "."));
                                    final OffsetDateTime aNotAfter = PDTFactory.createOffsetDateTime(aX509Cert.getNotAfter());
                                    if (aNowDT.isAfter(aNotAfter))
                                        aULPerEndpoint.addItem(_createError("The endpoint certificate is already expired."), div("It was valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
                                    else if (aNowPlusDT.isAfter(aNotAfter))
                                        aULPerEndpoint.addItem(_createWarning("The endpoint certificate will expire soon."), div("It is only valid until " + PDTToString.getAsString(aNotAfter, aDisplayLocale) + "."));
                                }
                                // Show per endpoint errors
                                if (aULPerEndpoint.hasChildren())
                                    aULPerProcess.addItem(div("Transport profile ").addChild(code(aEndpoint.getTransportProfile())), aULPerEndpoint);
                            }
                            // Show per process errors
                            if (aULPerProcess.hasChildren())
                                aULPerDocType.addItem(div("Process ").addChild(code(aProcess.getProcessIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerProcess);
                        }
                        // Show per document type errors
                        if (aULPerDocType.hasChildren())
                            aULPerSG.addItem(div("Document type ").addChild(code(aServiceInfo.getDocumentTypeIdentifier().getURIEncoded()).addClass(CUICoreCSS.CSS_CLASS_NOWRAP)), aULPerDocType);
                    }
                }
                // Show per service group errors
                if (aULPerSG.hasChildren())
                    aOL.addItem(div("Service group ").addChild(code(aServiceGroup.getParticipantIdentifier().getURIEncoded())), aULPerSG);
            }
        }
    }
    // Show results
    if (aOL.hasChildren()) {
        aNodeList.addChild(warn("The following list of tasks and problems were identified:"));
        aNodeList.addChild(aOL);
    } else
        aNodeList.addChild(success("Great job, no tasks or problems identified!"));
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) CertificateException(java.security.cert.CertificateException) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) X509Certificate(java.security.cert.X509Certificate) HCUL(com.helger.html.hc.html.grouping.HCUL) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) OffsetDateTime(java.time.OffsetDateTime) HCOL(com.helger.html.hc.html.grouping.HCOL) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)

Aggregations

HCOL (com.helger.html.hc.html.grouping.HCOL)10 Locale (java.util.Locale)10 HCNodeList (com.helger.html.hc.impl.HCNodeList)9 PDTToString (com.helger.commons.datetime.PDTToString)7 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)6 ICommonsList (com.helger.commons.collection.impl.ICommonsList)5 IHCNode (com.helger.html.hc.IHCNode)5 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)4 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)4 Nonempty (com.helger.commons.annotation.Nonempty)3 StringHelper (com.helger.commons.string.StringHelper)3 PDStoredMLName (com.helger.pd.indexer.storage.PDStoredMLName)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)3 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)3 BootstrapViewForm (com.helger.photon.bootstrap4.form.BootstrapViewForm)3 BootstrapTabBox (com.helger.photon.bootstrap4.nav.BootstrapTabBox)3 Nonnull (javax.annotation.Nonnull)3 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)2 ICommonsIterable (com.helger.commons.collection.impl.ICommonsIterable)2 ICommonsSortedSet (com.helger.commons.collection.impl.ICommonsSortedSet)2