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!"));
}
}
}
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);
}
Aggregations