Fixed NullPointerExceptions and other bugs in the PublicPersonalProfile
git-svn-id: https://svn.libreccm.org/ccm/trunk@2111 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
ca7cc4db35
commit
f23c30d8f9
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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,23 +76,25 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
|
||||||
|
|
||||||
final GenericPerson owner = profile.getOwner();
|
final GenericPerson owner = profile.getOwner();
|
||||||
|
|
||||||
final PublicPersonalProfileXmlGenerator generator =
|
if (owner != null) {
|
||||||
new PublicPersonalProfileXmlGenerator(
|
final PublicPersonalProfileXmlGenerator generator =
|
||||||
owner);
|
new PublicPersonalProfileXmlGenerator(
|
||||||
generator.setItemElemName("owner", "");
|
owner);
|
||||||
generator.generateXML(state, profileOwner, "");
|
generator.setItemElemName("owner", "");
|
||||||
|
generator.generateXML(state, profileOwner, "");
|
||||||
|
|
||||||
final Element contactsElem =
|
final Element contactsElem =
|
||||||
profileOwner.newChildElement("contacts");
|
profileOwner.newChildElement("contacts");
|
||||||
final GenericPersonContactCollection contacts = owner.getContacts();
|
final GenericPersonContactCollection contacts = owner.getContacts();
|
||||||
while (contacts.next()) {
|
while (contacts.next()) {
|
||||||
PublicPersonalProfileXmlGenerator cGenerator =
|
PublicPersonalProfileXmlGenerator cGenerator =
|
||||||
new PublicPersonalProfileXmlGenerator(
|
new PublicPersonalProfileXmlGenerator(
|
||||||
contacts.getContact());
|
contacts.getContact());
|
||||||
cGenerator.setItemElemName("contact", "");
|
cGenerator.setItemElemName("contact", "");
|
||||||
cGenerator.addItemAttribute("contactType",
|
cGenerator.addItemAttribute("contactType",
|
||||||
contacts.getContactType());
|
contacts.getContactType());
|
||||||
cGenerator.generateXML(state, contactsElem, "");
|
cGenerator.generateXML(state, contactsElem, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
@ -189,9 +189,12 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
|
||||||
public void setListMode(final boolean listMode) {
|
public void setListMode(final boolean listMode) {
|
||||||
//nothing
|
//nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -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 =
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,11 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements
|
||||||
ownerSelect.addPrintListener(new PrintListener() {
|
ownerSelect.addPrintListener(new PrintListener() {
|
||||||
public void prepare(final PrintEvent event) {
|
public void prepare(final PrintEvent event) {
|
||||||
final SingleSelect ownerSelect = (SingleSelect) event.getTarget();
|
final SingleSelect ownerSelect = (SingleSelect) event.getTarget();
|
||||||
|
|
||||||
final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event.
|
final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event.
|
||||||
getPageState());
|
getPageState());
|
||||||
final GenericPerson owner = profile.getOwner();
|
final GenericPerson owner = profile.getOwner();
|
||||||
|
|
||||||
String personType = PublicPersonalProfiles.getConfig().getPersonType();
|
String personType = PublicPersonalProfiles.getConfig().getPersonType();
|
||||||
if ((personType == null) || (personType.isEmpty())) {
|
if ((personType == null) || (personType.isEmpty())) {
|
||||||
personType = "com.arsdigita.cms.contenttypes.GenericPerson";
|
personType = "com.arsdigita.cms.contenttypes.GenericPerson";
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
ownerSelect.addOption(new Option(owner.getID().toString(), owner.getFullName()));
|
if (owner != null) {
|
||||||
|
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 {
|
||||||
|
|
@ -116,7 +119,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements
|
||||||
processed.add(person.getParent().getID());
|
processed.add(person.getParent().getID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@ public class PersonalProjects implements ContentGenerator {
|
||||||
final List<SciProjectBundle> projects =
|
final List<SciProjectBundle> projects =
|
||||||
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());
|
||||||
|
|
@ -114,7 +115,8 @@ public class PersonalProjects implements ContentGenerator {
|
||||||
final List<SciProjectBundle> projects,
|
final List<SciProjectBundle> projects,
|
||||||
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());
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue