- Tabs für SciDepartment

- Kleinere Verbesserungen am Code der Tabs für SciProject
- Weitere kleinere Verbesserungen an ein paar anderen Klassen
- Zentrale Klasse für Paginator für Listen in den Tabs


git-svn-id: https://svn.libreccm.org/ccm/trunk@1213 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-10-31 18:30:10 +00:00
parent 2d18b5ad3e
commit 53a976222f
23 changed files with 1792 additions and 95 deletions

View File

@ -152,7 +152,8 @@ query getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType{
}
//Gets the members of several orga units
//@param orgaUnitsIds comma separated list of the ids of orga units to include
//add a filter (organizationalunit_id = $id1 or organizationalunit_id = $id2 or ...)
//to restrict to orga units
query getIdsOfMembersOfOrgaUnits {
BigDecimal memberId;
BigDecimal orgaunitId;

View File

@ -49,6 +49,8 @@ public class GenericOrganizationalUnitSubordinateCollection extends DomainCollec
}
public void swapWithNext(final GenericOrganizationalUnit orgaunit) {
if (orgaunit == null) {
throw new IllegalArgumentException(
"Parameter orgaunit is null. Can't swap position with null");

View File

@ -20,8 +20,6 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
import org.apache.log4j.Logger;

View File

@ -0,0 +1,120 @@
package com.arsdigita.cms.contenttypes.ui.panels;
import com.arsdigita.cms.contenttypes.ui.GenericOrgaUnitTab;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.URL;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
/**
* Paginator class for the classes implementing {@link GenericOrgaUnitTab}.
*
* @author Jens Pelzetter
* @version $Id$
*/
public class Paginator {
private static final String PAGE_NUMBER = "pageNumber";
private final int pageSize;
private int pageNumber;
private final int objectCount;
public Paginator(final HttpServletRequest request,
final int objectCount) {
this(request, objectCount, 30);
}
public Paginator(final HttpServletRequest request,
final int objectCount,
final int pageSize) {
pageNumber = Integer.parseInt(request.getParameter(PAGE_NUMBER));
this.objectCount = objectCount;
this.pageSize = pageSize;
normalizePageNumber();
}
public void generateXml(final Element parent) {
final Element paginatorElem = parent.newChildElement(
"nav:paginator", "http://ccm.redhat.com/london/navigation");
final URL requestUrl = Web.getContext().getRequestURL();
final ParameterMap parameters = new ParameterMap();
if (requestUrl.getParameterMap() != null) {
final Iterator<?> current = requestUrl.getParameterMap().keySet().
iterator();
while (current.hasNext()) {
copyParameter(requestUrl, (String) current.next(), parameters);
}
}
paginatorElem.addAttribute("pageParam", PAGE_NUMBER);
paginatorElem.addAttribute("baseURL", URL.there(requestUrl.getPathInfo(),
parameters).toString());
paginatorElem.addAttribute("pageNumber", Integer.toString(pageNumber));
paginatorElem.addAttribute("pageCount", Integer.toString(getPageCount()));
paginatorElem.addAttribute("pageSize", Integer.toString(pageSize));
paginatorElem.addAttribute("objectBegin", Integer.toString(getBegin()));
paginatorElem.addAttribute("objectEnd", Integer.toString(getEnd()));
paginatorElem.addAttribute("objectCount", Integer.toString(objectCount));
}
public void applyLimits(final DataQuery query) {
query.setRange(getBegin(), getEnd());
}
public int getPageCount() {
return (int) Math.ceil((double) objectCount / (double) pageSize);
}
private int normalizePageNumber() {
final int pageCount = getPageCount();
int num;
num = pageNumber;
if (num < 1) {
num = 1;
}
if (num > pageCount) {
if (pageCount == 0) {
num = 1;
} else {
num = pageCount;
}
}
return num;
}
private int getBegin() {
return (pageNumber - 1) * pageSize;
}
private int getCount() {
return Math.min(pageSize, (objectCount - getBegin()));
}
private int getEnd() {
int paginatorEnd = getBegin() + getCount();
if (paginatorEnd < 0) {
paginatorEnd = 0;
}
return paginatorEnd;
}
private void copyParameter(final URL requestUrl,
final String key,
final ParameterMap parameters) {
if (PAGE_NUMBER.equals(key)) {
return;
} else {
parameters.setParameterValues(key,
requestUrl.getParameterValues(key));
}
}
}

View File

@ -67,6 +67,69 @@ association {
Integer[0..1] publicationOrder = cms_organizationalunits_publications_map.publication_order INTEGER;
}
//Retrieves the publications (the ids). Allows filtering for a orgaunit id
//For each author there will be on row in the result
query getIdsOfPublicationsForOrgaUnitOneRowPerAuthor {
BigDecimal publicationId;
String objectType;
BigDecimal orgaunitId;
String title;
Integer year;
String authorSurname;
String authorGivenname;
do {
select cms_pages.item_id, cms_pages.title, acs_objects.object_type, cms_organizationalunits.organizationalunit_id, ct_publications.year, cms_persons.surname, cms_persons.givenname
from cms_pages
join ct_publications on cms_pages.item_id = ct_publications.publication_id
join ct_publications_authorship on ct_publications.publication_id = ct_publications_authorship.publication_id
join cms_persons on ct_publications_authorship.person_id = cms_persons.person_id
join cms_organizationalunits_publications_map on cms_pages.item_id = cms_organizationalunits_publications_map.publication_id
join cms_organizationalunits on cms_organizationalunits_publications_map.orgaunit_id = cms_organizationalunits.organizationalunit_id
join acs_objects on cms_pages.item_id = acs_objects.object_id
} map {
publicationId = cms_pages.item_id;
objectType = acs_objects.object_type;
orgaunitId = cms_organizationalunits.organizationalunit_id;
title = cms_pages.title;
year = ct_publications.year;
authorSurname = cms_persons.surname;
authorGivenname = cms_persons.givenname;
}
}
//Retrieves the publications (the ids). Allows filtering for a orgaunit id
//The authors are merged into one field in the result, each publication will
//only appear one time
query getIdsOfPublicationsForOrgaUnit {
BigDecimal publicationId;
String objectType;
BigDecimal orgaunitId;
String title;
Integer year;
String authors;
do {
select cms_pages.item_id, acs_object.object_type, cms_pages.title, cms_organizationalunits.organizationalunit_id, ct_publications.year, (select array_to_string (array (select cms_persons.surname || ', ' || cms_persons.givenname
from cms_persons
join ct_publications_authorship_map on cms_persons.person_id = ct_publications_authorship.person_id
where ct_publications_authorship.publication_id = cms_pages.item_id), '; ')) as authors
from cms_pages
join ct_publications on cms_pages.item_id = ct_publications.publication_id
join cms_organizationalunits_publications_map on cms_pages.item_id = cms_organizationalunits_publications_map.publication_id
join cms_organizationalunits on cms_organizationalunits_publications_map.orgaunit_id = cms_organizationalunits.organizationalunit_id
join acs_objects on cms_pages.item_id = acs_objects.object_id
} map {
publicationId = cms_pages.item_id;
objectType = acs_objects.object_type;
orgaunitId = cms_organizationalunits.organizationalunit_id;
title = cms_pages.title;
year = ct_publications.year;
authors = authors;
}
}
//Old, possible obsolete queries. Will be removed soon
query getAllYearsOfPublication {
Integer yearOfPublication;

View File

@ -2,6 +2,12 @@
<registry>
<config class="com.arsdigita.cms.contenttypes.SciDepartmentConfig"
storage="ccm-sci-types-department/scidepartment.properties"/>
<!-- <config class="com.arsdigita.cms.contenttypes.ui.SciDepartmentSummaryTabConfig"
storage="ccm-sci-types-department/summarytab.properties"/> -->
<config class="com.arsdigita.cms.contenttypes.ui.SciDepartmentSummaryTabConfig"
storage="ccm-sci-types-department/summarytab.properties"/>
<config class="com.arsdigita.cms.contenttypes.ui.SciDepartmentMemberTabConfig"
storage="ccm-sci-types-department/memberstab.properties"/>
<config class="com.arsdigita.cms.contenttypes.ui.SciDepartmentProjectsTabConfig"
storage="ccm-sci-types-department/projectstab.properties"/>
<config class="com.arsdigita.cms.contenttypes.ui.SciDepartmentPublicationsTabConfig"
storage="ccm-sci-types-department/publicationstab.properties"/>
</registry>

View File

@ -0,0 +1,96 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.xml.Element;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentDescTab implements GenericOrgaUnitTab {
public final Logger logger = Logger.getLogger(SciDepartmentDescTab.class);
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
boolean result;
final Desc desc = getData(orgaunit);
if (desc.getDesc() == null) {
result = false;
} else {
result = !desc.getDesc().trim().isEmpty();
}
logger.debug(String.format("Needed %d ms to determine if department '%s' "
+ "has a description.",
System.currentTimeMillis() - start,
orgaunit.getName()));
return result;
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final Desc desc = getData(orgaunit);
if ((desc.getShortDesc() != null)
&& !desc.getShortDesc().trim().isEmpty()) {
final Element shortDescElem = parent.newChildElement(
"shortDescription");
shortDescElem.setText(desc.getShortDesc());
}
final Element descElem = parent.newChildElement("description");
descElem.setText(desc.getDesc());
logger.debug(String.format("Generated XML for description tab of "
+ "department '%s' in %d ms",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
private Desc getData(final GenericOrganizationalUnit orgaunit) {
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format(
"This tab can only process instances of "
+ "'com.arsdigita.cms.contenttypes.SciDepartment'. Provided "
+ "object is of type '%s'",
orgaunit.getClass().getName()));
}
final SciDepartment department = (SciDepartment) orgaunit;
final Desc desc = new Desc();
desc.setShortDesc(department.getDepartmentShortDescription());
desc.setDesc(department.getDepartmentDescription());
return desc;
}
private class Desc {
private String shortDesc;
private String desc;
public String getShortDesc() {
return shortDesc;
}
public void setShortDesc(final String shortDesc) {
this.shortDesc = shortDesc;
}
public String getDesc() {
return desc;
}
public void setDesc(final String desc) {
this.desc = desc;
}
}
}

View File

@ -0,0 +1,216 @@
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.GenericPerson;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.ui.panels.CompareFilter;
import com.arsdigita.cms.contenttypes.ui.panels.Paginator;
import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
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 javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentMembersTab implements GenericOrgaUnitTab {
private final Logger logger = Logger.getLogger(SciDepartmentMembersTab.class);
private static final SciDepartmentMembersTabConfig config =
new SciDepartmentMembersTabConfig();
private static final String STATUS_PARAM = "memberStatus";
private static final String SURNAME_PARAM = "memberSurname";
private final CompareFilter statusFilter = new CompareFilter(
STATUS_PARAM,
GenericOrganizationalUnitPersonCollection.LINK_STATUS,
false,
false,
false);
private final TextFilter surnameFilter =
new TextFilter(SURNAME_PARAM,
GenericPerson.SURNAME);
static {
config.load();
}
public SciDepartmentMembersTab() {
super();
final String[] statusValues = config.getStatusValues();
for (String status : statusValues) {
statusFilter.addOption(status, status);
}
}
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
if ((orgaunit.getPersons() != null)
&& orgaunit.getPersons().size() > 0) {
return true;
} else if (config.isMergingMembers()) {
final DataQuery persons = getData(orgaunit);
return persons.isEmpty();
} else {
return false;
}
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final DataQuery persons = getData(orgaunit);
final HttpServletRequest request = state.getRequest();
applyStatusFilter(persons, request);
applySurnameFilter(persons, request);
final Element depMembersElem = parent.newChildElement(
"departmentMembers");
final Element filtersElem = depMembersElem.newChildElement("filters");
final Paginator paginator = new Paginator(request,
(int) persons.size(),
config.getPageSize());
statusFilter.generateXml(filtersElem);
if (paginator.getPageCount() > config.getEnableSearchLimit()) {
surnameFilter.generateXml(filtersElem);
}
paginator.applyLimits(persons);
paginator.generateXml(depMembersElem);
while (persons.next()) {
generateMemberXml((BigDecimal) persons.get("memberId"),
depMembersElem,
state);
}
logger.debug(String.format("Generated members list of department '%s' "
+ "in %d ms.",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format(
"This tab can only process instances of "
+ "'com.arsdigita.cms.contenttypes.SciDepartment'. Provided "
+ "object is of type '%s'",
orgaunit.getClass().getName()));
}
final DataQuery personsQuery = SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits");
final StringBuffer personsFilter = new StringBuffer();
if (config.isMergingMembers()) {
final DataQuery subDepartmentsQuery =
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType");
subDepartmentsQuery.setParameter("orgaunitId",
orgaunit.getID().toString());
subDepartmentsQuery.setParameter("assocType",
SciDepartmentSubDepartmentsStep.ASSOC_TYPE);
while (subDepartmentsQuery.next()) {
if (personsFilter.length() > 0) {
personsFilter.append(" or ");
}
personsFilter.append(String.format("orgaunitId = %s",
subDepartmentsQuery.get(
"orgaunitId").toString()));
}
} else {
personsFilter.append(String.format("orgaunitId = %s",
orgaunit.getID().toString()));
}
personsQuery.addFilter(personsFilter.toString());
personsQuery.addOrder(GenericPerson.SURNAME);
personsQuery.addOrder(GenericPerson.GIVENNAME);
logger.debug(String.format(
"Got members of department '%s'"
+ "in '%d ms'. MergeMembers is set to '%b'.",
orgaunit.getName(),
System.currentTimeMillis() - start,
config.isMergingMembers()));
return personsQuery;
}
private void applyStatusFilter(final DataQuery persons,
final HttpServletRequest request) {
final String statusValue = request.getParameter(STATUS_PARAM);
if ((statusValue != null) && !(statusValue.trim().isEmpty())) {
statusFilter.setValue(statusValue);
}
persons.addFilter(statusFilter.getFilter());
}
private void applySurnameFilter(final DataQuery persons,
final HttpServletRequest request) {
final String surnameValue = request.getParameter(SURNAME_PARAM);
if ((surnameValue != null) && !(surnameValue.trim().isEmpty())) {
surnameFilter.setValue(surnameValue);
}
persons.addFilter(surnameFilter.getFilter());
}
protected void generateMemberXml(final BigDecimal memberId,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final GenericPerson member = new GenericPerson(memberId);
logger.debug(String.format("Got domain object for member '%s' "
+ "in %d ms.",
member.getFullName(),
System.currentTimeMillis() - start));
generateMemberXml(member, parent, state);
}
protected void generateMemberXml(final GenericPerson member,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(member);
generator.setUseExtraXml(false);
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for member '%s' in %d ms.",
member.getFullName(),
System.currentTimeMillis() - start));
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;
public XmlGenerator(final ContentItem item) {
super();
this.item = item;
}
@Override
protected ContentItem getContentItem(final PageState state) {
return item;
}
}
}

