diff --git a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl index ed1f209fc..aa3256447 100644 --- a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl @@ -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; + } } \ No newline at end of file diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java new file mode 100644 index 000000000..0d8dd3b59 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitMembersTab.java @@ -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 paginator = + new GenericOrgaUnitPaginator( + 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 getAssocTypesToMerge(); + + protected abstract List getRolesToInclude(); + + protected abstract List 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; + } + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitPaginator.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitPaginator.java index de2e20f2e..ae4350c15 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitPaginator.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitPaginator.java @@ -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 { +public class GenericOrgaUnitPaginator { private final static String PAGE_NUMBER = "pageNumber"; private final long pageSize; diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitSubordinateTab.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitSubordinateTab.java index 996dfdd14..50b8d40c4 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitSubordinateTab.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrgaUnitSubordinateTab.java @@ -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; } diff --git a/ccm-sci-types-project/src/ccm-sci-types-project.config b/ccm-sci-types-project/src/ccm-sci-types-project.config index 294adcbf2..834caae6e 100644 --- a/ccm-sci-types-project/src/ccm-sci-types-project.config +++ b/ccm-sci-types-project/src/ccm-sci-types-project.config @@ -2,4 +2,6 @@ + diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java index d64e6547c..4a21d58d0 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProject.java @@ -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; /** *

@@ -284,4 +287,11 @@ public class SciProject extends GenericOrganizationalUnit { } } } + + @Override + public List getExtraXMLGenerators() { + final List generators = super.getExtraXMLGenerators(); + generators.add(new SciProjectExtraXmlGenerator()); + return generators; + } } diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig.java index 1d91e7efc..cf4e1fcd9 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig.java +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig.java @@ -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); + } } diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig_parameter.properties b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig_parameter.properties index 73bc1b72c..e7e7a8960 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig_parameter.properties +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/SciProjectConfig_parameter.properties @@ -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] \ No newline at end of file +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] \ No newline at end of file diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectExtraXmlGenerator.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectExtraXmlGenerator.java new file mode 100644 index 000000000..56791e634 --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectExtraXmlGenerator.java @@ -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(); + } +} diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectMembersTab.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectMembersTab.java new file mode 100644 index 000000000..4699b733d --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectMembersTab.java @@ -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 getAssocTypesToMerge() { + final List assocTypes = new ArrayList(); + assocTypes.add(SciProjectSubProjectsStep.ASSOC_TYPE); + return assocTypes; + } + + @Override + protected int getPageSize() { + return 25; + } + + @Override + protected List getRolesToInclude() { + final List roles = new ArrayList(); + return roles; + } + + @Override + protected List getStatusesToInclude() { + final List statuses = new ArrayList(); + return statuses; + } +} diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources.properties b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources.properties index 7a10dc6f7..db0d3a58a 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources.properties +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources.properties @@ -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 diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources_de.properties b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources_de.properties index 617817f60..3bf6653e8 100644 --- a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources_de.properties +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectResources_de.properties @@ -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 diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java new file mode 100644 index 000000000..795a971f0 --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTab.java @@ -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; + } + } +} diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig.java b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig.java new file mode 100644 index 000000000..a49b85b6b --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig.java @@ -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); + } +} diff --git a/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig_parameter.properties b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig_parameter.properties new file mode 100644 index 000000000..67ec42c48 --- /dev/null +++ b/ccm-sci-types-project/src/com/arsdigita/cms/contenttypes/ui/SciProjectSummaryTabConfig_parameter.properties @@ -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]