- Weitere Ergänzungen an GenericOrganizationalUnit und zugehörigen Klassen
- Erste Tabs für SciProject git-svn-id: https://svn.libreccm.org/ccm/trunk@1188 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
85885a777e
commit
094bf7d1ba
|
|
@ -90,6 +90,9 @@ association {
|
|||
Integer[0..1] subordinateOrgaUnitOrder = cms_organizationalunits_hierarchy_map.subordinate_orgaunit_order INTEGER;
|
||||
}
|
||||
|
||||
//Returns the ids of all organizational units which are a subordinate orga unit
|
||||
//of this orga unit of a subordinate orga unit
|
||||
//@param orgaunitId The id of the organizational unit to start with
|
||||
query getIdsOfSubordinateOrgaUnitsRecursivly{
|
||||
BigDecimal orgaunitId;
|
||||
String orgaunitName;
|
||||
|
|
@ -105,18 +108,22 @@ query getIdsOfSubordinateOrgaUnitsRecursivly{
|
|||
select ou.organizationalunit_id as orgaunit_id,
|
||||
cms_items.name as orgaunit_name
|
||||
from subordinate_orgaunits sou,
|
||||
cms_organizationalunits.organizationalunit_id
|
||||
join cms_items on cms_organizationalunits.organizationalunit_id = cms_items.item_id
|
||||
cms_organizationalunits ou
|
||||
join cms_items on ou.organizationalunit_id = cms_items.item_id
|
||||
join cms_organizationalunits_hierarchy_map on ou.organizationalunit_id = cms_organizationalunits_hierarchy_map.subordinate_orgaunit_id
|
||||
where cms_organizationalunits_hierarchy_map.superior_orgaunit_id = sou.orgaunit_id
|
||||
)
|
||||
select orgaunit_id, orgaunit_name from subordinateOrgaUnits;
|
||||
select orgaunit_id, orgaunit_name from subordinate_orgaunits
|
||||
} map {
|
||||
orgaunitId = subordinate_orgaunits.orgaunit_id;
|
||||
orgaunitName = subordinate_orgaunits.orgaunit_name;
|
||||
}
|
||||
}
|
||||
|
||||
//Same as above but with an addional parameter
|
||||
//@param orgaunitId The id of the organizational unit to start with
|
||||
//@param assocType Include only subordinate orga units with the specified assoc
|
||||
//type
|
||||
query getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType{
|
||||
BigDecimal orgaunitId;
|
||||
String orgaunitName;
|
||||
|
|
@ -132,14 +139,38 @@ query getIdsOfSubordinateOrgaUnitsRecursivlyWithAssocType{
|
|||
select ou.organizationalunit_id as orgaunit_id,
|
||||
cms_items.name as orgaunit_name
|
||||
from subordinate_orgaunits sou,
|
||||
cms_organizationalunits.organizationalunit_id
|
||||
join cms_items on cms_organizationalunits.organizationalunit_id = cms_items.item_id
|
||||
cms_organizationalunits ou
|
||||
join cms_items on ou.organizationalunit_id = cms_items.item_id
|
||||
join cms_organizationalunits_hierarchy_map on ou.organizationalunit_id = cms_organizationalunits_hierarchy_map.subordinate_orgaunit_id
|
||||
where cms_organizationalunits_hierarchy_map.superior_orgaunit_id = sou.orgaunit_id and cms_organizationalunits_hierarchy_map.assoc_type = :assocType
|
||||
)
|
||||
select orgaunit_id, orgaunit_name from subordinateOrgaUnits;
|
||||
select orgaunit_id, orgaunit_name from subordinate_orgaunits
|
||||
} map {
|
||||
orgaunitId = subordinate_orgaunits.orgaunit_id;
|
||||
orgaunitName = subordinate_orgaunits.orgaunit_name;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets the members of several orga units
|
||||
//@param orgaUnitsIds comma separated list of the ids of orga units to include
|
||||
query getIdsOfMembersOfOrgaUnits {
|
||||
BigDecimal memberId;
|
||||
BigDecimal orgaunitId;
|
||||
String surname;
|
||||
String givenname;
|
||||
String roleName;
|
||||
String status;
|
||||
|
||||
do {
|
||||
select distinct on (cms_persons.person_id) cms_persons.person_id, cms_persons.surname, cms_persons.givenname, cms_organizationalunits_person_map.organizationalunit_id, cms_organizationalunits_person_map.role_name, cms_organizationalunits_person_map.status
|
||||
from cms_persons
|
||||
join cms_organizationalunits_person_map on cms_persons.person_id = cms_organizationalunits_person_map.person_id
|
||||
} map {
|
||||
memberId = cms_persons.person_id;
|
||||
orgaunitId = cms_organizationalunits_person_map.organizationalunit_id;
|
||||
surname = cms_persons.surname;
|
||||
givenname = cms_persons.givenname;
|
||||
roleName = cms_organizationalunits_person_map.role_name;
|
||||
status = cms_organizationalunits_person_map.status;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
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.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;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class GenericOrgaUnitMembersTab implements GenericOrgaUnitTab {
|
||||
|
||||
private final static Logger logger =
|
||||
Logger.getLogger(GenericOrgaUnitMembersTab.class);
|
||||
|
||||
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = !getData(orgaunit).isEmpty();
|
||||
logger.debug(String.format(
|
||||
"Needed %d ms to determine if "
|
||||
+ "organizational unit '%s' has members. Merge is set to '%b'.",
|
||||
System.currentTimeMillis() - start,
|
||||
orgaunit.getName(),
|
||||
isMergingMembers()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public void generateXml(final GenericOrganizationalUnit orgaunit,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
final DataQuery persons = getData(orgaunit, state);
|
||||
|
||||
final Element personsElem = parent.newChildElement(getXmlElementName());
|
||||
|
||||
if (getPageSize() != 0) {
|
||||
final GenericOrgaUnitPaginator<DataQuery> paginator =
|
||||
new GenericOrgaUnitPaginator<DataQuery>(
|
||||
persons, state, getPageSize());
|
||||
paginator.setRange(persons);
|
||||
paginator.generateXml(personsElem);
|
||||
}
|
||||
|
||||
while (persons.next()) {
|
||||
generatePersonXml((BigDecimal) persons.get("memberId"),
|
||||
parent,
|
||||
state);
|
||||
}
|
||||
logger.debug(String.format("Generated member list of organizational "
|
||||
+ "unit '%s' in %d ms.",
|
||||
orgaunit.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
private void generatePersonXml(final BigDecimal personId,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final GenericPerson person = new GenericPerson(personId);
|
||||
|
||||
final XmlGenerator generator = new XmlGenerator(person);
|
||||
generator.generateXML(state, parent, "");
|
||||
}
|
||||
|
||||
protected abstract String getXmlElementName();
|
||||
|
||||
protected abstract boolean isMergingMembers();
|
||||
|
||||
protected abstract List<String> getAssocTypesToMerge();
|
||||
|
||||
protected abstract List<String> getRolesToInclude();
|
||||
|
||||
protected abstract List<String> getStatusesToInclude();
|
||||
|
||||
protected abstract int getPageSize();
|
||||
|
||||
protected DataQuery getData(final GenericOrganizationalUnit orgaunit,
|
||||
final PageState state) {
|
||||
return getData(orgaunit);
|
||||
}
|
||||
|
||||
protected DataQuery getData(final GenericOrganizationalUnit orgaunit) {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
final DataQuery personsQuery = SessionManager.getSession().retrieveQuery(
|
||||
"com.arsdigita.cms.contenttypes.getIdsOfMembersOfOrgaUnits");
|
||||
|
||||
if (isMergingMembers()) {
|
||||
final DataQuery subOrgaUnitsQuery =
|
||||
SessionManager.getSession().retrieveQuery(
|
||||
"com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivly");
|
||||
subOrgaUnitsQuery.setParameter("orgaunitId", orgaunit.getID().
|
||||
toString());
|
||||
final StringBuffer assocTypeFilter = new StringBuffer();
|
||||
for (String assocType : getAssocTypesToMerge()) {
|
||||
if (assocTypeFilter.length() > 0) {
|
||||
assocTypeFilter.append(" or ");
|
||||
}
|
||||
assocTypeFilter.append(String.format("assocType = '%s'",
|
||||
assocType));
|
||||
}
|
||||
subOrgaUnitsQuery.addFilter(assocTypeFilter.toString());
|
||||
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
while (subOrgaUnitsQuery.next()) {
|
||||
if (buffer.length() > 0) {
|
||||
buffer.append(" or ");
|
||||
}
|
||||
buffer.append(String.format("orgaunitId = %s",
|
||||
subOrgaUnitsQuery.get("orgaunitId").
|
||||
toString()));
|
||||
}
|
||||
|
||||
personsQuery.addFilter(buffer.toString());
|
||||
} else {
|
||||
personsQuery.addFilter(String.format("orgaunitId = %s",
|
||||
orgaunit.getID().toString()));
|
||||
}
|
||||
|
||||
if ((getRolesToInclude() != null) && !getRolesToInclude().isEmpty()) {
|
||||
final StringBuffer roleFilter = new StringBuffer();
|
||||
for (String role : getRolesToInclude()) {
|
||||
if (roleFilter.length() > 0) {
|
||||
roleFilter.append(" or ");
|
||||
}
|
||||
roleFilter.append(String.format("roleName = '%s'", role));
|
||||
}
|
||||
personsQuery.addFilter(roleFilter.toString());
|
||||
}
|
||||
|
||||
if ((getStatusesToInclude() != null)
|
||||
&& !getStatusesToInclude().isEmpty()) {
|
||||
final StringBuffer statusFilter = new StringBuffer();
|
||||
for (String status : getStatusesToInclude()) {
|
||||
if (statusFilter.length() > 0) {
|
||||
statusFilter.append(" or ");
|
||||
}
|
||||
statusFilter.append(String.format("status = '%s'", status));
|
||||
}
|
||||
personsQuery.addFilter(statusFilter.toString());
|
||||
}
|
||||
|
||||
personsQuery.addOrder("surname");
|
||||
personsQuery.addOrder("givenname");
|
||||
|
||||
logger.debug(String.format(
|
||||
"Got persons for organizational unit '%s'"
|
||||
+ "in %d ms. isMergingMembers is set to '%b'.",
|
||||
orgaunit.getName(),
|
||||
System.currentTimeMillis() - start,
|
||||
isMergingMembers()));
|
||||
return personsQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite to create filters for the list.
|
||||
*
|
||||
* @param orgaunit
|
||||
* @param subOrgaUnits
|
||||
* @param element
|
||||
* @param state
|
||||
*/
|
||||
protected void generateFiltersXml(
|
||||
final GenericOrganizationalUnit orgaunit,
|
||||
final GenericOrganizationalUnitPersonCollection subOrgaUnits,
|
||||
final Element element,
|
||||
final PageState state) {
|
||||
//Nothing now
|
||||
}
|
||||
|
||||
/**
|
||||
* If you have filters for the list of subordinate organizational units,
|
||||
* overwrite this method to process them.
|
||||
*
|
||||
* @param subOrgaUnits
|
||||
* @param state
|
||||
*/
|
||||
protected void processFilters(
|
||||
final GenericOrganizationalUnitPersonCollection subOrgaUnits,
|
||||
final PageState state) {
|
||||
//Nothing now
|
||||
}
|
||||
|
||||
private class XmlGenerator extends SimpleXMLGenerator {
|
||||
|
||||
private final GenericPerson person;
|
||||
|
||||
public XmlGenerator(final GenericPerson person) {
|
||||
super();
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContentItem getContentItem(final PageState state) {
|
||||
return person;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
package com.arsdigita.cms.contenttypes.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.domain.DomainCollection;
|
||||
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 java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper class for generating a paginator in lists generated by
|
||||
|
|
@ -17,7 +16,7 @@ import java.util.Map;
|
|||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GenericOrgaUnitPaginator<T extends DomainCollection> {
|
||||
public class GenericOrgaUnitPaginator<T extends DataQuery> {
|
||||
|
||||
private final static String PAGE_NUMBER = "pageNumber";
|
||||
private final long pageSize;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public abstract class GenericOrgaUnitSubordinateTab
|
|||
final GenericOrganizationalUnit orgaunit,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final SubordinateXmlLGenerator generator = new SubordinateXmlLGenerator(
|
||||
final XmlLGenerator generator = new XmlLGenerator(
|
||||
orgaunit);
|
||||
generator.generateXML(state, parent, "");
|
||||
}
|
||||
|
|
@ -136,11 +136,11 @@ public abstract class GenericOrgaUnitSubordinateTab
|
|||
//Nothing now
|
||||
}
|
||||
|
||||
private class SubordinateXmlLGenerator extends SimpleXMLGenerator {
|
||||
private class XmlLGenerator extends SimpleXMLGenerator {
|
||||
|
||||
private final GenericOrganizationalUnit orgaunit;
|
||||
|
||||
public SubordinateXmlLGenerator(final GenericOrganizationalUnit orgaunit) {
|
||||
public XmlLGenerator(final GenericOrganizationalUnit orgaunit) {
|
||||
super();
|
||||
this.orgaunit = orgaunit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,6 @@
|
|||
<registry>
|
||||
<config class="com.arsdigita.cms.contenttypes.SciProjectConfig"
|
||||
storage="ccm-sci-types-project/sciproject.properties"/>
|
||||
<config class="com.arsdigita.cms.contenttypes.ui.SciProjectSummaryTabConfig"
|
||||
storage="ccm-sci-types-project/summarytab.properties"/>
|
||||
</registry>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||
import com.arsdigita.cms.contenttypes.ui.SciProjectExtraXmlGenerator;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.DataQuery;
|
||||
|
|
@ -7,6 +9,7 @@ import com.arsdigita.persistence.OID;
|
|||
import com.arsdigita.persistence.SessionManager;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -284,4 +287,11 @@ public class SciProject extends GenericOrganizationalUnit {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExtraXMLGenerator> getExtraXMLGenerators() {
|
||||
final List<ExtraXMLGenerator> generators = super.getExtraXMLGenerators();
|
||||
generators.add(new SciProjectExtraXmlGenerator());
|
||||
return generators;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class SciProjectConfig extends AbstractConfig {
|
|||
private final Parameter enableFundingVolume;
|
||||
private final Parameter fundingVolumeLength;
|
||||
private final Parameter permittedPersonType;
|
||||
private final Parameter tabs;
|
||||
|
||||
public SciProjectConfig() {
|
||||
|
||||
|
|
@ -86,6 +87,11 @@ public class SciProjectConfig extends AbstractConfig {
|
|||
"com.arsdigita.cms.contenttypes.sciproject.permitted_person_type",
|
||||
Parameter.REQUIRED,
|
||||
"com.arsdigita.cms.contenttypes.GenericPerson");
|
||||
|
||||
tabs = new StringParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.tabs",
|
||||
Parameter.REQUIRED,
|
||||
"summary:com.arsdigita.cms.contenttypes.ui.SciProjectSummaryTab;desc:com.arsdigita.cms.contenttypes.ui.SciProjectDescTab");
|
||||
|
||||
register(enableSubProjectsStep);
|
||||
register(enableSuperProjectsStep);
|
||||
|
|
@ -98,6 +104,7 @@ public class SciProjectConfig extends AbstractConfig {
|
|||
register(enableFundingVolume);
|
||||
register(fundingVolumeLength);
|
||||
register(permittedPersonType);
|
||||
register(tabs);
|
||||
|
||||
loadInfo();
|
||||
}
|
||||
|
|
@ -147,4 +154,8 @@ public class SciProjectConfig extends AbstractConfig {
|
|||
public final String getPermittedPersonType() {
|
||||
return (String) get(permittedPersonType);
|
||||
}
|
||||
|
||||
public final String getTabs() {
|
||||
return (String) get(tabs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,4 +51,9 @@ com.arsdigita.cms.contenttypes.sciproject.enable_funding_volume_length.format =
|
|||
com.arsdigita.cms.contenttypes.sciproject.permitted_person_type.title = Permitted person type for members of the project
|
||||
com.arsdigita.cms.contenttypes.sciproject.permitted_person_type.purpose = Restrict the selectable persons for adding as member to a subtype of GenericPerson
|
||||
com.arsdigita.cms.contenttypes.sciproject.permitted_person_type.example = com.arsdigita.cms.contenttypes.GenericPerson
|
||||
com.arsdigita.cms.contenttypes.sciproject.permitted_person_type.format = [String]
|
||||
com.arsdigita.cms.contenttypes.sciproject.permitted_person_type.format = [String]
|
||||
|
||||
com.arsdigita.cms.contenttypes.sciproject.tabs.title = Tabs for SciProject detail view
|
||||
com.arsdigita.cms.contenttypes.sciproject.tabs.purpose = Defines which tabs are shown in the detail view of a SciProject
|
||||
com.arsdigita.cms.contenttypes.sciproject.tabs.example = summary:com.arsdigita.cms.contenttypes.ui.SciProjectSummaryTab;desc:com.arsdigita.cms.contenttypes.ui.SciProjectDescTab
|
||||
com.arsdigita.cms.contenttypes.sciproject.tabs.format = [String]
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.arsdigita.cms.contenttypes.ui;
|
||||
|
||||
import com.arsdigita.cms.contenttypes.SciProject;
|
||||
import com.arsdigita.cms.contenttypes.SciProjectConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SciProjectExtraXmlGenerator
|
||||
extends GenericOrgaUnitExtraXmlGenerator {
|
||||
|
||||
@Override
|
||||
public String getTabConfig() {
|
||||
final SciProjectConfig config = SciProject.getConfig();
|
||||
return config.getTabs();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.arsdigita.cms.contenttypes.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SciProjectMembersTab extends GenericOrgaUnitMembersTab {
|
||||
|
||||
@Override
|
||||
protected String getXmlElementName() {
|
||||
return "members";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMergingMembers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getAssocTypesToMerge() {
|
||||
final List<String> assocTypes = new ArrayList<String>();
|
||||
assocTypes.add(SciProjectSubProjectsStep.ASSOC_TYPE);
|
||||
return assocTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageSize() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getRolesToInclude() {
|
||||
final List<String> roles = new ArrayList<String>();
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getStatusesToInclude() {
|
||||
final List<String> statuses = new ArrayList<String>();
|
||||
return statuses;
|
||||
}
|
||||
}
|
||||
|
|
@ -65,3 +65,4 @@ sciorganization.ui.project_properties.title=Basic properties
|
|||
sciorganization.ui.project.members=Members
|
||||
sciorganization.ui.project_description.title=Description
|
||||
sciproject.ui.edit_basic_sheet=Edit basic properties
|
||||
sciproject.ui.members.add=Add member
|
||||
|
|
|
|||
|
|
@ -66,3 +66,4 @@ sciorganization.ui.project_properties.title=Basiseigenschaften
|
|||
sciorganization.ui.project.members=Mitglieder
|
||||
sciorganization.ui.project_description.title=Beschreibung
|
||||
sciproject.ui.edit_basic_sheet=Basiseigenschaften bearbeiten
|
||||
sciproject.ui.members.add=Mitglied hinzuf\u00fcgen
|
||||
|
|
|
|||
|
|
@ -0,0 +1,278 @@
|
|||
package com.arsdigita.cms.contenttypes.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.contenttypes.GenericContact;
|
||||
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
|
||||
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection;
|
||||
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection;
|
||||
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollection;
|
||||
import com.arsdigita.cms.contenttypes.GenericPerson;
|
||||
import com.arsdigita.cms.contenttypes.SciProject;
|
||||
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.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SciProjectSummaryTab implements GenericOrgaUnitTab {
|
||||
|
||||
private final Logger logger = Logger.getLogger(SciProjectSummaryTab.class);
|
||||
private final static SciProjectSummaryTabConfig config =
|
||||
new SciProjectSummaryTabConfig();
|
||||
|
||||
static {
|
||||
config.load();
|
||||
}
|
||||
|
||||
public boolean hasData(final GenericOrganizationalUnit orgaunit) {
|
||||
//Some of 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 SciProject)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"This tab can only process instances of SciProject."
|
||||
+ "The provided object is of type '%s'.",
|
||||
orgaunit.getClass().getName()));
|
||||
}
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
final SciProject project = (SciProject) orgaunit;
|
||||
|
||||
final Element projectSummaryElem = parent.newChildElement(
|
||||
"projectSummary");
|
||||
|
||||
generateBasicDataXml(project, parent);
|
||||
|
||||
if(config.isShowingMembers()) {
|
||||
generateMembersXml(project, parent, state);
|
||||
}
|
||||
|
||||
if (config.isShowingContacts()) {
|
||||
generateContactsXml(project, parent, state);
|
||||
}
|
||||
|
||||
if (config.isShowingSubProjects()) {
|
||||
generateSubProjectsXml(project, parent, state);
|
||||
}
|
||||
|
||||
|
||||
logger.debug(String.format("Generated XML for summary tab of project "
|
||||
+ "'%s' in %d ms.",
|
||||
orgaunit.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the XML for the basic data (addendum, begin, end, shortDesc)
|
||||
* @param project
|
||||
* @param parent
|
||||
*/
|
||||
protected void generateBasicDataXml(
|
||||
final SciProject project,
|
||||
final Element parent) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final Element addendumElem = parent.newChildElement("addendum");
|
||||
if ((project.getAddendum() != null) && !project.getAddendum().isEmpty()) {
|
||||
addendumElem.setText(project.getAddendum());
|
||||
}
|
||||
|
||||
final Element lifeSpanElem = parent.newChildElement("lifeSpan");
|
||||
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
if (project.getBegin() != null) {
|
||||
lifeSpanElem.addAttribute("begin",
|
||||
dateFormat.format(project.getBegin()));
|
||||
}
|
||||
if (project.getEnd() != null) {
|
||||
lifeSpanElem.addAttribute("end",
|
||||
dateFormat.format(project.getEnd()));
|
||||
}
|
||||
|
||||
if ((project.getProjectShortDescription() != null)
|
||||
&& !project.getProjectShortDescription().isEmpty()) {
|
||||
final Element shortDescElem = parent.newChildElement("shortDesc");
|
||||
shortDescElem.setText(project.getProjectShortDescription());
|
||||
}
|
||||
|
||||
logger.debug(String.format("Generated basic data XML for project '%s' "
|
||||
+ "in %d ms",
|
||||
project.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
protected void generateMembersXml(final SciProject project,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
if ((project.getPersons() == null) || project.getPersons().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
while (subProjectsQuery.next()) {
|
||||
if (personsFilter.length() > 0) {
|
||||
personsFilter.append(" or ");
|
||||
}
|
||||
personsFilter.append(String.format("orgaunitId = %s",
|
||||
subProjectsQuery.get(
|
||||
"orgaunitId").toString()));
|
||||
}
|
||||
personsQuery.addFilter(personsFilter.toString());
|
||||
|
||||
personsQuery.addOrder("surname");
|
||||
personsQuery.addOrder("givenname");
|
||||
|
||||
while (personsQuery.next()) {
|
||||
generateMemberXml((BigDecimal) personsQuery.get("memberId"),
|
||||
parent,
|
||||
state);
|
||||
}
|
||||
} else {
|
||||
final GenericOrganizationalUnitPersonCollection members = project.
|
||||
getPersons();
|
||||
|
||||
members.addOrder("surname");
|
||||
members.addOrder("givenname");
|
||||
|
||||
while (members.next()) {
|
||||
generateMemberXml(members.getPerson(), membersElem, state);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug(String.format("Generated members XML for project '%s'"
|
||||
+ "in '%d ms'. MergeMembers is set to '%b'.",
|
||||
project.getName(),
|
||||
System.currentTimeMillis() - start,
|
||||
config.isMergingMembers()));
|
||||
}
|
||||
|
||||
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.generateXML(state, parent, "");
|
||||
logger.debug(String.format("Generated XML for member '%s' in %d ms.",
|
||||
member.getFullName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
protected void generateContactsXml(final SciProject project,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final GenericOrganizationalUnitContactCollection contacts = project.
|
||||
getContacts();
|
||||
|
||||
final Element contactsElem = parent.newChildElement("contacts");
|
||||
|
||||
while (contacts.next()) {
|
||||
generateContactXml(contacts.getContact(), contactsElem, state);
|
||||
}
|
||||
logger.debug(String.format("Generated XML for contacts of project '%s'"
|
||||
+ " in %d ms.",
|
||||
project.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
protected void generateContactXml(final GenericContact contact,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final XmlGenerator generator = new XmlGenerator(contact);
|
||||
generator.generateXML(state, parent, "");
|
||||
logger.debug(String.format("Generated XML for contact '%s' in %d ms.",
|
||||
contact.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
protected void generateSubProjectsXml(final SciProject project,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final GenericOrganizationalUnitSubordinateCollection subProjects =
|
||||
project.
|
||||
getSubordinateOrgaUnits();
|
||||
subProjects.addFilter(
|
||||
String.format("link.assocType = '%s'",
|
||||
SciProjectSubProjectsStep.ASSOC_TYPE));
|
||||
while (subProjects.next()) {
|
||||
generateSubProjectXml(
|
||||
(SciProject) subProjects.getGenericOrganizationalUnit(),
|
||||
parent,
|
||||
state);
|
||||
}
|
||||
logger.debug(String.format("Generated XML for subprojects of "
|
||||
+ "project '%s' in %d ms.",
|
||||
project.getName(),
|
||||
System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
protected void generateSubProjectXml(final SciProject subProject,
|
||||
final Element parent,
|
||||
final PageState state) {
|
||||
final long start = System.currentTimeMillis();
|
||||
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(),
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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.Parameter;
|
||||
|
||||
/**
|
||||
* Configuration for the {@link SciProjectSummaryTab}.
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SciProjectSummaryTabConfig extends AbstractConfig {
|
||||
|
||||
private final Parameter showMembers;
|
||||
private final Parameter mergeMembers;
|
||||
private final Parameter showContacts;
|
||||
private final Parameter showInvolvedOrgas;
|
||||
private final Parameter showSubProjects;
|
||||
|
||||
public SciProjectSummaryTabConfig() {
|
||||
showMembers =
|
||||
new BooleanParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.summarytab.members.show",
|
||||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
mergeMembers =
|
||||
new BooleanParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.summarytab.members.merge",
|
||||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
showContacts =
|
||||
new BooleanParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.summarytab.contacts.show",
|
||||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
showInvolvedOrgas =
|
||||
new BooleanParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.summarytab.involved_orgas.show",
|
||||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
showSubProjects =
|
||||
new BooleanParameter(
|
||||
"com.arsdigita.cms.contenttypes.sciproject.summarytab.subprojects.show",
|
||||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
register(showMembers);
|
||||
register(mergeMembers);
|
||||
register(showContacts);
|
||||
register(showInvolvedOrgas);
|
||||
register(showSubProjects);
|
||||
|
||||
loadInfo();
|
||||
}
|
||||
|
||||
public final boolean isShowingMembers() {
|
||||
return (Boolean) get(showMembers);
|
||||
}
|
||||
|
||||
public final boolean isMergingMembers() {
|
||||
return (Boolean) get(mergeMembers);
|
||||
}
|
||||
|
||||
public final boolean isShowingContacts() {
|
||||
return (Boolean) get(showContacts);
|
||||
}
|
||||
|
||||
public final boolean isShowingInvolvedOrgas() {
|
||||
return (Boolean) get(showInvolvedOrgas);
|
||||
}
|
||||
|
||||
public final boolean isShowingSubProjects() {
|
||||
return (Boolean) get(showSubProjects);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.show.title = Show members of project?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.show.purpose = Show members of project?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.show.example = true
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.show.format = [Boolean]
|
||||
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.merge.title = Merge members of the project and its subprojects?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.merge.purpose = Merge members of the project and its subprojects?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.merge.example = true
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.members.merge.format = [Boolean]
|
||||
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.contacts.show.title = Show contacts?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.contacts.show.purpose = Show contacts?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.contacts.show.example = true
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.contacts.show.format = [Boolean]
|
||||
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.involved_orgas.show.title = Show involved organizations
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.involved_orgas.show.purpose = Show involved organizations
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.involved_orgas.show.example = true
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.involved_orgas.show.format = [Boolean]
|
||||
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.subprojects.show.title = Show subprojects?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.subprojects.show.purpose = Show subprojects?
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.subprojects.show.example = true
|
||||
com.arsdigita.cms.contenttypes.sciproject.summarytab.subprojects.show.format = [Boolean]
|
||||
Loading…
Reference in New Issue