View File

@ -0,0 +1,69 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringArrayParameter;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentMembersTabConfig extends AbstractConfig {
private Parameter statusValues;
private Parameter pageSize;
private Parameter enableSearchLimit;
private Parameter mergeMembers;
public SciDepartmentMembersTabConfig() {
statusValues =
new StringArrayParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.members.status_values",
Parameter.REQUIRED,
new String[]{"active", "associated", "former"});
pageSize =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.embers.page_size",
Parameter.REQUIRED,
30);
enableSearchLimit =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.members.enable_search_limit",
Parameter.REQUIRED,
2);
mergeMembers =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge",
Parameter.REQUIRED,
Boolean.TRUE);
register(statusValues);
register(pageSize);
register(enableSearchLimit);
register(mergeMembers);
loadInfo();
}
public final String[] getStatusValues() {
return (String[]) get(statusValues);
}
public final int getPageSize() {
return (Integer) get(pageSize);
}
public final int getEnableSearchLimit() {
return (Integer) get(enableSearchLimit);
}
public final boolean isMergingMembers() {
return (Boolean) get(mergeMembers);
}
}

View File

@ -0,0 +1,19 @@
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.status_values.title = Status values
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.status_values.purpose = Possible values for status attribute of the SciDepartment -> GenericPerson association. Used to build the select box and the filter for the status.
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.status_values.example = active,associated,former
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.status_values.format = [String]
com.arsdigita.cms.contenttypes.scidepartment.tabs.embers.page_size.title = Page size
com.arsdigita.cms.contenttypes.scidepartment.tabs.embers.page_size.purpose = Maximum number of members per page
com.arsdigita.cms.contenttypes.scidepartment.tabs.embers.page_size.example = 30
com.arsdigita.cms.contenttypes.scidepartment.tabs.embers.page_size.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.enable_search_limit.title = Enable search limit
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.enable_search_limit.purpose = Number of result pages when to activate the search. Set to 1 or 0 to show the search on every time.
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.enable_search_limit.example = 2
com.arsdigita.cms.contenttypes.scidepartment.tabs.members.enable_search_limit.format = Integer
com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge.title = Merge members
com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge.purpose = Merge the members of the department and its sub departments into one list?
com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge.example = true
com.arsdigita.cms.contenttypes.scidepartments.tabs.members.merge.format = [Boolean]

View File

@ -0,0 +1,236 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ContentTypeCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.ui.panels.CompareFilter;
import com.arsdigita.cms.contenttypes.ui.panels.Paginator;
import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentProjectsTab implements GenericOrgaUnitTab {
private final Logger logger = Logger.getLogger(
SciDepartmentProjectsTab.class);
private static final SciDepartmentProjectsTabConfig config =
new SciDepartmentProjectsTabConfig();
private static final String STATUS_PARAM = "projectStatus";
private static final String TITLE_PARAM = "projectTitle";
private final CompareFilter statusFilter = new CompareFilter(STATUS_PARAM,
"projectEnd",
false,
false,
true);
private final TextFilter titleFilter = new TextFilter(TITLE_PARAM,
ContentPage.TITLE);
static {
config.load();
}
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
final ContentTypeCollection types = ContentType.getAllContentTypes();
types.addFilter(
"associatedObjectType = 'com.arsdigita.cms.contenttypes.SciProject'");
if (types.size() == 0) {
return false;
}
types.close();
final boolean result = !getData(orgaunit).isEmpty();
logger.debug(String.format("Needed %d ms to determine if department "
+ "'%s' has projects.",
System.currentTimeMillis() - start,
orgaunit.getName()));
return result;
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final DataQuery projects = getData(orgaunit);
final HttpServletRequest request = state.getRequest();
final Element depProjectsElem = parent.newChildElement(
"departmentProjects");
final Element filtersElem = depProjectsElem.newChildElement(
"filters");
statusFilter.generateXml(filtersElem);
if (((request.getParameter(STATUS_PARAM) == null)
|| (request.getParameter(STATUS_PARAM).trim().isEmpty()))
&& ((request.getParameter(TITLE_PARAM) == null)
|| request.getParameter(TITLE_PARAM).trim().isEmpty())) {
depProjectsElem.newChildElement("greeting");
projects.addOrder("projectBegin");
projects.addOrder("title");
projects.setRange(1, config.getGreetingSize() + 1);
titleFilter.generateXml(filtersElem);
} else {
projects.addOrder("title");
applyStatusFilter(projects, request);
applyTitleFilter(projects, request);
final Paginator paginator = new Paginator(request,
(int) projects.size(),
config.getPageSize());
if (paginator.getPageCount() > config.getEnableSearchLimit()) {
titleFilter.generateXml(filtersElem);
}
paginator.applyLimits(projects);
paginator.generateXml(depProjectsElem);
}
while (projects.next()) {
generateProjectXml((BigDecimal) projects.get("projectId"),
depProjectsElem,
state);
}
logger.debug(String.format("Generated projects list of department '%s' "
+ "in %d ms.",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format(
"This tab can only process instances of "
+ "'com.arsdigita.cms.contenttypes.SciDepartment'. Provided "
+ "object is of type '%s'",
orgaunit.getClass().getName()));
}
final DataQuery projectsQuery = SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes. getIdsOfProjectsOfOrgaUnit");
final StringBuffer projectsFilter = new StringBuffer();
if (config.isMergingProjects()) {
final DataQuery subDepartmentsQuery =
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType");
subDepartmentsQuery.setParameter("orgaunitId",
orgaunit.getID().toString());
subDepartmentsQuery.setParameter("assocType",
SciDepartmentSubDepartmentsStep.ASSOC_TYPE);
while (subDepartmentsQuery.next()) {
if (projectsFilter.length() > 0) {
projectsFilter.append(" or ");
}
projectsFilter.append(String.format("orgaunitId = %s",
subDepartmentsQuery.get(
"orgaunitId").toString()));
}
} else {
projectsFilter.append(String.format("orgaunitId = %s",
orgaunit.getID().toString()));
}
projectsQuery.addFilter(projectsFilter.toString());
logger.debug(String.format(
"Got projects of department '%s'"
+ "in '%d ms'. MergeProjects is set to '%b'.",
orgaunit.getName(),
System.currentTimeMillis() - start,
config.isMergingProjects()));
return projectsQuery;
}
private void applyStatusFilter(final DataQuery projects,
final HttpServletRequest request) {
final String statusValue = request.getParameter(STATUS_PARAM);
if ((statusValue != null) && !(statusValue.trim().isEmpty())) {
statusFilter.setValue(statusValue);
}
projects.addFilter(statusFilter.getFilter());
}
private void applyTitleFilter(final DataQuery projects,
final HttpServletRequest request) {
final String titleValue = request.getParameter(TITLE_PARAM);
if ((titleValue != null) && !(titleValue.trim().isEmpty())) {
titleFilter.setValue(titleValue);
}
projects.addFilter(titleFilter.getFilter());
}
private void generateProjectXml(final BigDecimal projectId,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final ContentPage project = (ContentPage) DomainObjectFactory.
newInstance(new OID(
"com.arsdigita.cms.contenttypes.SciProject", projectId));
logger.debug(String.format("Got domain object for project '%s' "
+ "in %d ms.",
project.getName(),
System.currentTimeMillis() - start));
generateProjectXml(project, parent, state);
}
private void generateProjectXml(final ContentPage project,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(project);
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for project '%s' in %d ms.",
project.getName(),
System.currentTimeMillis() - start));
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;
public XmlGenerator(final ContentItem item) {
super();
this.item = item;
}
@Override
protected ContentItem getContentItem(final PageState state) {
return item;
}
}
}

