PublicPersonalProfile: Ausgabe Personen und Kontakt-Informationen

git-svn-id: https://svn.libreccm.org/ccm/trunk@1055 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-08-10 13:48:25 +00:00
parent 375fa32580
commit 481d877ad9
5 changed files with 137 additions and 39 deletions

View File

@ -13,6 +13,7 @@ import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ContentType;
@ -40,20 +41,20 @@ import java.util.Date;
* @version $Id$ * @version $Id$
*/ */
public class PublicPersonalProfileCreate extends PageCreate { public class PublicPersonalProfileCreate extends PageCreate {
private static final String SELECTED_PERSON = "selectedPerson"; private static final String SELECTED_PERSON = "selectedPerson";
private static final PublicPersonalProfileConfig config = private static final PublicPersonalProfileConfig config =
new PublicPersonalProfileConfig(); new PublicPersonalProfileConfig();
static { static {
config.load(); config.load();
} }
public PublicPersonalProfileCreate(final ItemSelectionModel itemModel, public PublicPersonalProfileCreate(final ItemSelectionModel itemModel,
final CreationSelector parent) { final CreationSelector parent) {
super(itemModel, parent); super(itemModel, parent);
} }
@Override @Override
public void addWidgets() { public void addWidgets() {
//super.addWidgets(); //super.addWidgets();
@ -66,19 +67,19 @@ public class PublicPersonalProfileCreate extends PageCreate {
add(new Label(type.getLabel())); add(new Label(type.getLabel()));
add(new Label(GlobalizationUtil.globalize("cms.ui.language.field"))); add(new Label(GlobalizationUtil.globalize("cms.ui.language.field")));
add(new LanguageWidget(LANGUAGE)); add(new LanguageWidget(LANGUAGE));
add(new Label(PublicPersonalProfileGlobalizationUtil.globalize( add(new Label(PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.create.select_person"))); "publicpersonalprofile.ui.create.select_person")));
ParameterModel ownerModel = ParameterModel ownerModel =
new StringParameter(PublicPersonalProfile.OWNER); new StringParameter(PublicPersonalProfile.OWNER);
SingleSelect ownerSelect = new SingleSelect(ownerModel); SingleSelect ownerSelect = new SingleSelect(ownerModel);
ownerSelect.addValidationListener(new NotNullValidationListener()); ownerSelect.addValidationListener(new NotNullValidationListener());
String personType = config.getPersonType(); String personType = config.getPersonType();
if ((personType == null) || (personType.isEmpty())) { if ((personType == null) || (personType.isEmpty())) {
personType = "com.arsdigita.cms.contenttypes.GenericPerson"; personType = "com.arsdigita.cms.contenttypes.GenericPerson";
} }
ContentTypeCollection types = ContentType.getAllContentTypes(); ContentTypeCollection types = ContentType.getAllContentTypes();
types.addFilter(String.format("className = '%s'", personType)); types.addFilter(String.format("className = '%s'", personType));
if (types.size() == 0) { if (types.size() == 0) {
@ -87,6 +88,8 @@ public class PublicPersonalProfileCreate extends PageCreate {
DataCollection persons = SessionManager.getSession().retrieve( DataCollection persons = SessionManager.getSession().retrieve(
personType); personType);
persons.addFilter("profile is null"); persons.addFilter("profile is null");
persons.addFilter(String.format("version = '%s'", ContentItem.DRAFT));
ownerSelect.addOption(new Option("", ""));
while (persons.next()) { while (persons.next()) {
GenericPerson person = GenericPerson person =
(GenericPerson) DomainObjectFactory.newInstance(persons. (GenericPerson) DomainObjectFactory.newInstance(persons.
@ -95,7 +98,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
getFullName())); getFullName()));
} }
add(ownerSelect); add(ownerSelect);
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
add(new Label(GlobalizationUtil.globalize( add(new Label(GlobalizationUtil.globalize(
"cms.ui.authoring.page_launch_date"))); "cms.ui.authoring.page_launch_date")));
@ -112,40 +115,46 @@ public class PublicPersonalProfileCreate extends PageCreate {
add(launchDate); add(launchDate);
} }
} }
@Override @Override
public void validate(FormSectionEvent fse) throws FormProcessException { public void validate(FormSectionEvent fse) throws FormProcessException {
Folder folder = m_parent.getFolder(fse.getPageState()); Folder folder = m_parent.getFolder(fse.getPageState());
Assert.exists(folder); Assert.exists(folder);
String id = (String) fse.getFormData().get( String id = (String) fse.getFormData().get(
PublicPersonalProfile.OWNER); PublicPersonalProfile.OWNER);
if ((id == null) || id.trim().isEmpty()) {
fse.getFormData().addError(PublicPersonalProfileGlobalizationUtil.
globalize("publicpersonalprofile.ui.person.required"));
return;
}
GenericPerson owner = new GenericPerson(new BigDecimal(id)); GenericPerson owner = new GenericPerson(new BigDecimal(id));
validateNameUniqueness(folder, validateNameUniqueness(folder,
fse, fse,
String.format("%s-profile", String.format("%s-profile",
GenericPerson.urlSave( GenericPerson.urlSave(
owner.getFullName()))); owner.getFullName())));
} }
@Override @Override
public void process(FormSectionEvent fse) throws FormProcessException { public void process(FormSectionEvent fse) throws FormProcessException {
final FormData data = fse.getFormData(); final FormData data = fse.getFormData();
final PageState state = fse.getPageState(); final PageState state = fse.getPageState();
final ContentSection section = m_parent.getContentSection(state); final ContentSection section = m_parent.getContentSection(state);
final Folder folder = m_parent.getFolder(state); final Folder folder = m_parent.getFolder(state);
Assert.exists(section, ContentSection.class); Assert.exists(section, ContentSection.class);
String id = (String) fse.getFormData().get( String id = (String) fse.getFormData().get(
PublicPersonalProfile.OWNER); PublicPersonalProfile.OWNER);
GenericPerson owner = new GenericPerson(new BigDecimal(id)); GenericPerson owner = new GenericPerson(new BigDecimal(id));
String name = String.format("%s-profile", String name = String.format("%s-profile",
GenericPerson.urlSave(owner.getFullName())); GenericPerson.urlSave(owner.getFullName()));
String title = String.format("%s (Profil)", owner.getFullName()); String title = String.format("%s (Profil)", owner.getFullName());
final ContentPage item = createContentPage(state); final ContentPage item = createContentPage(state);
item.setLanguage((String) data.get(LANGUAGE)); item.setLanguage((String) data.get(LANGUAGE));
item.setName(name); item.setName(name);
@ -153,18 +162,17 @@ public class PublicPersonalProfileCreate extends PageCreate {
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
item.setLaunchDate((Date) data.get(LAUNCH_DATE)); item.setLaunchDate((Date) data.get(LAUNCH_DATE));
} }
final ContentBundle bundle = new ContentBundle(item); final ContentBundle bundle = new ContentBundle(item);
bundle.setParent(folder); bundle.setParent(folder);
bundle.setContentSection(m_parent.getContentSection(state)); bundle.setContentSection(m_parent.getContentSection(state));
bundle.save(); bundle.save();
PublicPersonalProfile profile = new PublicPersonalProfile(item. PublicPersonalProfile profile = new PublicPersonalProfile(item.getOID());
getOID());
profile.setOwner(owner); profile.setOwner(owner);
profile.setProfileUrl(owner.getSurname().toLowerCase()); profile.setProfileUrl(owner.getSurname().toLowerCase());
profile.save(); profile.save();
m_parent.editItem(state, item); m_parent.editItem(state, item);
} }
} }

View File

@ -1,6 +1,7 @@
package com.arsdigita.cms.publicpersonalprofile; package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.Parameter; import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter; import com.arsdigita.util.parameter.StringParameter;
@ -12,19 +13,42 @@ import com.arsdigita.util.parameter.StringParameter;
public class PublicPersonalProfileConfig extends AbstractConfig { public class PublicPersonalProfileConfig extends AbstractConfig {
private final Parameter homeNavItemLabels; private final Parameter homeNavItemLabels;
private final Parameter showPersonInfoEverywhere;
private final Parameter contactType;
public PublicPersonalProfileConfig() { public PublicPersonalProfileConfig() {
homeNavItemLabels = new StringParameter( homeNavItemLabels = new StringParameter(
"com.arsdigita.cms.publicpersonalprofile.navitem.home.labels", "com.arsdigita.cms.publicpersonalprofile.navitem.home.labels",
Parameter.REQUIRED, Parameter.REQUIRED,
"en:Home, de:Allgemein"); "en:Home, de:Allgemein");
showPersonInfoEverywhere =
new BooleanParameter(
"com.arsdigita.cms.publicpersonalprofile.show_person_info_everywhere",
Parameter.REQUIRED,
false);
contactType = new StringParameter(
"com.arsdigita.cms.publicpersonalprofile.contactType",
Parameter.REQUIRED,
"commonContact");
register(homeNavItemLabels); register(homeNavItemLabels);
register(showPersonInfoEverywhere);
register(contactType);
loadInfo(); loadInfo();
} }
public final String getHomeNavItemLabels() { public final String getHomeNavItemLabels() {
return (String) get(homeNavItemLabels); return (String) get(homeNavItemLabels);
} }
public final Boolean getShowPersonInfoEverywhere() {
return (Boolean) get(showPersonInfoEverywhere);
}
public final String getContactType() {
return (String) get(contactType);
}
} }

View File

@ -3,3 +3,13 @@ com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.purpose = The labels
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.example = en:Home,de:Start com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.example = en:Home,de:Start
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.format = [String] com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.format = [String]
com.arsdigita.cms.publicpersonalprofile.show_person_info_everywhere.title = Show person information everywhere
com.arsdigita.cms.publicpersonalprofile.show_person_info_everywhere.purpose = If set to true, the information about the person (name, title, contacts etc.) are included in the XML output regardless which navigation item has been chosen. If set to false (default) the information will only be included into the XML output if no navigation item is selected.
com.arsdigita.cms.publicpersonalprofile.show_person_info_everywhere.example = false
com.arsdigita.cms.publicpersonalprofile.show_person_info_everywhere.format = [Boolean]
com.arsdigita.cms.publicpersonalprofile.contactType.title = Contact type to use
com.arsdigita.cms.publicpersonalprofile.contactType.purpose = Determines the type of the contact to use in the profiles
com.arsdigita.cms.publicpersonalprofile.contactType.title.example = commonContact
com.arsdigita.cms.publicpersonalprofile.contactType.title.format = [String]

View File

@ -15,7 +15,7 @@ public class PublicPersonalProfiles extends Application {
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfile"; "com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfile";
private static PublicPersonalProfileConfig config = private final static PublicPersonalProfileConfig config =
new PublicPersonalProfileConfig(); new PublicPersonalProfileConfig();
static { static {

View File

@ -6,6 +6,7 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contentassets.RelatedLink; import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.GenericPersonContactCollection;
import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.contenttypes.Link;
import com.arsdigita.cms.contenttypes.PublicPersonalProfile; import com.arsdigita.cms.contenttypes.PublicPersonalProfile;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem;
@ -41,12 +42,15 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
Logger.getLogger( Logger.getLogger(
PublicPersonalProfilesServlet.class); PublicPersonalProfilesServlet.class);
private static final String PREVIEW = "preview"; private static final String PREVIEW = "preview";
private final PublicPersonalProfileConfig config = PublicPersonalProfiles.
getConfig();
@Override @Override
protected void doService(final HttpServletRequest request, protected void doService(final HttpServletRequest request,
final HttpServletResponse response, final HttpServletResponse response,
final Application app) throws ServletException, final Application app) throws ServletException,
IOException { IOException {
PublicPersonalProfileConfig config = PublicPersonalProfiles.getConfig();
String path = ""; String path = "";
logger.debug("PublicPersonalProfileServlet is starting..."); logger.debug("PublicPersonalProfileServlet is starting...");
@ -81,7 +85,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
response.getWriter().append("Please choose an application."); response.getWriter().append("Please choose an application.");
} else { } else {
final String[] pathTokens = path.split("/"); final String[] pathTokens = path.split("/");
boolean preview = false;; boolean preview = false;
String profileOwner = ""; String profileOwner = "";
String navPath = null; String navPath = null;
@ -129,8 +133,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
Document document = page.buildDocument(request, response); Document document = page.buildDocument(request, response);
Element root = document.getRootElement(); Element root = document.getRootElement();
Element test = root.newChildElement("test"); //Element test = root.newChildElement("test");
test.setText("test"); //test.setText("test");
final Session session = SessionManager.getSession(); final Session session = SessionManager.getSession();
@ -153,6 +157,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
throw new IllegalStateException( throw new IllegalStateException(
"More than one matching members found..."); "More than one matching members found...");
} else { } else {
final PageState state = new PageState(page, request, response);
profiles.next(); profiles.next();
PublicPersonalProfile profile = PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory. (PublicPersonalProfile) DomainObjectFactory.
@ -168,7 +174,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
createNavigation(profile, root, navPath); createNavigation(profile, root, navPath);
if (navPath == null) { if (navPath == null) {
//ToDo: Show start page. generateProfileOwnerXml(profileElem, owner, state);
} else { } else {
final DataCollection links = final DataCollection links =
RelatedLink.getRelatedLinks(profile, RelatedLink.getRelatedLinks(profile,
@ -179,6 +185,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return; return;
} else { } else {
if (config.getShowPersonInfoEverywhere()) {
generateProfileOwnerXml(profileElem, owner, state);
}
links.next(); links.next();
final RelatedLink link = final RelatedLink link =
(RelatedLink) DomainObjectFactory. (RelatedLink) DomainObjectFactory.
@ -194,9 +204,6 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
} }
} }
PresentationManager presentationManager = Templating. PresentationManager presentationManager = Templating.
getPresentationManager(); getPresentationManager();
presentationManager.servePage(document, request, response); presentationManager.servePage(document, request, response);
@ -207,8 +214,6 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
private void createNavigation(final PublicPersonalProfile profile, private void createNavigation(final PublicPersonalProfile profile,
final Element root, final Element root,
final String navPath) { final String navPath) {
PublicPersonalProfileConfig config = PublicPersonalProfiles.getConfig();
String homeLabelsStr = config.getHomeNavItemLabels(); String homeLabelsStr = config.getHomeNavItemLabels();
Map<String, String> homeLabels = new HashMap<String, String>(); Map<String, String> homeLabels = new HashMap<String, String>();
@ -317,7 +322,58 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
navLinkKey)); navLinkKey));
} }
}
private void generateProfileOwnerXml(final Element profileElem,
final GenericPerson owner,
final PageState state) {
Element profileOwnerElem = profileElem.newChildElement(
"profileOwner");
/*if ((owner.getSurname() != null)
&& !owner.getSurname().trim().isEmpty()) {
Element surname =
profileOwnerElem.newChildElement("surname");
surname.setText(owner.getSurname());
}
if ((owner.getGivenName() != null)
&& !owner.getGivenName().trim().isEmpty()) {
Element givenName = profileOwnerElem.newChildElement(
"givenName");
givenName.setText(owner.getGivenName());
}
if ((owner.getTitlePre() != null)
&& !owner.getTitlePre().trim().isEmpty()) {
Element titlePre = profileOwnerElem.newChildElement("titlePre");
titlePre.setText(owner.getTitlePre());
}
if ((owner.getTitlePost() != null)
&& !owner.getTitlePost().trim().isEmpty()) {
Element titlePost = profileOwnerElem.newChildElement(
"titlePost");
titlePost.setText(owner.getTitlePost());
}*/
PublicPersonalProfileXmlGenerator personXml =
new PublicPersonalProfileXmlGenerator(
owner);
personXml.generateXML(state,
profileOwnerElem,
"");
/*if (owner.hasContacts()) {
final GenericPersonContactCollection contacts = owner.getContacts();
final String contactType = config.getContactType();
contacts.addFilter(String.format("link.link_key = '%s'",
contactType));
if (contacts.size() > 0) {
contacts.next();
PublicPersonalProfileXmlGenerator contactXml =
new PublicPersonalProfileXmlGenerator(
contacts.getContact());
contactXml.generateXML(state, profileOwnerElem, "");
}
}*/
} }
} }