PublicPersonalProfile Owner Assoziation auf neue Struktur umgestellt (Ticket 1112)

git-svn-id: https://svn.libreccm.org/ccm/trunk@1490 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-02-06 08:39:58 +00:00
parent 9a3cced24e
commit 8e172f73e7
4 changed files with 126 additions and 81 deletions

View File

@ -14,17 +14,22 @@ object type PublicPersonalProfile extends ContentPage {
reference key (ct_public_personal_profiles.profile_id);
}
object type PublicPersonalProfileBundle extends ContentBundle {
reference key (ct_public_personal_profile_bundles.bundle_id);
}
association {
PublicPersonalProfile[0..n] profile = join cms_persons.person_id
to ct_public_personal_profile_owner_map.owner_id,
join ct_public_personal_profile_owner_map.profile_id
to ct_public_personal_profiles.profile_id;
PublicPersonalProfileBundle[0..n] profile = join cms_person_bundles.bundle_id
to ct_public_personal_profile_owner_map.owner_id,
join ct_public_personal_profile_owner_map.profile_id
to ct_public_personal_profile_bundles.bundle_id;
GenericPerson[0..n] owner = join ct_public_personal_profiles.profile_id
to ct_public_personal_profile_owner_map.profile_id,
join ct_public_personal_profile_owner_map.owner_id
to cms_persons.person_id;
GenericPersonBundle[0..n] owner = join ct_public_personal_profile_bundles.bundle_id
to ct_public_personal_profile_owner_map.profile_id,
join ct_public_personal_profile_owner_map.owner_id
to cms_person_bundles.bundle_id;
Integer[0..1] ownerOrder = ct_public_personal_profile_owner_map.owner_order INTEGER;
}

View File

