diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/CompoundContentItemPanel.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/CompoundContentItemPanel.java
index efc28df2b..f7078ed1f 100644
--- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/CompoundContentItemPanel.java
+++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/CompoundContentItemPanel.java
@@ -37,6 +37,7 @@ import com.arsdigita.web.URL;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import java.util.Iterator;
+import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
@@ -61,6 +62,8 @@ public abstract class CompoundContentItemPanel
* Parameter which indicates which page to show
*/
protected StringParameter m_show;
+ private String showDefault;
+ private boolean showOnlyDefault = false;
private static final String PAGE_NUMBER = "pageNumber";
/**
* Parameter for a paginator
@@ -125,7 +128,7 @@ public abstract class CompoundContentItemPanel
if (!context.hasContentItem()) {
return null;
}
- return context.getContentItem();
+ return context.getContentItem().getLiveVersion();
} else {
return m_item;
}
@@ -151,7 +154,7 @@ public abstract class CompoundContentItemPanel
resolved = bundle.getPrimaryInstance();
}
- m_item = resolved;
+ m_item = resolved.getLiveVersion();
} else {
m_item = item;
}
@@ -245,8 +248,28 @@ public abstract class CompoundContentItemPanel
*
* @return Default value for the show parameter.
*/
- protected abstract String getDefaultForShowParam();
+ protected final String getDefaultForShowParam() {
+ if ((showDefault == null) || showDefault.isEmpty()) {
+ return getDefaultShowParam();
+ } else {
+ return showDefault;
+ }
+ }
+
+ public void setDefaultForShowParam(final String showDefault) {
+ this.showDefault = showDefault;
+ }
+
+ protected abstract String getDefaultShowParam();
+ public boolean isShowOnlyDefault() {
+ return showOnlyDefault;
+ }
+
+ public void setShowOnlyDefault(final boolean showOnlyDefault) {
+ this.showOnlyDefault = showOnlyDefault;
+ }
+
protected String getShowParam(final PageState state) {
String show;
try {
@@ -267,6 +290,15 @@ public abstract class CompoundContentItemPanel
return show;
}
+
+ protected String getHttpParam(final String param, final PageState state) {
+ final HttpServletRequest request = state.getRequest();
+ String value;
+
+ value = request.getParameter(param);
+
+ return value;
+ }
protected long getPageNumber(final PageState state) {
int pageNumber = 1;
diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPanel.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPanel.java
index db5d00c67..40746b9b4 100644
--- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPanel.java
+++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPanel.java
@@ -40,15 +40,15 @@ import org.apache.log4j.Logger;
*/
public class GenericOrganizationalUnitPanel extends CompoundContentItemPanel {
- private final static Logger logger = Logger.getLogger(GenericOrganizationalUnit.class);
-
+ private final static Logger logger =
+ Logger.getLogger(GenericOrganizationalUnit.class);
public static final String SHOW_CONTACTS = "contacts";
public static final String SHOW_MEMBERS = "members";
private boolean displayContacts = true;
private boolean displayMembers = true;
@Override
- protected String getDefaultForShowParam() {
+ protected String getDefaultShowParam() {
return SHOW_CONTACTS;
}
@@ -75,7 +75,7 @@ public class GenericOrganizationalUnitPanel extends CompoundContentItemPanel {
protected void generateContactsXML(GenericOrganizationalUnit orga,
Element parent, PageState state) {
- long start = System.currentTimeMillis();
+ long start = System.currentTimeMillis();
GenericOrganizationalUnitContactCollection contacts;
contacts = orga.getContacts();
@@ -97,12 +97,14 @@ public class GenericOrganizationalUnitPanel extends CompoundContentItemPanel {
contact = contacts.getContact();
generateGenericContactXML(contact,
- contactsElem,
- state,
- Integer.toString(contacts.getContactOrder()),
- true);
+ contactsElem,
+ state,
+ Integer.toString(
+ contacts.getContactOrder()),
+ true);
}
- System.out.printf("Generated Contacts XML in %d ms.\n", System.currentTimeMillis() - start);
+ System.out.printf("Generated Contacts XML in %d ms.\n", System.
+ currentTimeMillis() - start);
}
protected void generateMembersXML(GenericOrganizationalUnit orga,
@@ -162,12 +164,12 @@ public class GenericOrganizationalUnitPanel extends CompoundContentItemPanel {
}
}
}
-
+
protected void generateContactXML(final GenericContact contact,
final Element parent,
final PageState state,
final String order,
- final boolean withPerson) {
+ final boolean withPerson) {
Element contactElem = parent.newChildElement("contact");
contactElem.addAttribute("order", order);
@@ -249,43 +251,75 @@ public class GenericOrganizationalUnitPanel extends CompoundContentItemPanel {
}
protected void generateGenericContactXML(final GenericContact contact,
- final Element parent,
- final PageState state,
- final String order,
- final boolean withPerson) {
+ final Element parent,
+ final PageState state,
+ final String order,
+ final boolean withPerson) {
ContactXmlLGenerator generator = new ContactXmlLGenerator(contact);
-
- generator.generateXML(state, parent, order);
+
+ generator.generateXML(state, parent, order);
}
- @Override
- public void generateXML(ContentItem item, Element element,
- PageState state) {
- Element content = generateBaseXML(item, element, state);
-
- Element availableData = content.newChildElement("availableData");
-
- GenericOrganizationalUnit orga = (GenericOrganizationalUnit) item;
-
+ protected void generateAvailableDataXml(final GenericOrganizationalUnit orga,
+ final Element element,
+ final PageState state) {
if ((orga.getContacts() != null)
&& (orga.getContacts().size() > 0)
&& displayMembers) {
- availableData.newChildElement("contacts");
+ element.newChildElement("contacts");
}
if ((orga.getPersons() != null)
&& (orga.getPersons().size() > 0)
&& displayMembers) {
- availableData.newChildElement("members");
+ element.newChildElement("members");
}
+ }
+ protected void generateDataXml(final GenericOrganizationalUnit orga,
+ final Element element,
+ final PageState state) {
String show = getShowParam(state);
if (SHOW_CONTACTS.equals(show)) {
- generateContactsXML(orga, content, state);
+ generateContactsXML(orga, element, state);
} else if (SHOW_MEMBERS.equals(show)) {
- generateMembersXML(orga, content, state);
+ generateMembersXML(orga, element, state);
}
}
+ @Override
+ public void generateXML(ContentItem item,
+ Element element,
+ PageState state) {
+ Element content = generateBaseXML(item, element, state);
+
+ GenericOrganizationalUnit orga = (GenericOrganizationalUnit) item;
+ Element availableData = content.newChildElement("availableData");
+
+ if (!isShowOnlyDefault()) {
+ generateAvailableDataXml(orga, availableData, state);
+ }
+
+ generateDataXml(orga, content, state);
+
+ /*if ((orga.getContacts() != null)
+ && (orga.getContacts().size() > 0)
+ && displayMembers) {
+ availableData.newChildElement("contacts");
+ }
+ if ((orga.getPersons() != null)
+ && (orga.getPersons().size() > 0)
+ && displayMembers) {
+ availableData.newChildElement("members");
+ }
+
+ String show = getShowParam(state);
+ if (SHOW_CONTACTS.equals(show)) {
+ generateContactsXML(orga, content, state);
+ } else if (SHOW_MEMBERS.equals(show)) {
+ generateMembersXML(orga, content, state);
+ }*/
+ }
+
private class ContactXmlLGenerator extends SimpleXMLGenerator {
private GenericContact contact;
diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/CompareFilter.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/CompareFilter.java
new file mode 100644
index 000000000..70b4cb3e5
--- /dev/null
+++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/CompareFilter.java
@@ -0,0 +1,207 @@
+package com.arsdigita.cms.contenttypes.ui.panels;
+
+import com.arsdigita.xml.Element;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The {@code CompareFilter}
+ * filters the object list using a provided value and a operator. Valid
+ * operators defined in the {@link Operators} enumeration.
+ *
+ * @author Jens Pelzetter
+ */
+public class CompareFilter implements Filter {
+
+ private static final String ALL = "--ALL--";
+ private final String property;
+ private final String label;
+ private final boolean allOption;
+ private final boolean allOptionIsDefault;
+ private final boolean propertyIsNumeric;
+ private Map options = new LinkedHashMap();
+ private String value;
+
+ public CompareFilter(final String label,
+ final String property,
+ final boolean allOption,
+ final boolean allOptionIsDefault,
+ final boolean propertyIsNumeric) {
+ this.property = property;
+ this.label = label;
+ this.allOption = allOption;
+ this.allOptionIsDefault = allOptionIsDefault;
+ this.propertyIsNumeric = propertyIsNumeric;
+ }
+
+ @Override
+ public String getProperty() {
+ return property;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ public CompareFilter addOption(final String label, final String value) {
+ return addOption(label, Operators.EQ, value, false);
+ }
+
+ public CompareFilter addOption(final String label,
+ final Operators operator,
+ final String value,
+ final boolean includeNull) {
+ Option option;
+ option = new Option(label, operator, value, includeNull);
+ options.put(label, option);
+ return this;
+ }
+
+ public String getFilter() {
+ Option selectedOption;
+ StringBuffer filter;
+
+ if ((value == null) || value.isEmpty()) {
+ if (allOptionIsDefault) {
+ value = ALL;
+ } else {
+ value =
+ new ArrayList
+ *
+ * {@code property LIKE 'value'}
+ *
+ *
+ * @author Jens Pelzetter
+ */
+public class TextFilter implements Filter {
+
+ private final String property;
+ private final String label;
+ private String value;
+
+ @Override
+ public String getProperty() {
+ return property;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Creates a new text filter.
+ *
+ * @param property The property which is used by this filter.
+ * @param label The label for the input component of the filter.
+ */
+ public TextFilter(final String label, final String property) {
+ this.property = property;
+ this.label = label;
+ }
+
+ @Override
+ public String getFilter() {
+ if ((value == null) || value.isEmpty()) {
+ return null;
+ } else {
+ return String.format("(lower(%s) LIKE lower('%%%s%%'))",
+ property, value);
+ }
+ }
+
+ @Override
+ public void generateXml(final Element parent) {
+ Element textFilter;
+
+ textFilter = parent.newChildElement("filter");
+ textFilter.addAttribute("type", "text");
+
+ textFilter.addAttribute("label", label);
+ if ((value != null) && !(value.isEmpty())) {
+ textFilter.addAttribute("value", value);
+ }
+ }
+
+ @Override
+ public void setValue(final String value) {
+ this.value = value;
+ }
+}
diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/object/CustomizableObjectList.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/object/CustomizableObjectList.java
index cd87dcdfa..4b1b61ff4 100644
--- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/object/CustomizableObjectList.java
+++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/object/CustomizableObjectList.java
@@ -297,7 +297,8 @@ public class CustomizableObjectList extends ComplexObjectList {
sortByKey = new ArrayList(sortFields.keySet()).get(0);
}
- Element controls = content.newChildElement("controls");
+ Element controls = content.newChildElement("filterControls");
+ controls.addAttribute("customName", m_customName);
Element filterElems = controls.newChildElement("filters");
for (Map.Entry filterEntry : filters.entrySet()) {
diff --git a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl
index 66472f5be..5f598e10c 100644
--- a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl
+++ b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl
@@ -58,7 +58,7 @@ query getIdsOfSubDepartmentsOfSciDepartment {
from ct_sciorga_departments_subdepartments_map
where ct_sciorga_departments_subdepartments_map.department_id = :department
} map {
- departmentId = ct_sciorga_departments_subdepartments_map;
+ departmentId = ct_sciorga_departments_subdepartments_map.department_id;
}
}
diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java
index 0c16c977f..a0e2e44a8 100644
--- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java
+++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java
@@ -179,6 +179,7 @@ public class SciOrganization extends GenericOrganizationalUnit {
*
* @param merge Should I also look into the departments and return true
* if the organization or at least one of the departments has members?
+ * @param status
* @return
*/
public boolean hasMembers(final boolean merge, final MemberStatus status) {
@@ -357,7 +358,7 @@ public class SciOrganization extends GenericOrganizationalUnit {
"com.arsdigita.cms.contenttypes.getIdsOfDepartmentsOfSciOrganization");
departmentsQuery.setParameter("organization", getID());
- if (query.size() > 0) {
+ if (departmentsQuery.size() > 0) {
BigDecimal departmentId;
boolean result = false;
while (departmentsQuery.next()) {
@@ -429,7 +430,7 @@ public class SciOrganization extends GenericOrganizationalUnit {
"com.arsdigita.cms.contenttypes.getIdsOfSubDepartmentsOfSciDepartment");
subDepartmentsQuery.setParameter("department", departmentId);
- if (query.size() > 0) {
+ if (subDepartmentsQuery.size() > 0) {
BigDecimal subDepartmentId;
boolean result = false;
while (subDepartmentsQuery.next()) {
diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPanel.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPanel.java
index 3ef6c46bd..d573a6937 100644
--- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPanel.java
+++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPanel.java
@@ -21,6 +21,7 @@ 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.GenericOrganizationalUnitContactCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
@@ -30,12 +31,17 @@ import com.arsdigita.cms.contenttypes.SciDepartmentSubDepartmentsCollection;
import com.arsdigita.cms.contenttypes.SciOrganization;
import com.arsdigita.cms.contenttypes.SciOrganizationConfig;
import com.arsdigita.cms.contenttypes.SciProject;
+import com.arsdigita.cms.contenttypes.ui.panels.Filter;
+import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
import com.arsdigita.xml.Element;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
@@ -54,16 +60,23 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
public static final String SHOW_PROJECTS = "projects";
public static final String SHOW_PROJECTS_ONGOING = "projectsOngoing";
public static final String SHOW_PROJECTS_FINISHED = "projectsFinished";
+ private static final String TITLE = "title";
+ private String show;
private boolean displayDescription = true;
private boolean displaySubDepartments = true;
- private boolean displayProjects = true;
- private boolean displayPublications = true;
-
- @Override
- protected String getDefaultForShowParam() {
- return SHOW_DESCRIPTION;
+ private boolean displayProjects = true;
+ private Map projectFilters =
+ new LinkedHashMap();
+
+ public SciDepartmentPanel() {
+ projectFilters.put(TITLE, new TextFilter(TITLE, TITLE));
}
+ @Override
+ protected String getDefaultShowParam() {
+ return SHOW_DESCRIPTION;
+ }
+
@Override
protected Class extends ContentItem> getAllowedClass() {
return SciDepartment.class;
@@ -84,7 +97,7 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
public void setDisplayProjects(boolean displayProjects) {
this.displayProjects = displayProjects;
}
-
+
public boolean isDisplaySubDepartments() {
return displaySubDepartments;
}
@@ -318,16 +331,45 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
}
}
+ protected void generateProjectFiltersXml(
+ final List projects,
+ final Element element) {
+ final Element filterElement = element.newChildElement("filters");
+
+ for (Map.Entry filterEntry : projectFilters.entrySet()) {
+ filterEntry.getValue().generateXml(filterElement);
+ }
+ }
+
+ protected void applyProjectFilters(
+ final List filters,
+ final HttpServletRequest request) {
+ //Get parameters from HTTP request
+ for (Map.Entry filterEntry : projectFilters.entrySet()) {
+ String value = request.getParameter(
+ filterEntry.getValue().getLabel());
+
+ if ((value != null) && !(value.trim().isEmpty())) {
+ filterEntry.getValue().setValue(value);
+ }
+ }
+ }
+
protected void generateProjectsXML(final SciDepartment department,
final Element parent,
final PageState state,
final List filters) {
+ Element controls = parent.newChildElement("filterControls");
+ controls.addAttribute("customName", "sciDepartmentProjects");
+ controls.addAttribute("show", show);
+
if (SciDepartment.getConfig().getOrganizationProjectsMerge()) {
List projects;
projects = new LinkedList();
SciDepartmentProjectsCollection departmentProjects;
departmentProjects = department.getProjects();
+ applyProjectFilters(filters, state.getRequest());
if ((filters != null)
&& !(filters.isEmpty())) {
for (String filter : filters) {
@@ -358,6 +400,7 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateProjectFiltersXml(projectsWithoutDoubles, controls);
createPaginatorElement(parent,
pageNumber,
pageCount,
@@ -399,6 +442,7 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateProjectFiltersXml(projects, controls);
createPaginatorElement(
parent, pageNumber, pageCount, begin, end, count, projects.
size());
@@ -412,11 +456,14 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
}
}
- protected void generateAvailableDataXml(final SciDepartment department,
+ @Override
+ protected void generateAvailableDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
final SciOrganizationConfig config = SciOrganization.getConfig();
+ SciDepartment department = (SciDepartment) orga;
+
if ((department.getDepartmentDescription() != null)
&& !department.getDepartmentDescription().isEmpty()
&& displayDescription) {
@@ -466,10 +513,13 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
}
}
- protected void generateDataXml(SciDepartment department,
+ @Override
+ protected void generateDataXml(GenericOrganizationalUnit orga,
Element element,
PageState state) {
- String show = getShowParam(state);
+ show = getShowParam(state);
+
+ SciDepartment department = (SciDepartment) orga;
if (SHOW_DESCRIPTION.equals(show)) {
String desc;
@@ -505,18 +555,18 @@ public class SciDepartmentPanel extends SciOrganizationBasePanel {
}
}
- @Override
+ /*@Override
public void generateXML(ContentItem item,
- Element element,
- PageState state) {
- Element content = generateBaseXML(item, element, state);
-
- Element availableData = content.newChildElement("availableData");
-
- SciDepartment department = (SciDepartment) item;
-
- generateAvailableDataXml(department, availableData, state);
-
- generateDataXml(department, content, state);
- }
+ Element element,
+ PageState state) {
+ Element content = generateBaseXML(item, element, state);
+
+ Element availableData = content.newChildElement("availableData");
+
+ SciDepartment department = (SciDepartment) item;
+
+ generateAvailableDataXml(department, availableData, state);
+
+ generateDataXml(department, content, state);
+ }*/
}
diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPanel.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPanel.java
index 0fb3a6c8c..b774832fe 100644
--- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPanel.java
+++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPanel.java
@@ -21,6 +21,7 @@ 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.GenericOrganizationalUnitContactCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
@@ -32,12 +33,17 @@ import com.arsdigita.cms.contenttypes.SciOrganizationConfig;
import com.arsdigita.cms.contenttypes.SciOrganizationDepartmentsCollection;
import com.arsdigita.cms.contenttypes.SciOrganizationProjectsCollection;
import com.arsdigita.cms.contenttypes.SciProject;
+import com.arsdigita.cms.contenttypes.ui.panels.Filter;
+import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
import com.arsdigita.xml.Element;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
@@ -57,17 +63,24 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
public static final String SHOW_DEPARTMENTS = "departments";
public static final String SHOW_PROJECTS = "projects";
public static final String SHOW_PROJECTS_ONGOING = "projectsOngoing";
- public static final String SHOW_PROJECTS_FINISHED = "projectsFinished";
+ public static final String SHOW_PROJECTS_FINISHED = "projectsFinished";
+ private static final String TTILE = "title";
+ private String show;
private boolean displayDescription = true;
private boolean displayDepartments = true;
private boolean displayProjects = true;
- //private boolean displayPublications = true;
+ private final Map projectFilters =
+ new LinkedHashMap();
- @Override
- protected String getDefaultForShowParam() {
- return SHOW_DESCRIPTION;
+ public SciOrganizationPanel() {
+ projectFilters.put(TTILE, new TextFilter(TTILE, TTILE));
}
+ @Override
+ protected String getDefaultShowParam() {
+ return SHOW_DESCRIPTION;
+ }
+
@Override
protected Class extends ContentItem> getAllowedClass() {
return SciOrganization.class;
@@ -298,7 +311,8 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
protected void mergeProjects(
final SciOrganizationDepartmentsCollection departments,
final List projects,
- final List filters) {
+ final List filters,
+ final PageState state) {
while (departments.next()) {
SciDepartmentProjectsCollection departmentProjects;
@@ -329,12 +343,17 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
final Element parent,
final PageState state,
final List filters) {
+ Element controls = parent.newChildElement("filterControls");
+ controls.addAttribute("customName", "sciOrganizationProjects");
+ controls.addAttribute("show", show);
+
if (SciOrganization.getConfig().getOrganizationProjectsMerge()) {
List projects;
projects = new LinkedList();
SciOrganizationProjectsCollection orgaProjects;
orgaProjects = orga.getProjects();
+ applyProjectFilters(filters, state.getRequest());
if ((filters != null)
&& !(filters.isEmpty())) {
for (String filter : filters) {
@@ -349,7 +368,7 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
projects.add(orgaProjects.getProject());
}
- mergeProjects(departments, projects, filters);
+ mergeProjects(departments, projects, filters, state);
Set projectsSet;
List projectsWithoutDoubles;
@@ -365,6 +384,7 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateProjectFiltersXml(projectsWithoutDoubles, controls);
createPaginatorElement(
parent, pageNumber, pageCount, begin, end, count,
projectsWithoutDoubles.size());
@@ -381,6 +401,7 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
SciOrganizationProjectsCollection orgaProjects;
orgaProjects = orga.getProjects();
+ applyProjectFilters(filters, state.getRequest());
if ((filters != null)
&& !(filters.isEmpty())) {
for (String filter : filters) {
@@ -403,6 +424,7 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateProjectFiltersXml(projects, controls);
createPaginatorElement(
parent, pageNumber, pageCount, begin, end, count, projects.
size());
@@ -416,12 +438,57 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
}
}
- protected void generateAvailableDataXml(final SciOrganization organization,
+ protected void generateProjectFiltersXml(
+ final List projects,
+ final Element element) {
+ final Element filterElement = element.newChildElement("filters");
+
+ for (Map.Entry filterEntry : projectFilters.entrySet()) {
+ filterEntry.getValue().generateXml(filterElement);
+ }
+ }
+
+ protected void applyProjectFilters(
+ final List filters,
+ final HttpServletRequest request) {
+ //Get parameters from HTTP request
+ for (Map.Entry filterEntry : projectFilters.entrySet()) {
+ String value = request.getParameter(
+ filterEntry.getValue().getLabel());
+
+ if ((value != null) && !(value.trim().isEmpty())) {
+ filterEntry.getValue().setValue(value);
+ }
+ }
+
+ //Apply filters to DomainCollection
+ final StringBuilder filterBuilder = new StringBuilder();
+ for (Map.Entry filterEntry : projectFilters.entrySet()) {
+ if ((filterEntry.getValue().getFilter() == null)
+ || (filterEntry.getValue().getFilter().isEmpty())) {
+ continue;
+ }
+
+ if (filterBuilder.length() > 0) {
+ filterBuilder.append(" AND ");
+ }
+ filterBuilder.append(filterEntry.getValue().getFilter());
+ s_log.debug(String.format("filters: %s", filterBuilder));
+ if (filterBuilder.length() > 0) {
+ filters.add(filterBuilder.toString());
+ }
+ }
+ }
+
+ @Override
+ protected void generateAvailableDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
SciOrganizationConfig config;
config = SciOrganization.getConfig();
+ SciOrganization organization = (SciOrganization) orga;
+
if ((organization.getOrganizationDescription() != null)
&& !(organization.getOrganizationDescription().isEmpty())
&& displayDescription) {
@@ -471,10 +538,13 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
}
}
- protected void generateDataXml(SciOrganization organization,
- Element element,
- PageState state) {
- String show = getShowParam(state);
+ @Override
+ protected void generateDataXml(final GenericOrganizationalUnit orga,
+ final Element element,
+ final PageState state) {
+ show = getShowParam(state);
+
+ SciOrganization organization = (SciOrganization) orga;
if (SHOW_DESCRIPTION.equals(show)) {
String desc;
@@ -511,17 +581,17 @@ public class SciOrganizationPanel extends SciOrganizationBasePanel {
}
}
- @Override
+ /*@Override
public void generateXML(ContentItem item,
- Element element,
- PageState state) {
- Element content = generateBaseXML(item, element, state);
-
- SciOrganization orga = (SciOrganization) item;
- Element availableData = content.newChildElement("availableData");
-
- generateAvailableDataXml(orga, availableData, state);
-
- generateDataXml(orga, content, state);
- }
+ Element element,
+ PageState state) {
+ Element content = generateBaseXML(item, element, state);
+
+ SciOrganization orga = (SciOrganization) item;
+ Element availableData = content.newChildElement("availableData");
+
+ generateAvailableDataXml(orga, availableData, state);
+
+ generateDataXml(orga, content, state);
+ }*/
}
diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPanel.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPanel.java
index 959562b0d..248485405 100644
--- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPanel.java
+++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPanel.java
@@ -21,6 +21,7 @@ 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.SciOrganizationConfig;
import com.arsdigita.cms.contenttypes.SciProject;
@@ -46,7 +47,7 @@ public class SciProjectPanel extends SciOrganizationBasePanel {
private boolean displayPublications = true;
@Override
- protected String getDefaultForShowParam() {
+ protected String getDefaultShowParam() {
return SHOW_DESCRIPTION;
}
@@ -189,11 +190,14 @@ public class SciProjectPanel extends SciOrganizationBasePanel {
generateMembersListXML(members, parent, state);
}
- protected void generateAvailableDataXml(final SciProject project,
+ @Override
+ protected void generateAvailableDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
SciOrganizationConfig config = SciProject.getConfig();
+
+ SciProject project = (SciProject) orga;
if ((project.getProjectDescription() != null)
&& !project.getProjectDescription().isEmpty()
@@ -229,11 +233,14 @@ public class SciProjectPanel extends SciOrganizationBasePanel {
}
}
- protected void generateDataXml(final SciProject project,
+ @Override
+ protected void generateDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
String show = getShowParam(state);
+
+ SciProject project = (SciProject) orga;
if (SHOW_DESCRIPTION.equals(show)) {
Element description = element.newChildElement("description");
@@ -257,7 +264,7 @@ public class SciProjectPanel extends SciOrganizationBasePanel {
}
}
- @Override
+ /*@Override
public void generateXML(ContentItem item,
Element element,
PageState state) {
@@ -271,5 +278,5 @@ public class SciProjectPanel extends SciOrganizationBasePanel {
generateDataXml(project, element, state);
- }
+ }*/
}
diff --git a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciDepartmentWithPublications.pdl b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciDepartmentWithPublications.pdl
index 241a0c22b..3c29d70bc 100644
--- a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciDepartmentWithPublications.pdl
+++ b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciDepartmentWithPublications.pdl
@@ -31,4 +31,18 @@ query getIdsOfPublicationsOfSciDepartment {
} map {
publicationId = ct_department_publication_map.publication_id;
}
+}
+
+query getIdsOfWorkingPapersOfSciDepartment {
+ BigDecimal workingPaperId;
+ String objectType;
+
+ do {
+ select ct_department_publication_map.publication_id, acs_objects.object_type
+ from ct_department_publication_map join acs_objects on ct_department_publication_map.publication_id = acs_objects.object_id
+ where ct_department_publication_map.department_id = :department and acs_objects.object_type = 'com.arsdigita.cms.contenttypes.WorkingPaper'
+ } map {
+ workingPaperId = ct_department_publication_map.publication_id;
+ objectType = acs_objects.object_type;
+ }
}
\ No newline at end of file
diff --git a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciOrganizationWithPublications.pdl b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciOrganizationWithPublications.pdl
index 72385f50b..0332fad7b 100644
--- a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciOrganizationWithPublications.pdl
+++ b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciOrganizationWithPublications.pdl
@@ -23,12 +23,40 @@ association {
query getIdsOfPublicationsOfSciOrganization {
BigDecimal publicationId;
+ String objectType;
do {
- select ct_organization_publication_map.publication_id
- from ct_organization_publication_map
+ select ct_organization_publication_map.publication_id, acs_objects.object_type
+ from ct_organization_publication_map join acs_objects on ct_organization_publication_map.publication_id = acs_objects.object_id
where ct_organization_publication_map.organization_id = :organization
} map {
publicationId = ct_organization_publication_map.publication_id;
+ objectType = acs_objects.object_type;
}
-}
\ No newline at end of file
+}
+
+query getIdsOfWorkingPapersOfSciOrganization {
+ BigDecimal workingPaperId;
+ String objectType;
+
+ do {
+ select ct_organization_publication_map.publication_id, acs_objects.object_type
+ from ct_organization_publication_map join acs_objects on ct_organization_publication_map.publication_id = acs_objects.object_id
+ where ct_organization_publication_map.organization_id = :organization and acs_objects.object_type = 'com.arsdigita.cms.contenttypes.WorkingPaper'
+ } map {
+ workingPaperId = ct_organization_publication_map.publication_id;
+ objectType = acs_objects.object_type;
+ }
+}
+
+query getAllYearsOfPublication {
+ Integer yearOfPublication;
+
+ do {
+ select distinct ct_publications.year
+ from ct_publications
+ } map {
+ yearOfPublication = ct_publications.year;
+ }
+}
+
diff --git a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciProjectWithPublications.pdl b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciProjectWithPublications.pdl
index 0f7230d8b..82fac65a6 100644
--- a/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciProjectWithPublications.pdl
+++ b/ccm-sci-types-organizationwithpublications/pdl/com/arsdigita/content-types/SciProjectWithPublications.pdl
@@ -34,3 +34,17 @@ query getIdsOfPublicationsOfSciProject {
publicationId = ct_project_publication_map.publication_id;
}
}
+
+query getIdsOfWorkingPapersOfSciProject {
+ BigDecimal workingPaperId;
+ String objectType;
+
+ do {
+ select ct_project_publication_map.publication_id, acs_objects.object_type
+ from ct_project_publication_map join acs_objects on ct_project_publication_map.publication_id = acs_objects.object_id
+ where ct_project_publication_map.project_id = :project and acs_objects.object_type = 'com.arsdigita.cms.contenttypes.WorkingPaper'
+ } map {
+ workingPaperId = ct_project_publication_map.publication_id;
+ objectType = acs_objects.object_type;
+ }
+}
\ No newline at end of file
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciDepartmentWithPublications.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciDepartmentWithPublications.java
index bca77d447..f10f1cfc5 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciDepartmentWithPublications.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciDepartmentWithPublications.java
@@ -61,7 +61,7 @@ public class SciDepartmentWithPublications extends SciDepartment {
public boolean hasPublications(final boolean merge) {
DataQuery query =
SessionManager.getSession().retrieveQuery(
- "com.arsdigita.cms.contentassets.getIdsOfPublicationsOfSciDepartment");
+ "com.arsdigita.cms.contenttypes.getIdsOfPublicationsOfSciDepartment");
query.setParameter("department", getID());
if (query.size() > 0) {
@@ -105,8 +105,8 @@ public class SciDepartmentWithPublications extends SciDepartment {
final boolean merge) {
DataQuery query =
SessionManager.getSession().retrieveQuery(
- "com.arsdigita.cms.contentassets.getIdsOfPublicationsOfSciDepartment");
- query.setParameter("departmentId", departmentId);
+ "com.arsdigita.cms.contenttypes.getIdsOfPublicationsOfSciDepartment");
+ query.setParameter("department", departmentId);
if (query.size() > 0) {
query.close();
@@ -119,7 +119,94 @@ public class SciDepartmentWithPublications extends SciDepartment {
"com.arsdigita.cms.contenttypes.getIdsOfSubDepartmentsOfSciDepartment");
subDepartmentsQuery.setParameter("department", departmentId);
- if (query.size() > 0) {
+ if (subDepartmentsQuery.size() > 0) {
+ BigDecimal subDepartmentId;
+ boolean result = false;
+ while (subDepartmentsQuery.next()) {
+ subDepartmentId = (BigDecimal) subDepartmentsQuery.get(
+ "departmentId");
+ result = hasPublications(subDepartmentId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ subDepartmentsQuery.close();
+ return result;
+ } else {
+ subDepartmentsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ public boolean hasWorkingPapers(final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfWorkingPapersOfSciDepartment");
+ query.setParameter("department", getID());
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+ DataQuery departmentsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubDepartmentsOfSciDepartment");
+ departmentsQuery.setParameter("department", getID());
+
+ if (departmentsQuery.size() > 0) {
+ BigDecimal departmentId;
+ boolean result = false;
+ while (departmentsQuery.next()) {
+ departmentId = (BigDecimal) departmentsQuery.get(
+ "departmentId");
+ result = hasWorkingPapers(departmentId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ departmentsQuery.close();
+ return result;
+ } else {
+ departmentsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ private boolean hasWorkingPapers(final BigDecimal departmentId,
+ final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfWorkingPapersOfSciDepartment");
+ query.setParameter("department", departmentId);
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+ DataQuery subDepartmentsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubDepartmentsOfSciDepartment");
+ subDepartmentsQuery.setParameter("department", departmentId);
+
+ if (subDepartmentsQuery.size() > 0) {
BigDecimal subDepartmentId;
boolean result = false;
while (subDepartmentsQuery.next()) {
@@ -149,18 +236,19 @@ public class SciDepartmentWithPublications extends SciDepartment {
return new SciDepartmentPublicationsCollection((DataCollection) get(
PUBLICATIONS));
}
-
+
public void addPublication(final Publication publication) {
Assert.exists(publication, Publication.class);
-
+
DataObject link = add(PUBLICATIONS, publication);
- link.set("publicationOrder", Integer.valueOf((int) getPublications().size()));
+ link.set("publicationOrder", Integer.valueOf((int) getPublications().
+ size()));
link.save();
}
-
+
public void removePublication(final Publication publication) {
Assert.exists(publication, Publication.class);
-
+
remove(PUBLICATIONS, publication);
}
}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublications.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublications.java
index b0004fe5e..c9d7c1e5a 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublications.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublications.java
@@ -73,6 +73,10 @@ public class SciOrganizationWithPublications extends SciOrganization {
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfPublicationsOfSciOrganization");
query.setParameter("organization", getID());
+ if (getConfig().getOrganizationPublicationsSeparateWorkingPapers()) {
+ query.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
if (query.size() > 0) {
query.close();
@@ -118,6 +122,103 @@ public class SciOrganizationWithPublications extends SciOrganization {
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contentassets.getIdsOfPublicationsOfSciOrganization");
query.setParameter("organization", departmentId);
+ if (getConfig().getOrganizationPublicationsSeparateWorkingPapers()) {
+ query.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+ DataQuery subDepartmentsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubDepartmentsOfSciDepartment");
+ subDepartmentsQuery.setParameter("department", departmentId);
+
+ if (subDepartmentsQuery.size() > 0) {
+ BigDecimal subDepartmentId;
+ boolean result = false;
+ while (subDepartmentsQuery.next()) {
+ subDepartmentId = (BigDecimal) subDepartmentsQuery.get(
+ "departmentId");
+ result = hasPublications(subDepartmentId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ subDepartmentsQuery.close();
+ return result;
+ } else {
+ subDepartmentsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ public boolean hasWorkingPapers(final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfWorkingPapersOfSciOrganization");
+ query.setParameter("organization", getID());
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+
+ DataQuery departmentsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfDepartmentsOfSciOrganization");
+ departmentsQuery.setParameter("organization",
+ getID());
+
+ if (departmentsQuery.size() > 0) {
+ BigDecimal departmentId;
+ boolean result = false;
+ while (departmentsQuery.next()) {
+ departmentId = (BigDecimal) departmentsQuery.get(
+ "departmentId");
+ result = hasWorkingPapers(departmentId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ departmentsQuery.close();
+ return result;
+ } else {
+ departmentsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ private boolean hasWorkingPapers(final BigDecimal departmentId,
+ final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contentassets.getIdsOfWorkingPapersOfSciOrganization");
+ query.setParameter("organization", departmentId);
+ if (getConfig().getOrganizationPublicationsSeparateWorkingPapers()) {
+ query.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
if (query.size() > 0) {
query.close();
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig.java
index c57af47bb..f9697ba61 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig.java
@@ -10,6 +10,9 @@ import com.arsdigita.util.parameter.Parameter;
public class SciOrganizationWithPublicationsConfig extends SciOrganizationConfig {
private final Parameter m_organizationPublicationsMerge;
+ private final Parameter m_organizationPublicationsSeparateWorkingPapers;
+ private final Parameter m_departmentPublicationsSeparateWorkingPapers;
+ private final Parameter m_projectPublicationsSeparateWorkingPapers;
public SciOrganizationWithPublicationsConfig() {
super();
@@ -17,15 +20,48 @@ public class SciOrganizationWithPublicationsConfig extends SciOrganizationConfig
m_organizationPublicationsMerge =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.sciorganization.publications_merge",
- Parameter.REQUIRED,
- Boolean.TRUE);
-
+ Parameter.REQUIRED,
+ Boolean.TRUE);
register(m_organizationPublicationsMerge);
-
+
+ m_organizationPublicationsSeparateWorkingPapers =
+ new BooleanParameter(
+ "com.arsdigita.cms.contenttypes.sciorganization..organization.workingpapers_separate",
+ Parameter.REQUIRED,
+ Boolean.TRUE);
+ register(m_organizationPublicationsSeparateWorkingPapers);
+
+ m_departmentPublicationsSeparateWorkingPapers =
+ new BooleanParameter(
+ "com.arsdigita.cms.contenttypes.sciorganization.department.workingpapers_separate",
+ Parameter.REQUIRED,
+ Boolean.TRUE);
+ register(m_departmentPublicationsSeparateWorkingPapers);
+
+ m_projectPublicationsSeparateWorkingPapers =
+ new BooleanParameter(
+ "com.arsdigita.cms.contenttypes.sciorganization.project.workingpapers_separate",
+ Parameter.REQUIRED,
+ Boolean.FALSE);
+ register(m_projectPublicationsSeparateWorkingPapers);
+
loadInfo();
}
-
+
public final boolean getOrganizationPublicationsMerge() {
return (Boolean) get(m_organizationPublicationsMerge);
}
+
+ public final boolean getOrganizationPublicationsSeparateWorkingPapers() {
+ return (Boolean) get(m_organizationPublicationsSeparateWorkingPapers);
+ }
+
+ public final boolean getDepartmentPublicationsSeparateWorkingPapers() {
+ return (Boolean) get(m_departmentPublicationsSeparateWorkingPapers);
+ }
+
+ public final boolean getProjectPublicationsSeparateWorkingPapers() {
+ return (Boolean) get(m_projectPublicationsSeparateWorkingPapers);
+ }
+
}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig_parameter.properties b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig_parameter.properties
index 353689341..48a0c0353 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig_parameter.properties
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciOrganizationWithPublicationsConfig_parameter.properties
@@ -3,4 +3,18 @@ com.arsdigita.cms.contenttypes.sciorganization.publications_merge.purpose = Merg
com.arsdigita.cms.contenttypes.sciorganization.publications_merge.example = true
com.arsdigita.cms.contenttypes.sciorganization.publications_merge.format = [boolean]
+com.arsdigita.cms.contenttypes.sciorganization.organization.workingpapers_separate.title = Separate working papers of SciOrganization
+com.arsdigita.cms.contenttypes.sciorganization.organization.workingpapers_separate.purpose = Show a separate panel for the working papers on SciOrganizationWithPublicationsPanel
+com.arsdigita.cms.contenttypes.sciorganization.organization.workingpapers_separate.example = true
+com.arsdigita.cms.contenttypes.sciorganization.organization.workingpapers_separate.format [boolean]
+
+com.arsdigita.cms.contenttypes.scidepartment.department.workingpapers_separate.title = Separate working papers of SciDepartment
+com.arsdigita.cms.contenttypes.scidepartment.department.workingpapers_separate.purpose = Show a separate panel for the working papers on SciDepartmentWithPublicationsPanel
+com.arsdigita.cms.contenttypes.scidepartment.department.workingpapers_separate.example = true
+com.arsdigita.cms.contenttypes.scidepartment.department.workingpapers_separate.format [boolean]
+
+com.arsdigita.cms.contenttypes.sciproject.project.workingpapers_separate.title = Separate working papers of SciProject
+com.arsdigita.cms.contenttypes.sciproject.project.workingpapers_separate.purpose = Show a separate panel for the working papers on SciProjectWithPublicationsPanel
+com.arsdigita.cms.contenttypes.sciproject.project.workingpapers_separate.example = false
+com.arsdigita.cms.contenttypes.sciproject.project.workingpapers_separate.format [boolean]
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciProjectWithPublications.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciProjectWithPublications.java
index f3c7a83f7..bfb1e3fc0 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciProjectWithPublications.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciProjectWithPublications.java
@@ -60,8 +60,8 @@ public class SciProjectWithPublications extends SciProject {
public boolean hasPublications(final boolean merge) {
DataQuery query =
SessionManager.getSession().retrieveQuery(
- "com.arsdigita.cms.contentassets.getIdsOfPublicationsOfSciProject");
- query.setParameter("organization", getID());
+ "com.arsdigita.cms.contenttypes.getIdsOfPublicationsOfSciProject");
+ query.setParameter("project", getID());
if (query.size() > 0) {
query.close();
@@ -104,7 +104,94 @@ public class SciProjectWithPublications extends SciProject {
final boolean merge) {
DataQuery query =
SessionManager.getSession().retrieveQuery(
- "com.arsdigita.cms.contentassets.getIdsOfPublicationsOfSciProject");
+ "com.arsdigita.cms.contenttypes.getIdsOfPublicationsOfSciProject");
+ query.setParameter("project", projectId);
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+ DataQuery subProjectsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubProjectsOfSciProject");
+ subProjectsQuery.setParameter("project", projectId);
+
+ if (subProjectsQuery.size() > 0) {
+ BigDecimal subProjectId;
+ boolean result = false;
+ while (subProjectsQuery.next()) {
+ subProjectId = (BigDecimal) subProjectsQuery.get(
+ "projectId");
+ result = hasPublications(subProjectId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ subProjectsQuery.close();
+ return result;
+ } else {
+ subProjectsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ public boolean hasWorkingPapers(final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfWorkingPapersOfSciProject");
+ query.setParameter("project", getID());
+
+ if (query.size() > 0) {
+ query.close();
+ return true;
+ } else {
+ if (merge) {
+ query.close();
+ DataQuery subProjectsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubProjectsOfSciProject");
+ subProjectsQuery.setParameter("project", getID());
+
+ if (subProjectsQuery.size() > 0) {
+ BigDecimal subProjectId;
+ boolean result = false;
+ while (subProjectsQuery.next()) {
+ subProjectId = (BigDecimal) subProjectsQuery.get(
+ "projectId");
+ result = hasPublications(subProjectId, merge);
+
+ if (result) {
+ break;
+ }
+ }
+
+ subProjectsQuery.close();
+ return result;
+ } else {
+ subProjectsQuery.close();
+ return false;
+ }
+ } else {
+ query.close();
+ return false;
+ }
+ }
+ }
+
+ private boolean hasWorkingPapers(final BigDecimal projectId,
+ final boolean merge) {
+ DataQuery query =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfWorkingPapersOfSciProject");
query.setParameter("projectId", projectId);
if (query.size() > 0) {
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationAuthorComparator.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationAuthorComparator.java
new file mode 100644
index 000000000..de1d562a8
--- /dev/null
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationAuthorComparator.java
@@ -0,0 +1,58 @@
+package com.arsdigita.cms.contenttypes;
+
+import com.arsdigita.persistence.DataQuery;
+import com.arsdigita.persistence.SessionManager;
+import java.math.BigDecimal;
+import java.util.Comparator;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class SciPublicationAuthorComparator implements Comparator {
+
+ private Logger logger = Logger.getLogger(
+ SciPublicationAuthorComparator.class);
+
+ public int compare(Publication publication1, Publication publication2) {
+ if ((publication1.getAuthors() == null)
+ || publication1.getAuthors().size() == 0) {
+ logger.debug("publication1 has no authors, returning -1");
+ return -1;
+ } else if ((publication2.getAuthors() == null)
+ || publication2.getAuthors().size() == 0) {
+ logger.debug("publication2 has no authors, returning ");
+ return 1;
+ } else {
+ logger.debug("Both publication have authors, comparing authors...");
+ int ret = 0;
+
+ AuthorshipCollection authors1 = publication1.getAuthors();
+ AuthorshipCollection authors2 = publication2.getAuthors();
+
+ while ((ret == 0) && authors1.next() && authors2.next()) {
+ GenericPerson author1 = authors1.getAuthor();
+ GenericPerson author2 = authors2.getAuthor();
+ logger.debug(String.format(
+ "Comparing surnames: author1.surname = '%s'; author2.surname = '%s'",
+ author1.getSurname(),
+ author2.getSurname()));
+ ret = author1.getSurname().compareTo(author2.getSurname());
+
+ if (ret == 0) {
+ logger.debug(String.format(
+ "Surnames are identical, comparing given names:"
+ + "author1.givenName = '%s'; author2.givenName = '%s'",
+ author1.getGivenName(),
+ author2.getGivenName()));
+ ret = author1.getGivenName().compareTo(
+ author2.getGivenName());
+ }
+ logger.debug(String.format("ret = %d", ret));
+ }
+
+ return ret;
+ }
+ }
+}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationTitleComparator.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationTitleComparator.java
index 80a0ff30a..1c61571c5 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationTitleComparator.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationTitleComparator.java
@@ -37,7 +37,7 @@ public class SciPublicationTitleComparator implements Comparator {
- return title1.compareTo(title2);
+ return title1.compareToIgnoreCase(title2);
//return publication1.getTitle().compareTo(publication2.getTitle());
}
}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearAscComparator.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearAscComparator.java
new file mode 100644
index 000000000..89d844079
--- /dev/null
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearAscComparator.java
@@ -0,0 +1,30 @@
+package com.arsdigita.cms.contenttypes;
+
+import java.util.Comparator;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class SciPublicationYearAscComparator implements Comparator {
+
+ public int compare(Publication publication1, Publication publication2) {
+ if (publication1.getYearOfPublication() == null) {
+ return -1;
+ } else if (publication2.getYearOfPublication() == null) {
+ return 1;
+ } else {
+ int ret = publication1.getYearOfPublication().compareTo(publication2.
+ getYearOfPublication());
+
+ if (ret == 0) {
+ SciPublicationTitleComparator titleComparator =
+ new SciPublicationTitleComparator();
+ ret = titleComparator.compare(publication1, publication2);
+ }
+
+ return ret;
+ }
+
+ }
+}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearDescComparator.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearDescComparator.java
new file mode 100644
index 000000000..5ee87a4a5
--- /dev/null
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/SciPublicationYearDescComparator.java
@@ -0,0 +1,28 @@
+package com.arsdigita.cms.contenttypes;
+
+import java.util.Comparator;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class SciPublicationYearDescComparator implements Comparator {
+
+ public int compare(Publication publication1, Publication publication2) {
+ if (publication1.getYearOfPublication() == null) {
+ return 1;
+ } else if (publication2.getYearOfPublication() == null) {
+ return -1;
+ } else {
+ int ret = publication2.getYearOfPublication().compareTo(publication1.
+ getYearOfPublication());
+ if (ret == 0) {
+ SciPublicationTitleComparator titleComparator = new SciPublicationTitleComparator();
+ ret = titleComparator.compare(publication1, publication2);
+ }
+
+ return ret;
+ }
+
+ }
+}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/PublicationXmlHelper.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/PublicationXmlHelper.java
index e23f0ff21..425783512 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/PublicationXmlHelper.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/PublicationXmlHelper.java
@@ -139,10 +139,14 @@ public class PublicationXmlHelper {
}
private void generatePublicationXml(final Element publicationElem) {
+ publicationElem.addAttribute("oid", publication.getOID().toString());
+ publicationElem.addAttribute("version", publication.getVersion());
generateXmlElement(publicationElem, "title", publication.getTitle());
- Element yearElem = publicationElem.newChildElement(
- "yearOfPublication");
- yearElem.setText(publication.getYearOfPublication().toString());
+ if (publication.getYearOfPublication() != null) {
+ Element yearElem = publicationElem.newChildElement(
+ "yearOfPublication");
+ yearElem.setText(publication.getYearOfPublication().toString());
+ }
generateXmlElement(publicationElem,
"yearOfPublication",
publication.getYearOfPublication());
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentWithPublicationsPanel.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentWithPublicationsPanel.java
index f9086a97c..4bcdf4bae 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentWithPublicationsPanel.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentWithPublicationsPanel.java
@@ -20,7 +20,8 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.cms.ContentItemXMLRenderer;
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.SciDepartmentPublicationsCollection;
@@ -29,13 +30,26 @@ import com.arsdigita.cms.contenttypes.SciDepartmentWithPublications;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublications;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublicationsConfig;
import com.arsdigita.cms.contenttypes.SciPublicationTitleComparator;
-import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
+import com.arsdigita.cms.contenttypes.SciPublicationYearAscComparator;
+import com.arsdigita.cms.contenttypes.SciPublicationYearDescComparator;
+import com.arsdigita.cms.contenttypes.ui.panels.Filter;
+import com.arsdigita.cms.contenttypes.ui.panels.SelectFilter;
+import com.arsdigita.cms.contenttypes.ui.panels.SortField;
+import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
+import com.arsdigita.domain.DomainCollection;
+import com.arsdigita.persistence.DataQuery;
+import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.log4j.Logger;
/**
*
@@ -43,8 +57,62 @@ import java.util.Set;
*/
public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
+ private static final Logger logger =
+ Logger.getLogger(
+ SciDepartmentWithPublicationsPanel.class);
public static final String SHOW_PUBLICATIONS = "publications";
+ public static final String SHOW_WORKING_PAPERS = "workingPapers";
+ private static final String SORT = "sort";
+ private static final String TITLE = "title";
+ private static final String AUTHORS = "authors";
+ private static final String YEAR_OF_PUBLICATION = "yearOfPublication";
+ private static final String YEAR_ASC = "yearAsc";
+ private static final String YEAR_DESC = "yearAsc";
+ private String show;
private boolean displayPublications = true;
+ private boolean displayWorkingPapers = true;
+ private final Map filters =
+ new LinkedHashMap();
+ private final Map> sortFields =
+ new LinkedHashMap>();
+ private String sortByKey;
+
+ public SciDepartmentWithPublicationsPanel() {
+ filters.put(TITLE, new TextFilter(TITLE, TITLE));
+ filters.put(AUTHORS, new TextFilter(AUTHORS, "authors.surname"));
+ SelectFilter yearFilter = new SelectFilter(YEAR_OF_PUBLICATION,
+ YEAR_OF_PUBLICATION,
+ true,
+ true,
+ true,
+ true);
+ DataQuery query = SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getAllYearsOfPublication");
+ yearFilter.setDataQuery(query, "yearOfPublication");
+ filters.put(YEAR_OF_PUBLICATION, yearFilter);
+ sortFields.put(TITLE,
+ new SortField(TITLE,
+ new SciPublicationTitleComparator()));
+ sortFields.put(YEAR_ASC,
+ new SortField(YEAR_ASC,
+ new SciPublicationYearAscComparator()));
+ sortFields.put(YEAR_DESC,
+ new SortField(YEAR_DESC,
+ new SciPublicationYearDescComparator()));
+ /*sortFields.put(AUTHORS,
+ new SortField(AUTHORS,
+ new SciPublicationAuthorComparator()));*/
+ }
+
+ @Override
+ public Class extends ContentItem> getAllowedClass() {
+ return SciDepartmentWithPublications.class;
+ }
+
+ @Override
+ protected String getPanelName() {
+ return SciDepartment.class.getSimpleName();
+ }
public boolean isDisplayPublications() {
return displayPublications;
@@ -54,10 +122,20 @@ public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
this.displayPublications = displayPublications;
}
+ public boolean isDisplayWorkingPapers() {
+ return displayWorkingPapers;
+ }
+
+ public void setDisplayWorkingPapers(final boolean displayWorkingPapers) {
+ this.displayWorkingPapers = displayWorkingPapers;
+ }
+
@Override
- protected void generateAvailableDataXml(final SciDepartment department,
+ protected void generateAvailableDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
+ SciDepartment department = (SciDepartment) orga;
+
super.generateAvailableDataXml(department, element, state);
SciOrganizationWithPublicationsConfig config =
@@ -72,65 +150,169 @@ public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
&& displayPublications) {
element.newChildElement("publications");
}
+ if ((dep.hasWorkingPapers(config.getOrganizationPublicationsMerge())
+ && displayWorkingPapers
+ && config.getDepartmentPublicationsSeparateWorkingPapers())) {
+ element.newChildElement("workingPapers");
+ }
}
protected void mergePublications(
final SciDepartmentSubDepartmentsCollection subDepartments,
- final List publications) {
+ final List publications,
+ final boolean workingPapersOnly,
+ final PageState state) {
while (subDepartments.next()) {
SciDepartment dep;
SciDepartmentWithPublications department;
SciDepartmentPublicationsCollection departmentPublications;
dep = subDepartments.getSubDepartment();
+ if (!(dep instanceof SciDepartmentWithPublications)) {
+ continue;
+ }
department = (SciDepartmentWithPublications) dep;
departmentPublications = department.getPublications();
+ applyFilters(departmentPublications, state.getRequest());
+ if (workingPapersOnly) {
+ departmentPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getDepartmentPublicationsSeparateWorkingPapers()) {
+ departmentPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+
+ if (publications instanceof ArrayList) {
+ ((ArrayList) publications).ensureCapacity(
+ publications.size()
+ + (int) departmentPublications.size());
+ }
Publication publication;
while (departmentPublications.next()) {
- publication = (Publication) departmentPublications.
- getPublication().getLiveVersion();
- if (publication == null) {
- continue;
- } else {
- publications.add(publication);
- }
+ publication = departmentPublications.getPublication();
+ publications.add(publication);
}
SciDepartmentSubDepartmentsCollection subSubDepartments = dep.
getSubDepartments();
if ((subSubDepartments != null) && subSubDepartments.size() > 0) {
- mergePublications(subDepartments, publications);
+ mergePublications(subDepartments,
+ publications,
+ workingPapersOnly,
+ state);
+ }
+ }
+ }
+
+ protected void generateFiltersXml(
+ final List publications,
+ final Element element) {
+ final Element sortFieldsElement = element.newChildElement("sortFields");
+ sortFieldsElement.addAttribute("sortBy", sortByKey);
+ for (Map.Entry> sortField :
+ sortFields.entrySet()) {
+ sortField.getValue().generateXml(sortFieldsElement);
+ }
+ }
+
+ protected void generateSortFieldsXml(final Element element) {
+ final Element sortFieldsElement = element.newChildElement("sortFields");
+ sortFieldsElement.addAttribute("sortBy", sortByKey);
+ for (Map.Entry> sortField :
+ sortFields.entrySet()) {
+ sortField.getValue().generateXml(sortFieldsElement);
+ }
+ }
+
+ protected void applySortFields(
+ final List publications,
+ final HttpServletRequest request) {
+ sortByKey = request.getParameter("sort");
+ if (!sortFields.containsKey(sortByKey)) {
+ sortByKey = new ArrayList(sortFields.keySet()).get(0);
+ }
+
+ if (sortFields.containsKey(sortByKey)) {
+ Collections.sort(publications, sortFields.get(sortByKey).
+ getComparator());
+ } else {
+ Collections.sort(publications, new SciPublicationTitleComparator());
+ }
+ }
+
+ protected void applyFilters(
+ final DomainCollection publications,
+ final HttpServletRequest request) {
+ //Get parameters from HTTP request
+ for (Map.Entry filterEntry : filters.entrySet()) {
+ String value = request.getParameter(
+ filterEntry.getValue().getLabel());
+
+ if ((value != null) && !(value.trim().isEmpty())) {
+ filterEntry.getValue().setValue(value);
+ }
+ }
+
+ //Apply filters to DomainCollection
+ final StringBuilder filterBuilder = new StringBuilder();
+ for (Map.Entry filterEntry : filters.entrySet()) {
+ if ((filterEntry.getValue().getFilter() == null)
+ || (filterEntry.getValue().getFilter().isEmpty())) {
+ continue;
+ }
+
+ if (filterBuilder.length() > 0) {
+ filterBuilder.append(" AND ");
+ }
+ filterBuilder.append(filterEntry.getValue().getFilter());
+ logger.debug(String.format("filters: %s", filterBuilder));
+ if (filterBuilder.length() > 0) {
+ publications.addFilter(filterBuilder.toString());
}
}
}
protected void generatePublicationsXml(final SciDepartment department,
final Element parent,
- final PageState state) {
+ final PageState state,
+ final boolean workingPapersOnly) {
final SciDepartmentWithPublications dep =
(SciDepartmentWithPublications) department;
+ Element controls = parent.newChildElement("filterControls");
+ controls.addAttribute("customName", "sciDepartmentPublications");
+ controls.addAttribute("show", show);
+
if (SciOrganizationWithPublications.getConfig().
getOrganizationPublicationsMerge()) {
List publications;
- publications = new LinkedList();
SciDepartmentPublicationsCollection departmentPublications;
departmentPublications = dep.getPublications();
+ applyFilters(departmentPublications, state.getRequest());
+ if (workingPapersOnly) {
+ departmentPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getDepartmentPublicationsSeparateWorkingPapers()) {
+ departmentPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+ publications =
+ new ArrayList((int) departmentPublications.size());
Publication publication;
while (departmentPublications.next()) {
- publication = (Publication) departmentPublications.
- getPublication().getLiveVersion();
- if (publication == null) {
- continue;
- } else {
- publications.add(publication);
- }
+ publication = departmentPublications.getPublication();
+ publications.add(publication);
}
- mergePublications(department.getSubDepartments(), publications);
+ mergePublications(department.getSubDepartments(),
+ publications,
+ workingPapersOnly,
+ state);
Set publicationsSet;
List publicationsWithoutDoubles;
@@ -138,8 +320,10 @@ public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
publicationsWithoutDoubles = new LinkedList(
publicationsSet);
- Collections.sort(publicationsWithoutDoubles,
- new SciPublicationTitleComparator());
+ applySortFields(publications, state.getRequest());
+
+ //Collections.sort(publicationsWithoutDoubles,
+ // new SciPublicationTitleComparator());
long pageNumber = getPageNumber(state);
long pageCount = getPageCount(publicationsWithoutDoubles.size());
@@ -149,30 +333,40 @@ public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateFiltersXml(publicationsWithoutDoubles, controls);
+ generateSortFieldsXml(controls);
createPaginatorElement(parent, pageNumber, pageCount, begin, end,
count, publicationsWithoutDoubles.size());
List publicationsToShow = publicationsWithoutDoubles.
subList((int) begin, (int) end);
- final Element publicationsElem = parent.newChildElement(
- "publications");
- final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(
- publicationsElem);
- renderer.setWrapAttributes(true);
for (Publication pub : publicationsToShow) {
- renderer.walk(pub, SimpleXMLGenerator.class.getName());
+ PublicationXmlHelper xmlHelper = new PublicationXmlHelper(parent,
+ pub);
+ xmlHelper.generateXml();
}
} else {
SciDepartmentPublicationsCollection departmentPublications;
departmentPublications = dep.getPublications();
+ applyFilters(departmentPublications, state.getRequest());
List publications = new LinkedList();
+ if (workingPapersOnly) {
+ departmentPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getDepartmentPublicationsSeparateWorkingPapers()) {
+ departmentPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
while (departmentPublications.next()) {
publications.add(departmentPublications.getPublication());
}
- Collections.sort(publications, new SciPublicationTitleComparator());
+ applySortFields(publications, state.getRequest());
+
+ //Collections.sort(publications, new SciPublicationTitleComparator());
long pageNumber = getPageNumber(state);
long pageCount = getPageCount(publications.size());
@@ -181,32 +375,34 @@ public class SciDepartmentWithPublicationsPanel extends SciDepartmentPanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generateFiltersXml(publications, controls);
+ generateSortFieldsXml(controls);
createPaginatorElement(parent, pageNumber, pageCount, begin, end,
count, publications.size());
List publicationsToShow = publications.subList(
(int) begin, (int) end);
- final Element publicationsElem = parent.newChildElement(
- "publications");
- final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(
- publicationsElem);
- renderer.setWrapAttributes(true);
for (Publication publication : publicationsToShow) {
- renderer.walk(publication, SimpleXMLGenerator.class.getName());
+ PublicationXmlHelper xmlHelper =
+ new PublicationXmlHelper(parent,
+ publication);
+ xmlHelper.generateXml();
}
}
}
@Override
- public void generateDataXml(final SciDepartment department,
+ public void generateDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
- String show = getShowParam(state);
+ show = getShowParam(state);
if (SHOW_PUBLICATIONS.equals(show)) {
- generatePublicationsXml(department, element, state);
+ generatePublicationsXml((SciDepartment) orga, element, state, false);
+ } else if (SHOW_WORKING_PAPERS.equals(show)) {
+ generatePublicationsXml((SciDepartment) orga, element, state, true);
} else {
- super.generateDataXml(department, element, state);
+ super.generateDataXml(orga, element, state);
}
}
}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationWithPublicationsPanel.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationWithPublicationsPanel.java
index 0dbfa4de6..f16c28638 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationWithPublicationsPanel.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationWithPublicationsPanel.java
@@ -21,7 +21,7 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
-import com.arsdigita.cms.ContentItemXMLRenderer;
+import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.SciDepartmentPublicationsCollection;
@@ -33,15 +33,27 @@ import com.arsdigita.cms.contenttypes.SciOrganizationPublicationsCollection;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublications;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublicationsConfig;
import com.arsdigita.cms.contenttypes.SciPublicationTitleComparator;
-import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
+import com.arsdigita.cms.contenttypes.SciPublicationYearAscComparator;
+import com.arsdigita.cms.contenttypes.SciPublicationYearDescComparator;
+import com.arsdigita.cms.contenttypes.ui.panels.Filter;
+import com.arsdigita.cms.contenttypes.ui.panels.SelectFilter;
+import com.arsdigita.cms.contenttypes.ui.panels.SortField;
+import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
+import com.arsdigita.domain.DomainCollection;
+import com.arsdigita.persistence.DataQuery;
+import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.log4j.Logger;
/**
*
@@ -49,8 +61,52 @@ import java.util.Set;
*/
public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
+ private static final Logger logger =
+ Logger.getLogger(
+ SciOrganizationWithPublicationsPanel.class);
public static final String SHOW_PUBLICATIONS = "publications";
+ public static final String SHOW_WORKING_PAPERS = "workingPapers";
+ private static final String SORT = "sort";
+ private static final String TITLE = "title";
+ private static final String AUTHORS = "authors";
+ private static final String YEAR_OF_PUBLICATION = "yearOfPublication";
+ private static final String YEAR_ASC = "yearAsc";
+ private static final String YEAR_DESC = "yearDesc";
+ private String show;
private boolean displayPublications = true;
+ private boolean displayWorkingPapers = true;
+ private final Map filters =
+ new LinkedHashMap();
+ private final Map> sortFields =
+ new LinkedHashMap>();
+ private String sortByKey;
+
+ public SciOrganizationWithPublicationsPanel() {
+ filters.put(TITLE, new TextFilter(TITLE, TITLE));
+ filters.put(AUTHORS, new TextFilter(AUTHORS, "authors.surname"));
+ SelectFilter yearFilter = new SelectFilter(YEAR_OF_PUBLICATION,
+ YEAR_OF_PUBLICATION,
+ true,
+ true,
+ true,
+ true);
+ DataQuery query = SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getAllYearsOfPublication");
+ yearFilter.setDataQuery(query, "yearOfPublication");
+ filters.put(YEAR_OF_PUBLICATION, yearFilter);
+ sortFields.put(TITLE,
+ new SortField(TITLE,
+ new SciPublicationTitleComparator()));
+ sortFields.put(YEAR_ASC,
+ new SortField(YEAR_ASC,
+ new SciPublicationYearAscComparator()));
+ sortFields.put(YEAR_DESC,
+ new SortField(YEAR_DESC,
+ new SciPublicationYearDescComparator()));
+ /*sortFields.put(AUTHORS,
+ new SortField(AUTHORS,
+ new SciPublicationAuthorComparator()));*/
+ }
@Override
protected Class extends ContentItem> getAllowedClass() {
@@ -70,10 +126,19 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
this.displayPublications = displayPublications;
}
+ public boolean isDisplayWorkingPapers() {
+ return displayWorkingPapers;
+ }
+
+ public void setDisplayWorkingPapers(final boolean displayWorkingPapers) {
+ this.displayWorkingPapers = displayWorkingPapers;
+ }
+
@Override
- protected void generateAvailableDataXml(final SciOrganization organization,
- final Element element,
- final PageState state) {
+ protected void generateAvailableDataXml(
+ final GenericOrganizationalUnit organization,
+ final Element element,
+ final PageState state) {
super.generateAvailableDataXml(organization, element, state);
SciOrganizationWithPublicationsConfig config;
@@ -87,6 +152,12 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
&& displayPublications) {
element.newChildElement("publications");
}
+ if ((orga.hasWorkingPapers(config.getOrganizationPublicationsMerge()))
+ && displayWorkingPapers
+ && config.getOrganizationPublicationsSeparateWorkingPapers()) {
+ element.newChildElement("workingPapers");
+ }
+
System.out.printf(
"\n\nNeeded %d ms to determine if organization has publications\n\n",
System.currentTimeMillis() - start);
@@ -94,21 +165,30 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
protected void mergePublications(
final SciOrganizationDepartmentsCollection departments,
- final Collection publications) {
+ final Collection publications,
+ final boolean workingPapersOnly,
+ final PageState state) {
while (departments.next()) {
SciDepartment dep;
SciDepartmentWithPublications department;
SciDepartmentPublicationsCollection departmentPublications;
dep = departments.getDepartment();
- if (!dep.isPublished()
- || !(dep instanceof SciDepartmentWithPublications)) {
+ if (!(dep instanceof SciDepartmentWithPublications)) {
continue;
}
department = (SciDepartmentWithPublications) dep;
departmentPublications = department.getPublications();
- departmentPublications.addFilter("version = 'live'");
-
+ applyPublicationFilters(departmentPublications, state.getRequest());
+ if (workingPapersOnly) {
+ departmentPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getOrganizationPublicationsSeparateWorkingPapers()) {
+ departmentPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+
if (publications instanceof ArrayList) {
((ArrayList) publications).ensureCapacity(
publications.size()
@@ -116,40 +196,121 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
}
Publication publication;
- while (departmentPublications.next()) {
- publication = departmentPublications.getPublication();
- publications.add(publication);
+ while (departmentPublications.next()) {
+ publication = departmentPublications.getPublication();
+ publications.add(publication);
}
SciDepartmentSubDepartmentsCollection subDepartments;
subDepartments = dep.getSubDepartments();
if ((subDepartments != null) && subDepartments.size() > 0) {
- mergePublications(departments, publications);
+ mergePublications(departments,
+ publications,
+ workingPapersOnly,
+ state);
+ }
+ }
+ }
+
+ protected void generatePublicationFiltersXml(
+ final List publications,
+ final Element element) {
+ final Element filterElement = element.newChildElement("filters");
+
+ for (Map.Entry filterEntry : filters.entrySet()) {
+ filterEntry.getValue().generateXml(filterElement);
+ }
+ }
+
+ protected void generatePublicationSortFieldsXml(final Element element) {
+ final Element sortFieldsElement = element.newChildElement("sortFields");
+ sortFieldsElement.addAttribute("sortBy", sortByKey);
+ for (Map.Entry> sortField :
+ sortFields.entrySet()) {
+ sortField.getValue().generateXml(sortFieldsElement);
+ }
+ }
+
+ protected void applyPublicationSortFields(
+ final List publications,
+ final HttpServletRequest request) {
+ sortByKey = request.getParameter("sort");
+ if (!sortFields.containsKey(sortByKey)) {
+ sortByKey = new ArrayList(sortFields.keySet()).get(0);
+ }
+
+ if (sortFields.containsKey(sortByKey)) {
+ Collections.sort(publications, sortFields.get(sortByKey).
+ getComparator());
+ } else {
+ Collections.sort(publications, new SciPublicationTitleComparator());
+ }
+ }
+
+ protected void applyPublicationFilters(
+ final DomainCollection publications,
+ final HttpServletRequest request) {
+ //Get parameters from HTTP request
+ for (Map.Entry filterEntry : filters.entrySet()) {
+ String value = request.getParameter(
+ filterEntry.getValue().getLabel());
+
+ if ((value != null) && !(value.trim().isEmpty())) {
+ filterEntry.getValue().setValue(value);
+ }
+ }
+
+ //Apply filters to DomainCollection
+ final StringBuilder filterBuilder = new StringBuilder();
+ for (Map.Entry filterEntry : filters.entrySet()) {
+ if ((filterEntry.getValue().getFilter() == null)
+ || (filterEntry.getValue().getFilter().isEmpty())) {
+ continue;
+ }
+
+ if (filterBuilder.length() > 0) {
+ filterBuilder.append(" AND ");
+ }
+ filterBuilder.append(filterEntry.getValue().getFilter());
+ logger.debug(String.format("filters: %s", filterBuilder));
+ if (filterBuilder.length() > 0) {
+ publications.addFilter(filterBuilder.toString());
}
}
}
protected void generatePublicationsXml(final SciOrganization organization,
final Element parent,
- final PageState state) {
+ final PageState state,
+ final boolean workingPapersOnly) {
final SciOrganizationWithPublications orga =
(SciOrganizationWithPublications) organization;
+ Element controls = parent.newChildElement("filterControls");
+ controls.addAttribute("customName", "sciOrganizationPublications");
+ controls.addAttribute("show", show);
+
if (SciOrganizationWithPublications.getConfig().
getOrganizationPublicationsMerge()) {
long start = System.currentTimeMillis();
List publications;
SciOrganizationPublicationsCollection orgaPublications;
orgaPublications = orga.getPublications();
- orgaPublications.addFilter("version = 'live'");
+ applyPublicationFilters(orgaPublications, state.getRequest());
+ if (workingPapersOnly) {
+ orgaPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getOrganizationPublicationsSeparateWorkingPapers()) {
+ orgaPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
publications = new ArrayList((int) orgaPublications.
size());
-
Publication publication;
while (orgaPublications.next()) {
- //publication = (Publication) orgaPublications.getPublication().getLiveVersion();
publication = orgaPublications.getPublication();
publications.add(publication);
}
@@ -157,44 +318,48 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
System.out.printf("Got publications of organization in %d ms\n",
System.currentTimeMillis() - start);
-
SciOrganizationDepartmentsCollection departments = organization.
getDepartments();
long mergeStart = System.currentTimeMillis();
- mergePublications(departments, publications);
+ mergePublications(departments,
+ publications,
+ workingPapersOnly,
+ state);
System.err.printf("Merged publications in %d ms\n", System.
currentTimeMillis() - mergeStart);
long sortStart = System.currentTimeMillis();
Set publicationsSet;
- List publicationWithoutDoubles;
+ List publicationsWithoutDoubles;
publicationsSet = new HashSet(publications);
- //publicationWithoutDoubles = new LinkedList(
- // publicationsSet);
- publicationWithoutDoubles = new ArrayList(
+ publicationsWithoutDoubles = new LinkedList(
publicationsSet);
- Collections.sort(publicationWithoutDoubles,
- new SciPublicationTitleComparator());
+ applyPublicationSortFields(publicationsWithoutDoubles, state.
+ getRequest());
+
+ //Collections.sort(publicationsWithoutDoubles,
+ // new SciPublicationTitleComparator());
System.out.printf("Sorted publications in %d ms\n", System.
currentTimeMillis() - sortStart);
-
long paginatorStart = System.currentTimeMillis();
long pageNumber = getPageNumber(state);
- long pageCount = getPageCount(publicationWithoutDoubles.size());
+ long pageCount = getPageCount(publicationsWithoutDoubles.size());
long begin = getPaginatorBegin(pageNumber);
long count = getPaginatorCount(begin,
- publicationWithoutDoubles.size());
+ publicationsWithoutDoubles.size());
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generatePublicationFiltersXml(publicationsWithoutDoubles, controls);
+ generatePublicationSortFieldsXml(controls);
createPaginatorElement(parent, pageNumber, pageCount, begin, end,
- count, publicationWithoutDoubles.size());
+ count, publicationsWithoutDoubles.size());
System.out.printf("Created paginator in %d ms", System.
currentTimeMillis() - paginatorStart);
- List publicationsToShow = publicationWithoutDoubles.
+ List publicationsToShow = publicationsWithoutDoubles.
subList((int) begin, (int) end);
System.out.printf(
@@ -215,6 +380,15 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
} else {
SciOrganizationPublicationsCollection orgaPublications;
orgaPublications = orga.getPublications();
+ applyPublicationFilters(orgaPublications, state.getRequest());
+ if (workingPapersOnly) {
+ orgaPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getOrganizationPublicationsSeparateWorkingPapers()) {
+ orgaPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
List publications = new LinkedList();
@@ -222,7 +396,9 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
publications.add(orgaPublications.getPublication());
}
- Collections.sort(publications, new SciPublicationTitleComparator());
+ applyPublicationSortFields(publications, state.getRequest());
+
+ //Collections.sort(publications, new SciPublicationTitleComparator());
long pageNumber = getPageNumber(state);
long pageCount = getPageCount(publications.size());
@@ -231,31 +407,38 @@ public class SciOrganizationWithPublicationsPanel extends SciOrganizationPanel {
long end = getPaginatorEnd(begin, count);
pageNumber = normalizePageNumber(pageCount, pageNumber);
+ generatePublicationFiltersXml(publications, controls);
+ generatePublicationSortFieldsXml(controls);
createPaginatorElement(parent, pageNumber, pageCount, begin, end,
count, publications.size());
List publicationsToShow = publications.subList(
(int) begin, (int) end);
- final Element publicationsElem = parent.newChildElement(
- "publications");
- final ContentItemXMLRenderer renderer =
- new ContentItemXMLRenderer(
- publicationsElem);
- renderer.setWrapAttributes(true);
for (Publication publication : publicationsToShow) {
- renderer.walk(publication, SimpleXMLGenerator.class.getName());
+ PublicationXmlHelper xmlHelper =
+ new PublicationXmlHelper(parent,
+ publication);
+ xmlHelper.generateXml();
}
}
}
@Override
- protected void generateDataXml(final SciOrganization organization,
+ protected void generateDataXml(final GenericOrganizationalUnit organization,
final Element element,
final PageState state) {
- String show = getShowParam(state);
+ show = getShowParam(state);
if (SHOW_PUBLICATIONS.equals(show)) {
- generatePublicationsXml(organization, element, state);
+ generatePublicationsXml((SciOrganization) organization,
+ element,
+ state,
+ false);
+ } else if (SHOW_WORKING_PAPERS.equals(show)) {
+ generatePublicationsXml((SciOrganization) organization,
+ element,
+ state,
+ true);
} else {
super.generateDataXml(organization, element, state);
}
diff --git a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciProjectWithPublicationsPanel.java b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciProjectWithPublicationsPanel.java
index 199ca8e43..3c4583ffe 100644
--- a/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciProjectWithPublicationsPanel.java
+++ b/ccm-sci-types-organizationwithpublications/src/com/arsdigita/cms/contenttypes/ui/SciProjectWithPublicationsPanel.java
@@ -20,7 +20,8 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.cms.ContentItemXMLRenderer;
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublications;
import com.arsdigita.cms.contenttypes.SciOrganizationWithPublicationsConfig;
@@ -29,8 +30,8 @@ import com.arsdigita.cms.contenttypes.SciProjectPublicationsCollection;
import com.arsdigita.cms.contenttypes.SciProjectSubProjectsCollection;
import com.arsdigita.cms.contenttypes.SciProjectWithPublications;
import com.arsdigita.cms.contenttypes.SciPublicationTitleComparator;
-import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.xml.Element;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
@@ -44,7 +45,22 @@ import java.util.Set;
public class SciProjectWithPublicationsPanel extends SciProjectPanel {
public static final String SHOW_PUBLICATIONS = "publications";
+ public static final String SHOW_WORKING_PAPERS = "workingPapers";
private boolean displayPublications = true;
+ private boolean displayWorkingPapers = true;
+
+ public SciProjectWithPublicationsPanel() {
+ }
+
+ @Override
+ public Class extends ContentItem> getAllowedClass() {
+ return SciProjectWithPublications.class;
+ }
+
+ @Override
+ protected String getPanelName() {
+ return SciProject.class.getSimpleName();
+ }
public boolean isDisplayPublications() {
return displayPublications;
@@ -54,10 +70,20 @@ public class SciProjectWithPublicationsPanel extends SciProjectPanel {
this.displayPublications = displayPublications;
}
+ public boolean isDisplayWorkingPapers() {
+ return displayWorkingPapers;
+ }
+
+ public void setDisplayWorkingPapers(final boolean displayWorkingPapers) {
+ this.displayWorkingPapers = displayWorkingPapers;
+ }
+
@Override
- public void generateAvailableDataXml(final SciProject project,
+ public void generateAvailableDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
+ SciProject project = (SciProject) orga;
+
super.generateAvailableDataXml(project, element, state);
SciOrganizationWithPublicationsConfig config =
@@ -71,11 +97,17 @@ public class SciProjectWithPublicationsPanel extends SciProjectPanel {
&& displayPublications) {
element.newChildElement("publications");
}
+ if ((proj.hasWorkingPapers(config.getOrganizationPublicationsMerge()))
+ && displayWorkingPapers
+ && config.getProjectPublicationsSeparateWorkingPapers()) {
+ element.newChildElement("workingPapers");
+ }
}
protected void mergePublications(
final SciProjectSubProjectsCollection subProjects,
- final List publications) {
+ final List publications,
+ final boolean workingPapersOnly) {
while (subProjects.next()) {
SciProject proj;
SciProjectWithPublications project;
@@ -84,51 +116,69 @@ public class SciProjectWithPublicationsPanel extends SciProjectPanel {
proj = subProjects.getSubProject();
project = (SciProjectWithPublications) proj;
projectPublications = project.getPublications();
+ if (workingPapersOnly) {
+ projectPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getProjectPublicationsSeparateWorkingPapers()) {
+ projectPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+
+ if (publications instanceof ArrayList) {
+ ((ArrayList) publications).ensureCapacity(
+ publications.size() + (int) projectPublications.size());
+ }
Publication publication;
while (projectPublications.next()) {
- publication = (Publication) projectPublications.getPublication().
- getLiveVersion();
- if (publication == null) {
- continue;
- } else {
- publications.add(publication);
- }
+ publication = projectPublications.getPublication();
+ publications.add(publication);
}
SciProjectSubProjectsCollection subSubProjects =
proj.getSubProjects();
if ((subSubProjects != null) && subSubProjects.size() > 0) {
- mergePublications(subSubProjects, publications);
+ mergePublications(subSubProjects, publications,
+ workingPapersOnly);
}
}
}
protected void generatePublicationsXml(final SciProject project,
final Element parent,
- final PageState state) {
+ final PageState state,
+ final boolean workingPapersOnly) {
final SciProjectWithPublications proj =
(SciProjectWithPublications) project;
if (SciOrganizationWithPublications.getConfig().
getOrganizationPublicationsMerge()) {
- List publications = new LinkedList();
+ List publications;
SciProjectPublicationsCollection projectPublications = proj.
getPublications();
+ if (workingPapersOnly) {
+ projectPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getProjectPublicationsSeparateWorkingPapers()) {
+ projectPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
+
+ publications =
+ new ArrayList((int) projectPublications.size());
Publication publication;
while (projectPublications.next()) {
- publication = (Publication) projectPublications.getPublication().
- getLiveVersion();
- if (publication == null) {
- continue;
- } else {
- publications.add(publication);
- }
+ publication = projectPublications.getPublication();
+ publications.add(publication);
}
- mergePublications(project.getSubProjects(), publications);
+ mergePublications(project.getSubProjects(),
+ publications,
+ workingPapersOnly);
Set publicationsSet;
List publicationsWithoutDoubles;
@@ -151,17 +201,22 @@ public class SciProjectWithPublicationsPanel extends SciProjectPanel {
List publicationsToShow = publicationsWithoutDoubles.
subList((int) begin, (int) end);
- final Element publicationsElem = parent.newChildElement(
- "publications");
- final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(
- publicationsElem);
- renderer.setWrapAttributes(true);
for (Publication pub : publicationsToShow) {
- renderer.walk(pub, SimpleXMLGenerator.class.getName());
+ PublicationXmlHelper xmlHelper = new PublicationXmlHelper(parent,
+ pub);
+ xmlHelper.generateXml();
}
} else {
SciProjectPublicationsCollection projectPublications = proj.
getPublications();
+ if (workingPapersOnly) {
+ projectPublications.addFilter(
+ "objectType = 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ } else if (SciOrganizationWithPublications.getConfig().
+ getProjectPublicationsSeparateWorkingPapers()) {
+ projectPublications.addFilter(
+ "objectType != 'com.arsdigita.cms.contenttypes.WorkingPaper'");
+ }
List publications = new LinkedList();
@@ -183,27 +238,27 @@ public class SciProjectWithPublicationsPanel extends SciProjectPanel {
List publicationsToShow = publications.subList(
(int) begin, (int) end);
- final Element publicationsElem = parent.newChildElement(
- "publications");
- final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(
- publicationsElem);
- renderer.setWrapAttributes(true);
for (Publication publication : publicationsToShow) {
- renderer.walk(publication, SimpleXMLGenerator.class.getName());
+ PublicationXmlHelper xmlHelper =
+ new PublicationXmlHelper(parent,
+ publication);
+ xmlHelper.generateXml();
}
}
}
@Override
- public void generateDataXml(final SciProject project,
+ public void generateDataXml(final GenericOrganizationalUnit orga,
final Element element,
final PageState state) {
String show = getShowParam(state);
if (SHOW_PUBLICATIONS.equals(show)) {
- generatePublicationsXml(project, element, state);
+ generatePublicationsXml((SciProject) orga, element, state, false);
+ } else if (SHOW_WORKING_PAPERS.equals(show)) {
+ generatePublicationsXml((SciProject) orga, element, state, true);
} else {
- super.generateDataXml(project, element, state);
+ super.generateDataXml(orga, element, state);
}
}
}
diff --git a/ccm-zes-aplaws/web/packages/content-section/www/projects4homepages.jsp b/ccm-zes-aplaws/web/packages/content-section/www/projects4homepages.jsp
index 42f03f73f..5579d1073 100644
--- a/ccm-zes-aplaws/web/packages/content-section/www/projects4homepages.jsp
+++ b/ccm-zes-aplaws/web/packages/content-section/www/projects4homepages.jsp
@@ -34,6 +34,7 @@
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) projectList).getDefinition().setDescendCategories(true);
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) projectList).getDefinition().setExcludeIndexObjects(false);
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) projectList).getDefinition().setFilterCategory(false);
+ ((com.arsdigita.london.navigation.ui.object.ComplexObjectList) projectList).getDefinition().setAddOrder("title");
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) projectList).getRenderer().setSpecializeObjectsContext("sciProjectList");
if((request.getParameterMap().get("DaBInId") != null) && (((String[])request.getParameterMap().get("DaBInId")).length > 0)) {
String[] params = (String[]) request.getParameterMap().get("DaBInId");
diff --git a/ccm-zes-aplaws/web/packages/content-section/www/publications4homepages.jsp b/ccm-zes-aplaws/web/packages/content-section/www/publications4homepages.jsp
index 203e6db39..6a3f587f7 100644
--- a/ccm-zes-aplaws/web/packages/content-section/www/publications4homepages.jsp
+++ b/ccm-zes-aplaws/web/packages/content-section/www/publications4homepages.jsp
@@ -22,7 +22,7 @@
+ cache="false">
@@ -34,6 +34,7 @@
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) publicationList).getDefinition().setDescendCategories(true);
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) publicationList).getDefinition().setExcludeIndexObjects(false);
((com.arsdigita.london.navigation.ui.object.ComplexObjectList) publicationList).getDefinition().setFilterCategory(false);
+ ((com.arsdigita.london.navigation.ui.object.ComplexObjectList) publicationList).getDefinition().addOrder("yearOfPublication desc");
if((request.getParameterMap().get("DaBInId") != null) && (((String[])request.getParameterMap().get("DaBInId")).length > 0)) {
String[] params = (String[]) request.getParameterMap().get("DaBInId");
String dabinid = params[0];