Search in sources :

Example 1 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-directory by phax.

the class PageSecureAdminSMLConfiguration method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLInfo aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final boolean bEdit = eFormAction.isEdit();
    aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit SML configuration '" + aSelectedObject.getDisplayName() + "'" : "Create new SML configuration"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_DISPLAY_NAME, aSelectedObject != null ? aSelectedObject.getDisplayName() : null))).setHelpText("The name of the SML configuration. This is for informational purposes only and has no effect on the functionality.").setErrorList(aFormErrors.getListOfField(FIELD_DISPLAY_NAME)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("DNS Zone").setCtrl(new HCEdit(new RequestField(FIELD_DNS_ZONE, aSelectedObject != null ? aSelectedObject.getDNSZone() : null))).setHelpText(new HCTextNode("The name of the DNS Zone that this SML is working upon (e.g. "), new HCCode().addChild("sml.peppolcentral.org"), new HCTextNode("). The value will automatically converted to all-lowercase!")).setErrorList(aFormErrors.getListOfField(FIELD_DNS_ZONE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Management Service URL").setCtrl(new HCEdit(new RequestField(FIELD_MANAGEMENT_ADDRESS_URL, aSelectedObject != null ? aSelectedObject.getManagementServiceURL() : null))).setHelpText("The service URL where the SML management application is running on including the host name. It may not contain the '" + CSMLDefault.MANAGEMENT_SERVICE_METADATA + "' or '" + CSMLDefault.MANAGEMENT_SERVICE_PARTICIPANTIDENTIFIER + "' path elements!").setErrorList(aFormErrors.getListOfField(FIELD_MANAGEMENT_ADDRESS_URL)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Client Certificate required?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_CLIENT_CERTIFICATE_REQUIRED, aSelectedObject != null ? aSelectedObject.isClientCertificateRequired() : true))).setHelpText("Check this if this SML requires a client certificate for access. Both Peppol production SML and SMK require a client certificate. Only a locally running SML software may not require a client certificate.").setErrorList(aFormErrors.getListOfField(FIELD_CLIENT_CERTIFICATE_REQUIRED)));
}
Also used : HCCode(com.helger.html.hc.html.textlevel.HCCode) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) HCTextNode(com.helger.html.hc.impl.HCTextNode) RequestField(com.helger.photon.core.form.RequestField)

Example 2 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-directory by phax.

the class PagePublicContact method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bShowForm = true;
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
        final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
        final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
        final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
        final String sReCaptcha = StringHelper.trim(aWPEC.params().getAsString("g-recaptcha-response"));
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
        if (StringHelper.hasNoText(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
        else if (!EmailAddressHelper.isValid(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
        if (StringHelper.hasNoText(sText))
            aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
        if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptcha)) {
            if (!CaptchaSessionSingleton.getInstance().isChecked()) {
                // Check only if no other errors occurred
                if (ReCaptchaServerSideValidator.check("6LfZFS0UAAAAAONDJHyDnuUUvMB_oNmJxz9Utxza", sReCaptcha).isFailure())
                    aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
                else
                    CaptchaSessionSingleton.getInstance().setChecked();
            }
        }
        if (aFormErrors.isEmpty()) {
            final EmailData aEmailData = new EmailData(EEmailType.TEXT);
            aEmailData.setFrom(CPDPublisher.EMAIL_SENDER);
            aEmailData.to().add(new EmailAddress("pd@helger.com"));
            aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
            aEmailData.setSubject("[" + CPDPublisher.getApplication() + "] Contact Form - " + sName);
            final StringBuilder aSB = new StringBuilder();
            aSB.append("Contact form from " + CPDPublisher.getApplication() + " was filled out.\n\n");
            aSB.append("Name: ").append(sName).append("\n");
            aSB.append("Email: ").append(sEmail).append("\n");
            aSB.append("Topic: ").append(sTopic).append("\n");
            aSB.append("Text:\n").append(sText).append("\n");
            aEmailData.setBody(aSB.toString());
            ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
            aWPEC.postRedirectGetInternal(success("Thank you for your message. We will come back to you asap."));
        }
    }
    if (bShowForm) {
        aNodeList.addChild(info("Alternatively write an email to pd[at]helger.com - usually using the below form is more effective!"));
        aNodeList.addChild(warn("Please don't request any change of data via this contact form - contact your service provider instead. Thank you."));
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
        final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
        aSelect.addOption("SMP integration");
        aSelect.addOption("Website");
        aSelect.addOption("REST service");
        aSelect.addOption("SMP Statement of use");
        aSelect.addOption("General question");
        aSelect.addOptionPleaseSelect(aDisplayLocale);
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
        if (!CaptchaSessionSingleton.getInstance().isChecked()) {
            // Add visible Captcha
            aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create("6LfZFS0UAAAAAJaqpHJdFS_xxY7dqMQjXoBIQWOD", aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
        }
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
        aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EDefaultIcon.YES));
        aForm.addChild(new BootstrapButton().addChild("No thanks").setIcon(EDefaultIcon.CANCEL).setOnClick(aWPEC.getLinkToMenuItem(CMenuPublic.MENU_SEARCH_SIMPLE)));
    }
}
Also used : Locale(java.util.Locale) HCExtSelect(com.helger.photon.uicore.html.select.HCExtSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) EmailData(com.helger.smtp.data.EmailData) EmailAddress(com.helger.commons.email.EmailAddress) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 3 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-directory by phax.

