From f23c30d8f95a64318b4a026c70a85c83a6c5e7f4 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 2 Apr 2013 09:28:57 +0000 Subject: [PATCH] Fixed NullPointerExceptions and other bugs in the PublicPersonalProfile git-svn-id: https://svn.libreccm.org/ccm/trunk@2111 8810af33-2d31-482b-a856-94f89814c4df --- .../contenttypes/PublicPersonalProfile.java | 10 ++-- ...ublicPersonalProfileExtraXmlGenerator.java | 47 ++++++++++--------- .../PublicPersonalProfileXmlUtil.java | 4 ++ .../ui/PublicPersonalProfilePropertyForm.java | 21 +++++---- .../PublicPersonalProfilesServlet.java | 4 ++ .../PersonalProjects.java | 6 ++- .../PersonalPublications.java | 2 + 7 files changed, 58 insertions(+), 36 deletions(-) diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java index 809797412..423226b5b 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java @@ -91,7 +91,7 @@ public class PublicPersonalProfile /** * - * @return The owner of the profile. + * @return The owner of the profile. May be {@code null} if no owner is assigned to the profile. */ public GenericPerson getOwner() { /* @@ -110,8 +110,12 @@ public class PublicPersonalProfile * return (GenericPerson) DomainObjectFactory.newInstance(dobj); } */ - return (GenericPerson) getPublicPersonalProfileBundle().getOwner(). - getPrimaryInstance(); + final GenericPersonBundle bundle = getPublicPersonalProfileBundle().getOwner(); + if (bundle == null) { + return null; + } else { + return (GenericPerson) bundle.getPrimaryInstance(); + } } /** diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java index 68370efee..fd71b9259 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java @@ -24,8 +24,7 @@ import javax.servlet.ServletException; * Generates the extra XML output for a profile for the embedded view. * * @author Jens Pelzetter - * @version $Id: PublicPersonalProfileExtraXmlGenerator.java 1466 2012-01-23 - * 12:59:16Z jensp $ + * @version $Id$ */ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator { @@ -77,23 +76,25 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator final GenericPerson owner = profile.getOwner(); - final PublicPersonalProfileXmlGenerator generator = - new PublicPersonalProfileXmlGenerator( - owner); - generator.setItemElemName("owner", ""); - generator.generateXML(state, profileOwner, ""); + if (owner != null) { + 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.addItemAttribute("contactType", - contacts.getContactType()); - cGenerator.generateXML(state, contactsElem, ""); + final Element contactsElem = + profileOwner.newChildElement("contacts"); + final GenericPersonContactCollection contacts = owner.getContacts(); + while (contacts.next()) { + PublicPersonalProfileXmlGenerator cGenerator = + new PublicPersonalProfileXmlGenerator( + contacts.getContact()); + cGenerator.setItemElemName("contact", ""); + cGenerator.addItemAttribute("contactType", + contacts.getContactType()); + cGenerator.generateXML(state, contactsElem, ""); + } } } else { @@ -118,15 +119,14 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator navItems.addKeyFilter(showItem); navItems.next(); - if (navItems.getNavItem().getGeneratorClass() - != null) { + if (navItems.getNavItem().getGeneratorClass() != null) { try { Object generatorObj = Class.forName(navItems.getNavItem(). getGeneratorClass()).getConstructor(). newInstance(); - if (generatorObj instanceof ContentGenerator) { + if ((generatorObj instanceof ContentGenerator) && profile.getOwner() != null) { final ContentGenerator generator = (ContentGenerator) generatorObj; @@ -189,9 +189,12 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator public void setListMode(final boolean listMode) { //nothing } - + private String getProfileUrl(final PublicPersonalProfile profile) { final GenericPerson owner = profile.getOwner(); + if (owner == null) { + return null; + } final GenericPersonContactCollection contacts = owner.getContacts(); String homepage = null; diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java index bb66a89e3..57881ff3c 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java @@ -153,7 +153,11 @@ public class PublicPersonalProfileXmlUtil { profileElem.addAttribute("url", String.format("%s/%s", appUrl, profile.getProfileUrl())); + if (profile.getOwner() == null) { + profileElem.addAttribute("title", String.format("Profile %s", profile.getOID().toString())); + } else { profileElem.addAttribute("title", profile.getOwner().getFullName()); + } //Get the related links of the profile final DataCollection links = 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 48018df6f..6a49f6306 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 @@ -73,11 +73,11 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements 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"; @@ -100,12 +100,15 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements // final GenericPerson owner = profile.getOwner(); // final GenericPerson alias = owner.getAlias(); - ownerSelect.addOption(new Option(owner.getID().toString(), owner.getFullName())); - + if (owner != null) { + 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()); + final List processed = new ArrayList(); + while (persons.next()) { + GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons. + getDataObject()); if (processed.contains(person.getParent().getID())) { continue; } else { @@ -116,7 +119,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements processed.add(person.getParent().getID()); } } - } + } } } }); @@ -147,7 +150,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements if ((profile != null) && getSaveCancelSection().getSaveButton().isSelected(state)) { final String ownerId = (String) data.get(PublicPersonalProfileBundle.OWNER); - if (!profile.getOwner().getID().equals(new BigDecimal(ownerId))) { + if ((profile.getOwner() != null) && !profile.getOwner().getID().equals(new BigDecimal(ownerId))) { final GenericPerson newOwner = new GenericPerson(new BigDecimal(ownerId)); profile.setOwner(newOwner); } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java index 5c9aec67c..d814e555a 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java @@ -790,6 +790,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { private void generateProfileOwnerXml(final Element profileElem, final GenericPerson owner, final PageState state) { + if (owner == null) { + return; + } + Element profileOwnerElem = profileElem.newChildElement( "profileOwner"); if ((owner.getSurname() != null) diff --git a/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java b/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java index a4391b837..ed73216a4 100644 --- a/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java +++ b/ccm-sci-personalprojects/src/com/arsdigita/cms/publicpersonalprofile/PersonalProjects.java @@ -94,7 +94,8 @@ public class PersonalProjects implements ContentGenerator { final List projects = new LinkedList(); final DataCollection collection = (DataCollection) person. - getGenericPersonBundle().get("organizationalunits"); + getGenericPersonBundle().get("organizationalunits"); + collection.addEqualsFilter("version", "live"); DomainObject obj; while (collection.next()) { obj = DomainObjectFactory.newInstance(collection.getDataObject()); @@ -114,7 +115,8 @@ public class PersonalProjects implements ContentGenerator { final List projects, final String language) { final DataCollection collection = (DataCollection) alias. - getGenericPersonBundle().get("organizationalunits"); + getGenericPersonBundle().get("organizationalunits"); + collection.addEqualsFilter("version", "live"); DomainObject obj; while (collection.next()) { obj = DomainObjectFactory.newInstance(collection.getDataObject()); diff --git a/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java b/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java index 6126307a1..ce955a5e3 100644 --- a/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java +++ b/ccm-sci-personalpublications/src/com/arsdigita/cms/publicpersonalprofile/PersonalPublications.java @@ -132,6 +132,7 @@ public class PersonalPublications implements ContentGenerator { new LinkedList(); //final List processed = new ArrayList(); final DataCollection collection = (DataCollection) author.getGenericPersonBundle().get("publication"); + collection.addEqualsFilter("version", "live"); DomainObject obj; while (collection.next()) { obj = DomainObjectFactory.newInstance(collection.getDataObject()); @@ -152,6 +153,7 @@ public class PersonalPublications implements ContentGenerator { final List publications, final String language) { final DataCollection collection = (DataCollection) alias.getGenericPersonBundle().get("publication"); + collection.addEqualsFilter("version", "live"); DomainObject obj; while (collection.next()) { obj = DomainObjectFactory.newInstance(collection.getDataObject());