View File

@ -0,0 +1,68 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentProjectsTabConfig extends AbstractConfig {
private final Parameter greetingSize;
private final Parameter pageSize;
private final Parameter enableSearchLimit;
private final Parameter mergeProjects;
public SciDepartmentProjectsTabConfig() {
greetingSize =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.greeting_number",
Parameter.REQUIRED,
10);
pageSize =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.page_size",
Parameter.REQUIRED,
30);
enableSearchLimit =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.enable_search_limit",
Parameter.REQUIRED,
2);
mergeProjects =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartments.tabs.projects.merge",
Parameter.REQUIRED,
Boolean.TRUE);
register(greetingSize);
register(pageSize);
register(enableSearchLimit);
register(mergeProjects);
loadInfo();
}
public final int getGreetingSize() {
return (Integer) get(greetingSize);
}
public final int getPageSize() {
return (Integer) get(pageSize);
}
public final int getEnableSearchLimit() {
return (Integer) get(enableSearchLimit);
}
public final boolean isMergingProjects() {
return (Boolean) get(mergeProjects);
}
}

View File

@ -0,0 +1,19 @@
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.greeting_number.title = Greeting size
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.greeting_number.purpose = Number of projects to show when no a user visits the page with no search parameters set. The projects shown are the n newest projects (determined by begin and end of the projects). Set the 0 to disable the greeting and show a complete list of current projects instead.
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.greeting_number.example = 10
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.greeting_number.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.page_size.title = Page size
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.page_size.purpose = Maximum number of projects on one page
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.page_size.example = 30
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.page_size.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.enable_search_limit.title = Search limit
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.enable_search_limit.purpose = Below this limit (number of pages) no search for titles is visible
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.enable_search_limit.example = 2
com.arsdigita.cms.contenttypes.scidepartment.tabs.projects.enable_search_limit.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartments.tabs.projects.merge.title = Merge projects?
com.arsdigita.cms.contenttypes.scidepartments.tabs.projects.merge.purpose = Merge the projects of the department and its sub departments into one list?
com.arsdigita.cms.contenttypes.scidepartments.tabs.projects.merge.example = true
com.arsdigita.cms.contenttypes.scidepartments.tabs.projects.merge.format = [Boolean]

View File

