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() {
/*
@ -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();
}
}
/**

View File

@ -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;

View File

@ -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 =

View File

@ -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<BigDecimal> processed = new ArrayList<BigDecimal>();
while(persons.next()) {
GenericPerson person = (GenericPerson) DomainObjectFactory.newInstance(persons.getDataObject());
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
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);
}

View File

@ -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)

View File

@ -94,7 +94,8 @@ public class PersonalProjects implements ContentGenerator {
final List<SciProjectBundle> projects =
new LinkedList<SciProjectBundle>();
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<SciProjectBundle> 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());

View File

@ -132,6 +132,7 @@ public class PersonalPublications implements ContentGenerator {
new LinkedList<PublicationBundle>();
//final List<BigDecimal> processed = new ArrayList<BigDecimal>();
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<PublicationBundle> 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());