Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java @ 170:8604b368ec19 public_by_author
still more work on publicByAuthor feature.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 31 May 2018 21:25:45 +0200 |
parents | 0b5d02012299 |
children | 50b8103ec85c |
comparison
equal
deleted
inserted
replaced
169:0b5d02012299 | 170:8604b368ec19 |
---|---|
1 package de.mpiwg.itgroup.ismi.merge; | 1 package de.mpiwg.itgroup.ismi.merge; |
2 | 2 |
3 import java.io.Serializable; | 3 import java.io.Serializable; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.HashMap; | |
5 import java.util.List; | 6 import java.util.List; |
7 import java.util.Map; | |
6 | 8 |
7 import javax.faces.event.ActionEvent; | 9 import javax.faces.event.ActionEvent; |
8 import javax.faces.event.ValueChangeEvent; | |
9 | 10 |
10 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
11 import org.mpi.openmind.repository.bo.Entity; | 12 import org.mpi.openmind.repository.bo.Entity; |
12 import org.mpi.openmind.repository.bo.Relation; | 13 import org.mpi.openmind.repository.bo.Relation; |
13 | 14 |
24 private String findAuthorName = ""; | 25 private String findAuthorName = ""; |
25 protected Long selectedPersonId = 0l; | 26 protected Long selectedPersonId = 0l; |
26 | 27 |
27 protected Entity selectedPerson; | 28 protected Entity selectedPerson; |
28 protected List<Entity> selectedPersonTexts; | 29 protected List<Entity> selectedPersonTexts; |
29 protected List<Entity> selectedPersonSubjects; | 30 protected List<String> selectedPersonSubjects; |
31 protected Map<String,List<Entity>> selectedPersonSubjectMap; | |
30 | 32 |
31 | 33 |
32 private EntityRepositoryBean browseBean; | 34 private EntityRepositoryBean browseBean; |
33 | 35 |
34 | 36 |
41 //logger.info("AdvancedSearchBean.reset()"); | 43 //logger.info("AdvancedSearchBean.reset()"); |
42 browseBean = new FullEntityRepositoryBean(); | 44 browseBean = new FullEntityRepositoryBean(); |
43 browseBean.setObjectClass("PERSON"); | 45 browseBean.setObjectClass("PERSON"); |
44 | 46 |
45 selectedPersonTexts = new ArrayList<Entity>(); | 47 selectedPersonTexts = new ArrayList<Entity>(); |
48 selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); | |
46 } | 49 } |
47 | 50 |
48 public void listenerAuthorIdSearch(ActionEvent event) { | 51 public void listenerAuthorIdSearch(ActionEvent event) { |
49 setSelectedPersonById(); | 52 setSelectedPersonById(); |
50 } | 53 } |
51 | 54 |
52 private void setSelectedPersonById() { | 55 protected void setSelectedPersonById() { |
53 Entity ent = getWrapper().getEntityById(selectedPersonId); | 56 Entity ent = getWrapper().getEntityById(selectedPersonId); |
54 if (ent != null) { | 57 if (ent != null) { |
55 ent = getWrapper().getEntityContent(ent); | 58 ent = getWrapper().getEntityContent(ent); |
56 selectedPerson = ent; | 59 selectedPerson = ent; |
57 updateSelectedPerson(); | 60 updateSelectedPerson(); |
61 | 64 |
62 | 65 |
63 public void updateSelectedPerson() { | 66 public void updateSelectedPerson() { |
64 // load all texts by this author | 67 // load all texts by this author |
65 selectedPersonTexts = new ArrayList<Entity>(); | 68 selectedPersonTexts = new ArrayList<Entity>(); |
69 selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); | |
66 List<Relation> textRels = selectedPerson.getTargetRelations("was_created_by", "TEXT"); | 70 List<Relation> textRels = selectedPerson.getTargetRelations("was_created_by", "TEXT"); |
67 for (Relation rel : textRels) { | 71 for (Relation rel : textRels) { |
68 Long textID = rel.getSourceId(); | 72 Long textID = rel.getSourceId(); |
73 // get text | |
69 Entity text = getWrapper().getEntityByIdWithContent(textID); | 74 Entity text = getWrapper().getEntityByIdWithContent(textID); |
70 selectedPersonTexts.add(text); | 75 selectedPersonTexts.add(text); |
76 // get subject | |
77 List<Relation> subjectRels = text.getSourceRelations("has_subject", "SUBJECT"); | |
78 if (subjectRels.isEmpty()) { | |
79 String subject = "NO SUBJECT"; | |
80 List<Entity> texts = selectedPersonSubjectMap.get(subject); | |
81 if (texts == null) { | |
82 texts = new ArrayList<Entity>(); | |
83 } | |
84 // add text to list | |
85 texts.add(text); | |
86 // add list to subject map | |
87 selectedPersonSubjectMap.put(subject, texts); | |
88 | |
89 } else { | |
90 for (Relation subjectRel : subjectRels) { | |
91 Long subjectId = subjectRel.getTargetId(); | |
92 Entity subject = getWrapper().getEntityByIdWithContent(subjectId); | |
93 List<Entity> texts = selectedPersonSubjectMap.get(subject.getOwnValue()); | |
94 if (texts == null) { | |
95 texts = new ArrayList<Entity>(); | |
96 } | |
97 // add text to list | |
98 texts.add(text); | |
99 // add list to subject map | |
100 selectedPersonSubjectMap.put(subject.getOwnValue(), texts); | |
101 } | |
102 } | |
103 } | |
104 // update list of subjects | |
105 selectedPersonSubjects = new ArrayList<String>(); | |
106 for (String sub : selectedPersonSubjectMap.keySet()) { | |
107 selectedPersonSubjects.add(sub); | |
71 } | 108 } |
72 } | 109 } |
73 | 110 |
74 | 111 |
75 public String actionSelectPerson() { | 112 public String actionSelectPerson() { |
143 } | 180 } |
144 | 181 |
145 /** | 182 /** |
146 * @return the selectedPersonSubjects | 183 * @return the selectedPersonSubjects |
147 */ | 184 */ |
148 public List<Entity> getSelectedPersonSubjects() { | 185 public Map<String, List<Entity>> getSelectedPersonSubjectMap() { |
149 return selectedPersonSubjects; | 186 return selectedPersonSubjectMap; |
150 } | 187 } |
151 | 188 |
152 /** | 189 /** |
153 * @param selectedPersonId the selectedPersonId to set | 190 * @param selectedPersonId the selectedPersonId to set |
154 */ | 191 */ |
155 public void setSelectedPersonId(Long selectedPersonId) { | 192 public void setSelectedPersonId(Long selectedPersonId) { |
156 this.selectedPersonId = selectedPersonId; | 193 this.selectedPersonId = selectedPersonId; |
157 } | 194 } |
158 | 195 |
196 /** | |
197 * @return the selectedPersonSubjects | |
198 */ | |
199 public List<String> getSelectedPersonSubjects() { | |
200 return selectedPersonSubjects; | |
201 } | |
202 | |
159 } | 203 } |