@ -0,0 +1,343 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ContentTypeCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.contenttypes.ui.panels.Paginator;
import com.arsdigita.cms.contenttypes.ui.panels.SelectFilter;
import com.arsdigita.cms.contenttypes.ui.panels.TextFilter;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentPublicationsTab implements GenericOrgaUnitTab {
private final Logger logger = Logger.getLogger(
SciDepartmentPublicationsTab.class);
private static final SciDepartmentPublicationsTabConfig config =
new SciDepartmentPublicationsTabConfig();
private static final String YEAR_PARAM = "year";
private static final String TITLE_PARAM = "title";
private static final String AUTHOR_PARAM = "author";
private static final String SORT_PARAM = "sortBy";
private static final String SORT_BY_YEAR_ASC = "yearAsc";
private static final String SORT_BY_YEAR_DESC = "yearDesc";
private static final String SORT_BY_TITLE = "title";
private static final String SORT_BY_AUTHOR = "author";
private final SelectFilter yearFilter = new SelectFilter(YEAR_PARAM,
YEAR_PARAM,
true,
false,
false,
true);
private final TextFilter titleFilter = new TextFilter(TITLE_PARAM,
ContentPage.TITLE);
private final TextFilter authorFilter;
static {
config.load();
}
public SciDepartmentPublicationsTab() {
super();
if (config.getOneRowPerAuthor()) {
authorFilter = new TextFilter(AUTHOR_PARAM, "authorSurname");
} else {
authorFilter = new TextFilter(AUTHOR_PARAM, "authors");
}
}
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
final ContentTypeCollection types = ContentType.getAllContentTypes();
types.addFilter(
"associatedObjectType = 'com.arsdigita.cms.contenttypes.Publication'");
if (types.size() == 0) {
return false;
}
types.close();
final boolean result = !getData(orgaunit).isEmpty();
logger.debug(String.format("Needed %d ms to determine if department "
+ "'%s' has publications.",
System.currentTimeMillis() - start,
orgaunit.getName()));
return result;
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final DataQuery publications = getData(orgaunit);
final HttpServletRequest request = state.getRequest();
final Element depPublicationsElem = parent.newChildElement(
"departmentPublications");
final String yearValue = request.getParameter(YEAR_PARAM);
final String titleValue = request.getParameter(TITLE_PARAM);
final String authorValue = request.getParameter(AUTHOR_PARAM);
final String sortValue = request.getParameter(SORT_PARAM);
final Element filtersElem = depPublicationsElem.newChildElement(
"filters");
if (((yearValue == null) || yearValue.trim().isEmpty())
&& ((titleValue == null) || titleValue.trim().isEmpty())
&& ((authorValue == null) || authorValue.trim().isEmpty())
&& ((sortValue == null) || sortValue.trim().isEmpty())) {
depPublicationsElem.newChildElement("greeting");
publications.addOrder("year");
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("title");
publications.setRange(1, config.getGreetingSize() + 1);
yearFilter.generateXml(filtersElem);
titleFilter.generateXml(filtersElem);
authorFilter.generateXml(filtersElem);
} else {
if (SORT_BY_AUTHOR.equals(sortValue)) {
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("title");
publications.addOrder("year asc");
} else if (SORT_BY_TITLE.equals(sortValue)) {
publications.addOrder("title");
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("year asc");
} else if (SORT_BY_YEAR_ASC.equals(sortValue)) {
publications.addOrder("year asc");
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("title");
} else if (SORT_BY_YEAR_DESC.equals(sortValue)) {
publications.addOrder("year desc");
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("title");
} else {
if (config.getOneRowPerAuthor()) {
publications.addOrder("surname");
} else {
publications.addOrder("authors");
}
publications.addOrder("title");
publications.addOrder("year asc");
}
applyYearFilter(publications, request);
applyTitleFilter(publications, request);
applyAuthorFilter(publications, request);
final Paginator paginator = new Paginator(request,
(int) publications.size(),
config.getPageSize());
if (paginator.getPageCount() > config.getEnableSearchLimit()) {
yearFilter.generateXml(filtersElem);
titleFilter.generateXml(filtersElem);
authorFilter.generateXml(filtersElem);
}
paginator.applyLimits(publications);
paginator.generateXml(depPublicationsElem);
}
final Element sortFieldsElem = depPublicationsElem.newChildElement(
"sortFields");
sortFieldsElem.addAttribute("sortBy", sortValue);
sortFieldsElem.newChildElement("sortField").addAttribute("label",
SORT_BY_AUTHOR);
sortFieldsElem.newChildElement("sortField").addAttribute("label",
SORT_BY_TITLE);
sortFieldsElem.newChildElement("sortField").addAttribute("label",
SORT_BY_YEAR_ASC);
sortFieldsElem.newChildElement("sortField").addAttribute("label",
SORT_BY_YEAR_DESC);
while (publications.next()) {
generatePublicationXml(
(BigDecimal) publications.get("publicationId"),
(String) publications.get("objectType"),
depPublicationsElem,
state);
}
logger.debug(String.format("Generated publications list of department '%s' "
+ "in %d ms.",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
final long start = System.currentTimeMillis();
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format(
"This tab can only process instances of "
+ "'com.arsdigita.cms.contenttypes.SciDepartment'. Provided "
+ "object is of type '%s'",
orgaunit.getClass().getName()));
}
final DataQuery publicationsQuery;
if (config.getOneRowPerAuthor()) {
publicationsQuery =
SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfPublicationsForOrgaUnitOneRowPerAuthor");
} else {
publicationsQuery =
SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfPublicationsForOrgaUnit");
}
final StringBuffer publicationsFilter = new StringBuffer();
if (config.isMergingPublications()) {
final DataQuery subDepartmentsQuery =
SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType");
subDepartmentsQuery.setParameter("orgaunitId",
orgaunit.getID().toString());
subDepartmentsQuery.setParameter("assocType",
SciDepartmentSubDepartmentsStep.ASSOC_TYPE);
while (subDepartmentsQuery.next()) {
if (publicationsFilter.length() > 0) {
publicationsFilter.append(" or ");
}
publicationsFilter.append(String.format("orgaunitId = %s",
subDepartmentsQuery.get(
"orgaunitId").toString()));
}
} else {
publicationsFilter.append(String.format("orgaunitId = %s",
orgaunit.getID().toString()));
}
publicationsQuery.addFilter(publicationsFilter.toString());
logger.debug(String.format(
"Got publications of department '%s'"
+ "in '%d ms'. MergeProjects is set to '%b'.",
orgaunit.getName(),
System.currentTimeMillis() - start,
config.isMergingPublications()));
return publicationsQuery;
}
private void applyYearFilter(final DataQuery publications,
final HttpServletRequest request) {
final String yearValue = request.getParameter(YEAR_PARAM);
if ((yearValue != null) && !(yearValue.trim().isEmpty())) {
yearFilter.setValue(yearValue);
}
publications.addFilter(yearFilter.getFilter());
}
private void applyTitleFilter(final DataQuery publications,
final HttpServletRequest request) {
final String titleValue = request.getParameter(TITLE_PARAM);
if ((titleValue != null) && !(titleValue.trim().isEmpty())) {
titleFilter.setValue(titleValue);
}
publications.addFilter(titleFilter.getFilter());
}
private void applyAuthorFilter(final DataQuery publications,
final HttpServletRequest request) {
final String authorValue = request.getParameter(AUTHOR_PARAM);
if ((authorValue != null) && !(authorValue.trim().isEmpty())) {
authorFilter.setValue(authorValue);
}
publications.addFilter(authorFilter.getFilter());
}
private void generatePublicationXml(final BigDecimal publicationId,
final String objectType,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final ContentPage publication = (ContentPage) DomainObjectFactory.
newInstance(new OID(objectType, publicationId));
logger.debug(String.format("Got domain object for publication '%s' "
+ "in %d ms.",
publication.getName(),
System.currentTimeMillis() - start));
generatePublicationXml(publication, parent, state);
}
private void generatePublicationXml(final ContentPage publication,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(publication);
generator.generateXML(state, parent, "");
logger.debug(String.format(
"Generated XML for publication '%s' in %d ms.",
publication.getName(),
System.currentTimeMillis() - start));
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;
public XmlGenerator(final ContentItem item) {
super();
this.item = item;
}
@Override
protected ContentItem getContentItem(final PageState state) {
return item;
}
}
}

