- PersonalPublications beachtet jetzt auch eventuelle Aliase einer Person
- ContentGenerator (PersonalProjects) für Projekte an denen eine Person beteiligt ist git-svn-id: https://svn.libreccm.org/ccm/trunk@1141 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
2b2d99e414
commit
d38c251600
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0"?>
|
||||
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
||||
name="ccm-sci-personalpublications"
|
||||
prettyName="OpenCCM PublicPersonalProfile Content generator"
|
||||
version="6.6.1"
|
||||
release="1"
|
||||
webapp="ROOT">
|
||||
<ccm:dependencies>
|
||||
<ccm:requires name="ccm-core" version="6.6.0" release="ge"/>
|
||||
<ccm:requires name="ccm-cms" version="6.6.0" release="ge"/>
|
||||
<ccm:requires name="ccm-cms-publicpersonalprofile" version="6.6.0" release="ge"/>
|
||||
<!-- For now this module depends on the complete organization module. Will
|
||||
be changed to ccm-sci-types-project when the current ccm-sci-types-organization
|
||||
module has been split -->
|
||||
<ccm:requires name="ccm-sci-types-organization" version="6.6.0" release="ge"/>
|
||||
</ccm:dependencies>
|
||||
<ccm:directories>
|
||||
<ccm:directory name="src"/>
|
||||
</ccm:directories>
|
||||
<ccm:contacts>
|
||||
<ccm:contact uri="http://www.redhat.com/software/rhea" type="website"/>
|
||||
<ccm:contact uri="mailto:rhea@redhat.com" type="support"/>
|
||||
</ccm:contacts>
|
||||
<ccm:description>
|
||||
Content generator creating a list of the projects a person is involved into.
|
||||
</ccm:description>
|
||||
</ccm:application>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<registry>
|
||||
<config class="com.arsdigita.cms.publicpersonalprofile.PersonalProjectsConfig"
|
||||
storage="ccm-sci-personalprojects/personalprojects.properties"/>
|
||||
</registry>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<load>
|
||||
<requires>
|
||||
<table name="inits"/>
|
||||
<table name="acs_objects"/>
|
||||
<table name="cms_items"/>
|
||||
<table name="ct_sciorga_projects"/>
|
||||
<table name="publicpersonalprofile"/>
|
||||
<table name="ct_public_personal_profiles"/>
|
||||
<initalizer class="com.arsdigita.cms.Initializer"/>
|
||||
<initalizer class="com.arsdigita.cms.contenttypes.PublicationInitalizer"/>
|
||||
<initalizer class="com.arsdigita.cms.scipublications.SciProjectInitalizer"/>
|
||||
<initalizer class="com.arsdigita.cms.contenttypes.PublicPersonalProfileInitalizer"/>
|
||||
<initalizer class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfilesInitalizer"/>
|
||||
</requires>
|
||||
<provides>
|
||||
<initalizer class="com.arsdigita.cms.publicpersonalprofile.PersonalProjectsInitalizer"/>
|
||||
</provides>
|
||||
</load>
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
package com.arsdigita.cms.publicpersonalprofile;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.contenttypes.GenericPerson;
|
||||
import com.arsdigita.cms.contenttypes.SciProject;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataCollection;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.xml.Element;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter (jensp)
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PersonalProjects implements ContentGenerator {
|
||||
|
||||
private final static String CURRENT_PROJECTS = "currentProjects";
|
||||
private final static String FINISHED_PROJECTS = "finishedProjects";
|
||||
private final static PersonalProjectsConfig config =
|
||||
new PersonalProjectsConfig();
|
||||
private final static Logger logger =
|
||||
Logger.getLogger(PersonalProjects.class);
|
||||
|
||||
static {
|
||||
config.load();
|
||||
}
|
||||
|
||||
public void generateContent(final Element parent,
|
||||
final GenericPerson person,
|
||||
final PageState state) {
|
||||
final List<SciProject> projects = collectProjects(person);
|
||||
|
||||
|
||||
if ((projects == null) || projects.size() == 0) {
|
||||
final Element projectsElem = parent.newChildElement("projects");
|
||||
projectsElem.newChildElement("noProjects");
|
||||
|
||||
return;
|
||||
} else {
|
||||
final List<SciProject> currentProjects = new ArrayList<SciProject>();
|
||||
final List<SciProject> finishedProjects =
|
||||
new ArrayList<SciProject>();
|
||||
|
||||
processProjects(projects, currentProjects, finishedProjects);
|
||||
generateGroupsXml(parent, currentProjects, finishedProjects);
|
||||
generateProjectsXml(parent,
|
||||
currentProjects,
|
||||
finishedProjects,
|
||||
state);
|
||||
}
|
||||
}
|
||||
|
||||
private List<SciProject> collectProjects(final GenericPerson person) {
|
||||
final List<SciProject> projects = new ArrayList<SciProject>();
|
||||
|
||||
final DataCollection collection = (DataCollection) person.get(
|
||||
"organizationalunit");
|
||||
DomainObject obj;
|
||||
while (collection.next()) {
|
||||
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
||||
if (obj instanceof SciProject) {
|
||||
projects.add((SciProject) obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (person.getAlias() != null) {
|
||||
collectProjects(person.getAlias(), projects);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
private void collectProjects(final GenericPerson alias,
|
||||
final List<SciProject> projects) {
|
||||
final DataCollection collection = (DataCollection) alias.get(
|
||||
"organizationalunit");
|
||||
DomainObject obj;
|
||||
while (collection.next()) {
|
||||
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
||||
if (obj instanceof SciProject) {
|
||||
projects.add((SciProject) obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (alias.getAlias() != null) {
|
||||
collectProjects(alias.getAlias(), projects);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void processProjects(final List<SciProject> projects,
|
||||
final List<SciProject> currentProjects,
|
||||
final List<SciProject> finishedProjects) {
|
||||
final Calendar today = new GregorianCalendar();
|
||||
final Date todayDate = today.getTime();
|
||||
for(SciProject project : projects) {
|
||||
if (project.getEnd().before(todayDate)) {
|
||||
finishedProjects.add(project);
|
||||
} else {
|
||||
currentProjects.add(project);
|
||||
}
|
||||
}
|
||||
|
||||
final ProjectComparator comparator = new ProjectComparator();
|
||||
Collections.sort(currentProjects, comparator);
|
||||
Collections.sort(finishedProjects, comparator);
|
||||
}
|
||||
|
||||
private void generateGroupsXml(final Element parent,
|
||||
final List<SciProject> currentProjects,
|
||||
final List<SciProject> finishedProjects) {
|
||||
final Element availableGroups = parent.newChildElement(
|
||||
"availableProjectGroups");
|
||||
|
||||
if (currentProjects.size() > 0) {
|
||||
createAvailableProjectGroupXml(availableGroups, CURRENT_PROJECTS);
|
||||
}
|
||||
|
||||
if (finishedProjects.size() > 0) {
|
||||
createAvailableProjectGroupXml(availableGroups, FINISHED_PROJECTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void createAvailableProjectGroupXml(final Element parent,
|
||||
final String name) {
|
||||
final Element group = parent.newChildElement("availableProjectGroup");
|
||||
group.addAttribute("name", name);
|
||||
}
|
||||
|
||||
private void generateProjectsXml(final Element parent,
|
||||
final List<SciProject> currentProjects,
|
||||
final List<SciProject> finishedProjects,
|
||||
final PageState state) {
|
||||
final Element projectsElem = parent.newChildElement("projects");
|
||||
|
||||
final int numberOfProjects = currentProjects.size()
|
||||
+ finishedProjects.size();
|
||||
final int groupSplit = config.getGroupSplit();
|
||||
|
||||
if (numberOfProjects < groupSplit) {
|
||||
projectsElem.addAttribute("all", "all");
|
||||
|
||||
generateProjectsGroupXml(projectsElem,
|
||||
CURRENT_PROJECTS,
|
||||
currentProjects,
|
||||
state);
|
||||
generateProjectsGroupXml(projectsElem,
|
||||
FINISHED_PROJECTS,
|
||||
finishedProjects,
|
||||
state);
|
||||
} else {
|
||||
final HttpServletRequest request = state.getRequest();
|
||||
|
||||
String groupToShow = request.getParameter("group");
|
||||
if (groupToShow == null) {
|
||||
groupToShow = CURRENT_PROJECTS;
|
||||
}
|
||||
|
||||
if (currentProjects.isEmpty()
|
||||
&& CURRENT_PROJECTS.equals(groupToShow)) {
|
||||
groupToShow = FINISHED_PROJECTS;
|
||||
}
|
||||
|
||||
if (CURRENT_PROJECTS.equals(groupToShow)) {
|
||||
generateProjectsGroupXml(projectsElem,
|
||||
CURRENT_PROJECTS,
|
||||
currentProjects,
|
||||
state);
|
||||
} else if (FINISHED_PROJECTS.equals(groupToShow)) {
|
||||
generateProjectsGroupXml(projectsElem,
|
||||
FINISHED_PROJECTS,
|
||||
finishedProjects,
|
||||
state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateProjectsGroupXml(final Element projectsElem,
|
||||
final String groupName,
|
||||
final List<SciProject> projects,
|
||||
final PageState state) {
|
||||
if (projects == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Element groupElem = projectsElem.newChildElement("projectGroup");
|
||||
groupElem.addAttribute("name", groupName);
|
||||
|
||||
for (SciProject project : projects) {
|
||||
generateProjectXml(groupElem, project, state);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateProjectXml(final Element projectGroupElem,
|
||||
final SciProject project,
|
||||
final PageState state) {
|
||||
final PublicPersonalProfileXmlGenerator generator =
|
||||
new PublicPersonalProfileXmlGenerator(
|
||||
project);
|
||||
generator.generateXML(state, projectGroupElem, "");
|
||||
}
|
||||
|
||||
private class ProjectComparator implements Comparator<SciProject> {
|
||||
|
||||
public int compare(final SciProject project1,
|
||||
final SciProject project2) {
|
||||
return project1.getTitle().compareTo(project2.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
package com.arsdigita.cms.publicpersonalprofile;
|
||||
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.parameter.IntegerParameter;
|
||||
import com.arsdigita.util.parameter.Parameter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter (jensp)
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PersonalProjectsConfig extends AbstractConfig {
|
||||
|
||||
private final Parameter groupSplit;
|
||||
|
||||
public PersonalProjectsConfig() {
|
||||
groupSplit = new IntegerParameter(
|
||||
"com.arsdigita.cms.publicpersonalprofile.projects.groupSplit",
|
||||
Parameter.REQUIRED,
|
||||
16);
|
||||
|
||||
register(groupSplit);
|
||||
|
||||
loadInfo();
|
||||
}
|
||||
|
||||
public final Integer getGroupSplit() {
|
||||
return (Integer) get(groupSplit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
com.arsdigita.cms.publicpersonalprofile.projects.groupSplit.title = Group Split
|
||||
com.arsdigita.cms.publicpersonalprofile.projects.groupSplit.purpose = If a person has more projects (>=) then this value, only the current or the finished projects are shown. Otherwise all projects are shown.
|
||||
com.arsdigita.cms.publicpersonalprofile.projects.groupSplit.example = 16
|
||||
com.arsdigita.cms.publicpersonalprofile.projects.groupSplit.format = [Integer]
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.arsdigita.cms.publicpersonalprofile;
|
||||
|
||||
import com.arsdigita.db.DbHelper;
|
||||
import com.arsdigita.persistence.pdl.ManifestSource;
|
||||
import com.arsdigita.persistence.pdl.NameFilter;
|
||||
import com.arsdigita.runtime.CompoundInitializer;
|
||||
import com.arsdigita.runtime.DomainInitEvent;
|
||||
import com.arsdigita.runtime.PDLInitializer;
|
||||
import com.arsdigita.runtime.RuntimeConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PersonalProjectsInitializer extends CompoundInitializer {
|
||||
|
||||
public PersonalProjectsInitializer() {
|
||||
|
||||
final String jdbcUrl = RuntimeConfig.getConfig().getJDBCURL();
|
||||
final int database = DbHelper.getDatabaseFromURL(jdbcUrl);
|
||||
|
||||
add(new PDLInitializer(new ManifestSource("empty.pdl.mf",
|
||||
new NameFilter(DbHelper.getDatabaseSuffix(database), "pdl"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final DomainInitEvent event) {
|
||||
super.init(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.arsdigita.cms.publicpersonalprofile;
|
||||
|
||||
import com.arsdigita.loader.PackageLoader;
|
||||
import com.arsdigita.runtime.ScriptContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PersonalProjectsLoader extends PackageLoader {
|
||||
|
||||
@Override
|
||||
public void run(final ScriptContext ctx) {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ public class PersonalPublications implements ContentGenerator {
|
|||
public void generateContent(final Element parent,
|
||||
final GenericPerson person,
|
||||
final PageState state) {
|
||||
DataCollection publications = (DataCollection) person.get("publication");
|
||||
|
||||
final List<DataObject> publications = collectPublications(person);
|
||||
|
||||
if ((publications == null) || publications.size() == 0) {
|
||||
final Element publicationsElem = parent.newChildElement(
|
||||
"publications");
|
||||
|
|
@ -59,6 +59,34 @@ public class PersonalPublications implements ContentGenerator {
|
|||
generatePublicationsXml(parent, groupedPublications, state);
|
||||
}
|
||||
}
|
||||
|
||||
private List<DataObject> collectPublications(final GenericPerson person) {
|
||||
final List<DataObject> publications = new ArrayList<DataObject>();
|
||||
final DataCollection collection = (DataCollection) person.get("publication");
|
||||
|
||||
while(collection.next()) {
|
||||
publications.add(collection.getDataObject());
|
||||
}
|
||||
|
||||
if (person.getAlias() != null) {
|
||||
collectPublications(person, publications);
|
||||
}
|
||||
|
||||
return publications;
|
||||
}
|
||||
|
||||
private void collectPublications(final GenericPerson alias,
|
||||
final List<DataObject> publications) {
|
||||
final DataCollection collection = (DataCollection) alias.get("publication");
|
||||
|
||||
while(collection.next()) {
|
||||
publications.add(collection.getDataObject());
|
||||
}
|
||||
|
||||
if (alias.getAlias() != null) {
|
||||
collectPublications(alias, publications);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the publications and puts them into the groups.
|
||||
|
|
@ -69,7 +97,7 @@ public class PersonalPublications implements ContentGenerator {
|
|||
* as value.
|
||||
*/
|
||||
private Map<String, List<Publication>> processPublications(
|
||||
final DataCollection publications) {
|
||||
final List<DataObject> publications) {
|
||||
|
||||
final GroupConfig groupConfig = new GroupConfig(config.
|
||||
getPublictionGroups());
|
||||
|
|
@ -80,15 +108,13 @@ public class PersonalPublications implements ContentGenerator {
|
|||
initalizePubGroupMap(pubGroups, group);
|
||||
}
|
||||
initalizePubGroupMap(pubGroups, MISC);
|
||||
|
||||
DataObject dobj;
|
||||
|
||||
Publication publication;
|
||||
String type;
|
||||
String groupName;
|
||||
Boolean reviewed;
|
||||
List<Publication> group;
|
||||
while (publications.next()) {
|
||||
dobj = publications.getDataObject();
|
||||
for(DataObject dobj : publications) {
|
||||
publication = (Publication) DomainObjectFactory.newInstance(dobj);
|
||||
type = publication.getClass().getName();
|
||||
|
||||
|
|
@ -160,7 +186,7 @@ public class PersonalPublications implements ContentGenerator {
|
|||
final Element publicationsElem = parent.newChildElement("publications");
|
||||
|
||||
int numberOfPubs = 0;
|
||||
int groupSplit = config.getGroupSplit();
|
||||
final int groupSplit = config.getGroupSplit();
|
||||
|
||||
for (List<Publication> list : publications.values()) {
|
||||
numberOfPubs += list.size();
|
||||
|
|
|
|||
Loading…
Reference in New Issue