Korrektur PersonalPublications (Ticket #1387)
git-svn-id: https://svn.libreccm.org/ccm/trunk@1865 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
8e5ca115bd
commit
e66a75e8b2
|
|
@ -12,7 +12,6 @@ import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.globalization.GlobalizationHelper;
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
@ -34,10 +33,10 @@ import org.apache.log4j.Logger;
|
||||||
public class PersonalPublications implements ContentGenerator {
|
public class PersonalPublications implements ContentGenerator {
|
||||||
|
|
||||||
private final static String MISC = "misc";
|
private final static String MISC = "misc";
|
||||||
private final static PersonalPublicationsConfig config =
|
private final static PersonalPublicationsConfig config = new PersonalPublicationsConfig();
|
||||||
new PersonalPublicationsConfig();
|
private final static Logger logger = Logger.getLogger(PersonalPublications.class);
|
||||||
private final static Logger logger = Logger.getLogger(
|
private static final String REVIEWED = "_reviewed";
|
||||||
PersonalPublications.class);
|
private static final String NOT_REVIEWED = "_notreviewed";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
config.load();
|
config.load();
|
||||||
|
|
@ -50,11 +49,9 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
final String language) {
|
final String language) {
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
|
|
||||||
final List<PublicationBundle> publications =
|
final List<PublicationBundle> publications = collectPublications(person, language);
|
||||||
collectPublications(person, language);
|
|
||||||
|
|
||||||
final Element personalPubsElem = parent.newChildElement(
|
final Element personalPubsElem = parent.newChildElement("personalPublications");
|
||||||
"personalPublications");
|
|
||||||
final long overallSize;
|
final long overallSize;
|
||||||
if (publications == null) {
|
if (publications == null) {
|
||||||
overallSize = 0;
|
overallSize = 0;
|
||||||
|
|
@ -77,16 +74,11 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
publicationsByGroup);
|
publicationsByGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<PublicationBundle> miscGroup =
|
final List<PublicationBundle> miscGroup = filterPublicationsForMiscGroup(publications, groupsConfig);
|
||||||
filterPublicationsForMiscGroup(
|
|
||||||
publications, groupsConfig);
|
|
||||||
publicationsByGroup.put(MISC, miscGroup);
|
publicationsByGroup.put(MISC, miscGroup);
|
||||||
|
|
||||||
final Element availableGroupsElem =
|
final Element availableGroupsElem = personalPubsElem.newChildElement("availablePublicationGroups");
|
||||||
personalPubsElem.newChildElement(
|
final Element publicationsElem = personalPubsElem.newChildElement("publications");
|
||||||
"availablePublicationGroups");
|
|
||||||
final Element publicationsElem = personalPubsElem.newChildElement(
|
|
||||||
"publications");
|
|
||||||
|
|
||||||
if (overallSize < config.getGroupSplit()) {
|
if (overallSize < config.getGroupSplit()) {
|
||||||
publicationsElem.addAttribute("all", "all");
|
publicationsElem.addAttribute("all", "all");
|
||||||
|
|
@ -146,14 +138,13 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
final String language) {
|
final String language) {
|
||||||
final List<PublicationBundle> publications =
|
final List<PublicationBundle> publications =
|
||||||
new LinkedList<PublicationBundle>();
|
new LinkedList<PublicationBundle>();
|
||||||
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
|
//final List<BigDecimal> processed = new ArrayList<BigDecimal>();
|
||||||
final DataCollection collection = (DataCollection) author.
|
final DataCollection collection = (DataCollection) author.getGenericPersonBundle().get("publication");
|
||||||
getGenericPersonBundle().get("publication");
|
|
||||||
DomainObject obj;
|
DomainObject obj;
|
||||||
while (collection.next()) {
|
while (collection.next()) {
|
||||||
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
||||||
if (obj instanceof PublicationBundle) {
|
if (obj instanceof PublicationBundle) {
|
||||||
processed.add(((PublicationBundle) obj).getParent().getID());
|
//processed.add(((PublicationBundle) obj).getParent().getID());
|
||||||
publications.add((PublicationBundle) obj);
|
publications.add((PublicationBundle) obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -168,8 +159,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
private void collectPublications(final GenericPerson alias,
|
private void collectPublications(final GenericPerson alias,
|
||||||
final List<PublicationBundle> publications,
|
final List<PublicationBundle> publications,
|
||||||
final String language) {
|
final String language) {
|
||||||
final DataCollection collection = (DataCollection) alias.
|
final DataCollection collection = (DataCollection) alias.getGenericPersonBundle().get("publication");
|
||||||
getGenericPersonBundle().get("publication");
|
|
||||||
DomainObject obj;
|
DomainObject obj;
|
||||||
while (collection.next()) {
|
while (collection.next()) {
|
||||||
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
obj = DomainObjectFactory.newInstance(collection.getDataObject());
|
||||||
|
|
@ -186,8 +176,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
private Map<String, List<String>> getGroupsConfig() {
|
private Map<String, List<String>> getGroupsConfig() {
|
||||||
final String conf = config.getPublictionGroups();
|
final String conf = config.getPublictionGroups();
|
||||||
|
|
||||||
final Map<String, List<String>> groups =
|
final Map<String, List<String>> groups = new LinkedHashMap<String, List<String>>();
|
||||||
new LinkedHashMap<String, List<String>>();
|
|
||||||
final String[] groupTokens = conf.split(";");
|
final String[] groupTokens = conf.split(";");
|
||||||
|
|
||||||
for (String groupToken : groupTokens) {
|
for (String groupToken : groupTokens) {
|
||||||
|
|
@ -213,11 +202,8 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
groups.put(tokens[0], types);
|
groups.put(tokens[0], types);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateAvailableForGroup(final String groupName,
|
private void generateAvailableForGroup(final String groupName, final Element availableGroupsElem) {
|
||||||
final Element availableGroupsElem) {
|
final Element group = availableGroupsElem.newChildElement("availablePublicationGroup");
|
||||||
final Element group =
|
|
||||||
availableGroupsElem.newChildElement(
|
|
||||||
"availablePublicationGroup");
|
|
||||||
group.addAttribute("name", groupName);
|
group.addAttribute("name", groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,8 +224,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
generateAvailableForGroup(groupName, availableGroupsElem);
|
generateAvailableForGroup(groupName, availableGroupsElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Element groupElem = publicationsElem.newChildElement(
|
final Element groupElem = publicationsElem.newChildElement("publicationGroup");
|
||||||
"publicationGroup");
|
|
||||||
groupElem.addAttribute("name", groupName);
|
groupElem.addAttribute("name", groupName);
|
||||||
|
|
||||||
if (withPaginator) {
|
if (withPaginator) {
|
||||||
|
|
@ -262,7 +247,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
private void generatePublicationXml(final Publication publication,
|
private void generatePublicationXml(final Publication publication,
|
||||||
final Element parent,
|
final Element parent,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
final XmlGenerator generator = new XmlGenerator(publication);
|
final PersonalPublications.XmlGenerator generator = new PersonalPublications.XmlGenerator(publication);
|
||||||
generator.setItemElemName("publications", "");
|
generator.setItemElemName("publications", "");
|
||||||
generator.setListMode(true);
|
generator.setListMode(true);
|
||||||
generator.generateXML(state, parent, "");
|
generator.generateXML(state, parent, "");
|
||||||
|
|
@ -281,6 +266,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
protected ContentItem getContentItem(final PageState state) {
|
protected ContentItem getContentItem(final PageState state) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String selectGroup(final HttpServletRequest request,
|
private String selectGroup(final HttpServletRequest request,
|
||||||
|
|
@ -308,25 +294,59 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
final List<String> typeTokens,
|
final List<String> typeTokens,
|
||||||
final List<PublicationBundle> publications,
|
final List<PublicationBundle> publications,
|
||||||
final Map<String, List<PublicationBundle>> publicationsByGroup) {
|
final Map<String, List<PublicationBundle>> publicationsByGroup) {
|
||||||
final List<PublicationBundle> group =
|
final List<PublicationBundle> group = new LinkedList<PublicationBundle>();
|
||||||
new LinkedList<PublicationBundle>();
|
|
||||||
|
|
||||||
for (PublicationBundle publication : publications) {
|
for (PublicationBundle publication : publications) {
|
||||||
for (String typeToken : typeTokens) {
|
for (String typeToken : typeTokens) {
|
||||||
if (publication.getContentType().getAssociatedObjectType().
|
// if (publication.getContentType().getAssociatedObjectType().equals(typeToken)) {
|
||||||
equals(
|
// group.add(publication);
|
||||||
typeToken)) {
|
// break;
|
||||||
group.add(publication);
|
// }
|
||||||
|
if (addPublicationToGroup(publication, typeToken, group)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.size() > 0) {
|
if (!group.isEmpty()) {
|
||||||
publicationsByGroup.put(groupName, group);
|
publicationsByGroup.put(groupName, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean addPublicationToGroup(final PublicationBundle publication,
|
||||||
|
final String typeToken,
|
||||||
|
final List<PublicationBundle> group) {
|
||||||
|
final String type;
|
||||||
|
final Boolean reviewed;
|
||||||
|
if (typeToken.endsWith(REVIEWED)) {
|
||||||
|
type = typeToken.substring(0, typeToken.indexOf(REVIEWED));
|
||||||
|
reviewed = Boolean.TRUE;
|
||||||
|
} else if (typeToken.endsWith(NOT_REVIEWED)) {
|
||||||
|
type = typeToken.substring(0, typeToken.indexOf(NOT_REVIEWED));
|
||||||
|
reviewed = Boolean.FALSE;
|
||||||
|
} else {
|
||||||
|
type = typeToken;
|
||||||
|
reviewed = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reviewed == null) {
|
||||||
|
if (publication.getContentType().getAssociatedObjectType().equals(type)) {
|
||||||
|
group.add(publication);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final Boolean pubReviewed = ((Publication) publication.getPrimaryInstance()).getReviewed();
|
||||||
|
if (publication.getContentType().getAssociatedObjectType().equals(type)
|
||||||
|
&& (reviewed.equals(pubReviewed)
|
||||||
|
|| (pubReviewed == null))) {
|
||||||
|
group.add(publication);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private List<PublicationBundle> filterPublicationsForMiscGroup(
|
private List<PublicationBundle> filterPublicationsForMiscGroup(
|
||||||
final List<PublicationBundle> publications,
|
final List<PublicationBundle> publications,
|
||||||
final Map<String, List<String>> groupsConfig) {
|
final Map<String, List<String>> groupsConfig) {
|
||||||
|
|
@ -336,8 +356,7 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
for (PublicationBundle publication : publications) {
|
for (PublicationBundle publication : publications) {
|
||||||
for (Map.Entry<String, List<String>> entry : groupsConfig.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : groupsConfig.entrySet()) {
|
||||||
for (String type : entry.getValue()) {
|
for (String type : entry.getValue()) {
|
||||||
if (publication.getContentType().getAssociatedObjectType().
|
if (publication.getContentType().getAssociatedObjectType().equals(getTypeFromTypeToken(type))) {
|
||||||
equals(type)) {
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,4 +369,15 @@ public class PersonalPublications implements ContentGenerator {
|
||||||
|
|
||||||
return misc;
|
return misc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTypeFromTypeToken(final String typeToken) {
|
||||||
|
if (typeToken.endsWith(REVIEWED)) {
|
||||||
|
return typeToken.substring(0, typeToken.indexOf(REVIEWED));
|
||||||
|
} else if (typeToken.endsWith(NOT_REVIEWED)) {
|
||||||
|
return typeToken.substring(0, typeToken.indexOf(NOT_REVIEWED));
|
||||||
|
} else {
|
||||||
|
return typeToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue