From e3ff2038c7ebfe9cd5e07168540bb86e427cc002 Mon Sep 17 00:00:00 2001 From: jensp Date: Sun, 19 Feb 2012 15:11:36 +0000 Subject: [PATCH] =?UTF-8?q?Verschiedene=20Erg=C3=A4nzungen=20und=20Korrekt?= =?UTF-8?q?uren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1517 8810af33-2d31-482b-a856-94f89814c4df --- .../ui/GenericOrgaUnitMembersTab.java | 12 +- .../ui/object/CustomizableObjectList.java | 190 +++++++++--------- .../arsdigita/cms/contenttypes/SciMember.java | 7 + .../cms/contenttypes/SciProject.java | 8 + .../ui/SciProjectListExtraXmlGenerator.java | 61 ++++++ .../contenttypes/ui/SciProjectSummaryTab.java | 111 +++++----- 6 files changed, 229 insertions(+), 160 deletions(-) create mode 100644 ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectListExtraXmlGenerator.java diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java index 0d8dd3b59..06dd1899b 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java @@ -7,7 +7,6 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection; import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; import com.arsdigita.persistence.DataQuery; -import com.arsdigita.persistence.SessionManager; import com.arsdigita.xml.Element; import java.math.BigDecimal; import java.util.List; @@ -53,7 +52,10 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab { } while (persons.next()) { - generatePersonXml((BigDecimal) persons.get("memberId"), + /*generatePersonXml((BigDecimal) persons.get("memberId"), + parent, + state);*/ + generatePersonXml(((GenericOrganizationalUnitPersonCollection) persons).getPerson().getID(), parent, state); } @@ -90,7 +92,9 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab { } protected DataQuery getData(final GenericOrganizationalUnit orgaunit) { - final long start = System.currentTimeMillis(); + return orgaunit.getPersons(); + + /*final long start = System.currentTimeMillis(); final DataQuery personsQuery = SessionManager.getSession().retrieveQuery( "com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits"); @@ -159,7 +163,7 @@ public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab { orgaunit.getName(), System.currentTimeMillis() - start, isMergingMembers())); - return personsQuery; + return personsQuery;*/ } /** diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/object/CustomizableObjectList.java b/ccm-navigation/src/com/arsdigita/navigation/ui/object/CustomizableObjectList.java index 2855dce8d..47a529567 100644 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/object/CustomizableObjectList.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/object/CustomizableObjectList.java @@ -13,42 +13,30 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** - *

- * An object list variant which can be filtered and sorted by the visitor of - * the website. The available filters and sort options are added in a JSP - * template. There are three kinds of filters yet: - *

- *
- *
TextFilter
- *
This filter filters the object list using a user provided string, which - * is put into the WHERE clause with LIKE operator. - * You might use this filter to allow the visitor to filter an object list for - * items with a specific name.
- *
SelectFilter
- *
This filter traverses through the objects displayed by the list and - * determines all distinct values of a property. The visitor can choose one - * of this values, and the displayed list will only contain items which where - * the property has the selected value.
- *
CompareFilter
- *
This filter also provides selectable options. But these options - * can be configured by the developer in the template.
- *
- *

- * If there is more than one filter, the values of all filters are combined - * using AND. - *

- *

- * This object list class was developed for displaying list of items from - * the Sci modules (SciPublications and SciOrganization). For example, we use - * this list to provide lists of publications which be filtered for publications - * from a specific year, for a specific author and for a specific title. The - * list can be sorted by the titles of the publications, the years of the - * publications and the (surnames of the) authors of the publications. - *

- *

- * As an example how to use this object list in a JSP template here are the - * relevant parts from the template for the publication list: - *

+ *

An object list variant which can be filtered and sorted by the visitor of + * the website. The available filters and sort options are added in a JSP + * template. There are three kinds of filters yet:

TextFilter
+ *
This filter filters the object list using a user provided string, which + * is put into the + * WHERE clause with + * LIKE operator. You might use this filter to allow the visitor to + * filter an object list for items with a specific name.
SelectFilter
+ *
This filter traverses through the objects displayed by the list and + * determines all distinct values of a property. The visitor can choose one of + * this values, and the displayed list will only contain items which where the + * property has the selected value.
CompareFilter
+ *
This filter also provides selectable options. But these options can be + * configured by the developer in the template.

If there is more + * than one filter, the values of all filters are combined using + * AND.

This object list class was developed for + * displaying list of items from the Sci modules (SciPublications and + * SciOrganization). For example, we use this list to provide lists of + * publications which be filtered for publications from a specific year, for a + * specific author and for a specific title. The list can be sorted by the + * titles of the publications, the years of the publications and the (surnames + * of the) authors of the publications.

As an example how to use this + * object list in a JSP template here are the relevant parts from the template + * for the publication list:

*
  * {@code
  * ...
@@ -56,35 +44,35 @@ import org.apache.log4j.Logger;
  *         classname="com.arsdigita.navigation.ui.object.CustomizableObjectList"/>
  * ...
  *   
-      CustomizableObjectList objList = (CustomizableObjectList) itemList;
-      objList.setDefinition(new CMSDataCollectionDefinition());
-      objList.setRenderer(new CMSDataCollectionRenderer());
-      objList.getDefinition().setObjectType("com.arsdigita.cms.contenttypes.Publication");
-      objList.getDefinition().setDescendCategories(false);
-      objList.addTextFilter("title", "title");
-      objList.addTextFilter("authors.surname", "author");
-      objList.addSelectFilter("yearOfPublication", "year", true, true, true, true);
-      objList.addSortField("title", "title asc");
-      objList.addSortField("yearAsc", "yearOfPublication asc");
-      objList.addSortField("yearDesc", "yearOfPublication desc");
-      objList.addSortField("authors", "authors.surname asc, authors.givenname asc");
-      objList.getDefinition().addOrder(objList.getOrder(request.getParameter("sort")));
-
-      objList.getRenderer().setPageSize(20);
-      objList.getRenderer().setSpecializeObjects(true);
-
-      
+ * CustomizableObjectList objList = (CustomizableObjectList) itemList;
+ * objList.setDefinition(new CMSDataCollectionDefinition());
+ * objList.setRenderer(new CMSDataCollectionRenderer());
+ * objList.getDefinition().setObjectType("com.arsdigita.cms.contenttypes.Publication");
+ * objList.getDefinition().setDescendCategories(false);
+ * objList.addTextFilter("title", "title");
+ * objList.addTextFilter("authors.surname", "author");
+ * objList.addSelectFilter("yearOfPublication", "year", true, true, true, true);
+ * objList.addSortField("title", "title asc");
+ * objList.addSortField("yearAsc", "yearOfPublication asc");
+ * objList.addSortField("yearDesc", "yearOfPublication desc");
+ * objList.addSortField("authors", "authors.surname asc, authors.givenname asc");
+ * objList.getDefinition().addOrder(objList.getOrder(request.getParameter("sort")));
+ *
+ * objList.getRenderer().setPageSize(20);
+ * objList.getRenderer().setSpecializeObjects(true);
+ *
+ * 
  * ...
  * }
- * 
- *

- * You may notice the line + *

You may notice the line * objList.getDefinition().addOrder(objList.getOrder(request.getParameter("sort")));. * This line may looks a bit weird to you. The reason is that it is not possible - * to access the DataCollectionDefinition from the methods in this - * class. If you try call the addOrder() from within this class - * you will cause an locking error. - *

+ * to access the + * DataCollectionDefinition from the methods in this class. If you + * try call the + * addOrder() from within this class you will cause an locking + * error.

+ * * @author Jens Pelzetter * @version $Id$ * @see Filter @@ -116,7 +104,7 @@ public class CustomizableObjectList extends ComplexObjectList { * * @param property The property to filter using the new filter. * @param label The label of the filter and its component. - * @see TextFilter#TextFilter(java.lang.String, java.lang.String) + * @see TextFilter#TextFilter(java.lang.String, java.lang.String) */ public void addTextFilter(final String property, final String label) { TextFilter filter; @@ -133,11 +121,11 @@ public class CustomizableObjectList extends ComplexObjectList { * @param allOption Add an all option to the filter. * @param allOptionIsDefault Is the all option the default? * @param propertyIsNumeric Is the property to filter numeric? - * @return The new filter. Options can be added to the filter by calling - * the {@link CompareFilter#addOption(java.lang.String, java.lang.String)} or - * the {@link CompareFilter#addOption(java.lang.String, com.arsdigita.navigation.ui.object.CompareFilter.Operators, java.lang.String)} + * @return The new filter. Options can be added to the filter by calling the {@link CompareFilter#addOption(java.lang.String, java.lang.String)} + * or the {@link CompareFilter#addOption(java.lang.String, com.arsdigita.navigation.ui.object.CompareFilter.Operators, java.lang.String)} * method. - * @see CompareFilter#CompareFilter(java.lang.String, java.lang.String, boolean, boolean, boolean) + * @see CompareFilter#CompareFilter(java.lang.String, java.lang.String, + * boolean, boolean, boolean) * */ public CompareFilter addCompareFilter(final String property, @@ -166,7 +154,9 @@ public class CustomizableObjectList extends ComplexObjectList { * @param allOption Add an all option? * @param allOptionIsDefault Is the all option the default. * @param propertyIsNumeric Is the property numeric? - * @see SelectFilter#SelectFilter(java.lang.String, java.lang.String, com.arsdigita.navigation.ui.object.CustomizableObjectList, boolean, boolean, boolean, boolean) + * @see SelectFilter#SelectFilter(java.lang.String, java.lang.String, + * com.arsdigita.navigation.ui.object.CustomizableObjectList, boolean, + * boolean, boolean, boolean) */ public void addSelectFilter(final String property, final String label, @@ -211,9 +201,10 @@ public class CustomizableObjectList extends ComplexObjectList { } /** - * This overwritten version of the getObjects method evaluates - * the parameters in HTTP request for the filters and creates an - * appropriate SQL filter and sets this filter. + * This overwritten version of the + * getObjects method evaluates the parameters in HTTP request + * for the filters and creates an appropriate SQL filter and sets this + * filter. * * @param request * @param response @@ -247,16 +238,12 @@ public class CustomizableObjectList extends ComplexObjectList { } /** - *

- * Generates the XML for the list. The root element for the list is - * customizableObjectList. The available filters are - * put into a filters element. - *

- *

- * The available sort fields are put into a sortFields element. - * This element has also an attribute indicating the current selected sort - * field. - *

+ *

Generates the XML for the list. The root element for the list is + * customizableObjectList. The available filters are put into a + * filters element.

The available sort fields are put + * into a + * sortFields element. This element has also an attribute + * indicating the current selected sort field.

* * @param request * @param response @@ -283,12 +270,14 @@ public class CustomizableObjectList extends ComplexObjectList { //- The HttpRequest is available here. //So we use the HTTP request directly, which allows use to use a //dedicated parameter for each of the filters. - /*if (request.getCharacterEncoding() == null) {*/ - try { - request.setCharacterEncoding("UTF-8"); - } catch (UnsupportedEncodingException ex) { - logger.error(ex); - } + /* + * if (request.getCharacterEncoding() == null) { + */ + try { + request.setCharacterEncoding("UTF-8"); + } catch (UnsupportedEncodingException ex) { + logger.error(ex); + } //} for (Map.Entry filterEntry : filters.entrySet()) { @@ -299,14 +288,6 @@ public class CustomizableObjectList extends ComplexObjectList { } } - //Look for a sort parameter. If one is found, use one to sort the data - //collection (if it is a valid value). If no sort parameter is found, - //use the first sort field as default. - String sortByKey = request.getParameter("sort"); - if (!sortFields.containsKey(sortByKey)) { - sortByKey = new ArrayList(sortFields.keySet()).get(0); - } - Element controls = content.newChildElement("filterControls"); controls.addAttribute("customName", m_customName); @@ -315,11 +296,22 @@ public class CustomizableObjectList extends ComplexObjectList { filterElems.addContent(filterEntry.getValue().getXml()); } - Element sortFieldElems = controls.newChildElement("sortFields"); - sortFieldElems.addAttribute("sortBy", sortByKey); - for (Map.Entry sortField : sortFields.entrySet()) { - Element sortFieldElem = sortFieldElems.newChildElement("sortField"); - sortFieldElem.addAttribute("label", sortField.getKey()); + if (sortFields.size() > 0) { + //Look for a sort parameter. If one is found, use one to sort the data + //collection (if it is a valid value). If no sort parameter is found, + //use the first sort field as default. + String sortByKey = request.getParameter("sort"); + if (!sortFields.containsKey(sortByKey)) { + sortByKey = new ArrayList(sortFields.keySet()).get(0); + } + + Element sortFieldElems = controls.newChildElement("sortFields"); + sortFieldElems.addAttribute("sortBy", sortByKey); + for (Map.Entry sortField : sortFields.entrySet()) { + Element sortFieldElem = sortFieldElems.newChildElement( + "sortField"); + sortFieldElem.addAttribute("label", sortField.getKey()); + } } //Add object list diff --git a/ccm-sci-types-member/src/com/arsdigita/cms/contenttypes/SciMember.java b/ccm-sci-types-member/src/com/arsdigita/cms/contenttypes/SciMember.java index e4960fefd..4fca3727e 100644 --- a/ccm-sci-types-member/src/com/arsdigita/cms/contenttypes/SciMember.java +++ b/ccm-sci-types-member/src/com/arsdigita/cms/contenttypes/SciMember.java @@ -61,5 +61,12 @@ public class SciMember extends GenericPerson { generators.add(new SciMemberExtraXmlGenerator()); return generators; } + + @Override + public List getExtraListXMLGenerators() { + final List generators = super.getExtraListXMLGenerators(); + generators.add(new SciMemberExtraXmlGenerator()); + return generators; + } } diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java index 18c69108b..17c4fa22f 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java @@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.cms.ExtraXMLGenerator; import com.arsdigita.cms.contenttypes.ui.SciProjectExtraXmlGenerator; +import com.arsdigita.cms.contenttypes.ui.SciProjectListExtraXmlGenerator; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; @@ -367,6 +368,13 @@ public class SciProject extends GenericOrganizationalUnit { return generators; } + @Override + public List getExtraListXMLGenerators() { + final List generators = super.getExtraListXMLGenerators(); + generators.add(new SciProjectListExtraXmlGenerator()); + return generators; + } + @Override public String getSearchSummary() { return getProjectShortDescription(); diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectListExtraXmlGenerator.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectListExtraXmlGenerator.java new file mode 100644 index 000000000..afad593d3 --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectListExtraXmlGenerator.java @@ -0,0 +1,61 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ExtraXMLGenerator; +import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; +import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.xml.Element; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class SciProjectListExtraXmlGenerator implements ExtraXMLGenerator { + + public void generateXML(final ContentItem item, + final Element element, + final PageState state) { + if (!(item instanceof SciProject)) { + throw new IllegalArgumentException( + "This ExtraXMLGenerator supports items of type " + + "'com.arsdigita.cms.contenttypes.SciProject' only."); + } + + final SciProject project = (SciProject) item; + final GenericOrganizationalUnitPersonCollection members = project. + getPersons(); + + final Element membersElem = element.newChildElement("members"); + while (members.next()) { + generateMemberXml(membersElem, + members.getPerson(), + members.getRoleName()); + } + + } + + public void addGlobalStateParams(final Page page) { + //Nothing for now + } + + private void generateMemberXml(final Element membersElem, + final GenericPerson member, + final String roleName) { + final Element memberElem = membersElem.newChildElement("member"); + memberElem.addAttribute("role", roleName); + + final Element surnameElem = memberElem.newChildElement("surname"); + surnameElem.setText(member.getSurname()); + final Element givenNameElem = memberElem.newChildElement("givenName"); + givenNameElem.setText(member.getGivenName()); + final Element titlePreElem = memberElem.newChildElement("titlePre"); + titlePreElem.setText(member.getTitlePre()); + final Element titlePostElem = memberElem.newChildElement("titlePost"); + titlePostElem.setText(member.getTitlePost()); + } +} diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java index 24ccf715b..78d58ab84 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java @@ -26,11 +26,11 @@ import java.util.Locale; import org.apache.log4j.Logger; /** - * Summary tab for projects, displays lifespan of the project, the short - * description, the project team (aka members), a contact, the involved + * Summary tab for projects, displays lifespan of the project, the short + * description, the project team (aka members), a contact, the involved * organizations and the information about the funding of the project. - * - * @author Jens Pelzetter + * + * @author Jens Pelzetter * @version $Id$ */ public class SciProjectSummaryTab implements GenericOrgaUnitTab { @@ -94,8 +94,9 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { /** * Generates the XML for the basic data (addendum, begin, end, shortDesc) + * * @param project - * @param parent + * @param parent */ protected void generateBasicDataXml(final SciProject project, final Element parent) { @@ -194,57 +195,50 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { final Element membersElem = parent.newChildElement("members"); - if (config.isMergingMembers()) { - final DataQuery subProjectsQuery = - SessionManager.getSession().retrieveQuery( - "com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType"); - subProjectsQuery.setParameter("orgaunitId", - project.getID().toString()); - subProjectsQuery.setParameter("assocType", - SciProjectSubProjectsStep.ASSOC_TYPE); - - final DataQuery personsQuery = SessionManager.getSession(). - retrieveQuery( - "com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits"); - - //final StringBuffer personsFilter = new StringBuffer(); - final List projectIds = new ArrayList(); - while (subProjectsQuery.next()) { - /*if (personsFilter.length() > 0) { - personsFilter.append(" or "); - } - personsFilter.append(String.format("orgaunitId = %s", - subProjectsQuery.get( - "orgaunitId").toString()));*/ - projectIds.add(subProjectsQuery.get("orgaunitId").toString()); - } - //personsQuery.addFilter(personsFilter.toString()); - personsQuery.setParameter("orgaunitIds", projectIds); - - personsQuery.addOrder(GenericPerson.SURNAME); - personsQuery.addOrder(GenericPerson.GIVENNAME); - - while (personsQuery.next()) { - generateMemberXml((BigDecimal) personsQuery.get("memberId"), - membersElem, - (String) personsQuery.get("roleName"), - state); - } - } else { - final GenericOrganizationalUnitPersonCollection members = project. - getPersons(); - - members.addOrder("surname"); - members.addOrder("givenname"); - - while (members.next()) { - generateMemberXml(members.getPerson(), - membersElem, - members.getRoleName(), - state); - } + final GenericOrganizationalUnitPersonCollection members = project. + getPersons(); + + while (members.next()) { + generateMemberXml(members.getPerson(), + membersElem, + members.getRoleName(), + state); } + /* + * if (config.isMergingMembers()) { final DataQuery subProjectsQuery = + * SessionManager.getSession().retrieveQuery( + * "com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType"); + * subProjectsQuery.setParameter("orgaunitId", + * project.getID().toString()); + * subProjectsQuery.setParameter("assocType", + * SciProjectSubProjectsStep.ASSOC_TYPE); + * + * final DataQuery personsQuery = SessionManager.getSession(). + * retrieveQuery( + * "com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits"); + * + * final List projectIds = new ArrayList(); while + * (subProjectsQuery.next()) { + * projectIds.add(subProjectsQuery.get("orgaunitId").toString()); } + * personsQuery.setParameter("orgaunitIds", projectIds); + * + * personsQuery.addOrder(GenericPerson.SURNAME); + * personsQuery.addOrder(GenericPerson.GIVENNAME); + * + * while (personsQuery.next()) { generateMemberXml((BigDecimal) + * personsQuery.get("memberId"), membersElem, (String) + * personsQuery.get("roleName"), state); } } else { final + * GenericOrganizationalUnitPersonCollection members = project. + * getPersons(); + * + * members.addOrder("surname"); members.addOrder("givenname"); + * + * while (members.next()) { generateMemberXml(members.getPerson(), + * membersElem, members.getRoleName(), state); } + } + */ + logger.debug(String.format("Generated members XML for project '%s'" + "in '%d ms'. MergeMembers is set to '%b'.", project.getName(), @@ -428,9 +422,12 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab { final XmlGenerator generator = new XmlGenerator(subProject); generator.setUseExtraXml(false); generator.generateXML(state, parent, ""); - /*final Element subProjectElem = parent.newChildElement("subProject"); - final Element subProjectTitle = subProjectElem.newChildElement("title"); - subProjectTitle.setText(subProject.getTitle());*/ + /* + * final Element subProjectElem = parent.newChildElement("subProject"); + * final Element subProjectTitle = + * subProjectElem.newChildElement("title"); + subProjectTitle.setText(subProject.getTitle()); + */ logger.debug(String.format("Generated XML for subproject '%s' in" + "%d ms", subProject.getName(),