@ -19,6 +19,7 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ExtraXMLGenerator;
import com.arsdigita.cms.publicpersonalprofile.ContentGenerator;
@ -51,15 +52,16 @@ public class PublicPersonalProfile
extends ContentPage
implements CustomizedPreviewLink {
private static final PublicPersonalProfileConfig config = PublicPersonalProfiles.getConfig();
public static final String OWNER = "owner";
private static final PublicPersonalProfileConfig config =
PublicPersonalProfiles.
getConfig();
public static final String PROFILE_URL = "profileUrl";
public static final String LINK_LIST_NAME = "publicPersonalProfileNavItems";
public static final String POSITION = "position";
public static final String INTERESTS = "interests";
public static final String MISC = "misc";
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.PublicPersonalProfile";
"com.arsdigita.cms.contenttypes.PublicPersonalProfile";
public PublicPersonalProfile() {
this(BASE_DATA_OBJECT_TYPE);
@ -83,24 +85,33 @@ public class PublicPersonalProfile
super(type);
}
public PublicPersonalProfileBundle getPublicPersonalProfileBundle() {
return (PublicPersonalProfileBundle) getContentBundle();
}
/**
*
* @return The owner of the profile.
*/
public GenericPerson getOwner() {
final DataCollection collection = (DataCollection) get(OWNER);
if (0 == collection.size()) {
return null;
} else {
DataObject dobj;
collection.next();
dobj = collection.getDataObject();
collection.close();
return (GenericPerson) DomainObjectFactory.newInstance(dobj);
/*
* final DataCollection collection = (DataCollection)
* getContentBundle(). get(OWNER);
*
* if (0 == collection.size()) { return null; } else { DataObject dobj;
*
* collection.next(); dobj = collection.getDataObject();
* collection.close();
*
* final GenericPersonBundle bundle = (GenericPersonBundle)
* DomainObjectFactory. newInstance(dobj);
*
*
* return (GenericPerson) DomainObjectFactory.newInstance(dobj);
}
*/
return (GenericPerson) getPublicPersonalProfileBundle().getOwner().
getPrimaryInstance();
}
/**
@ -109,17 +120,17 @@ public class PublicPersonalProfile
* @param owner
*/
public void setOwner(final GenericPerson owner) {
GenericPerson oldOwner;
oldOwner = getOwner();
if (oldOwner != null) {
remove(OWNER, oldOwner);
}
if (null != owner) {
Assert.exists(owner, GenericPerson.class);
add(OWNER, owner);
/*
* final ContentBundle bundle = getContentBundle(); final
* GenericPersonBundle oldOwner = (GenericPersonBundle) getOwner().
* getContentBundle(); if (oldOwner != null) { bundle.remove(OWNER,
* oldOwner); }
*
* if (null != owner) { Assert.exists(owner, GenericPerson.class);
* bundle.add(OWNER, owner.getContentBundle());
}
*/
getPublicPersonalProfileBundle().setOwner(owner);
}
/**
@ -139,27 +150,27 @@ public class PublicPersonalProfile
public String getPosition() {
return (String) get(POSITION);
}
public void setPosition(final String position) {
set(POSITION, position);
}
}
public String getResearchInterests() {
return (String) get(INTERESTS);
}
public void setResearchInterests(final String researchInterests) {
set(INTERESTS, researchInterests);
}
public String getMisc() {
return (String) get(MISC);
}
public void setMisc(final String misc) {
set(MISC, misc);
}
/**
* The profile has an extra XML Generator, which is primarily to render the
* items and the navigation of the profile for the embedded view.

View File

@ -22,9 +22,10 @@ import javax.servlet.ServletException;
/**
* Generates the extra XML output for a profile for the embedded view.
*
* @author Jens Pelzetter
* @version $Id$
*
* @author Jens Pelzetter
* @version $Id: PublicPersonalProfileExtraXmlGenerator.java 1466 2012-01-23
* 12:59:16Z jensp $
*/
public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator {
@ -43,21 +44,20 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
final PublicPersonalProfile profile = (PublicPersonalProfile) item;
final String showItem = state.getRequest().getParameter(SHOW_ITEM_PARAM);
if (!config.getEmbedded() && state.getRequestURI().contains(profile.getName())) {
/*try {
DispatcherHelper.forwardRequestByPath(getProfileUrl(profile),
state.getRequest(),
state.getResponse());
return;
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
} catch (ServletException ex) {
throw new UncheckedWrapperException(ex);
}*/
if (!config.getEmbedded() && state.getRequestURI().contains(profile.
getName())) {
/*
* try {
* DispatcherHelper.forwardRequestByPath(getProfileUrl(profile),
* state.getRequest(), state.getResponse()); return; } catch
* (IOException ex) { throw new UncheckedWrapperException(ex); }
* catch (ServletException ex) { throw new
* UncheckedWrapperException(ex); }
*/
throw new RedirectSignal(getProfileUrl(profile), true);
}
if (config.getEmbedded()) {
final Element navigation = element.newChildElement(
"profileNavigation");
@ -72,7 +72,29 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
false);
}
if ((showItem != null) && !showItem.trim().isEmpty()) {
if ((showItem == null) || showItem.trim().isEmpty()) {
final Element profileOwner = element.newChildElement("profileOwner");
final GenericPerson owner = profile.getOwner();
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
owner);
generator.setItemElemName("owner", "");
generator.generateXML(state, profileOwner, "");
final Element contactsElem =
profileOwner.newChildElement("contacts");
final GenericPersonContactCollection contacts = owner.getContacts();
while (contacts.next()) {
PublicPersonalProfileXmlGenerator cGenerator =
new PublicPersonalProfileXmlGenerator(
contacts.getContact());
cGenerator.setItemElemName("contact", "");
cGenerator.generateXML(state, contactsElem, "");
}
} else {
final Element profileContent = element.newChildElement(
"profileContent");
@ -88,7 +110,8 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
} else {
PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
navItems.addLanguageFilter(GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
navItems.addKeyFilter(showItem);
navItems.next();
@ -159,31 +182,32 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
public void addGlobalStateParams(final Page p) {
//Nothing yet
}
private String getProfileUrl(final PublicPersonalProfile profile) {
final GenericPerson owner = profile.getOwner();
final GenericPersonContactCollection contacts = owner.getContacts();
String homepage = null;
while(contacts.next() && (homepage == null)) {
while (contacts.next() && (homepage == null)) {
homepage = getHomepageContactEntry(contacts.getContact());
}
contacts.close();
return homepage;
}
private String getHomepageContactEntry(final GenericContact contact) {
final GenericContactEntryCollection entries = contact.getContactEntries();
final GenericContactEntryCollection entries =
contact.getContactEntries();
String homepage = null;
while(entries.next()) {
while (entries.next()) {
if ("homepage".equals(entries.getKey())) {
homepage = entries.getValue();
break;
}
}
entries.close();
return homepage;
}

View File

@ -5,16 +5,15 @@ import com.arsdigita.bebop.FormData;
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.event.FormSectionEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.parameters.DateParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
@ -24,6 +23,7 @@ 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;
@ -76,7 +76,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
add(new Label(PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.create.select_person")));
ParameterModel ownerModel =
new StringParameter(PublicPersonalProfile.OWNER);
new StringParameter(PublicPersonalProfileBundle.OWNER);
SingleSelect ownerSelect = new SingleSelect(ownerModel);
ownerSelect.addValidationListener(new NotNullValidationListener());
@ -104,7 +104,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
DataCollection persons = SessionManager.getSession().
retrieve(
personType);
persons.addFilter("profile is null");
//persons.addFilter("profile is null");
persons.addFilter(String.format("version = '%s'",
ContentItem.DRAFT));
persons.addOrder("surname asc");
@ -122,12 +122,17 @@ public class PublicPersonalProfileCreate extends PageCreate {
if (processed.contains(person.getParent().getID())) {
continue;
} else {
ownerSelect.addOption(new Option(
person.getID().toString(),
String.format("%s (%s)",
person.getFullName(),
person.getLanguage())));
processed.add(person.getParent().getID());
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());
}
}
}
}
@ -160,7 +165,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
Folder folder = m_parent.getFolder(fse.getPageState());
Assert.exists(folder);
String id = (String) fse.getFormData().get(
PublicPersonalProfile.OWNER);
PublicPersonalProfileBundle.OWNER);
if ((id == null) || id.trim().isEmpty()) {
fse.getFormData().addError(PublicPersonalProfileGlobalizationUtil.
@ -187,7 +192,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
Assert.exists(section, ContentSection.class);
String id = (String) fse.getFormData().get(
PublicPersonalProfile.OWNER);
PublicPersonalProfileBundle.OWNER);
GenericPerson owner = new GenericPerson(new BigDecimal(id));
String name = String.format("%s-profile",
@ -202,7 +207,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
item.setLaunchDate((Date) data.get(LAUNCH_DATE));
}
final ContentBundle bundle = new ContentBundle(item);
final PublicPersonalProfileBundle bundle = new PublicPersonalProfileBundle(item);
bundle.setParent(folder);
bundle.setContentSection(m_parent.getContentSection(state));
bundle.save();