the class PageSecureDeleteManually method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
        final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
        if (StringHelper.hasNoText(sParticipantID))
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
        else if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
        if (aFormErrors.isEmpty()) {
            int nDeleted = 0;
            try {
                nDeleted = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false);
            } catch (final IOException ex) {
                // ignore
                nDeleted = -1;
            }
            if (nDeleted > 0)
                aWPEC.postRedirectGetInternal(success("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted (" + nDeleted + " rows)"));
            else
                aWPEC.postRedirectGetInternal(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
        }
    }
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to delete.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addSubmitButton("Delete from index", EDefaultIcon.DELETE);
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) IOException(java.io.IOException) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) RequestField(com.helger.photon.core.form.RequestField)

Example 4 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class AbstractPageSecureEndpoint method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final boolean bEdit = eFormAction.isEdit();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_PROCESS);
    final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_ENDPOINT);
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit endpoint" : "Create new endpoint"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getServiceGroupID() : null), aDisplayLocale).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
    {
        final BootstrapRow aRow = new BootstrapRow();
        aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_DOCTYPE_ID_SCHEME, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getScheme() : aIdentifierFactory.getDefaultDocumentTypeIdentifierScheme())).setPlaceholder("Identifier scheme").setReadOnly(bEdit));
        aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_DOCTYPE_ID_VALUE, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getValue() : null)).setPlaceholder("Identifier value").setReadOnly(bEdit));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document type ID").setCtrl(aRow).setErrorList(aFormErrors.getListOfFields(FIELD_DOCTYPE_ID_SCHEME, FIELD_DOCTYPE_ID_VALUE)));
    }
    {
        final BootstrapRow aRow = new BootstrapRow();
        aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_PROCESS_ID_SCHEME, aSelectedProcess != null ? aSelectedProcess.getProcessIdentifier().getScheme() : aIdentifierFactory.getDefaultProcessIdentifierScheme())).setPlaceholder("Identifier scheme").setReadOnly(bEdit));
        aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_PROCESS_ID_VALUE, aSelectedProcess != null ? aSelectedProcess.getProcessIdentifier().getValue() : null)).setPlaceholder("Identifier value").setReadOnly(bEdit));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Process ID").setCtrl(aRow).setErrorList(aFormErrors.getListOfFields(FIELD_PROCESS_ID_SCHEME, FIELD_PROCESS_ID_VALUE)));
    }
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Transport Profile").setCtrl(new HCSMPTransportProfileSelect(new RequestField(FIELD_TRANSPORT_PROFILE, aSelectedEndpoint != null ? aSelectedEndpoint.getTransportProfile() : ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID())).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_TRANSPORT_PROFILE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Endpoint Reference").setCtrl(new HCEdit(new RequestField(FIELD_ENDPOINT_REFERENCE, aSelectedEndpoint != null ? aSelectedEndpoint.getEndpointReference() : null))).setHelpText("The URL where messsages of this type should be targeted to.").setErrorList(aFormErrors.getListOfField(FIELD_ENDPOINT_REFERENCE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Requires Business Level Signature").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE, aSelectedEndpoint != null ? aSelectedEndpoint.isRequireBusinessLevelSignature() : SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE))).setHelpText("Check the box if the recipient requires business-level signatures for " + "the message, meaning a signature applied to the business message " + "before the message is put on the transport. This is independent of " + "the transport-level signatures that a specific transport profile, such " + "as the START profile, might mandate. This flag does not indicate " + "which type of business-level signature might be required. Setting or " + "consuming business-level signatures would typically be the " + "responsibility of the final senders and receivers of messages, rather " + "than a set of APs.").setErrorList(aFormErrors.getListOfField(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Minimum Authentication Level").setCtrl(new HCEdit(new RequestField(FIELD_MINIMUM_AUTHENTICATION_LEVEL, aSelectedEndpoint != null ? aSelectedEndpoint.getMinimumAuthenticationLevel() : null))).setHelpText("Indicates the minimum authentication level that recipient requires. " + "The specific semantics of this field is defined in a specific instance " + "of the BUSDOX infrastructure. It could for example reflect the " + "value of the \"urn:eu:busdox:attribute:assurance-level\" SAML " + "attribute defined in the START specification.").setErrorList(aFormErrors.getListOfField(FIELD_MINIMUM_AUTHENTICATION_LEVEL)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Not before").setCtrl(BootstrapDateTimePicker.create(FIELD_NOT_BEFORE, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceActivationDate() : null, aDisplayLocale)).setHelpText("Activation date of the service. Senders should ignore services that " + "are not yet activated.").setErrorList(aFormErrors.getListOfField(FIELD_NOT_BEFORE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Not after").setCtrl(BootstrapDateTimePicker.create(FIELD_NOT_AFTER, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceExpirationDate() : null, aDisplayLocale)).setHelpText("Expiration date of the service. Senders should ignore services that " + "are expired.").setErrorList(aFormErrors.getListOfField(FIELD_NOT_AFTER)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Certificate").setCtrl(new HCTextArea(new RequestField(FIELD_CERTIFICATE, aSelectedEndpoint != null ? aSelectedEndpoint.getCertificate() : null))).setHelpText("Holds the complete signing certificate of the recipient AP, as a " + "PEM base 64 encoded X509 DER formatted value.").setErrorList(aFormErrors.getListOfField(FIELD_CERTIFICATE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Description").setCtrl(new HCEdit(new RequestField(FIELD_SERVICE_DESCRIPTION, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceDescription() : null))).setHelpText("A human readable description of the service.").setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_DESCRIPTION)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Technical Contact").setCtrl(new HCEdit(new RequestField(FIELD_TECHNICAL_CONTACT, aSelectedEndpoint != null ? aSelectedEndpoint.getTechnicalContactUrl() : null))).setHelpText("Represents a link to human readable contact information. This " + "might also be an email address.").setErrorList(aFormErrors.getListOfField(FIELD_TECHNICAL_CONTACT)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Technical Information").setCtrl(new HCEdit(new RequestField(FIELD_TECHNICAL_INFORMATION, aSelectedEndpoint != null ? aSelectedEndpoint.getTechnicalInformationUrl() : null))).setHelpText("A URL to human readable documentation of the service format. " + "This could for example be a web site containing links to XML " + "Schemas, WSDLs, Schematrons and other relevant resources.").setErrorList(aFormErrors.getListOfField(FIELD_TECHNICAL_INFORMATION)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION, aSelectedEndpoint != null ? aSelectedEndpoint.getFirstExtensionXML() : null))).setHelpText("Optional extension to the endpoint. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
Also used : Locale(java.util.Locale) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) HCEdit(com.helger.html.hc.html.forms.HCEdit) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) HCSMPTransportProfileSelect(com.helger.phoss.smp.ui.secure.hc.HCSMPTransportProfileSelect) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) BootstrapRow(com.helger.photon.bootstrap4.grid.BootstrapRow) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) RequestField(com.helger.photon.core.form.RequestField)

