From a350d6fb0508cd9597514e77c00ff9d088b3fb68 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 15 Nov 2012 10:45:08 +0000 Subject: [PATCH] =?UTF-8?q?Der=20Eigent=C3=BCmer=20eines=20PublicPersonalP?= =?UTF-8?q?rofiles=20l=C3=A4sst=20sich=20jetzt=20=C3=A4ndern.=20Die=20Ausw?= =?UTF-8?q?ahl=20ist=20auf=20den=20aktuellen=20Eigent=C3=BCmer=20und=20Per?= =?UTF-8?q?sonen-Items=20mit=20denen=20der=20aktuelle=20Eigent=C3=BCmer=20?= =?UTF-8?q?als=20Alias=20verkn=C3=BCpft=20ist,=20beschr=C3=A4nkt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1933 8810af33-2d31-482b-a856-94f89814c4df --- .../ui/PublicPersonalProfileCreate.java | 128 ++++++++---------- .../ui/PublicPersonalProfilePropertyForm.java | 77 +++++++++-- 2 files changed, 122 insertions(+), 83 deletions(-) diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java index a8eb5d1a3..e88a1548e 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java @@ -6,6 +6,9 @@ import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.parameters.DateParameter; import com.arsdigita.bebop.parameters.NotNullValidationListener; @@ -15,36 +18,42 @@ import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ContentTypeCollection; import com.arsdigita.cms.Folder; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.PublicPersonalProfile; import com.arsdigita.cms.contenttypes.PublicPersonalProfileBundle; +import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig; +import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles; import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection; import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.CreationSelector; import com.arsdigita.cms.ui.authoring.LanguageWidget; import com.arsdigita.cms.ui.authoring.PageCreate; import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Assert; import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.TooManyListenersException; /** * * @author Jens Pelzetter - * @version $Id: PublicPersonalProfileCreate.java 1384 2011-12-20 18:07:11Z - * jensp $ + * @version $Id$ */ public class PublicPersonalProfileCreate extends PageCreate { //private static final String SELECTED_PERSON = "selectedPerson"; - //private static final PublicPersonalProfileConfig config = - // PublicPersonalProfiles. getConfig(); + private static final PublicPersonalProfileConfig config = + PublicPersonalProfiles.getConfig(); + public PublicPersonalProfileCreate(final ItemSelectionModel itemModel, final CreationSelector parent) { super(itemModel, parent); @@ -69,63 +78,46 @@ public class PublicPersonalProfileCreate extends PageCreate { ownerSelect.addValidationListener(new NotNullValidationListener()); try { - ownerSelect.addPrintListener(new PPPOwnerSelectPrintListener()); -// ownerSelect.addPrintListener(new PrintListener() { -// -// public void prepare(final PrintEvent event) { -// final SingleSelect ownerSelect = (SingleSelect) event. -// getTarget(); -// -// String personType = config.getPersonType(); -// if ((personType == null) || (personType.isEmpty())) { -// personType = -// "com.arsdigita.cms.contenttypes.GenericPerson"; -// } -// -// ContentTypeCollection types = -// ContentType.getAllContentTypes(); -// types.addFilter( -// String.format("className = '%s'", personType)); -// if (types.size() == 0) { -// personType = -// "com.arsdigita.cms.contenttypes.GenericPerson"; -// } -// DataCollection persons = SessionManager.getSession(). -// retrieve( -// personType); -// //persons.addFilter("profile is null"); -// persons.addFilter(String.format("version = '%s'", -// ContentItem.DRAFT)); -// persons.addOrder("surname asc"); -// persons.addOrder("givenname asc"); -// persons.addOrder("language asc"); -// ownerSelect.addOption(new Option("", "")); -// -// //Store the parent ids of processed items to remove double entries. -// final List processed = -// new ArrayList(); -// while (persons.next()) { -// GenericPerson person = -// (GenericPerson) DomainObjectFactory. -// newInstance(persons.getDataObject()); -// if (processed.contains(person.getParent().getID())) { -// continue; -// } else { -// if (person.getGenericPersonBundle().get("profile") -// == null) { -// continue; -// } else { -// ownerSelect.addOption(new Option( -// person.getID().toString(), -// String.format("%s (%s)", -// person.getFullName(), -// person.getLanguage()))); -// processed.add(person.getParent().getID()); -// } -// } -// } -// } -// }); + + ownerSelect.addPrintListener(new PrintListener() { + public void prepare(final PrintEvent event) { + final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); + + String personType = config.getPersonType(); + if ((personType == null) || (personType.isEmpty())) { + personType = "com.arsdigita.cms.contenttypes.GenericPerson"; + } + + ContentTypeCollection types = ContentType.getAllContentTypes(); + types.addFilter(String.format("className = '%s'", personType)); + if (types.size() == 0) { + personType = "com.arsdigita.cms.contenttypes.GenericPerson"; + } + DataCollection persons = SessionManager.getSession().retrieve(personType); + //persons.addFilter("profile is null"); + persons.addFilter(String.format("version = '%s'", ContentItem.DRAFT)); + persons.addOrder("surname asc"); + persons.addOrder("givenname asc"); + persons.addOrder("language asc"); + ownerSelect.addOption(new Option("", "")); + + //Store the parent ids of processed items to remove double entries. + final List processed = new ArrayList(); + while (persons.next()) { + GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons.getDataObject()); + if (processed.contains(person.getParent().getID())) { + continue; + } else { + if (person.getGenericPersonBundle().get("profile") == null) { + continue; + } else { + ownerSelect.addOption(new Option(person.getID().toString(), person.getFullName())); + processed.add(person.getParent().getID()); + } + } + } + } + }); } catch (TooManyListenersException ex) { throw new UncheckedWrapperException(ex); } @@ -133,8 +125,7 @@ public class PublicPersonalProfileCreate extends PageCreate { add(ownerSelect); if (!ContentSection.getConfig().getHideLaunchDate()) { - add(new Label(GlobalizationUtil.globalize( - "cms.ui.authoring.page_launch_date"))); + add(new Label(GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date"))); final ParameterModel launchDateParam = new DateParameter(LAUNCH_DATE); final com.arsdigita.bebop.form.Date launchDate = new com.arsdigita.bebop.form.Date(launchDateParam); if (ContentSection.getConfig().getRequireLaunchDate()) { @@ -148,11 +139,11 @@ public class PublicPersonalProfileCreate extends PageCreate { } /** - * Ensure name uniqueness. Note: We can't call {@code super.validate(FormSectionEvent)} here - * because the super method {@link BasicPageForm#validate(com.arsdigita.bebop.event.FormSectionEvent)} tries - * to access properties which are not set yet. - * - * @param fse + * Ensure name uniqueness. Note: We can't call {@code super.validate(FormSectionEvent)} here because the super + * method {@link BasicPageForm#validate(com.arsdigita.bebop.event.FormSectionEvent)} tries to access properties + * which are not set yet. + * + * @param fse */ @Override public void validate(final FormSectionEvent fse) throws FormProcessException { @@ -231,5 +222,4 @@ public class PublicPersonalProfileCreate extends PageCreate { return GenericPerson.urlSave(profileUrl).toLowerCase(); } - } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java index 6fb1ca344..48018df6f 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java @@ -10,28 +10,33 @@ import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormValidationListener; import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.NotNullValidationListener; import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ContentTypeCollection; import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.PublicPersonalProfile; import com.arsdigita.cms.contenttypes.PublicPersonalProfileBundle; +import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles; import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; import java.util.TooManyListenersException; -import java.util.logging.Level; -import java.util.logging.Logger; /** * - * @author Jens Pelzetter + * @author Jens Pelzetter * @version $Id$ */ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements FormProcessListener, @@ -62,12 +67,57 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements final ParameterModel ownerModel = new StringParameter(PublicPersonalProfileBundle.OWNER); final SingleSelect ownerSelect = new SingleSelect(ownerModel); ownerSelect.addValidationListener(new NotNullValidationListener()); - + add(ownerSelect); + try { ownerSelect.addPrintListener(new PrintListener() { + public void prepare(final PrintEvent event) { + final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); + + final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event. + getPageState()); + final GenericPerson owner = profile.getOwner(); + + String personType = PublicPersonalProfiles.getConfig().getPersonType(); + if ((personType == null) || (personType.isEmpty())) { + personType = "com.arsdigita.cms.contenttypes.GenericPerson"; + } - public void prepare(PrintEvent e) { - throw new UnsupportedOperationException("Not supported yet."); + ContentTypeCollection types = ContentType.getAllContentTypes(); + types.addFilter(String.format("className = '%s'", personType)); + if (types.size() == 0) { + personType = "com.arsdigita.cms.contenttypes.GenericPerson"; + } + DataCollection persons = SessionManager.getSession().retrieve(personType); + //persons.addFilter("profile is null"); + persons.addFilter(String.format("version = '%s'", ContentItem.DRAFT)); + persons.addFilter(String.format("alias.id = '%s'", owner.getID().toString())); + persons.addOrder("surname asc"); + persons.addOrder("givenname asc"); + persons.addOrder("language asc"); + + +// final GenericPerson owner = profile.getOwner(); +// final GenericPerson alias = owner.getAlias(); + + ownerSelect.addOption(new Option(owner.getID().toString(), owner.getFullName())); + + if (!persons.isEmpty()) { + final List processed = new ArrayList(); + while(persons.next()) { + GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons.getDataObject()); + if (processed.contains(person.getParent().getID())) { + continue; + } else { + if (person.getGenericPersonBundle().get("profile") == null) { + continue; + } else { + ownerSelect.addOption(new Option(person.getID().toString(), person.getFullName())); + processed.add(person.getParent().getID()); + } + } + } + } } }); } catch (TooManyListenersException ex) { @@ -82,7 +132,6 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements @Override public void init(final FormSectionEvent fse) throws FormProcessException { - //final PageState state = fse.getPageState(); final FormData data = fse.getFormData(); final PublicPersonalProfile profile = (PublicPersonalProfile) super.initBasicWidgets(fse); @@ -94,14 +143,15 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements final PublicPersonalProfile profile = (PublicPersonalProfile) processBasicWidgets(fse); final FormData data = fse.getFormData(); final PageState state = fse.getPageState(); - + if ((profile != null) && getSaveCancelSection().getSaveButton().isSelected(state)) { - - final String ownerId = (String)data.get(PublicPersonalProfileBundle.OWNER); + + final String ownerId = (String) data.get(PublicPersonalProfileBundle.OWNER); if (!profile.getOwner().getID().equals(new BigDecimal(ownerId))) { - - } - + final GenericPerson newOwner = new GenericPerson(new BigDecimal(ownerId)); + profile.setOwner(newOwner); + } + profile.setProfileUrl(((String) data.get(PublicPersonalProfile.PROFILE_URL)).toLowerCase()); profile.save(); @@ -146,5 +196,4 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements } } } - }