Fixed NullPointerExceptions and other bugs in the PublicPersonalProfile

git-svn-id: https://svn.libreccm.org/ccm/trunk@2111 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-04-02 09:28:57 +00:00
parent ca7cc4db35
commit f23c30d8f9
7 changed files with 58 additions and 36 deletions

View File

@ -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() { public GenericPerson getOwner() {
/* /*
@ -110,8 +110,12 @@ public class PublicPersonalProfile
* return (GenericPerson) DomainObjectFactory.newInstance(dobj); * return (GenericPerson) DomainObjectFactory.newInstance(dobj);
} }
*/ */
return (GenericPerson) getPublicPersonalProfileBundle().getOwner(). final GenericPersonBundle bundle = getPublicPersonalProfileBundle().getOwner();
getPrimaryInstance(); if (bundle == null) {
return null;
} else {
return (GenericPerson) bundle.getPrimaryInstance();
}
} }
/** /**

View File

@ -24,8 +24,7 @@ import javax.servlet.ServletException;
* Generates the extra XML output for a profile for the embedded view. * Generates the extra XML output for a profile for the embedded view.
* *
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id: PublicPersonalProfileExtraXmlGenerator.java 1466 2012-01-23 * @version $Id$
* 12:59:16Z jensp $
*/ */
public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator { public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator {
@ -77,6 +76,7 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
final GenericPerson owner = profile.getOwner(); final GenericPerson owner = profile.getOwner();
if (owner != null) {
final PublicPersonalProfileXmlGenerator generator = final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator( new PublicPersonalProfileXmlGenerator(
owner); owner);
@ -95,6 +95,7 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
contacts.getContactType()); contacts.getContactType());
cGenerator.generateXML(state, contactsElem, ""); cGenerator.generateXML(state, contactsElem, "");
} }
}
} else { } else {
final Element profileContent = element.newChildElement( final Element profileContent = element.newChildElement(
@ -118,15 +119,14 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
navItems.addKeyFilter(showItem); navItems.addKeyFilter(showItem);
navItems.next(); navItems.next();
if (navItems.getNavItem().getGeneratorClass() if (navItems.getNavItem().getGeneratorClass() != null) {
!= null) {
try { try {
Object generatorObj = Object generatorObj =
Class.forName(navItems.getNavItem(). Class.forName(navItems.getNavItem().
getGeneratorClass()).getConstructor(). getGeneratorClass()).getConstructor().
newInstance(); newInstance();
if (generatorObj instanceof ContentGenerator) { if ((generatorObj instanceof ContentGenerator) && profile.getOwner() != null) {
final ContentGenerator generator = final ContentGenerator generator =
(ContentGenerator) generatorObj; (ContentGenerator) generatorObj;
@ -192,6 +192,9 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
private String getProfileUrl(final PublicPersonalProfile profile) { private String getProfileUrl(final PublicPersonalProfile profile) {
final GenericPerson owner = profile.getOwner(); final GenericPerson owner = profile.getOwner();
if (owner == null) {
return null;
}
final GenericPersonContactCollection contacts = owner.getContacts(); final GenericPersonContactCollection contacts = owner.getContacts();
String homepage = null; String homepage = null;

View File

@ -153,7 +153,11 @@ public class PublicPersonalProfileXmlUtil {
profileElem.addAttribute("url", String.format("%s/%s", profileElem.addAttribute("url", String.format("%s/%s",
appUrl, appUrl,
profile.getProfileUrl())); profile.getProfileUrl()));
if (profile.getOwner() == null) {
profileElem.addAttribute("title", String.format("Profile %s", profile.getOID().toString()));
} else {
profileElem.addAttribute("title", profile.getOwner().getFullName()); profileElem.addAttribute("title", profile.getOwner().getFullName());
}
//Get the related links of the profile //Get the related links of the profile
final DataCollection links = final DataCollection links =

View File

@ -100,12 +100,15 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements
// final GenericPerson owner = profile.getOwner(); // final GenericPerson owner = profile.getOwner();
// final GenericPerson alias = owner.getAlias(); // final GenericPerson alias = owner.getAlias();
if (owner != null) {
ownerSelect.addOption(new Option(owner.getID().toString(), owner.getFullName())); ownerSelect.addOption(new Option(owner.getID().toString(), owner.getFullName()));
}
if (!persons.isEmpty()) { if (!persons.isEmpty()) {
final List<BigDecimal> processed = new ArrayList<BigDecimal>(); final List<BigDecimal> processed = new ArrayList<BigDecimal>();
while(persons.next()) { while (persons.next()) {
GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons.getDataObject()); GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons.
getDataObject());
if (processed.contains(person.getParent().getID())) { if (processed.contains(person.getParent().getID())) {
continue; continue;
} else { } else {
@ -147,7 +150,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements
if ((profile != null) && getSaveCancelSection().getSaveButton().isSelected(state)) { 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))) { if ((profile.getOwner() != null) && !profile.getOwner().getID().equals(new BigDecimal(ownerId))) {
final GenericPerson newOwner = new GenericPerson(new BigDecimal(ownerId)); final GenericPerson newOwner = new GenericPerson(new BigDecimal(ownerId));
profile.setOwner(newOwner); profile.setOwner(newOwner);
} }

View File

@ -790,6 +790,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
private void generateProfileOwnerXml(final Element profileElem, private void generateProfileOwnerXml(final Element profileElem,
final GenericPerson owner, final GenericPerson owner,
final PageState state) { final PageState state) {
if (owner == null) {
return;
}
Element profileOwnerElem = profileElem.newChildElement( Element profileOwnerElem = profileElem.newChildElement(
"profileOwner"); "profileOwner");
if ((owner.getSurname() != null) if ((owner.getSurname() != null)

View File

@ -95,6 +95,7 @@ public class PersonalProjects implements ContentGenerator {
new LinkedList<SciProjectBundle>(); new LinkedList<SciProjectBundle>();
final DataCollection collection = (DataCollection) person. final DataCollection collection = (DataCollection) person.
getGenericPersonBundle().get("organizationalunits"); getGenericPersonBundle().get("organizationalunits");
collection.addEqualsFilter("version", "live");
DomainObject obj; DomainObject obj;
while (collection.next()) { while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject()); obj = DomainObjectFactory.newInstance(collection.getDataObject());
@ -115,6 +116,7 @@ public class PersonalProjects implements ContentGenerator {
final String language) { final String language) {
final DataCollection collection = (DataCollection) alias. final DataCollection collection = (DataCollection) alias.
getGenericPersonBundle().get("organizationalunits"); getGenericPersonBundle().get("organizationalunits");
collection.addEqualsFilter("version", "live");
DomainObject obj; DomainObject obj;
while (collection.next()) { while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject()); obj = DomainObjectFactory.newInstance(collection.getDataObject());

View File

@ -132,6 +132,7 @@ public class PersonalPublications implements ContentGenerator {
new LinkedList<PublicationBundle>(); new LinkedList<PublicationBundle>();
//final List<BigDecimal> processed = new ArrayList<BigDecimal>(); //final List<BigDecimal> processed = new ArrayList<BigDecimal>();
final DataCollection collection = (DataCollection) author.getGenericPersonBundle().get("publication"); final DataCollection collection = (DataCollection) author.getGenericPersonBundle().get("publication");
collection.addEqualsFilter("version", "live");
DomainObject obj; DomainObject obj;
while (collection.next()) { while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject()); obj = DomainObjectFactory.newInstance(collection.getDataObject());
@ -152,6 +153,7 @@ public class PersonalPublications implements ContentGenerator {
final List<PublicationBundle> publications, final List<PublicationBundle> publications,
final String language) { final String language) {
final DataCollection collection = (DataCollection) alias.getGenericPersonBundle().get("publication"); final DataCollection collection = (DataCollection) alias.getGenericPersonBundle().get("publication");
collection.addEqualsFilter("version", "live");
DomainObject obj; DomainObject obj;
while (collection.next()) { while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject()); obj = DomainObjectFactory.newInstance(collection.getDataObject());