Search in sources :

Example 1 with CRMSubscriberManager

use of com.helger.peppol.crm.CRMSubscriberManager in project peppol-practical by phax.

the class PageSecureCRMGroup method showSelectedObject.

@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, final ICRMGroup aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final BootstrapViewForm aForm = aNodeList.addAndReturnChild(new BootstrapViewForm());
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Name").setCtrl(aSelectedObject.getDisplayName()));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Sender email address").setCtrl(aSelectedObject.getSenderEmailAddress()));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Assigned participants").setCtrl(Long.toString(aCRMSubscriberMgr.getCRMSubscriberCountOfGroup(aSelectedObject))));
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup)

Example 2 with CRMSubscriberManager

use of com.helger.peppol.crm.CRMSubscriberManager in project peppol-practical by phax.

the class PageSecureCRMSubscriber method _getListForMailing.

@Nonnull
private static IHCNode _getListForMailing() {
    final StringBuilder aSB = new StringBuilder();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    int nCount = 0;
    for (final ICRMSubscriber aSubscriber : aCRMSubscriberMgr.getAllActiveCRMSubscribers().getSortedInline(Comparator.comparing(ICRMSubscriber::getEmailAddress))) {
        if (aSB.length() > 0)
            aSB.append("\n");
        aSB.append(aSubscriber.getEmailAddress());
        ++nCount;
    }
    final HCTextArea aTA = new HCTextArea().setValue(aSB.toString()).setRows(Math.min(nCount, 20));
    BootstrapFormHelper.markAsFormControl(aTA);
    return aTA;
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) Nonnull(javax.annotation.Nonnull)

Example 3 with CRMSubscriberManager

use of com.helger.peppol.crm.CRMSubscriberManager in project peppol-practical by phax.

the class PagePublicNewsletterSubscribe method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    ICommonsList<String> aSelectedCRMGroupIDs = null;
    if (aWPEC.hasAction(CPageParam.ACTION_SAVE)) {
        final String sSalutationID = aWPEC.params().getAsString(FIELD_SALUTATION);
        final ESalutation eSalutation = ESalutation.getFromIDOrNull(sSalutationID);
        final String sName = aWPEC.params().getAsString(FIELD_NAME);
        final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
        aSelectedCRMGroupIDs = aWPEC.params().getAsStringList(FIELD_GROUP);
        final ICommonsSet<ICRMGroup> aSelectedCRMGroups = new CommonsHashSet<>();
        ICRMSubscriber aSameEmailAddressSubscriber = null;
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "You must provide your name!");
        if (StringHelper.hasNoText(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "You must provide your email address!");
        else if (!EmailAddressHelper.isValid(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
        else {
            // Check if the email address is already in use
            aSameEmailAddressSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
        }
        if (aSelectedCRMGroupIDs != null)
            for (final String sCRMGroupID : aSelectedCRMGroupIDs) {
                final ICRMGroup aGroup = aCRMGroupMgr.getCRMGroupOfID(sCRMGroupID);
                if (aGroup == null)
                    aFormErrors.addFieldError(FIELD_GROUP, "The selected mailing list is not existing!");
                else
                    aSelectedCRMGroups.add(aGroup);
            }
        if (aSelectedCRMGroups.isEmpty())
            aFormErrors.addFieldError(FIELD_GROUP, "At least one mailing list must be selected!");
        else {
            if (aSameEmailAddressSubscriber != null) {
                // Merge with existing subscriber
                aSelectedCRMGroups.addAll(aSameEmailAddressSubscriber.getAllAssignedGroups());
            }
        }
        if (aFormErrors.isEmpty()) {
            // Save
            if (aSameEmailAddressSubscriber == null) {
                // Create a new one
                aCRMSubscriberMgr.createCRMSubscriber(eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            } else {
                // Update an existing one
                aCRMSubscriberMgr.updateCRMSubscriber(aSameEmailAddressSubscriber.getID(), eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            }
            aNodeList.addChild(success("Successfully subscribed '" + sEmailAddress + "' to mailing lists"));
        } else {
            aNodeList.addChild(getUIHandler().createIncorrectInputBox(aWPEC));
        }
    }
    final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
    aForm.setLeft(3);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Your salutation").setCtrl(new HCSalutationSelect(new RequestField(FIELD_SALUTATION), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SALUTATION)));
    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_ADDRESS))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    {
        final ICommonsList<? extends ICRMGroup> aAllCRMGroups = aCRMGroupMgr.getAll();
        if (aAllCRMGroups.size() == 1) {
            // No need for selection - use hidden field
            aForm.addChild(new HCHiddenField(FIELD_GROUP, aAllCRMGroups.getFirst().getID()));
        } else if (aAllCRMGroups.isNotEmpty()) {
            // Show selection
            final HCNodeList aGroups = new HCNodeList();
            for (final ICRMGroup aCRMGroup : aAllCRMGroups.getSorted(IHasDisplayName.getComparatorCollating(aDisplayLocale))) {
                final String sCRMGroupID = aCRMGroup.getID();
                final RequestFieldBooleanMultiValue aRFB = new RequestFieldBooleanMultiValue(FIELD_GROUP, sCRMGroupID, false);
                aGroups.addChild(new HCDiv().addChild(new HCCheckBox(aRFB)).addChild(" " + aCRMGroup.getDisplayName()));
            }
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Mailing lists to subscribe to").setCtrl(aGroups).setErrorList(aFormErrors.getListOfField(FIELD_GROUP)));
        }
    }
    // Toolbar
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_SAVE);
    aToolbar.addSubmitButton("Subscribe", EDefaultIcon.YES);
    aNodeList.addChild(aForm);
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) RequestFieldBooleanMultiValue(com.helger.photon.core.form.RequestFieldBooleanMultiValue) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) ESalutation(com.helger.masterdata.person.ESalutation) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICRMGroup(com.helger.peppol.crm.ICRMGroup) HCSalutationSelect(com.helger.photon.uicore.html.select.HCSalutationSelect) RequestField(com.helger.photon.core.form.RequestField)