View File

@ -0,0 +1,80 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentPublicationsTabConfig extends AbstractConfig {
private final Parameter greetingSize;
private final Parameter pageSize;
private final Parameter enableSearchLimit;
private final Parameter mergePublications;
private final Parameter oneRowPerAuthor;
public SciDepartmentPublicationsTabConfig() {
greetingSize =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.greeting_number",
Parameter.REQUIRED,
10);
pageSize =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.page_size",
Parameter.REQUIRED,
30);
enableSearchLimit =
new IntegerParameter(
"com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.enable_search_limit",
Parameter.REQUIRED,
2);
mergePublications =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.merge",
Parameter.REQUIRED,
Boolean.TRUE);
oneRowPerAuthor =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.one_row_per_author",
Parameter.REQUIRED,
Boolean.FALSE);
register(greetingSize);
register(pageSize);
register(enableSearchLimit);
register(mergePublications);
register(oneRowPerAuthor);
loadInfo();
}
public final int getGreetingSize() {
return (Integer) get(greetingSize);
}
public final int getPageSize() {
return (Integer) get(pageSize);
}
public final int getEnableSearchLimit() {
return (Integer) get(enableSearchLimit);
}
public final boolean isMergingPublications() {
return (Boolean) get(mergePublications);
}
public final boolean getOneRowPerAuthor() {
return (Boolean) get(oneRowPerAuthor);
}
}

View File

@ -0,0 +1,25 @@
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.greeting_number.title = Greeting size
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.greeting_number.purpose = Number of publications to show when no a user visits the page with no search parameters set. The publications shown are the n newest publications (determined by begin and end of the publications). Set the 0 to disable the greeting and show a complete list of current publications instead.
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.greeting_number.example = 10
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.greeting_number.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.page_size.title = Page size
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.page_size.purpose = Maximum number of publications on one page
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.page_size.example = 30
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.page_size.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.enable_search_limit.title = Search limit
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.enable_search_limit.purpose = Below this limit (number of pages) no search for titles is visible
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.enable_search_limit.example = 2
com.arsdigita.cms.contenttypes.scidepartment.tabs.publications.enable_search_limit.format = [Integer]
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.merge.title = Merge publications?
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.merge.purpose = Merge the publications of the department and its sub departments into one list?
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.merge.example = true
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.merge.format = [Boolean]
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.one_row_per_author.title = One row per author?
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.one_row_per_author.purpose = If set to true, the list of publications will contain each publication n times, where n is the number of authors. Only used if the list of publications is sorted by the authors.
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.one_row_per_author.example = false
com.arsdigita.cms.contenttypes.scidepartments.tabs.publications.one_row_per_author.format = [Boolean]

View File

@ -0,0 +1,228 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
private final Logger logger =
Logger.getLogger(SciDepartmentSummaryTab.class);
private final static SciDepartmentSummaryTabConfig config =
new SciDepartmentSummaryTabConfig();
static {
config.load();
}
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
//Some of the the data shown by this tab will ever be there
return true;
}
public void generateXml(final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format(
"This tab can only process instances of SciDpartment."
+ "The provided object is of type '%s',",
orgaunit.getClass().getName()));
}
final long start = System.currentTimeMillis();
final SciDepartment department = (SciDepartment) orgaunit;
final Element departmentSummaryElem = parent.newChildElement(
"departmentSummary");
generateShortDescXml(department, departmentSummaryElem);
if (config.isShowingHead()) {
generateHeadOfDepartmentXml(department, departmentSummaryElem, state);
}
if (config.isShowingHead()) {
generateSubDepartmentsXml(department, departmentSummaryElem, state);
}
logger.debug(String.format("Generated XML for summary tab of department "
+ "'%s' in %d ms.",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
protected void generateShortDescXml(final SciDepartment department,
final Element parent) {
final long start = System.currentTimeMillis();
if ((department != null)
&& !department.getDepartmentShortDescription().trim().isEmpty()) {
final Element shortDescElem = parent.newChildElement("shortDesc");
shortDescElem.setText(department.getDepartmentShortDescription());
}
logger.debug(String.format("Generated short desc XML for department '%s' "
+ "in %d ms",
department.getName(),
System.currentTimeMillis() - start));
}
protected void generateHeadOfDepartmentXml(final SciDepartment department,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final String headRoleStr = config.getHeadRole();
final String activeStatusStr = config.getActiveStatus();
final String[] headRoles = headRoleStr.split(",");
final String[] activeStatuses = activeStatusStr.split(",");
final StringBuffer roleFilter = new StringBuffer();
for (String headRole : headRoles) {
if (roleFilter.length() > 0) {
roleFilter.append(',');
}
roleFilter.append(String.format("%s = '%s'",
GenericOrganizationalUnitPersonCollection.LINK_PERSON_ROLE,
headRole));
}
final StringBuffer statusFilter = new StringBuffer();
for (String activeStatus : activeStatuses) {
if (statusFilter.length() > 0) {
statusFilter.append(",");
}
statusFilter.append(String.format("%s = '%s'",
GenericOrganizationalUnitPersonCollection.LINK_STATUS,
activeStatus));
}
final Element headsElem = parent.newChildElement("heads");
final GenericOrganizationalUnitPersonCollection heads = department.
getPersons();
heads.addFilter(roleFilter.toString());
heads.addFilter(statusFilter.toString());
heads.addOrder("surname");
heads.addOrder("givenname");
while (heads.next()) {
generateMemberXml(heads.getPerson(), headsElem, state);
}
logger.debug(String.format("Generated head of department XML for department '%s' "
+ "in %d ms",
department.getName(),
System.currentTimeMillis() - start));
}
protected void generateSubDepartmentsXml(final SciDepartment department,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final GenericOrganizationalUnitSubordinateCollection subDepartments =
department.
getSubordinateOrgaUnits();
subDepartments.addFilter(
String.format("%s = '%s",
GenericOrganizationalUnitSubordinateCollection.LINK_ASSOCTYPE,
SciDepartmentSubDepartmentsStep.ASSOC_TYPE));
final Element subDepsElem = parent.newChildElement("subDepartments");
while (subDepartments.next()) {
generateSubDepartmentXml(
subDepartments.getGenericOrganizationalUnit(),
subDepsElem,
state);
}
logger.debug(String.format("Generated sub departments XML for department '%s' "
+ "in %d ms",
department.getName(),
System.currentTimeMillis() - start));
}
protected void generateSubDepartmentXml(
final GenericOrganizationalUnit orgaunit,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format("Can't process "
+ "orgaunit '%s' as sub department because the orgaunit is "
+ "not a SciDepartment but of type '%s'.",
orgaunit.getName(),
orgaunit.getClass().getName()));
}
final SciDepartment subDepartment = (SciDepartment) orgaunit;
final Element subDepElem = parent.newChildElement("subDepartment");
subDepElem.addAttribute("oid", subDepartment.getOID().toString());
final Element nameElem = subDepElem.newChildElement("title");
nameElem.setText(subDepartment.getTitle());
generateHeadOfDepartmentXml(subDepartment, subDepElem, state);
logger.debug(String.format("Generated XML for sub department '%s' "
+ "in %d ms",
orgaunit.getName(),
System.currentTimeMillis() - start));
}
protected void generateMemberXml(final BigDecimal memberId,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final GenericPerson member = new GenericPerson(memberId);
logger.debug(String.format("Got domain object for member '%s' "
+ "in %d ms.",
member.getFullName(),
System.currentTimeMillis() - start));
generateMemberXml(member, parent, state);
}
protected void generateMemberXml(final GenericPerson member,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(member);
generator.setUseExtraXml(false);
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for member '%s' in %d ms.",
member.getFullName(),
System.currentTimeMillis() - start));
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;
public XmlGenerator(final ContentItem item) {
super();
this.item = item;
}
@Override
protected ContentItem getContentItem(final PageState state) {
return item;
}
}
}