Example 5 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class PageSecureEndpointChangeURL method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    boolean bShowList = true;
    final ICommonsMap<String, ICommonsList<ISMPEndpoint>> aEndpointsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsMap<String, ICommonsSet<ISMPServiceGroup>> aServiceGroupsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsList<ISMPServiceInformation> aAllSIs = aServiceInfoMgr.getAllSMPServiceInformation();
    int nTotalEndpointCount = 0;
    int nTotalEndpointCountWithURL = 0;
    for (final ISMPServiceInformation aSI : aAllSIs) {
        final ISMPServiceGroup aSG = aSI.getServiceGroup();
        for (final ISMPProcess aProcess : aSI.getAllProcesses()) for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
            ++nTotalEndpointCount;
            if (aEndpoint.hasEndpointReference()) {
                aEndpointsGroupedPerURL.computeIfAbsent(aEndpoint.getEndpointReference(), k -> new CommonsArrayList<>()).add(aEndpoint);
                aServiceGroupsGroupedPerURL.computeIfAbsent(aEndpoint.getEndpointReference(), k -> new CommonsHashSet<>()).add(aSG);
                ++nTotalEndpointCountWithURL;
            }
        }
    }
    {
        final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aNodeList.addChild(aToolbar);
        final int nCount = BulkChangeEndpointURL.getRunningJobCount();
        if (nCount > 0) {
            aNodeList.addChild(warn((nCount == 1 ? "1 bulk change is" : nCount + " bulk changes are") + " currently running in the background"));
        }
    }
    if (aWPEC.hasAction(CPageParam.ACTION_EDIT)) {
        bShowList = false;
        final FormErrorList aFormErrors = new FormErrorList();
        final String sOldURL = aWPEC.params().getAsString(FIELD_OLD_URL);
        if (aWPEC.hasSubAction(CPageParam.ACTION_SAVE)) {
            // Find selected service group (if any)
            final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP);
            ISMPServiceGroup aServiceGroup = null;
            if (StringHelper.hasText(sServiceGroupID)) {
                final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
                if (aParticipantID != null)
                    aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID);
            }
            final String sNewURL = aWPEC.params().getAsString(FIELD_NEW_URL);
            if (StringHelper.hasNoText(sOldURL))
                aFormErrors.addFieldInfo(FIELD_OLD_URL, "An old URL must be provided");
            else if (!URLValidator.isValid(sOldURL))
                aFormErrors.addFieldInfo(FIELD_OLD_URL, "The old URL is invalid");
            if (StringHelper.hasNoText(sNewURL))
                aFormErrors.addFieldInfo(FIELD_NEW_URL, "A new URL must be provided");
            else if (!URLValidator.isValid(sNewURL))
                aFormErrors.addFieldInfo(FIELD_NEW_URL, "The new URL is invalid");
            else if (sNewURL.equals(sOldURL))
                aFormErrors.addFieldInfo(FIELD_NEW_URL, "The new URL is identical to the old URL");
            // Validate parameters
            if (aFormErrors.isEmpty()) {
                PhotonWorkerPool.getInstance().run("BulkChangeEndpointURL", new BulkChangeEndpointURL(aAllSIs, aServiceGroup, sOldURL, sNewURL));
                aWPEC.postRedirectGetInternal(success("The bulk change of the endpoint URL from '" + sOldURL + "' to '" + sNewURL + "' is now running in the background. Please manually refresh the page to see the update."));
            }
        }
        final ICommonsSet<ISMPServiceGroup> aServiceGroups = aServiceGroupsGroupedPerURL.get(sOldURL);
        final int nSGCount = CollectionHelper.getSize(aServiceGroups);
        final int nEPCount = CollectionHelper.getSize(aEndpointsGroupedPerURL.get(sOldURL));
        aNodeList.addChild(info("The selected old URL '" + sOldURL + "' is currently used in " + nEPCount + " " + (nEPCount == 1 ? "endpoint" : "endpoints") + " of " + nSGCount + " " + (nSGCount == 1 ? "service group" : "service groups") + "."));
        // Show edit screen
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_SUBACTION, CPageParam.ACTION_SAVE));
        if (nSGCount > 1) {
            // Select the affected service groups if more than one is available
            final HCSelect aSGSelect = new HCSelect(new RequestField(FIELD_SERVICE_GROUP));
            aSGSelect.addOption(SERVICE_GROUP_ALL, "All affected Service Groups");
            if (aServiceGroups != null)
                for (final ISMPServiceGroup aSG : aServiceGroups.getSorted(ISMPServiceGroup.comparator())) aSGSelect.addOption(aSG.getID(), aSG.getParticipantIdentifier().getURIEncoded());
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("Service group").setCtrl(aSGSelect).setHelpText("If a specific service group is selected, the URL change will only happen in the endpoints of the selected service group. Othwerwise the endpoint is changed in ALL service groups with matching endpoints.").setErrorList(aFormErrors.getListOfField(FIELD_OLD_URL)));
        } else {
            // If less than 2 service groups are affected, use the 0/1
            // automatically.
            aForm.addChild(new HCHiddenField(FIELD_SERVICE_GROUP, SERVICE_GROUP_ALL));
        }
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Old endpoint URL").setCtrl(new HCEdit(new RequestField(FIELD_OLD_URL, sOldURL))).setHelpText("The old URL that is to be changed in all matching endpoints").setErrorList(aFormErrors.getListOfField(FIELD_OLD_URL)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New endpoint URL").setCtrl(new HCEdit(new RequestField(FIELD_NEW_URL, sOldURL))).setHelpText("The new URL that is used instead").setErrorList(aFormErrors.getListOfField(FIELD_NEW_URL)));
        final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
        aToolbar.addSubmitButton("Save changes", EDefaultIcon.SAVE);
        aToolbar.addButtonCancel(aDisplayLocale);
    }
    if (bShowList) {
        aNodeList.addChild(info().addChildren(div("This page lets you change the URLs of multiple endpoints at once. This is e.g. helpful when the underlying server got a new URL."), div("Currently " + (nTotalEndpointCount == 1 ? "1 endpoint is" : nTotalEndpointCount + " endpoints are") + " registered" + (nTotalEndpointCountWithURL < nTotalEndpointCount ? " of which " + nTotalEndpointCountWithURL + " have an endpoint reference" : "") + ".")));
        final HCTable aTable = new HCTable(new DTCol("Endpoint URL").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Service Group Count").setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol("Endpoint Count").setDisplayType(EDTColType.INT, aDisplayLocale), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
        aEndpointsGroupedPerURL.forEach((sURL, aEndpoints) -> {
            final HCRow aRow = aTable.addBodyRow();
            aRow.addCell(sURL);
            final int nSGCount = CollectionHelper.getSize(aServiceGroupsGroupedPerURL.get(sURL));
            aRow.addCell(Integer.toString(nSGCount));
            aRow.addCell(Integer.toString(aEndpoints.size()));
            final ISimpleURL aEditURL = aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT).add(FIELD_OLD_URL, sURL);
            aRow.addCell(new HCA(aEditURL).setTitle("Change all endpoints pointing to " + sURL).addChild(EDefaultIcon.EDIT.getAsNode()));
        });
        final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
        aNodeList.addChild(aTable).addChild(aDataTables);
    }
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCRow(com.helger.html.hc.html.tabular.HCRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) RequestField(com.helger.photon.core.form.RequestField) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) 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) HCSelect(com.helger.html.hc.html.forms.HCSelect) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCTable(com.helger.html.hc.html.tabular.HCTable) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)21 RequestField (com.helger.photon.core.form.RequestField)20 HCEdit (com.helger.html.hc.html.forms.HCEdit)16 Locale (java.util.Locale)16 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)13 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)12 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 FormErrorList (com.helger.photon.core.form.FormErrorList)11 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)10 HCTextArea (com.helger.html.hc.html.forms.HCTextArea)7 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)6 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)6 RequestFieldBoolean (com.helger.photon.core.form.RequestFieldBoolean)6 PDTToString (com.helger.commons.datetime.PDTToString)5 HCA (com.helger.html.hc.html.textlevel.HCA)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 ISimpleURL (com.helger.commons.url.ISimpleURL)4 HCRow (com.helger.html.hc.html.tabular.HCRow)4 HCTable (com.helger.html.hc.html.tabular.HCTable)4 BootstrapDTColAction (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction)4