PublicPersonalProfile/PersonProjects und PublicPersonProfile/PersonalProjects sind jetzt kompatibel mit neuen

Datenstrukturen für Projekte und Publikationen. (Tickets #1215 und #1216)


git-svn-id: https://svn.libreccm.org/ccm/trunk@1610 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-04-22 17:54:30 +00:00
parent 36b38964e1
commit af807b85ff
16 changed files with 509 additions and 902 deletions

View File

@ -91,6 +91,8 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
new PublicPersonalProfileXmlGenerator(
contacts.getContact());
cGenerator.setItemElemName("contact", "");
cGenerator.addItemAttribute("contactType",
contacts.getContactType());
cGenerator.generateXML(state, contactsElem, "");
}

View File

@ -171,12 +171,12 @@ query getIdsOfMembersOfOrgaUnits {
do {
select distinct on (cms_persons.person_id)
cms_persons.person_id,
cms_persons.surname,
cms_persons.givenname,
cms_organizationalunits_person_map.organizationalunit_id,
cms_organizationalunits_person_map.role_name,
cms_organizationalunits_person_map.status
cms_persons.person_id,
cms_persons.surname,
cms_persons.givenname,
cms_organizationalunits_person_map.organizationalunit_id,
cms_organizationalunits_person_map.role_name,
cms_organizationalunits_person_map.status
from cms_persons
join cms_organizationalunits_person_map on cms_persons.person_id = cms_organizationalunits_person_map.person_id
where cms_organizationalunits_person_map.organizationalunit_id in :orgaunitIds

View File

@ -158,6 +158,14 @@ public class GenericOrganizationalUnitSubordinateCollection extends DomainCollec
return (GenericOrganizationalUnit) bundle.getPrimaryInstance();
}
public GenericOrganizationalUnit getGenericOrganizationalUnit(
final String language) {
final ContentBundle bundle = (ContentBundle) DomainObjectFactory.
newInstance(m_dataCollection.getDataObject());
return (GenericOrganizationalUnit) bundle.getInstance(language);
}
public BigDecimal getId() {
return (BigDecimal) m_dataCollection.getDataObject().get(ACSObject.ID);
}

View File

@ -4,11 +4,13 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.ui.panels.Paginator;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
@ -23,15 +25,16 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
Logger.getLogger(GenericOrgaUnitMembersTab.class);
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
final boolean result = !getData(orgaunit).isEmpty();
logger.debug(String.format(
"Needed %d ms to determine if "
+ "organizational unit '%s' has members. Merge is set to '%b'.",
System.currentTimeMillis() - start,
orgaunit.getName(),
isMergingMembers()));
return result;
/*final long start = System.currentTimeMillis();
final boolean result = !getData(orgaunit).isEmpty();
logger.debug(String.format(
"Needed %d ms to determine if "
+ "organizational unit '%s' has members. Merge is set to '%b'.",
System.currentTimeMillis() - start,
orgaunit.getName(),
isMergingMembers()));
return result;*/
return !orgaunit.getPersons().isEmpty();
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
@ -39,26 +42,23 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
final PageState state) {
final long start = System.currentTimeMillis();
final DataQuery persons = getData(orgaunit, state);
List<GenericPerson> persons = getPersons(orgaunit, state);
final Element personsElem = parent.newChildElement(getXmlElementName());
if (getPageSize() != 0) {
final GenericOrgaUnitPaginator<DataQuery> paginator =
new GenericOrgaUnitPaginator<DataQuery>(
persons, state, getPageSize());
paginator.setRange(persons);
final Paginator paginator = new Paginator(
state.getRequest(), persons.size(), getPageSize());
paginator.generateXml(personsElem);
if (paginator.getEnd() < persons.size()) {
persons = persons.subList(paginator.getBegin(), paginator.getEnd());
}
}
while (persons.next()) {
/*generatePersonXml((BigDecimal) persons.get("memberId"),
parent,
state);*/
generatePersonXml(((GenericOrganizationalUnitPersonCollection) persons).getPerson().getID(),
parent,
state);
for(GenericPerson person : persons) {
generatePersonXml(person, personsElem, state);
}
logger.debug(String.format("Generated member list of organizational "
+ "unit '%s' in %d ms.",
orgaunit.getName(),
@ -70,6 +70,14 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
final PageState state) {
final GenericPerson person = new GenericPerson(personId);
final XmlGenerator generator = new XmlGenerator(person);
generator.setItemElemName("person", "");
generator.generateXML(state, parent, "");
}
private void generatePersonXml(final GenericPerson person,
final Element parent,
final PageState state) {
final XmlGenerator generator = new XmlGenerator(person);
generator.generateXML(state, parent, "");
}
@ -86,50 +94,15 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
protected abstract int getPageSize();
protected DataQuery getData(final GenericOrganizationalUnit orgaunit,
final PageState state) {
return getData(orgaunit);
}
protected List<GenericPerson> getPersons(
final GenericOrganizationalUnit orgaunit,
final PageState state) {
final long start = System.currentTimeMillis();
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
return orgaunit.getPersons();
final List<GenericPerson> persons = new LinkedList<GenericPerson>();
/*final long start = System.currentTimeMillis();
final DataQuery personsQuery = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits");
if (isMergingMembers()) {
final DataQuery subOrgaUnitsQuery =
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivly");
subOrgaUnitsQuery.setParameter("orgaunitId", orgaunit.getID().
toString());
final StringBuffer assocTypeFilter = new StringBuffer();
for (String assocType : getAssocTypesToMerge()) {
if (assocTypeFilter.length() > 0) {
assocTypeFilter.append(" or ");
}
assocTypeFilter.append(String.format("assocType = '%s'",
assocType));
}
subOrgaUnitsQuery.addFilter(assocTypeFilter.toString());
final StringBuffer buffer = new StringBuffer();
while (subOrgaUnitsQuery.next()) {
if (buffer.length() > 0) {
buffer.append(" or ");
}
buffer.append(String.format("orgaunitId = %s",
subOrgaUnitsQuery.get("orgaunitId").
toString()));
}
personsQuery.addFilter(buffer.toString());
} else {
personsQuery.addFilter(String.format("orgaunitId = %s",
orgaunit.getID().toString()));
}
final GenericOrganizationalUnitPersonCollection personColl = orgaunit.
getPersons();
if ((getRolesToInclude() != null) && !getRolesToInclude().isEmpty()) {
final StringBuffer roleFilter = new StringBuffer();
@ -137,9 +110,10 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
if (roleFilter.length() > 0) {
roleFilter.append(" or ");
}
roleFilter.append(String.format("roleName = '%s'", role));
roleFilter.append(String.format("link.roleName = '%s'",
role));
}
personsQuery.addFilter(roleFilter.toString());
personColl.addFilter(roleFilter.toString());
}
if ((getStatusesToInclude() != null)
@ -149,21 +123,56 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
if (statusFilter.length() > 0) {
statusFilter.append(" or ");
}
statusFilter.append(String.format("status = '%s'", status));
statusFilter.append(String.format("link.status = '%s'", status));
}
personsQuery.addFilter(statusFilter.toString());
personColl.addFilter(statusFilter.toString());
}
personsQuery.addOrder("surname");
personsQuery.addOrder("givenname");
while (personColl.next()) {
persons.add(personColl.getPerson());
}
if (isMergingMembers()) {
getPersonsFromSubordinateOrgaUnits(orgaunit, persons, state);
}
logger.debug(String.format(
"Got persons for organizational unit '%s'"
+ "in %d ms. isMergingMembers is set to '%b'.",
"Got members of orgaunit '%s'"
+ "in '%d ms'. MergeMembers is set to '%b'.",
orgaunit.getName(),
System.currentTimeMillis() - start,
isMergingMembers()));
return personsQuery;*/
return persons;
}
protected void getPersonsFromSubordinateOrgaUnits(
final GenericOrganizationalUnit orgaunit,
final List<GenericPerson> persons,
final PageState state) {
final GenericOrganizationalUnitSubordinateCollection subOrgaUnits =
orgaunit.
getSubordinateOrgaUnits();
final StringBuffer assocTypeFilter = new StringBuffer();
for (String assocType : getAssocTypesToMerge()) {
if (assocTypeFilter.length() > 0) {
assocTypeFilter.append(" or ");
}
assocTypeFilter.append(String.format("assocType = '%s'", assocType));
}
subOrgaUnits.addFilter(assocTypeFilter.toString());
while (subOrgaUnits.next()) {
getPersonsFromSubordinateOrgaUnit(orgaunit, persons, state);
}
}
protected void getPersonsFromSubordinateOrgaUnit(
final GenericOrganizationalUnit subOrgaUnit,
final List<GenericPerson> persons,
final PageState state) {
final List<GenericPerson> subOrgaUnitMembers = getPersons(subOrgaUnit,
state);
persons.addAll(subOrgaUnitMembers);
}
/**

View File

@ -19,7 +19,7 @@ import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
@ -152,7 +152,9 @@ public class GenericOrganizationalUnitSubordinateOrgaUnitsTable
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case 0:
return subordinateOrgaUnits.getTitle();
return subordinateOrgaUnits.getGenericOrganizationalUnit(
GlobalizationHelper.getNegotiatedLocale().
getLanguage()).getTitle();
case 1:
return customizer.getDeleteLabel();
case 2:
@ -166,7 +168,9 @@ public class GenericOrganizationalUnitSubordinateOrgaUnitsTable
@Override
public Object getKeyAt(final int columnIndex) {
return subordinateOrgaUnits.getId();
return subordinateOrgaUnits.getGenericOrganizationalUnit(
GlobalizationHelper.getNegotiatedLocale().getLanguage()).
getID();
}
}
@ -182,7 +186,7 @@ public class GenericOrganizationalUnitSubordinateOrgaUnitsTable
final Object key,
final int row,
final int column) {
final com.arsdigita.cms.SecurityManager securityManager = Utilities.
final com.arsdigita.cms.SecurityManager securityManager = CMS.
getSecurityManager(state);
final GenericOrganizationalUnit subordinateOrgaUnit =
new GenericOrganizationalUnit(
@ -230,7 +234,7 @@ public class GenericOrganizationalUnitSubordinateOrgaUnitsTable
final Object key,
final int row,
final int column) {
final com.arsdigita.cms.SecurityManager securityManager = Utilities.
final com.arsdigita.cms.SecurityManager securityManager = CMS.
getSecurityManager(state);
final GenericOrganizationalUnit orgaunit =
(GenericOrganizationalUnit) itemModel.
@ -303,9 +307,9 @@ public class GenericOrganizationalUnitSubordinateOrgaUnitsTable
}
if ((customizer.getContentType() != null)
&& !(customizer.getContentType().isEmpty())) {
subOrgaUnits.addFilter(String.format("objectType = '%s'",
customizer.
getContentType()));
subOrgaUnits.addFilter(
String.format("objectType = '%s'",
customizer.getContentType()));
}
if ((subOrgaUnits.size() - 1) == row) {

View File

@ -136,6 +136,14 @@ public class CompareFilter implements Filter {
return filter.toString();
}
public String getValue() {
return value;
}
public Operators getOperator() {
return options.get(value).getOperator();
}
public void generateXml(final Element parent) {
Element filter;
String selected;

View File

@ -6,6 +6,7 @@ import com.arsdigita.web.URL;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
@ -122,7 +123,7 @@ public class Paginator {
return num;
}
private int getBegin() {
public int getBegin() {
if (pageNumber == 1) {
return 1;
} else {
@ -130,11 +131,11 @@ public class Paginator {
}
}
private int getCount() {
public int getCount() {
return Math.min(pageSize, (objectCount - getBegin() + 1));
}
private int getEnd() {
public int getEnd() {
int paginatorEnd = getBegin() + getCount() - 1;
if (paginatorEnd < 0) {
paginatorEnd = 0;

View File

@ -63,6 +63,10 @@ public class TextFilter implements Filter {
}
}
public String getValue() {
return value;
}
@Override
public void setValue(final String value) {
this.value = value;

View File

@ -238,7 +238,7 @@ public class DomainObjectFactory {
*/
public synchronized static DomainObjectInstantiator registerInstantiator(
ObjectType dataObjectType,
DomainObjectInstantiator instantiator) {
DomainObjectInstantiator instantiator) {
if (null == dataObjectType) {
throw new InstantiatorRegistryException("null", instantiator);
}

View File

@ -1,6 +1,7 @@
package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericAddress;
import com.arsdigita.cms.contenttypes.GenericContactEntry;
import com.arsdigita.cms.contenttypes.GenericContactEntryCollection;
@ -9,10 +10,11 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.GenericPersonContactCollection;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.cms.contenttypes.SciProjectBundle;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.OID;
import com.arsdigita.xml.Element;
@ -24,6 +26,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
@ -57,8 +60,8 @@ public class PersonalProjects implements ContentGenerator {
final GenericPerson person,
final PageState state,
final String profileLanguage) {
final List<SciProject> projects = collectProjects(person,
profileLanguage);
final List<SciProjectBundle> projects = collectProjects(person,
profileLanguage);
final Element personalProjectsElem = parent.newChildElement(
"personalProjects");
@ -66,9 +69,10 @@ public class PersonalProjects implements ContentGenerator {
if ((projects == null) || projects.isEmpty()) {
personalProjectsElem.newChildElement("noProjects");
} else {
final List<SciProject> currentProjects = new ArrayList<SciProject>();
final List<SciProject> finishedProjects =
new ArrayList<SciProject>();
final List<SciProjectBundle> currentProjects =
new ArrayList<SciProjectBundle>();
final List<SciProjectBundle> finishedProjects =
new ArrayList<SciProjectBundle>();
String sortBy = config.getSortBy();
String sortByParam = state.getRequest().getParameter("sortBy");
@ -86,67 +90,17 @@ public class PersonalProjects implements ContentGenerator {
}
}
private List<SciProject> collectProjects(final GenericPerson person,
final String language) {
final List<SciProject> projects = new ArrayList<SciProject>();
/*final DataCollection collection = (DataCollection) person.get(
"organizationalunit");
if (Kernel.getConfig().languageIndependentItems()) {*/
/* FilterFactory ff = collection.getFilterFactory();
Filter filter = ff.or().*/
/*addFilter(ff.equals("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())).*/
/*addFilter(ff.equals("language", language)).
addFilter(ff.and().
addFilter(ff.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent",
"com.arsdigita.london.navigation.getParentIDsOfMatchedItems").
set("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())));
collection.addFilter(filter);*/
/*collection.addFilter(
String.format("(language = '%s' or language = '%s')",
language,
GlobalizationHelper.LANG_INDEPENDENT));
} else {
/*collection.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());*/
/* collection.addEqualsFilter("language", language);
}*/
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
final DataCollection collection = (DataCollection) person.get(
"organizationalunit");
collection.addFilter(String.format("language = '%s'", language));
private List<SciProjectBundle> collectProjects(final GenericPerson person,
final String language) {
final List<SciProjectBundle> projects =
new LinkedList<SciProjectBundle>();
final DataCollection collection = (DataCollection) person.
getGenericPersonBundle().get("organizationalunits");
DomainObject obj;
while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject());
if (obj instanceof SciProject) {
processed.add(((SciProject) obj).getParent().getID());
projects.add((SciProject) obj);
}
}
if (Kernel.getConfig().languageIndependentItems()) {
final DataCollection collectionLi = (DataCollection) person.get(
"organizationalunit");
collectionLi.addFilter(
String.format("language = '%s'",
GlobalizationHelper.LANG_INDEPENDENT));
while (collectionLi.next()) {
obj =
DomainObjectFactory.newInstance(collectionLi.getDataObject());
if (obj instanceof SciProject) {
if (!(processed.contains(((SciProject) obj).getParent().
getID()))) {
projects.add((SciProject) obj);
}
}
if (obj instanceof SciProjectBundle) {
projects.add((SciProjectBundle) obj);
}
}
@ -158,63 +112,40 @@ public class PersonalProjects implements ContentGenerator {
}
private void collectProjects(final GenericPerson alias,
final List<SciProject> projects,
final List<SciProjectBundle> projects,
final String language) {
final DataCollection collection = (DataCollection) alias.get(
"organizationalunit");
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
collection.addFilter(String.format("language = '%s'", language));
final DataCollection collection = (DataCollection) alias.
getGenericPersonBundle().get("organizationalunits");
DomainObject obj;
while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject());
if (obj instanceof SciProject) {
processed.add(((SciProject) obj).getParent().getID());
projects.add((SciProject) obj);
if (obj instanceof SciProjectBundle) {
projects.add((SciProjectBundle) obj);
}
}
if (Kernel.getConfig().languageIndependentItems()) {
final DataCollection collectionLi = (DataCollection) alias.get(
"organizationalunit");
collectionLi.addFilter(
String.format("language = '%s'",
GlobalizationHelper.LANG_INDEPENDENT));
while (collectionLi.next()) {
obj =
DomainObjectFactory.newInstance(collectionLi.getDataObject());
if (obj instanceof SciProject) {
if (!(processed.contains(((SciProject) obj).getParent().
getID()))) {
projects.add((SciProject) obj);
}
}
}
}
if (alias.getAlias() != null) {
collectProjects(alias.getAlias(), projects, language);
}
}
private void processProjects(final List<SciProject> projects,
final List<SciProject> currentProjects,
final List<SciProject> finishedProjects,
private void processProjects(final List<SciProjectBundle> projects,
final List<SciProjectBundle> currentProjects,
final List<SciProjectBundle> finishedProjects,
final String sortBy) {
final Calendar today = new GregorianCalendar();
final Date todayDate = today.getTime();
for (SciProject project : projects) {
if ((project.getEnd() != null)
&& project.getEnd().before(todayDate)) {
for (SciProjectBundle project : projects) {
if ((project.getProject().getEnd() != null)
&& project.getProject().getEnd().before(todayDate)) {
finishedProjects.add(project);
} else {
currentProjects.add(project);
}
}
Comparator<SciProject> comparator;
Comparator<SciProjectBundle> comparator;
if ("date".equals(sortBy)) {
comparator = new ProjectByDateComparator();
} else {
@ -226,8 +157,8 @@ public class PersonalProjects implements ContentGenerator {
}
private void generateGroupsXml(final Element parent,
final List<SciProject> currentProjects,
final List<SciProject> finishedProjects) {
final List<SciProjectBundle> currentProjects,
final List<SciProjectBundle> finishedProjects) {
final Element availableGroups = parent.newChildElement(
"availableProjectGroups");
@ -247,8 +178,8 @@ public class PersonalProjects implements ContentGenerator {
}
private void generateProjectsXml(final Element parent,
final List<SciProject> currentProjects,
final List<SciProject> finishedProjects,
final List<SciProjectBundle> currentProjects,
final List<SciProjectBundle> finishedProjects,
final PageState state) {
final Element projectsElem = parent.newChildElement("projects");
@ -297,7 +228,7 @@ public class PersonalProjects implements ContentGenerator {
private void generateProjectsGroupXml(final Element projectsElem,
final String groupName,
final List<SciProject> projects,
final List<SciProjectBundle> projects,
final PageState state) {
if (projects == null) {
return;
@ -306,18 +237,17 @@ public class PersonalProjects implements ContentGenerator {
final Element groupElem = projectsElem.newChildElement("projectGroup");
groupElem.addAttribute("name", groupName);
for (SciProject project : projects) {
for (SciProjectBundle project : projects) {
generateProjectXml(groupElem, project, state);
}
}
private void generateProjectXml(final Element projectGroupElem,
final SciProject project,
final SciProjectBundle projectBundle,
final PageState state) {
/*final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
project);
generator.generateXML(state, projectGroupElem, "");*/
final SciProject project = projectBundle.getProject(GlobalizationHelper.
getNegotiatedLocale().getLanguage());
Element projectElem = projectGroupElem.newChildElement("project");
projectElem.addAttribute("oid", project.getOID().toString());
@ -380,7 +310,7 @@ public class PersonalProjects implements ContentGenerator {
GenericOrganizationalUnitPersonCollection members;
members = project.getPersons();
members.addOrder("surname asc, givenname asc");
//members.addOrder("surname asc, givenname asc");
if (members.size() > 0) {
Element membersElem = projectElem.newChildElement("members");
@ -444,7 +374,7 @@ public class PersonalProjects implements ContentGenerator {
Element surname = memberElem.newChildElement("surname");
surname.setText(person.getSurname());
Element givenName = memberElem.newChildElement("givenname");
Element givenName = memberElem.newChildElement("givenName");
givenName.setText(person.getGivenName());
if ((person.getTitlePost() != null)
@ -578,8 +508,8 @@ public class PersonalProjects implements ContentGenerator {
final String role,
final String status) {
/*this.member = member;
this.role = role;
this.status = status;*/
this.role = role;
this.status = status;*/
this(member.getOID(),
member.getSurname(),
member.getGivenName(),
@ -616,8 +546,8 @@ public class PersonalProjects implements ContentGenerator {
}
/*public GenericPerson getMember() {
return member;
}*/
return member;
}*/
public OID getOID() {
return oid;
}
@ -659,15 +589,15 @@ public class PersonalProjects implements ContentGenerator {
}
/*@Override
public boolean equals(Object obj) {
if (obj instanceof MemberListItem) {
MemberListItem other = (MemberListItem) obj;
public boolean equals(Object obj) {
if (obj instanceof MemberListItem) {
MemberListItem other = (MemberListItem) obj;
return member.equals(other.getMember());
} else {
return false;
}
}*/
return member.equals(other.getMember());
} else {
return false;
}
}*/
@Override
public boolean equals(Object obj) {
if (obj == null) {
@ -714,9 +644,9 @@ public class PersonalProjects implements ContentGenerator {
}
/*@Override
public int hashCode() {
return member.hashCode();
}*/
public int hashCode() {
return member.hashCode();
}*/
@Override
public int hashCode() {
int hash = 3;
@ -739,29 +669,38 @@ public class PersonalProjects implements ContentGenerator {
}
}
private class ProjectByTitleComparator implements Comparator<SciProject> {
private class ProjectByTitleComparator
implements Comparator<SciProjectBundle> {
public int compare(final SciProject project1,
final SciProject project2) {
return project1.getTitle().compareTo(project2.getTitle());
public int compare(final SciProjectBundle project1,
final SciProjectBundle project2) {
return project1.getProject().getTitle().compareTo(project2.
getProject().getTitle());
}
}
private class ProjectByDateComparator implements Comparator<SciProject> {
private class ProjectByDateComparator implements
Comparator<SciProjectBundle> {
public int compare(final SciProject project1,
final SciProject project2) {
public int compare(final SciProjectBundle project1,
final SciProjectBundle project2) {
int ret = 0;
if ((project2.getBegin() != null) && (project1.getBegin() != null)) {
ret = project2.getBegin().compareTo(project1.getBegin());
if ((project2.getProject().getBegin() != null) && (project1.
getProject().
getBegin()
!= null)) {
ret = project2.getProject().getBegin().compareTo(project1.
getProject().getBegin());
}
if ((ret == 0)
&& (project2.getEnd() != null)
&& (project1.getEnd() != null)) {
ret = project2.getEnd().compareTo(project1.getBegin());
&& (project2.getProject().getEnd() != null)
&& (project1.getProject().getEnd() != null)) {
ret = project2.getProject().getEnd().compareTo(project1.
getProject().getBegin());
}
if (ret == 0) {
ret = project1.getTitle().compareTo(project2.getTitle());
ret = project1.getProject().getTitle().compareTo(project2.
getProject().getTitle());
}
return ret;
@ -802,4 +741,19 @@ public class PersonalProjects implements ContentGenerator {
elem.addAttribute("longDate", longDateFormat.format(date));
elem.addAttribute("time", timeFormat.format(date));
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;
public XmlGenerator(final ContentItem item) {
super();
this.item = item;
}
@Override
protected ContentItem getContentItem(final PageState state) {
return item;
}
}
}

View File

@ -4,21 +4,19 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.ui.PublicationXmlHelper;
import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.contenttypes.ui.panels.Paginator;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -52,136 +50,85 @@ public class PersonalPublications implements ContentGenerator {
final String language) {
final long start = System.currentTimeMillis();
final DataQuery allQuery = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(person, allQuery, true, language);
final List<PublicationBundle> publications =
collectPublications(person, language);
final Element personalPubsElem = parent.newChildElement(
"personalPublications");
final long overallSize;
if (allQuery == null) {
if (publications == null) {
overallSize = 0;
} else {
overallSize = allQuery.size();
overallSize = publications.size();
}
if (overallSize <= 0) {
personalPubsElem.newChildElement("noPublications");
return;
} else {
logger.debug(String.format("1: %d ms until now...", System.
currentTimeMillis() - start));
final Map<String, List<String>> groupsConfig = getGroupsConfig();
final Map<String, List<PublicationBundle>> publicationsByGroup =
new HashMap<String, List<PublicationBundle>>();
for (Map.Entry<String, List<String>> entry : groupsConfig.entrySet()) {
filterPublicationsByGroup(entry.getKey(),
entry.getValue(),
publications,
publicationsByGroup);
}
final List<PublicationBundle> miscGroup =
filterPublicationsForMiscGroup(
publications, groupsConfig);
publicationsByGroup.put(MISC, miscGroup);
final Element availableGroupsElem =
personalPubsElem.newChildElement(
"availablePublicationGroups");
final Element publicationsElem = personalPubsElem.newChildElement(
"publications");
final Map<String, List<String>> groupsConfig = getGroupsConfig();
final Map<String, DataQuery> groupQueries =
new LinkedHashMap<String, DataQuery>();
logger.debug(String.format("2: %d ms until now...", System.
currentTimeMillis() - start));
for (Map.Entry<String, List<String>> entry : groupsConfig.entrySet()) {
createGroupQuery(person,
entry.getKey(),
entry.getValue(),
groupQueries,
language);
logger.debug(String.format("3: %d ms until now...", System.
currentTimeMillis() - start));
}
final String miscFilter = generateFilterForMiscGroup(groupsConfig);
final DataQuery miscQuery = SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(person, miscQuery, true, language);
miscQuery.addFilter(miscFilter);
groupQueries.put(MISC, miscQuery);
logger.debug(String.format("4: %d ms until now...", System.
currentTimeMillis() - start));
logger.debug(String.format("5: %d ms until now...", System.
currentTimeMillis() - start));
if (overallSize < config.getGroupSplit()) {
publicationsElem.addAttribute("all", "all");
for (Map.Entry<String, List<String>> entry : groupsConfig.
entrySet()) {
generateXmlForGroup(entry.getKey(),
for (Map.Entry<String, List<PublicationBundle>> group :
publicationsByGroup.entrySet()) {
generateXmlForGroup(group.getKey(),
availableGroupsElem,
publicationsElem,
groupQueries.get(entry.getKey()),
state,
group.getValue(),
false,
true);
true,
state);
}
generateXmlForGroup(MISC,
availableGroupsElem,
publicationsElem,
groupQueries.get(MISC),
state,
false,
true);
} else {
final List<String> availableGroups = new ArrayList<String>();
logger.debug(String.format("6: %d ms until now...", System.
currentTimeMillis() - start));
final List<String> availableGroups = new LinkedList<String>();
for (Map.Entry<String, List<String>> entry : groupsConfig.
entrySet()) {
if (!(groupQueries.get(entry.getKey()).isEmpty())) {
if (!(publicationsByGroup.get(entry.getKey()).isEmpty())) {
generateAvailableForGroup(entry.getKey(),
availableGroupsElem);
availableGroups.add(entry.getKey());
}
logger.debug(String.format("7: %d ms until now...", System.
currentTimeMillis() - start));
}
logger.debug(String.format("8: %d ms until now...", System.
currentTimeMillis() - start));
final long b1 = System.currentTimeMillis();
if (!(groupQueries.get(MISC).isEmpty())) {
generateAvailableForGroup(MISC,
availableGroupsElem);
if (!(publicationsByGroup.get(MISC).isEmpty())) {
generateAvailableForGroup(MISC, availableGroupsElem);
availableGroups.add(MISC);
}
if (logger.isDebugEnabled()) {
logger.debug(String.format("9: %d ms until now...", System.
currentTimeMillis() - start));
logger.debug(String.format(
"Determined if misc group is available in %d ms",
System.currentTimeMillis() - b1));
logger.debug(String.format("Determined available groups "
+ "in %d ms.",
System.currentTimeMillis()
- start));
}
final HttpServletRequest request = state.getRequest();
String group = selectGroup(request, config.getDefaultGroup(),
availableGroups);
if (logger.isDebugEnabled()) {
logger.debug(String.format("Selected group: '%s'", group));
}
logger.debug(String.format("10: %d ms until now...", System.
currentTimeMillis() - start));
final String group = selectGroup(request,
config.getDefaultGroup(),
availableGroups);
generateXmlForGroup(group,
availableGroupsElem,
publicationsElem,
groupQueries.get(group),
state,
publicationsByGroup.get(group),
true,
false);
logger.debug(String.format("11: %d ms until now...", System.
currentTimeMillis() - start));
false,
state);
}
allQuery.close();
logger.debug(String.format("12: %d ms until now...", System.
currentTimeMillis() - start));
}
if (logger.isDebugEnabled()) {
@ -194,62 +141,45 @@ public class PersonalPublications implements ContentGenerator {
}
}
private void applyAuthorFilter(final GenericPerson person,
final DataQuery query,
final boolean addOrders,
final String language) {
final StringBuilder authorFilterBuilder = new StringBuilder();
authorFilterBuilder.append('(');
authorFilterBuilder.append(String.format("authorId = %s",
person.getID().toString()));
if (person.getAlias() != null) {
addAliasToFilter(authorFilterBuilder, person.getAlias());
}
authorFilterBuilder.append(')');
query.addFilter(authorFilterBuilder.toString());
/*query.addFilter(String.format("authorId = %s",
person.getID().toString()));*/
if (Kernel.getConfig().languageIndependentItems()) {
FilterFactory ff = query.getFilterFactory();
Filter filter = ff.or().
addFilter(ff.equals("language", language)).
addFilter(ff.and().
addFilter(ff.equals("language", GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent", "com.arsdigita.navigation.getParentIDsOfMatchedItems")
.set("language", language)));
query.addFilter(filter);
/*query.addFilter(
String.format("(language = '%s' or language = '%s')",
GlobalizationHelper.getNegotiatedLocale().
getLanguage(),
GlobalizationHelper.LANG_INDEPENDENT));*/
/*query.addFilter(String.format("language = '%s' or language = '%s'",
language,
GlobalizationHelper.LANG_INDEPENDENT));*/
} else {
/*query.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());*/
query.addEqualsFilter("language", language);
}
if (addOrders) {
final String[] orders = config.getOrder().split(",");
for (String order : orders) {
query.addOrder(order);
private List<PublicationBundle> collectPublications(
final GenericPerson author,
final String language) {
final List<PublicationBundle> publications =
new LinkedList<PublicationBundle>();
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
final DataCollection collection = (DataCollection) author.
getGenericPersonBundle().get("publication");
DomainObject obj;
while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject());
if (obj instanceof PublicationBundle) {
processed.add(((PublicationBundle) obj).getParent().getID());
publications.add((PublicationBundle) obj);
}
}
if (author.getAlias() != null) {
collectPublications(author.getAlias(), publications, language);
}
return publications;
}
private void addAliasToFilter(final StringBuilder builder,
final GenericPerson alias) {
builder.append(String.format("or authorId = %s",
alias.getID().toString()));
private void collectPublications(final GenericPerson alias,
final List<PublicationBundle> publications,
final String language) {
final DataCollection collection = (DataCollection) alias.
getGenericPersonBundle().get("publication");
DomainObject obj;
while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject());
if (obj instanceof PublicationBundle) {
publications.add((PublicationBundle) obj);
}
}
if (alias.getAlias() != null) {
addAliasToFilter(builder, alias.getAlias());
collectPublications(alias.getAlias(), publications, language);
}
}
@ -283,52 +213,6 @@ public class PersonalPublications implements ContentGenerator {
groups.put(tokens[0], types);
}
private String generateFilterForTypeToken(String typeToken) {
if (typeToken.endsWith("_reviewed")) {
return String.format("(objectType = '%s' and reviewed = 'true')",
typeToken.substring(0, typeToken.length() - 9));
} else if (typeToken.endsWith("_notreviewed")) {
return String.format(
"(objectType = '%s' and (reviewed = 'false' or reviewed is null))",
typeToken.substring(0, typeToken.length() - 12));
} else {
return String.format("(objectType = '%s')", typeToken);
}
}
private String generateFilterForTypeTokens(final List<String> typeTokens) {
final StringBuffer buffer = new StringBuffer();
for (String typeToken : typeTokens) {
if (buffer.length() > 0) {
buffer.append(" or ");
}
buffer.append(generateFilterForTypeToken(typeToken));
}
return buffer.toString();
}
private String generateFilterForMiscGroup(
final Map<String, List<String>> groups) {
final StringBuffer buffer = new StringBuffer();
for (Map.Entry<String, List<String>> entry : groups.entrySet()) {
if (buffer.length() > 0) {
buffer.append(" and ");
}
buffer.append(String.format("not (%s)",
generateFilterForTypeTokens(entry.
getValue())));
}
return buffer.toString();
}
private void applyFiltersForTypeTokens(final List<String> typeTokens,
final DataQuery query) {
query.addFilter(generateFilterForTypeTokens(typeTokens));
}
private void generateAvailableForGroup(final String groupName,
final Element availableGroupsElem) {
final Element group =
@ -340,11 +224,13 @@ public class PersonalPublications implements ContentGenerator {
private void generateXmlForGroup(final String groupName,
final Element availableGroupsElem,
final Element publicationsElem,
final DataQuery query,
final PageState state,
final List<PublicationBundle> publications,
final boolean withPaginator,
final boolean generateAvailable) {
if ((query == null) || query.isEmpty()) {
final boolean generateAvailable,
final PageState state) {
List<PublicationBundle> publicationList = publications;
if ((publications == null) || publications.isEmpty()) {
return;
}
@ -358,48 +244,28 @@ public class PersonalPublications implements ContentGenerator {
if (withPaginator) {
final Paginator paginator = new Paginator(state.getRequest(),
(int) query.size(),
publications.size(),
config.getPageSize());
paginator.applyLimits(query);
publicationList = publicationList.subList(paginator.getBegin(),
paginator.getEnd());
paginator.generateXml(groupElem);
}
while (query.next()) {
generatePublicationXml((BigDecimal) query.get("publicationId"),
(String) query.get("objectType"),
for (PublicationBundle publication : publicationList) {
generatePublicationXml(publication.getPublication(
GlobalizationHelper.getNegotiatedLocale().getLanguage()),
groupElem,
state);
}
}
private void generatePublicationXml(final BigDecimal publicationId,
final String objectType,
private void generatePublicationXml(final Publication publication,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final ContentItem publication = (ContentItem) DomainObjectFactory.
newInstance(new OID(
objectType, publicationId));
if (logger.isDebugEnabled()) {
logger.debug(String.format("Got domain object for publication "
+ "'%s' in %d ms.",
publication.getName(),
System.currentTimeMillis() - start));
}
/*final XmlGenerator generator = new XmlGenerator(publication);
final XmlGenerator generator = new XmlGenerator(publication);
generator.setItemElemName("publications", "");
generator.generateXML(state, parent, "");*/
final PublicationXmlHelper xmlHelper =
new PublicationXmlHelper(parent,
(Publication) publication);
xmlHelper.generateXml();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Generated XML for publication '%s' "
+ "in %d ms.",
publication.getName(),
System.currentTimeMillis() - start));
}
generator.setListMode(true);
generator.generateXML(null, parent, "");
}
private class XmlGenerator extends SimpleXMLGenerator {
@ -437,362 +303,51 @@ public class PersonalPublications implements ContentGenerator {
return group;
}
private void createGroupQuery(final GenericPerson author,
final String groupName,
final List<String> typeTokens,
final Map<String, DataQuery> groupQueries,
final String language) {
final DataQuery query = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(author, query, true, language);
applyFiltersForTypeTokens(typeTokens, query);
private void filterPublicationsByGroup(
final String groupName,
final List<String> typeTokens,
final List<PublicationBundle> publications,
final Map<String, List<PublicationBundle>> publicationsByGroup) {
final List<PublicationBundle> group =
new LinkedList<PublicationBundle>();
groupQueries.put(groupName, query);
for (PublicationBundle publication : publications) {
for (String typeToken : typeTokens) {
if (publication.getContentType().getAssociatedObjectType().
equals(
typeToken)) {
group.add(publication);
break;
}
}
}
if (group.size() > 0) {
publicationsByGroup.put(groupName, group);
}
}
/* ------------ */
// public void generateContentOld(final Element parent,
// final GenericPerson person,
// final PageState state) {
// final long start = System.currentTimeMillis();
// final List<DataObject> publications = collectPublications(person);
//
// final Element personalPubsElem = parent.newChildElement(
// "personalPublications");
//
// if ((publications == null) || publications.isEmpty()) {
// personalPubsElem.newChildElement("noPublications");
//
// return;
// } else {
// final Map<String, List<Publication>> groupedPublications =
// processPublications(
// publications);
//
// generateGroupsXml(personalPubsElem, groupedPublications);
// generatePublicationsXml(personalPubsElem, groupedPublications, state);
// }
// if (logger.isDebugEnabled()) {
// logger.debug(String.format("Generated publications of %d publications "
// + "for '%s' in %d ms.",
// publications.size(),
// person.getFullName(),
// System.currentTimeMillis() - start));
// }
// }
//
// private List<DataObject> collectPublications(final GenericPerson person) {
// final long start = System.currentTimeMillis();
// final List<DataObject> publications = new ArrayList<DataObject>();
// final DataCollection collection = (DataCollection) person.get(
// "publication");
//
// while (collection.next()) {
// publications.add(collection.getDataObject());
// }
//
// if (person.getAlias() != null) {
// collectPublications(person, publications);
// }
//
// if (logger.isDebugEnabled()) {
// logger.debug(String.format(
// "Collected publications of '%s' in %d ms.",
// person.getFullName(),
// System.currentTimeMillis() - start));
// }
// return publications;
// }
//
// private void collectPublications(final GenericPerson alias,
// final List<DataObject> publications) {
// final DataCollection collection = (DataCollection) alias.get(
// "publication");
//
// while (collection.next()) {
// publications.add(collection.getDataObject());
// }
//
// if (alias.getAlias() != null) {
// collectPublications(alias, publications);
// }
// }
//
// /**
// * Processes the publications and puts them into the groups.
// *
// * @param publications The publications to process
// * @param typeGroupMap The group-type map
// * @return A map with the group names as keys and a list of publications
// * as value.
// */
// private Map<String, List<Publication>> processPublications(
// final List<DataObject> publications) {
//
// final long start = System.currentTimeMillis();
// final GroupConfig groupConfig = new GroupConfig(config.
// getPublictionGroups());
// final Map<String, List<Publication>> pubGroups =
// new LinkedHashMap<String, List<Publication>>();
//
// for (String group : groupConfig.getGroups()) {
// initalizePubGroupMap(pubGroups, group);
// }
// initalizePubGroupMap(pubGroups, MISC);
//
// Publication publication;
// String type;
// String groupName;
// Boolean reviewed;
// List<Publication> group;
// int i = 1;
// for (DataObject dobj : publications) {
// if (logger.isDebugEnabled()) {
// logger.debug(String.format("Processing publications %d "
// + "of %d...",
// i,
// publications.size()));
// }
// i++;
// publication = (Publication) DomainObjectFactory.newInstance(dobj);
// type = publication.getClass().getName();
//
// if (dobj.getObjectType().hasProperty("reviewed")) {
// reviewed = (Boolean) dobj.get("reviewed");
// if (reviewed == null) {
// reviewed = Boolean.FALSE;
// }
// if (reviewed) {
// groupName = groupConfig.getTypeGroupMap().get(String.format(
// "%s_ref", type));
// } else {
// groupName = groupConfig.getTypeGroupMap().get(String.format(
// "%s_noref", type));
// }
//
// if (groupName == null) {
// groupName = groupConfig.getTypeGroupMap().get(type);
// }
// } else {
// groupName = groupConfig.getTypeGroupMap().get(type);
// }
//
// if (groupName == null) {
// groupName = MISC;
// }
//
// group = pubGroups.get(groupName);
// group.add(publication);
// }
//
// final PublicationGroupComparator comparator =
// new PublicationGroupComparator();
// for (List<Publication> currentGroup : pubGroups.values()) {
// Collections.sort(currentGroup, comparator);
// }
//
// if (logger.isDebugEnabled()) {
// logger.debug(String.format("Proceessed %d publications in %d ms.",
// publications.size(),
// System.currentTimeMillis() - start));
// }
// return pubGroups;
// }
//
// private void initalizePubGroupMap(
// final Map<String, List<Publication>> pubGroups,
// final String groupName) {
// pubGroups.put(groupName, new ArrayList<Publication>());
// }
//
// private void generateGroupsXml(final Element parent,
// final Map<String, List<Publication>> publications) {
// final Element availableGroups = parent.newChildElement(
// "availablePublicationGroups");
//
// for (Map.Entry<String, List<Publication>> entry :
// publications.entrySet()) {
// if (!entry.getValue().isEmpty()) {
// createAvailablePublicationGroupXml(availableGroups,
// entry.getKey());
// }
// }
// }
//
// private void createAvailablePublicationGroupXml(final Element parent,
// final String name) {
// final Element group =
// parent.newChildElement("availablePublicationGroup");
// group.addAttribute("name", name);
// }
//
// private void generatePublicationsXml(
// final Element parent,
// final Map<String, List<Publication>> publications,
// final PageState state) {
// final Element publicationsElem = parent.newChildElement("publications");
//
// int numberOfPubs = 0;
// final int groupSplit = config.getGroupSplit();
//
// for (List<Publication> list : publications.values()) {
// numberOfPubs += list.size();
// }
//
// if (numberOfPubs < groupSplit) {
// publicationsElem.addAttribute("all", "all");
//
// for (Map.Entry<String, List<Publication>> entry : publications.
// entrySet()) {
// if (entry.getValue().size() > 0) {
// generatePublicationGroupXml(publicationsElem,
// entry.getKey(),
// entry.getValue(),
// state);
// }
// }
// } else {
// final HttpServletRequest request = state.getRequest();
// final String[] defaultGroup = config.getDefaultGroup().split(",");
//
// String groupToShow = request.getParameter("group");
// if ((groupToShow == null)
// || groupToShow.isEmpty()
// || !(publications.containsKey(groupToShow))) {
// int i = 0;
// groupToShow = defaultGroup[i];
// while ((publications.get(groupToShow).isEmpty())
// && i < defaultGroup.length) {
// groupToShow = defaultGroup[i];
// i++;
// }
// }
//
// if (groupToShow == null) {
// groupToShow = MISC;
// }
//
// generatePublicationGroupXml(publicationsElem,
// groupToShow,
// publications.get(groupToShow),
// state);
// }
// }
//
// private void generatePublicationGroupXml(final Element publicationsElem,
// final String groupName,
// final List<Publication> publications,
// final PageState state) {
// if (publications == null) {
// return;
// }
//
// final Element groupElem = publicationsElem.newChildElement(
// "publicationGroup");
// groupElem.addAttribute("name", groupName);
//
// for (Publication publication : publications) {
// generatePublicationXml(groupElem, publication, state);
// }
// }
//
// private void generatePublicationXml(final Element publicationGroupElem,
// final Publication publication,
// final PageState state) {
// /*final PublicPersonalProfileXmlGenerator generator =
// new PublicPersonalProfileXmlGenerator(
// publication);
// generator.generateXML(state, publicationGroupElem, "");*/
// final PublicationXmlHelper xmlHelper = new PublicationXmlHelper(
// publicationGroupElem, publication);
// xmlHelper.generateXml();
// }
//
// /**
// * Processes the publications and puts them into the groups.
// *
// * @param publications The publications to process
// * @param typeGroupMap The group-type map
// * @return A map with the group names as keys and a list of publications
// * as value.
// */
// private class GroupConfig {
//
// private final Map<String, String> typeGroupMap =
// new HashMap<String, String>();
// private final List<String> groups = new ArrayList<String>();
//
// /**
// * Processes the configuration string and puts the result into the
// * collections.
// *
// * @param groupStr
// */
// public GroupConfig(final String groupStr) {
// final String[] groupTokens = groupStr.split(";");
// String[] groupTokenSplit;
// String groupName;
// String publicationTypeTokens;
// String[] publicationTypeTokensSplit;
// List<String> types;
// for (String groupToken : groupTokens) {
// groupTokenSplit = groupToken.split(":");
// if (groupTokenSplit.length != 2) {
// logger.warn(String.format(
// "Invalid entry in publication group config: '%s'. "
// + "Ignoring.",
// groupToken));
// continue;
// }
//
// groupName = groupTokenSplit[0];
// groups.add(groupName);
// publicationTypeTokens = groupTokenSplit[1];
// publicationTypeTokensSplit = publicationTypeTokens.split(",");
// for (String publicationTypeToken : publicationTypeTokensSplit) {
// typeGroupMap.put(publicationTypeToken, groupName);
// }
// }
// }
//
// public Map<String, String> getTypeGroupMap() {
// return Collections.unmodifiableMap(typeGroupMap);
// }
//
// public List<String> getGroups() {
// return Collections.unmodifiableList(groups);
// }
// }
//
// private class PublicationGroupComparator implements Comparator<Publication> {
//
// public int compare(final Publication publication1,
// final Publication publication2) {
// AuthorshipCollection authors1;
// AuthorshipCollection authors2;
// GenericPerson author;
// String authorsStr1;
// String authorsStr2;
// final StringBuffer authors1Buffer = new StringBuffer();
// final StringBuffer authors2Buffer = new StringBuffer();
//
// authors1 = publication1.getAuthors();
// while (authors1.next()) {
// author = authors1.getAuthor();
// authors1Buffer.append(author.getSurname());
// authors1Buffer.append(author.getGivenName());
// }
// authors2 = publication2.getAuthors();
// while (authors2.next()) {
// author = authors2.getAuthor();
// authors2Buffer.append(author.getSurname());
// authors2Buffer.append(author.getGivenName());
// }
//
// authorsStr1 = authors1Buffer.toString();
// authorsStr2 = authors2Buffer.toString();
//
// return authorsStr1.compareTo(authorsStr2);
// }
// }
private List<PublicationBundle> filterPublicationsForMiscGroup(
final List<PublicationBundle> publications,
final Map<String, List<String>> groupsConfig) {
final List<PublicationBundle> misc = new LinkedList<PublicationBundle>();
boolean found = false;
for (PublicationBundle publication : publications) {
for (Map.Entry<String, List<String>> entry : groupsConfig.entrySet()) {
for (String type : entry.getValue()) {
if (publication.getContentType().getAssociatedObjectType().
equals(type)) {
found = true;
}
}
}
if (!found) {
misc.add(publication);
}
found = false;
}
return misc;
}
}

View File

@ -336,4 +336,12 @@ public class PublicationBundle extends ContentBundle {
remove(SERIES, series.getSeriesBundle());
}
public Publication getPublication() {
return (Publication) getPrimaryInstance();
}
public Publication getPublication(final String language) {
return (Publication) getInstance(language);
}
}

View File

@ -3,6 +3,8 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.ui.panels.CompareFilter;
@ -15,6 +17,9 @@ import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
@ -34,13 +39,13 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
private static final String SURNAME_PARAM = "memberSurname";
private final CompareFilter statusFilter = new CompareFilter(
STATUS_PARAM,
"status",
"link.status",
false,
false,
false);
private final TextFilter surnameFilter =
new TextFilter(SURNAME_PARAM,
GenericPerson.SURNAME);
"name");
static {
config.load();
@ -55,28 +60,29 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
}
}
@Override
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
if ((orgaunit.getPersons() != null)
&& orgaunit.getPersons().size() > 0) {
return true;
} else if (config.isMergingMembers()) {
final DataQuery persons = getData(orgaunit);
return persons.isEmpty();
} else {
return false;
}
// if ((orgaunit.getPersons() != null)
// && orgaunit.getPersons().size() > 0) {
// return true;
// } else if (config.isMergingMembers()) {
// final DataQuery persons = getData(orgaunit);
// return persons.isEmpty();
// } else {
// return false;
// }
return !orgaunit.getPersons().isEmpty();
}
@Override
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final DataQuery persons = getData(orgaunit);
List<GenericPerson> members = getMembers(orgaunit, state);
final HttpServletRequest request = state.getRequest();
applyStatusFilter(persons, request);
applySurnameFilter(persons, request);
final Element depMembersElem = parent.newChildElement(
"departmentMembers");
@ -84,7 +90,8 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
statusFilter.generateXml(filtersElem);
if (persons.isEmpty()) {
if (members.isEmpty()) {
//if (persons.isEmpty()) {
if ((surnameFilter != null)
&& (surnameFilter.getFilter() != null)
&& !(surnameFilter.getFilter().trim().isEmpty())) {
@ -94,8 +101,23 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
return;
}
Collections.sort(members, new Comparator<GenericPerson>() {
public int compare(final GenericPerson person1,
final GenericPerson person2) {
String name1 = String.format("%s %s", person1.getSurname(),
person1.getGivenName());
String name2 = String.format("%s %s", person2.getSurname(),
person2.getGivenName());
return name1.compareTo(name2);
}
});
final Paginator paginator = new Paginator(request,
(int) persons.size(),
//(int) persons.size(),
members.size(),
config.getPageSize());
if ((paginator.getPageCount() > config.getEnableSearchLimit())
@ -104,11 +126,13 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
surnameFilter.generateXml(filtersElem);
}
paginator.applyLimits(persons);
paginator.generateXml(depMembersElem);
if (paginator.getEnd() < members.size()) {
members = members.subList(paginator.getBegin(), paginator.getEnd());
}
while (persons.next()) {
generateMemberXml((BigDecimal) persons.get("memberId"),
for (GenericPerson member : members) {
generateMemberXml(member,
depMembersElem,
state);
}
@ -119,6 +143,62 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
System.currentTimeMillis() - start));
}
protected List<GenericPerson> getMembers(
final GenericOrganizationalUnit orgaunit,
final PageState state) {
final long start = System.currentTimeMillis();
final List<GenericPerson> members = new LinkedList<GenericPerson>();
final GenericOrganizationalUnitPersonCollection persons = orgaunit.
getPersons();
if (state != null) {
applyStatusFilter(persons, state.getRequest());
applySurnameFilter(persons, state.getRequest());
}
while (persons.next()) {
members.add(persons.getPerson());
}
if (config.isMergingMembers()) {
getMembersFromSubordinateOrgaUnits(orgaunit, members, state);
}
logger.debug(String.format(
"Got members of department '%s'"
+ "in '%d ms'. MergeMembers is set to '%b'.",
orgaunit.getName(),
System.currentTimeMillis() - start,
config.isMergingMembers()));
return members;
}
protected void getMembersFromSubordinateOrgaUnits(
final GenericOrganizationalUnit orgaunit,
final List<GenericPerson> members,
final PageState state) {
final GenericOrganizationalUnitSubordinateCollection subDeps = orgaunit.
getSubordinateOrgaUnits();
subDeps.addFilter(
"objecttype = 'com.arsdigita.cms.contenttypes.SciDepartment'");
while (subDeps.next()) {
getMembersFromSubordinateOrgaUnit(
subDeps.getGenericOrganizationalUnit(), members, state);
}
}
protected void getMembersFromSubordinateOrgaUnit(
final GenericOrganizationalUnit subOrgaUnit,
final List<GenericPerson> members,
final PageState state) {
final List<GenericPerson> subOrgaUnitMembers = getMembers(subOrgaUnit,
state);
members.addAll(subOrgaUnitMembers);
}
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
@ -133,7 +213,6 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
final DataQuery personsQuery = SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits");
//final StringBuffer personsFilter = new StringBuffer();
final List<String> orgaUnitIds = new ArrayList<String>();
if (config.isMergingMembers()) {
@ -146,48 +225,14 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
SciDepartmentSubDepartmentsStep.ASSOC_TYPE);
while (subDepartmentsQuery.next()) {
/*if (personsFilter.length() > 0) {
personsFilter.append(" or ");
}
personsFilter.append(String.format("orgaunitId = %s",
subDepartmentsQuery.get(
"orgaunitId").toString()));*/
orgaUnitIds.add(subDepartmentsQuery.get("orgaunitId").toString());
}
} else {
/*personsFilter.append(String.format("orgaunitId = %s",
orgaunit.getID().toString()));*/
orgaUnitIds.add(orgaunit.getID().toString());
}
//personsQuery.addFilter(personsFilter.toString());
personsQuery.setParameter("orgaunitIds", orgaUnitIds);
/**
* Filter for language independent items
*/
/*if (Kernel.getConfig().languageIndependentItems()) {
FilterFactory ff = personsQuery.getFilterFactory();
Filter filter = ff.or().
addFilter(ff.equals("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())).
addFilter(ff.and().
addFilter(ff.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parentId",
"com.arsdigita.cms.contenttypes.getParentIDsOfMatchedItems").
set("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())));
personsQuery.addFilter(filter);
} else {
personsQuery.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());
}*/
personsQuery.addOrder(GenericPerson.SURNAME);
personsQuery.addOrder(GenericPerson.GIVENNAME);
@ -245,7 +290,8 @@ public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(member);
generator.setUseExtraXml(false);
//generator.setUseExtraXml(false);
//generator.setListMode(true);
generator.setItemElemName("member", "");
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for member '%s' in %d ms.",

View File

@ -41,7 +41,7 @@ public class SciDepartmentMembersTabConfig extends AbstractConfig {
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge",
Parameter.REQUIRED,
Boolean.TRUE);
Boolean.FALSE);
register(statusValues);
register(pageSize);

View File

@ -10,7 +10,7 @@
objectType="com.arsdigita.cms.contenttypes.SciProject"
classname="com.arsdigita.cms.contenttypes.SciProject">
<ctd:authoring-kit createComponent="com.arsdigita.cms.contenttypes.ui.GenericOrganizationalUnitCreate">
<ctd:authoring-kit createComponent="com.arsdigita.cms.contenttypes.ui.SciProjectCreate">
<ctd:authoring-step
labelKey="sciorganization.ui.project_properties.title"

View File

@ -46,4 +46,12 @@ public class SciProjectBundle extends GenericOrganizationalUnitBundle {
public SciProjectBundle(final String type) {
super(type);
}
public SciProject getProject() {
return (SciProject) getPrimaryInstance();
}
public SciProject getProject(final String language) {
return (SciProject) getInstance(language);
}
}