View File

@ -0,0 +1,67 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class SciDepartmentSummaryTabConfig extends AbstractConfig {
private final Parameter showHeads;
private final Parameter headRole;
private final Parameter activeStatus;
private final Parameter showSubDepartments;
public SciDepartmentSummaryTabConfig() {
showHeads =
new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.show",
Parameter.REQUIRED,
true);
headRole =
new StringParameter(
"com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.role",
Parameter.REQUIRED,
"head");
activeStatus = new StringParameter(
"com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.status.active",
Parameter.REQUIRED,
"active");
showSubDepartments = new BooleanParameter(
"com.arsdigita.cms.contenttypes.scidepartment.summarytab.subdepartments.show",
Parameter.REQUIRED,
true);
register(showHeads);
register(headRole);
register(activeStatus);
register(showSubDepartments);
loadInfo();
}
public final boolean isShowingHead() {
return (Boolean) get(showHeads);
}
public final String getHeadRole() {
return (String) get(headRole);
}
public final String getActiveStatus() {
return (String) get(activeStatus);
}
public final boolean isShowingSubDepartment() {
return (Boolean) get(showSubDepartments);
}
}

View File

@ -0,0 +1,14 @@
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.show.title = Show heads of department in summary tab?
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.show.purpose = Show heads of department in summary tab?
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.show.example = true
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.show.format = [Boolean]
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.role = Role of the heads of the department
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.role = Role of the heads of the department. This is an attribute of the association between GenericOrganizationalUnit and GenericPerson. This value may contains more than value, separated by ','.
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.role = active,heading
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.role = [String]
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.status.active = Status of active members
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.status.active = Status of the active members of the department. Used to filter out former heads. This is an attribute of the association between GenericOrganizationalUnit and GenericPerson. This value may contains more than value, separated by ','.
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.status.active = former,formerHead
com.arsdigita.cms.contenttypes.scidepartment.summarytab.heads.status.active = [String]

View File

