use of com.helger.photon.core.form.FormErrorList 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)));
}
}
use of com.helger.photon.core.form.FormErrorList 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);
}
use of com.helger.photon.core.form.FormErrorList in project phoss-smp by phax.
the class PageSecureBusinessCard method _createEntityInputForm.
@Nonnull
private static IHCNode _createEntityInputForm(@Nonnull final LayoutExecutionContext aLEC, @Nullable final SMPBusinessCardEntity aExistingEntity, @Nullable final String sExistingID, @Nonnull final FormErrorList aFormErrors, final boolean bFormSubmitted) {
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
final String sEntityID = StringHelper.hasText(sExistingID) ? sExistingID : TMP_ID_PREFIX + Integer.toString(GlobalIDFactory.getNewIntID());
final BootstrapCard aPanel = new BootstrapCard().setID(sEntityID);
aPanel.createAndAddHeader().addChild("Business Entity");
final BootstrapCardBody aBody = aPanel.createAndAddBody();
final BootstrapViewForm aForm = aBody.addAndReturnChild(new BootstrapViewForm());
final String sFieldName = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_NAME);
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(sFieldName, aExistingEntity == null ? null : aExistingEntity.names().getFirst().getName()))).setErrorList(aFormErrors.getListOfField(sFieldName)));
final String sFieldCountryCode = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_COUNTRY_CODE);
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Country").setCtrl(new HCCountrySelect(new RequestField(sFieldCountryCode, aExistingEntity == null ? null : aExistingEntity.getCountryCode()), aDisplayLocale, HCCountrySelect.getAllCountries(EWithDeprecated.DEFAULT), (aLocale, aContentLocale) -> aLocale.getDisplayCountry(aContentLocale) + " (" + aLocale.getCountry() + ")")).setErrorList(aFormErrors.getListOfField(sFieldCountryCode)));
final String sFieldGeoInfo = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_GEO_INFO);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Geographical Information").setCtrl(new HCTextArea(new RequestField(sFieldGeoInfo, aExistingEntity == null ? null : aExistingEntity.getGeographicalInformation()))).setErrorList(aFormErrors.getListOfField(sFieldGeoInfo)));
// Identifiers
{
final String sBodyID = sEntityID + PREFIX_IDENTIFIER;
final HCNodeList aNL = new HCNodeList();
final BootstrapTable aTable = aNL.addAndReturnChild(new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star()));
aTable.addHeaderRow().addCells("Scheme", "Value", "");
aTable.setBodyID(sBodyID);
final IRequestParamMap aIdentifiers = aLEC.getRequestParamMap().getMap(PREFIX_ENTITY, sEntityID, PREFIX_IDENTIFIER);
if (bFormSubmitted) {
// Re-show of form
if (aIdentifiers != null)
for (final String sIdentifierRowID : aIdentifiers.keySet()) aTable.addBodyRow(_createIdentifierInputForm(aLEC, sEntityID, null, sIdentifierRowID, aFormErrors));
} else {
if (aExistingEntity != null) {
// add all existing stored entities
for (final SMPBusinessCardIdentifier aIdentifier : aExistingEntity.identifiers()) aTable.addBodyRow(_createIdentifierInputForm(aLEC, sEntityID, aIdentifier, (String) null, aFormErrors));
}
}
{
final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
final JSVar aJSAppendData = aJSAppend.param("data");
aJSAppend.body().add(JQuery.idRef(sBodyID).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
final JSPackage aOnAdd = new JSPackage();
aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_IDENTIFIER.getInvocationURL(aRequestScope).add(PARAM_ENTITY_ID, sEntityID)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
aNL.addChild(new BootstrapButton().setIcon(EDefaultIcon.PLUS).addChild("Add Identifier").setOnClick(aOnAdd));
}
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Identifiers").setCtrl(aNL));
}
// Website URIs
final String sFieldWebsiteURIs = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_WEBSITE_URIS);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Website URIs").setCtrl(new HCTextArea(new RequestField(sFieldWebsiteURIs, aExistingEntity == null ? null : StringHelper.getImploded('\n', aExistingEntity.websiteURIs())))).setHelpText("Put each Website URI in a separate line").setErrorList(aFormErrors.getListOfField(sFieldWebsiteURIs)));
// Contacts
{
final String sBodyID = sEntityID + PREFIX_CONTACT;
final HCNodeList aNL = new HCNodeList();
final BootstrapTable aTable = aNL.addAndReturnChild(new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star()));
aTable.addHeaderRow().addCells("Type", "Name", "Phone number", "Email address", "");
aTable.setBodyID(sBodyID);
final IRequestParamMap aContacts = aLEC.getRequestParamMap().getMap(PREFIX_ENTITY, sEntityID, PREFIX_CONTACT);
if (bFormSubmitted) {
// Re-show of form
if (aContacts != null)
for (final String sIdentifierRowID : aContacts.keySet()) aTable.addBodyRow(_createContactInputForm(aLEC, sEntityID, null, sIdentifierRowID, aFormErrors));
} else {
if (aExistingEntity != null) {
// add all existing stored entities
for (final SMPBusinessCardContact aContact : aExistingEntity.contacts()) aTable.addBodyRow(_createContactInputForm(aLEC, sEntityID, aContact, (String) null, aFormErrors));
}
}
{
final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
final JSVar aJSAppendData = aJSAppend.param("data");
aJSAppend.body().add(JQuery.idRef(sBodyID).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
final JSPackage aOnAdd = new JSPackage();
aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_CONTACT.getInvocationURL(aRequestScope).add(PARAM_ENTITY_ID, sEntityID)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
aNL.addChild(new BootstrapButton().setIcon(EDefaultIcon.PLUS).addChild("Add Contact").setOnClick(aOnAdd));
}
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Contacts").setCtrl(aNL));
}
final String sFieldAdditionalInfo = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_ADDITIONAL_INFO);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional Information").setCtrl(new HCTextArea(new RequestField(sFieldAdditionalInfo, aExistingEntity == null ? null : aExistingEntity.getAdditionalInformation()))).setErrorList(aFormErrors.getListOfField(sFieldAdditionalInfo)));
final String sFieldRegDate = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_REG_DATE);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Registration Date").setCtrl(BootstrapDateTimePicker.create(sFieldRegDate, aExistingEntity == null ? null : aExistingEntity.getRegistrationDate(), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(sFieldRegDate)));
final BootstrapButtonToolbar aToolbar = aBody.addAndReturnChild(new BootstrapButtonToolbar(aLEC));
aToolbar.addButton("Delete this Entity", JQuery.idRef(aPanel).remove(), EDefaultIcon.DELETE);
return aPanel;
}
use of com.helger.photon.core.form.FormErrorList in project phoss-smp by phax.
the class PageSecureBusinessCard method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPBusinessCard aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final boolean bEdit = eFormAction.isEdit();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
final String sServiceGroupID = bEdit ? aSelectedObject.getID() : aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
ISMPServiceGroup aServiceGroup = null;
final ICommonsList<SMPBusinessCardEntity> aSMPEntities = new CommonsArrayList<>();
// validations
if (StringHelper.hasNoText(sServiceGroupID))
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A Service Group must be selected!");
else {
aServiceGroup = aServiceGroupManager.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided Service Group does not exist!");
else if (!bEdit) {
final ISMPBusinessCard aExistingBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroup.getParticipantIdentifier());
if (aExistingBusinessCard != null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The selected Service Group already has a Business Card assigned!");
}
}
final IRequestParamMap aEntities = aWPEC.getRequestParamMap().getMap(PREFIX_ENTITY);
if (aEntities != null)
for (final String sEntityRowID : aEntities.keySet()) {
final ICommonsMap<String, String> aEntityRow = aEntities.getValueMap(sEntityRowID);
final int nErrors = aFormErrors.size();
// Entity name
final String sFieldName = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_NAME);
final String sEntityName = aEntityRow.get(SUFFIX_NAME);
if (StringHelper.hasNoText(sEntityName))
aFormErrors.addFieldError(sFieldName, "The Name of the Entity must be provided!");
// Entity country code
final String sFieldCountryCode = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_COUNTRY_CODE);
final String sCountryCode = aEntityRow.get(SUFFIX_COUNTRY_CODE);
if (StringHelper.hasNoText(sCountryCode))
aFormErrors.addFieldError(sFieldCountryCode, "The Country Code of the Entity must be provided!");
// Entity Geographical Information
final String sGeoInfo = aEntityRow.get(SUFFIX_GEO_INFO);
// Entity Identifiers
final ICommonsList<SMPBusinessCardIdentifier> aSMPIdentifiers = new CommonsArrayList<>();
final IRequestParamMap aIdentifiers = aEntities.getMap(sEntityRowID, PREFIX_IDENTIFIER);
if (aIdentifiers != null)
for (final String sIdentifierRowID : aIdentifiers.keySet()) {
final ICommonsMap<String, String> aIdentifierRow = aIdentifiers.getValueMap(sIdentifierRowID);
final int nErrors2 = aFormErrors.size();
// Scheme
final String sFieldScheme = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_SCHEME);
final String sScheme = aIdentifierRow.get(SUFFIX_SCHEME);
if (StringHelper.hasNoText(sScheme))
aFormErrors.addFieldError(sFieldScheme, "The Scheme of the Identifier must be provided!");
// Value
final String sFieldValue = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_VALUE);
final String sValue = aIdentifierRow.get(SUFFIX_VALUE);
if (StringHelper.hasNoText(sValue))
aFormErrors.addFieldError(sFieldValue, "The Value of the Identifier must be provided!");
if (aFormErrors.size() == nErrors2) {
final boolean bIsNewIdentifier = sIdentifierRowID.startsWith(TMP_ID_PREFIX);
aSMPIdentifiers.add(bIsNewIdentifier ? new SMPBusinessCardIdentifier(sScheme, sValue) : new SMPBusinessCardIdentifier(sIdentifierRowID, sScheme, sValue));
}
}
aSMPIdentifiers.sort((o1, o2) -> {
int ret = o1.getScheme().compareToIgnoreCase(o2.getScheme());
if (ret == 0)
ret = o1.getValue().compareToIgnoreCase(o2.getValue());
return ret;
});
// Entity Website URIs
final String sFieldWebsiteURIs = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_WEBSITE_URIS);
final String sWebsiteURIs = aEntityRow.get(SUFFIX_WEBSITE_URIS);
final ICommonsList<String> aWebsiteURIs = new CommonsArrayList<>();
for (final String sWebsiteURI : RegExHelper.getSplitToArray(sWebsiteURIs, "\\n")) {
final String sRealWebsiteURI = sWebsiteURI.trim();
if (sRealWebsiteURI.length() > 0)
if (URLValidator.isValid(sRealWebsiteURI))
aWebsiteURIs.add(sRealWebsiteURI);
else
aFormErrors.addFieldError(sFieldWebsiteURIs, "The website URI '" + sRealWebsiteURI + "' is invalid!");
}
// Entity Contacts
final ICommonsList<SMPBusinessCardContact> aSMPContacts = new CommonsArrayList<>();
final IRequestParamMap aContacts = aEntities.getMap(sEntityRowID, PREFIX_CONTACT);
if (aContacts != null)
for (final String sContactRowID : aContacts.keySet()) {
final ICommonsMap<String, String> aContactRow = aContacts.getValueMap(sContactRowID);
final int nErrors2 = aFormErrors.size();
final String sType = aContactRow.get(SUFFIX_TYPE);
final String sName = aContactRow.get(SUFFIX_NAME);
final String sPhoneNumber = aContactRow.get(SUFFIX_PHONE);
final String sFieldEmail = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_CONTACT, sContactRowID, SUFFIX_EMAIL);
final String sEmail = aContactRow.get(SUFFIX_EMAIL);
if (StringHelper.hasText(sEmail))
if (!EmailAddressValidator.isValid(sEmail))
aFormErrors.addFieldError(sFieldEmail, "The provided email address is invalid!");
final boolean bIsAnySet = StringHelper.hasText(sType) || StringHelper.hasText(sName) || StringHelper.hasText(sPhoneNumber) || StringHelper.hasText(sEmail);
if (aFormErrors.size() == nErrors2 && bIsAnySet) {
final boolean bIsNewContact = sContactRowID.startsWith(TMP_ID_PREFIX);
aSMPContacts.add(bIsNewContact ? new SMPBusinessCardContact(sType, sName, sPhoneNumber, sEmail) : new SMPBusinessCardContact(sContactRowID, sType, sName, sPhoneNumber, sEmail));
}
}
aSMPContacts.sort((o1, o2) -> {
int ret = CompareHelper.compareIgnoreCase(o1.getType(), o2.getType());
if (ret == 0) {
ret = CompareHelper.compareIgnoreCase(o1.getName(), o2.getName());
if (ret == 0) {
ret = CompareHelper.compareIgnoreCase(o1.getPhoneNumber(), o2.getPhoneNumber());
if (ret == 0)
ret = CompareHelper.compareIgnoreCase(o1.getEmail(), o2.getEmail());
}
}
return ret;
});
// Entity Additional Information
final String sAdditionalInfo = aEntityRow.get(SUFFIX_ADDITIONAL_INFO);
// Entity Registration Date
final String sFieldRegDate = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_REG_DATE);
final String sRegDate = aEntityRow.get(SUFFIX_REG_DATE);
final LocalDate aRegDate = PDTFromString.getLocalDateFromString(sRegDate, aDisplayLocale);
if (aRegDate == null && StringHelper.hasText(sRegDate))
aFormErrors.addFieldError(sFieldRegDate, "The entered registration date is invalid!");
if (aFormErrors.size() == nErrors) {
// Add to list
final boolean bIsNewEntity = sEntityRowID.startsWith(TMP_ID_PREFIX);
final SMPBusinessCardEntity aEntity = bIsNewEntity ? new SMPBusinessCardEntity() : new SMPBusinessCardEntity(sEntityRowID);
aEntity.names().add(new SMPBusinessCardName(sEntityName, null));
aEntity.setCountryCode(sCountryCode);
aEntity.setGeographicalInformation(sGeoInfo);
aEntity.identifiers().setAll(aSMPIdentifiers);
aEntity.websiteURIs().setAll(aWebsiteURIs);
aEntity.contacts().setAll(aSMPContacts);
aEntity.setAdditionalInformation(sAdditionalInfo);
aEntity.setRegistrationDate(aRegDate);
aSMPEntities.add(aEntity);
}
}
if (aSMPEntities.isEmpty())
if (aFormErrors.isEmpty())
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "At least one entity must be provided.");
if (aFormErrors.isEmpty()) {
// Store in a consistent manner
aSMPEntities.sort((o1, o2) -> o1.names().getFirst().getName().compareToIgnoreCase(o2.names().getFirst().getName()));
if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aSMPEntities) != null) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
aWPEC.postRedirectGetInternal(success("The Business Card for Service Group '" + aServiceGroup.getID() + "' was successfully saved." + (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate() ? " " + SMPWebAppConfiguration.getDirectoryName() + " server should have been updated." : "")));
} else
aWPEC.postRedirectGetInternal(error("Error creating the Business Card for Service Group '" + aServiceGroup.getID() + "'"));
}
}
use of com.helger.photon.core.form.FormErrorList 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);
}
}
Aggregations