Search in sources :

Example 1 with EIDType

use of com.helger.peppol.domain.EIDType in project peppol-practical by phax.

the class PagePublicToolsIdentifierInformation method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final FormErrorList aFormErrors = new FormErrorList();
    final boolean bShowInput = true;
    boolean bShowHeader = true;
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        // Validate fields
        final String sIDType = aWPEC.params().getAsString(FIELD_ID_TYPE);
        final EIDType eIDType = EIDType.getFromIDOrNull(sIDType);
        String sIDValue = aWPEC.params().getAsStringTrimmed(FIELD_ID_VALUE);
        final boolean bDecodeValue = aWPEC.params().isCheckBoxChecked(FIELD_ID_DECODE, DEFAULT_DECODE);
        if (bDecodeValue) {
            // Try decoding - else stick with the original
            sIDValue = URLHelper.urlDecodeOrDefault(sIDValue, sIDValue);
        }
        if (StringHelper.hasNoText(sIDType))
            aFormErrors.addFieldError(FIELD_ID_TYPE, "An identifier type must be selected");
        else if (eIDType == null)
            aFormErrors.addFieldError(FIELD_ID_TYPE, "An identifier type must be selected");
        if (StringHelper.hasNoText(sIDValue))
            aFormErrors.addFieldError(FIELD_ID_VALUE, "An identifier value must be provided");
        if (aFormErrors.isEmpty()) {
            STATS_COUNT.increment();
            STATS_ID_TYPE.increment(eIDType.getID());
            bShowHeader = false;
            LOGGER.info("Checking identifier type " + eIDType.name() + " for value '" + sIDValue + "'");
            final ErrorList aIDErrors = new ErrorList();
            final ICommonsList<KVPair> aDetails = new CommonsArrayList<>();
            // Perform the main validation
            eIDType.getValidator().validate(sIDValue, aIDErrors, aDetails);
            final IHCNode aDetailsNode;
            if (aDetails.isEmpty())
                aDetailsNode = null;
            else {
                final HCUL aULDetails = new HCUL();
                for (final KVPair aPair : aDetails) aULDetails.addAndReturnItem(aPair.getKey() + ": ").addChild(aPair.hasValue() ? code(aPair.getValue()) : badgeInfo("empty string"));
                aDetailsNode = new HCNodeList().addChild(div("Determined details are:")).addChild(aULDetails);
            }
            if (aIDErrors.containsNoError()) {
                STATS_COUNT_SUCCESS.increment();
                final IHCNode aWarningsNode;
                final EBootstrapAlertType eAlertType;
                if (aIDErrors.isEmpty()) {
                    // No errors, no warnings
                    eAlertType = EBootstrapAlertType.SUCCESS;
                    aWarningsNode = null;
                } else {
                    // No errors but warnings
                    eAlertType = EBootstrapAlertType.WARNING;
                    final HCUL aUL = new HCUL();
                    for (final IError aError : aIDErrors) aUL.addItem(aError.getAsString(aDisplayLocale));
                    aWarningsNode = new HCNodeList().addChild(div("But there are some warnings:")).addChild(aUL);
                }
                aNodeList.addChild(new BootstrapBox(eAlertType).addChild(div("The identifier ").addChild(code(sIDValue)).addChild(" is valid according to the rules of '" + eIDType.getDisplayName() + "'")).addChild(aWarningsNode).addChild(aDetailsNode));
                LOGGER.info(aIDErrors.isEmpty() ? "success" : "success with warning");
            } else {
                // At least one error
                final HCUL aUL = new HCUL();
                for (final IError aError : aIDErrors) aUL.addItem(aError.getAsString(aDisplayLocale));
                aNodeList.addChild(error(div("The identifier ").addChild(code(sIDValue)).addChild(" is NOT valid according to the rules of '" + eIDType.getDisplayName() + "'")).addChild(aUL).addChild(aDetailsNode));
                LOGGER.info("failure");
            }
        }
    }
    if (bShowInput) {
        if (bShowHeader) {
            final ICommonsOrderedMap<String, String> aRuleSets = new CommonsLinkedHashMap<>();
            aRuleSets.put("Peppol Policy for use of Identifiers v" + IDENTIFIER_POLICY_VERSION, "https://docs.peppol.eu/edelivery/");
            aRuleSets.put("Peppol Participant Identifier Code List v" + EPredefinedParticipantIdentifierScheme.CODE_LIST_VERSION, "https://docs.peppol.eu/edelivery/codelists/");
            aRuleSets.put("Peppol Document Type Identifier Code List v" + EPredefinedDocumentTypeIdentifier.CODE_LIST_VERSION, "https://docs.peppol.eu/edelivery/codelists/");
            aRuleSets.put("Peppol Process Identifier Code List v" + EPredefinedProcessIdentifier.CODE_LIST_VERSION, "https://docs.peppol.eu/edelivery/codelists/");
            final HCUL aULRules = new HCUL();
            for (final Map.Entry<String, String> aEntry : aRuleSets.entrySet()) aULRules.addAndReturnItem(aEntry.getKey() + " - ").addChild(new HCA(new SimpleURL(aEntry.getValue())).setTargetBlank().addChild("see details"));
            aNodeList.addChild(info(div("This page lets you verify identifiers against official rules. Current rule sets are:")).addChild(aULRules));
        }
        final HCExtSelect aTypeSelect = new HCExtSelect(new RequestField(FIELD_ID_TYPE));
        for (final EIDType e : EIDType.values()) aTypeSelect.addOption(e.getID(), e.getDisplayName());
        aTypeSelect.addOptionPleaseSelect(aDisplayLocale);
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC).setFormType(EBootstrapFormType.DEFAULT).setMethod(EHCFormMethod.GET).setLeft(2));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier type").setCtrl(aTypeSelect).setErrorList(aFormErrors.getListOfField(FIELD_ID_TYPE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier value").setCtrl(new HCEdit(new RequestField(FIELD_ID_VALUE)).setPlaceholder("scheme::value")).setHelpText(div("The identifier value to be checked for consistency. It MUST contain the scheme (like ").addChild(code(PeppolIdentifierHelper.PARTICIPANT_SCHEME_ISO6523_ACTORID_UPIS)).addChild(", ").addChild(code(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS)).addChild(" or ").addChild(code(PeppolIdentifierHelper.PROCESS_SCHEME_CENBII_PROCID_UBL)).addChild(") AND the value as one long string")).setErrorList(aFormErrors.getListOfField(FIELD_ID_VALUE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Try to URL decode the identifier value?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_ID_DECODE, DEFAULT_DECODE))).setErrorList(aFormErrors.getListOfField(FIELD_ID_DECODE)));
        final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
        aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
        aToolbar.addSubmitButton("Check identifier");
    }
}
Also used : Locale(java.util.Locale) BootstrapBox(com.helger.photon.bootstrap4.alert.BootstrapBox) HCExtSelect(com.helger.photon.uicore.html.select.HCExtSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) EBootstrapAlertType(com.helger.photon.bootstrap4.alert.EBootstrapAlertType) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) RequestField(com.helger.photon.core.form.RequestField) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) HCA(com.helger.html.hc.html.textlevel.HCA) IError(com.helger.commons.error.IError) SimpleURL(com.helger.commons.url.SimpleURL) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCUL(com.helger.html.hc.html.grouping.HCUL) ErrorList(com.helger.commons.error.list.ErrorList) FormErrorList(com.helger.photon.core.form.FormErrorList) KVPair(com.helger.peppol.domain.KVPair) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) Map(java.util.Map) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) EIDType(com.helger.peppol.domain.EIDType) IHCNode(com.helger.html.hc.IHCNode)

Aggregations

CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)1 ICommonsOrderedMap (com.helger.commons.collection.impl.ICommonsOrderedMap)1 IError (com.helger.commons.error.IError)1 ErrorList (com.helger.commons.error.list.ErrorList)1 SimpleURL (com.helger.commons.url.SimpleURL)1 IHCNode (com.helger.html.hc.IHCNode)1 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)1 HCEdit (com.helger.html.hc.html.forms.HCEdit)1 HCUL (com.helger.html.hc.html.grouping.HCUL)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 EIDType (com.helger.peppol.domain.EIDType)1 KVPair (com.helger.peppol.domain.KVPair)1 BootstrapBox (com.helger.photon.bootstrap4.alert.BootstrapBox)1 EBootstrapAlertType (com.helger.photon.bootstrap4.alert.EBootstrapAlertType)1 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)1 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)1 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)1 FormErrorList (com.helger.photon.core.form.FormErrorList)1