@ -20,78 +20,102 @@ object type SciProject extends GenericOrganizationalUnit {
}
query getIdsOfContactsOfSciProject {
BigDecimal contactId;
do {
select cms_organizationalunits_contact_map.contact_id
from cms_organizationalunits_contact_map
where cms_organizationalunits_contact_map.organizationalunit_id = :project
} map {
contactId = cms_organizationalunits_contact_map.contact_id;
}
}
query getIdsOfSubProjectsOfSciProject {
query getIdsOfProjectsOfOrgaUnit {
BigDecimal projectId;
BigDecimal orgaunitId;
String title;
Date projectBegin;
Date projectEnd;
do {
select cms_organizationalunit_hierarchy_map.subordinate_orgaunit_id
from cms_organizationalunit_hierarchy_map
where cms_organizationalunit_hierarchy_map.superior_orgaunit_id = :project
and cms_organizationalunit_hierarchy_map.assoc_type = 'subproject'
select distinct on (ct_sci_projects.project_id) ct_sci_projects.project_id, cms_pages.title, ct_sci_projects.projectbegin, ct_sci_projects.projectend, cms_organizationalunits_hierarchy_map.superior_orgaunit_id
from ct_sci_projects
join cms_pages on ct_sci_project.project_id = cms_pages.item_id
join cms_organizationalunits_hierarchy_map on ct_sci_projects = cms_organizationalunits_hierarchy_map.subordinate_orgaunit_id
where cms_organizationalunits_hierarchy_map.assoc_type = 'ProjectOf'
} map {
projectId = ct_sciorga_projects_subprojects_map.project_id;
projectId = ct_sci_projects.project_id;
orgaunitId = cms_organizationalunits_hierarchy_map.superior_orgaunit_id;
title = cms_pages.title;
projectBegin = ct_sci_projects.projectbegin;
projectEnd = ct_sci_projects.projectend;
}
}
query getIdsOfMembersOfSciProject {
BigDecimal memberId;
// Some queries from old SciProjects, from ccm-sci-types-organization module
//Not used anywhere. Kept for reference.
//query getIdsOfContactsOfSciProject {
// BigDecimal contactId;
//
// do {
// select cms_organizationalunits_contact_map.contact_id
// from cms_organizationalunits_contact_map
// where cms_organizationalunits_contact_map.organizationalunit_id = :project
// } map {
// contactId = cms_organizationalunits_contact_map.contact_id;
// }
//}
do {
select cms_organizationalunits_person_map.person_id
from cms_organizationalunits_person_map
where cms_organizationalunits_person_map.organizationalunit_id = :project
} map {
memberId = cms_organizationalunits_person_map.person_id;
}
}
//query getIdsOfSubProjectsOfSciProject {
// BigDecimal projectId;
//
// do {
// select cms_organizationalunit_hierarchy_map.subordinate_orgaunit_id
// from cms_organizationalunit_hierarchy_map
// where cms_organizationalunit_hierarchy_map.superior_orgaunit_id = :project
// and cms_organizationalunit_hierarchy_map.assoc_type = 'subproject'
// } map {
// projectId = ct_sciorga_projects_subprojects_map.project_id;
// }
//}
query getIdsOfActiveMembersOfSciProject {
BigDecimal memberId;
//query getIdsOfMembersOfSciProject {
// BigDecimal memberId;
//
// do {
// select cms_organizationalunits_person_map.person_id
// from cms_organizationalunits_person_map
// where cms_organizationalunits_person_map.organizationalunit_id = :project
// } map {
// memberId = cms_organizationalunits_person_map.person_id;
// }
//}
do {
select cms_organizationalunits_person_map.person_id
from cms_organizationalunits_person_map
where cms_organizationalunits_person_map.organizationalunit_id = :project
and cms_organizationalunits_person_map.status = 'active'
} map {
memberId = cms_organizationalunits_person_map.person_id;
}
}
//query getIdsOfActiveMembersOfSciProject {
// BigDecimal memberId;
//
// do {
// select cms_organizationalunits_person_map.person_id
// from cms_organizationalunits_person_map
// where cms_organizationalunits_person_map.organizationalunit_id = :project
// and cms_organizationalunits_person_map.status = 'active'
// } map {
// memberId = cms_organizationalunits_person_map.person_id;
// }
//}
//
//query getIdsOfAssociatedMembersOfSciProject {
// BigDecimal memberId;
//
// do {
// select cms_organizationalunits_person_map.person_id
// from cms_organizationalunits_person_map
// where cms_organizationalunits_person_map.organizationalunit_id = :project
// and cms_organizationalunits_person_map.status = 'associated'
// } map {
// memberId = cms_organizationalunits_person_map.personId;
//// }
//}
query getIdsOfAssociatedMembersOfSciProject {
BigDecimal memberId;
do {
select cms_organizationalunits_person_map.person_id
from cms_organizationalunits_person_map
where cms_organizationalunits_person_map.organizationalunit_id = :project
and cms_organizationalunits_person_map.status = 'associated'
} map {
memberId = cms_organizationalunits_person_map.personId;
}
}
query getIdsOfFormerMembersOfSciProject {
BigDecimal memberId;
do {
select cms_organizationalunits_person_map.cms_persons.person_id
from cms_organizationalunits_person_map
where cms_organizationalunits_person_map.organizationalunit_id = :project
and (cms_organizationalunits_person_map.status = 'former' or cms_organizationalunits_person_map.status = 'associatedFormer')
} map {
memberId = cms_organizationalunits_person_map.personId;
}
}
//query getIdsOfFormerMembersOfSciProject {
// BigDecimal memberId;
//
// do {
// select cms_organizationalunits_person_map.cms_persons.person_id
// from cms_organizationalunits_person_map
// where cms_organizationalunits_person_map.organizationalunit_id = :project
// and (cms_organizationalunits_person_map.status = 'former' or cms_organizationalunits_person_map.status = 'associatedFormer')
// } map {
// memberId = cms_organizationalunits_person_map.personId;
// }
//}

View File

@ -184,7 +184,9 @@ public class SciProject extends GenericOrganizationalUnit {
set(FUNDING_VOLUME, fundingVolume);
}
@Override
/*Method is not use commented out.
* @Override
public boolean hasContacts() {
boolean result = false;
@ -202,16 +204,16 @@ public class SciProject extends GenericOrganizationalUnit {
query.close();
return result;
}
}*/
/**
*
/*
* Not used anywhere
* @param merge Should I also look into the projects and return true
* if the organization or at least one of the projects has members?
* @param status
* @return
*/
public boolean hasMembers(final boolean merge,
/*public boolean hasMembers(final boolean merge,
final SciProjectMemberStatus status) {
String queryName;
@ -276,9 +278,9 @@ public class SciProject extends GenericOrganizationalUnit {
return false;
}
}
}
}*/
private boolean hasMembers(final BigDecimal projectId,
/*private boolean hasMembers(final BigDecimal projectId,
final boolean merge,
final SciProjectMemberStatus status) {
String queryName;
@ -344,7 +346,7 @@ public class SciProject extends GenericOrganizationalUnit {
return false;
}
}
}
}*/
@Override
public List<ExtraXMLGenerator> getExtraXMLGenerators() {

View File

@ -4,7 +4,6 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.SciProject;
import com.arsdigita.xml.Element;
import com.redhat.persistence.pdl.adapters.ShortAd;
import org.apache.log4j.Logger;
/**
@ -24,7 +23,7 @@ public class SciProjectDescTab implements GenericOrgaUnitTab {
if (desc.getDesc() == null) {
result = false;
} else {
result = !desc.getDesc().isEmpty();
result = !desc.getDesc().trim().isEmpty();
}
logger.debug(String.format("Needed %d ms to determine if project '%s' "

View File

@ -84,9 +84,8 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
* @param project
* @param parent
*/
protected void generateBasicDataXml(
final SciProject project,
final Element parent) {
protected void generateBasicDataXml(final SciProject project,
final Element parent) {
final long start = System.currentTimeMillis();
if ((project.getAddendum() != null)
&& !project.getAddendum().trim().isEmpty()) {
@ -154,8 +153,8 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
}
personsQuery.addFilter(personsFilter.toString());
personsQuery.addOrder("surname");
personsQuery.addOrder("givenname");
personsQuery.addOrder(GenericPerson.SURNAME);
personsQuery.addOrder(GenericPerson.GIVENNAME);
while (personsQuery.next()) {
generateMemberXml((BigDecimal) personsQuery.get("memberId"),
@ -243,23 +242,26 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final GenericOrganizationalUnitSuperiorCollection orgas = project.getSuperiorOrgaUnits();
final GenericOrganizationalUnitSuperiorCollection orgas = project.
getSuperiorOrgaUnits();
if (orgas == null) {
return;
}
orgas.addFilter(String.format("link.assocType = '%s'",
SciProjectInvolvedOrganizationsStep.ASSOC_TYPE));
orgas.addFilter(
String.format("link.assocType = '%s'",
SciProjectInvolvedOrganizationsStep.ASSOC_TYPE));
if (orgas.isEmpty()) {
return;
}
final Element involvedElem = parent.newChildElement("involvedOrganizations");
while(orgas.next()) {
generateInvolvedOrgaXml(orgas.getGenericOrganizationalUnit(),
involvedElem,
final Element involvedElem = parent.newChildElement(
"involvedOrganizations");
while (orgas.next()) {
generateInvolvedOrgaXml(orgas.getGenericOrganizationalUnit(),
involvedElem,
state);
}
logger.debug(String.format("Generated XML for involved organizations "