Search in sources :

Example 6 with CRMSubscriberManager

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

the class PageSecureCRMSubscriber method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ICRMSubscriber aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    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);
    final ICommonsList<String> aSelectedCRMGroupIDs = aWPEC.params().getAsStringList(FIELD_GROUP);
    final ICommonsSet<ICRMGroup> aSelectedCRMGroups = new CommonsHashSet<>();
    if (StringHelper.hasNoText(sName))
        aFormErrors.addFieldError(FIELD_NAME, "A name for the CRM subscriber must be provided!");
    if (StringHelper.hasNoText(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "An email address must be provided!");
    else if (!EmailAddressHelper.isValid(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
    else {
        final ICRMSubscriber aSameEmailAddresSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
        if (aSameEmailAddresSubscriber != null) {
            if (!eFormAction.isEdit() || aSameEmailAddresSubscriber != aSelectedObject)
                aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "A subscription for the provided email address is already present!");
        }
    }
    if (aSelectedCRMGroupIDs != null)
        for (final String sCRMGroupID : aSelectedCRMGroupIDs) {
            final ICRMGroup aGroup = aCRMGroupMgr.getCRMGroupOfID(sCRMGroupID);
            if (aGroup == null)
                aFormErrors.addFieldError(FIELD_GROUP, "The selected group is not existing!");
            else
                aSelectedCRMGroups.add(aGroup);
        }
    if (aSelectedCRMGroups.isEmpty())
        aFormErrors.addFieldError(FIELD_GROUP, "At least one group must be selected!");
    if (aFormErrors.isEmpty()) {
        // All fields are valid -> save
        if (eFormAction.isEdit()) {
            // We're editing an existing object
            aCRMSubscriberMgr.updateCRMSubscriber(aSelectedObject.getID(), eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            aNodeList.addChild(success("The CRM subscriber was successfully edited!"));
        } else {
            // We're creating a new object
            aCRMSubscriberMgr.createCRMSubscriber(eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            aNodeList.addChild(success("The new CRM subscriber was successfully created!"));
        }
    }
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ESalutation(com.helger.masterdata.person.ESalutation) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) PDTToString(com.helger.commons.datetime.PDTToString) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICRMGroup(com.helger.peppol.crm.ICRMGroup)

Example 7 with CRMSubscriberManager

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

the class PageSecureCRMSubscriber method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    // Toolbar on top
    final BootstrapButtonToolbar aToolbar = aNodeList.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addButtonNew("Create new CRM subscriber", createCreateURL(aWPEC));
    final BootstrapTabBox aTabBox = new BootstrapTabBox();
    aTabBox.addTab("active", "Active", _getList(aWPEC, aCRMSubscriberMgr.getAllActiveCRMSubscribers(), "active"));
    aTabBox.addTab("deleted", "Deleted", _getList(aWPEC, aCRMSubscriberMgr.getAllDeletedCRMSubscribers(), "del"));
    aTabBox.addTab("mailing", "Mailing", _getListForMailing());
    aNodeList.addChild(aTabBox);
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox)

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