Example 4 with CRMSubscriberManager

use of com.helger.peppol.crm.CRMSubscriberManager in project peppol-practical by phax.

the class PagePublicNewsletterUnsubscribe method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_SAVE)) {
        final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
        ICRMSubscriber aCRMSubscriber = null;
        if (StringHelper.hasNoText(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "You must provide your email address!");
        else if (!EmailAddressHelper.isValid(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
        else {
            aCRMSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
            if (aCRMSubscriber == null)
                aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is not registered to any mailing list!");
        }
        if (aFormErrors.isEmpty()) {
            // Update an existing one
            aCRMSubscriberMgr.updateCRMSubscriberGroupAssignments(aCRMSubscriber.getID(), null);
            aNodeList.addChild(success("Successfully unsubscribed '" + sEmailAddress + "' from all mailing lists"));
        } else {
            aNodeList.addChild(getUIHandler().createIncorrectInputBox(aWPEC));
        }
    }
    final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
    aForm.setLeft(3);
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL_ADDRESS))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    // Toolbar
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_SAVE);
    aToolbar.addSubmitButton("Unsubscribe", EDefaultIcon.YES);
    aNodeList.addChild(aForm);
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) RequestField(com.helger.photon.core.form.RequestField)

Example 5 with CRMSubscriberManager

use of com.helger.peppol.crm.CRMSubscriberManager in project peppol-practical by phax.

the class PPMetaManager method onAfterInstantiation.

@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
    try {
        m_aCRMGroupMgr = new CRMGroupManager(CRMGROUP_XML);
        m_aCRMSubscriberMgr = new CRMSubscriberManager(CRMSUBSCRIBER_XML);
        // Before TestEndpoint manager!
        m_aSMLConfigurationMgr = new SMLConfigurationManager(SML_INFO_XML);
        m_aTestEndpointMgr = new TestEndpointManager(TEST_ENDPOINT_XML);
        LOGGER.info("MetaManager was initialized");
    } catch (final DAOException ex) {
        throw new InitializationException("Failed to init MetaManager", ex);
    }
}
Also used : DAOException(com.helger.dao.DAOException) CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) TestEndpointManager(com.helger.peppol.testendpoint.TestEndpointManager) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) InitializationException(com.helger.commons.exception.InitializationException)

Aggregations

CRMSubscriberManager (com.helger.peppol.crm.CRMSubscriberManager)7 HCNodeList (com.helger.html.hc.impl.HCNodeList)5 ICRMSubscriber (com.helger.peppol.crm.ICRMSubscriber)4 CRMGroupManager (com.helger.peppol.crm.CRMGroupManager)3 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)3 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)3 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)2 HCEdit (com.helger.html.hc.html.forms.HCEdit)2 ESalutation (com.helger.masterdata.person.ESalutation)2 ICRMGroup (com.helger.peppol.crm.ICRMGroup)2 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)2 FormErrorList (com.helger.photon.core.form.FormErrorList)2 RequestField (com.helger.photon.core.form.RequestField)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 PDTToString (com.helger.commons.datetime.PDTToString)1 InitializationException (com.helger.commons.exception.InitializationException)1 DAOException (com.helger.dao.DAOException)1 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)1 HCHiddenField (com.helger.html.hc.html.forms.HCHiddenField)1 HCTextArea (com.helger.html.hc.html.forms.HCTextArea)1