annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children 4ec8d4cfad26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
jurzua
parents:
diff changeset
1 package de.mpiwg.itgroup.ismi.entry.beans;
jurzua
parents:
diff changeset
2
jurzua
parents:
diff changeset
3 import java.io.Serializable;
jurzua
parents:
diff changeset
4 import java.util.ArrayList;
jurzua
parents:
diff changeset
5 import java.util.HashMap;
jurzua
parents:
diff changeset
6 import java.util.HashSet;
jurzua
parents:
diff changeset
7 import java.util.List;
jurzua
parents:
diff changeset
8 import java.util.Map;
jurzua
parents:
diff changeset
9
jurzua
parents:
diff changeset
10 import javax.faces.context.FacesContext;
jurzua
parents:
diff changeset
11 import javax.faces.event.ActionEvent;
jurzua
parents:
diff changeset
12 import javax.faces.event.ValueChangeEvent;
jurzua
parents:
diff changeset
13 import javax.faces.model.SelectItem;
jurzua
parents:
diff changeset
14
jurzua
parents:
diff changeset
15 import org.apache.commons.lang.StringUtils;
jurzua
parents:
diff changeset
16 import org.apache.log4j.Logger;
jurzua
parents:
diff changeset
17 import org.mpi.openmind.cache.WrapperService;
jurzua
parents:
diff changeset
18 import org.mpi.openmind.repository.bo.Attribute;
jurzua
parents:
diff changeset
19 import org.mpi.openmind.repository.bo.Entity;
jurzua
parents:
diff changeset
20 import org.mpi.openmind.repository.bo.Node;
jurzua
parents:
diff changeset
21 import org.mpi.openmind.repository.bo.Relation;
jurzua
parents:
diff changeset
22 import org.mpi.openmind.security.SecurityService;
jurzua
parents:
diff changeset
23 import org.mpi.openmind.security.bo.User;
jurzua
parents:
diff changeset
24 import org.mpiwg.itgroup.escidoc.bo.ESciDocItem;
jurzua
parents:
diff changeset
25 import org.mpiwg.itgroup.escidoc.bo.Publication;
jurzua
parents:
diff changeset
26 import org.mpiwg.itgroup.escidoc.utils.ESciDocItemDataTable;
jurzua
parents:
diff changeset
27 import org.mpiwg.itgroup.escidoc.utils.SelectedESciDocItems;
jurzua
parents:
diff changeset
28
jurzua
parents:
diff changeset
29 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
jurzua
parents:
diff changeset
30 import de.mpiwg.itgroup.ismi.entry.dataBeans.SimpleSearchCache;
jurzua
parents:
diff changeset
31 import de.mpiwg.itgroup.ismi.util.guiComponents.Reference;
jurzua
parents:
diff changeset
32 import de.mpiwg.itgroup.ismi.util.guiComponents.ReferenceTable;
jurzua
parents:
diff changeset
33 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusChecker;
jurzua
parents:
diff changeset
34 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusImage;
jurzua
parents:
diff changeset
35 import de.mpiwg.itgroup.ismi.utils.SelectableObject;
jurzua
parents:
diff changeset
36
jurzua
parents:
diff changeset
37 /**
jurzua
parents:
diff changeset
38 *
jurzua
parents:
diff changeset
39 * @author jurzua
jurzua
parents:
diff changeset
40 */
jurzua
parents:
diff changeset
41 public class AbstractISMIBean extends AbstractBean implements Serializable{
jurzua
parents:
diff changeset
42
jurzua
parents:
diff changeset
43 private static final long serialVersionUID = 9193140306343947209L;
jurzua
parents:
diff changeset
44
jurzua
parents:
diff changeset
45 private static Logger logger = Logger.getLogger(AbstractISMIBean.class);
jurzua
parents:
diff changeset
46
jurzua
parents:
diff changeset
47 public static String WITNESS = "WITNESS";
jurzua
parents:
diff changeset
48 public static String TEXT = "TEXT";
jurzua
parents:
diff changeset
49 public static String PERSON = "PERSON";
jurzua
parents:
diff changeset
50 public static String COLLECTION = "COLLECTION";
jurzua
parents:
diff changeset
51 public static String CODEX = "CODEX";
jurzua
parents:
diff changeset
52 public static String REPOSITORY = "REPOSITORY";
jurzua
parents:
diff changeset
53 public static String ALIAS = "ALIAS";
jurzua
parents:
diff changeset
54 public static String PLACE = "PLACE";
jurzua
parents:
diff changeset
55 public static String SUBJECT = "SUBJECT";
jurzua
parents:
diff changeset
56 public static String REFERENCE = "REFERENCE";
jurzua
parents:
diff changeset
57 public static String ROLE = "ROLE";
jurzua
parents:
diff changeset
58 public static String DIGITALIZATION = "DIGITALIZATION";
jurzua
parents:
diff changeset
59 public static String FLORUIT_DATE = "FLORUIT_DATE";
jurzua
parents:
diff changeset
60
jurzua
parents:
diff changeset
61 public static String is_digitalization_of = "is_digitalization_of";
jurzua
parents:
diff changeset
62 public static String is_part_of = "is_part_of";
jurzua
parents:
diff changeset
63 public static String is_in = "is_in";
jurzua
parents:
diff changeset
64 public static String has_subject = "has_subject";
jurzua
parents:
diff changeset
65 public static String misattributed_to = "misattributed_to";
jurzua
parents:
diff changeset
66 public static String lived_in = "lived_in";
jurzua
parents:
diff changeset
67 public static String owned_by = "owned_by";
jurzua
parents:
diff changeset
68 public static String has_role = "has_role";
jurzua
parents:
diff changeset
69 public static String was_student_of = "was_student_of";
jurzua
parents:
diff changeset
70 public static String is_alias_name_of = "is_alias_name_of";
jurzua
parents:
diff changeset
71 public static String is_prime_alias_name_of = "is_prime_alias_name_of";
jurzua
parents:
diff changeset
72 public static String is_alias_title_of = "is_alias_title_of";
jurzua
parents:
diff changeset
73 public static String is_prime_alias_title_of = "is_prime_alias_title_of";
jurzua
parents:
diff changeset
74 public static String alias = "alias";
jurzua
parents:
diff changeset
75 public static String has_floruit_date = "has_floruit_date";
jurzua
parents:
diff changeset
76
jurzua
parents:
diff changeset
77 public static String rel_was_created_by = "was_created_by";
jurzua
parents:
diff changeset
78 public static String rel_was_copied_by = "was_copied_by";
jurzua
parents:
diff changeset
79 public static String is_exemplar_of = "is_exemplar_of";
jurzua
parents:
diff changeset
80 public static String is_possible_exemplar_of = "is_possible_exemplar_of";
jurzua
parents:
diff changeset
81 public static String rel_had_patron = "had_patron";
jurzua
parents:
diff changeset
82 public static String rel_has_title_written_as = "has_title_written_as";
jurzua
parents:
diff changeset
83 public static String rel_has_author_written_as = "has_author_written_as";
jurzua
parents:
diff changeset
84 public static String rel_is_reference_of = "is_reference_of";
jurzua
parents:
diff changeset
85
jurzua
parents:
diff changeset
86 public static String rel_was_studied_by = "was_studied_by";
jurzua
parents:
diff changeset
87
jurzua
parents:
diff changeset
88 public static String PAGE_EDITOR = "entry_edit_entity";
jurzua
parents:
diff changeset
89 public static String PAGE_SIMPLE_SEARCH = "simple_search";
jurzua
parents:
diff changeset
90 public static String PAGE_MERGE = "general_merge";
jurzua
parents:
diff changeset
91
jurzua
parents:
diff changeset
92 //some attributes names
jurzua
parents:
diff changeset
93 public static String name = "name";
jurzua
parents:
diff changeset
94 public static String name_translit = "name_translit";
jurzua
parents:
diff changeset
95 public static String full_title_translit = "full_title_translit";
jurzua
parents:
diff changeset
96
jurzua
parents:
diff changeset
97 public static int MAX_SUGGEST = 25;
jurzua
parents:
diff changeset
98
jurzua
parents:
diff changeset
99 protected boolean selectedSaveAsNew = false;
jurzua
parents:
diff changeset
100
jurzua
parents:
diff changeset
101 private HashSet<StatusChecker> statusChecker = new HashSet<StatusChecker>();
jurzua
parents:
diff changeset
102 private boolean warning = false;
jurzua
parents:
diff changeset
103 private String warningMessage = "";
jurzua
parents:
diff changeset
104 private boolean displayWarning = false;
jurzua
parents:
diff changeset
105
jurzua
parents:
diff changeset
106 //private PanelPopup popup = new PanelPopup();
jurzua
parents:
diff changeset
107 //private String popupText = "";
jurzua
parents:
diff changeset
108
jurzua
parents:
diff changeset
109 private String currentId;
jurzua
parents:
diff changeset
110 private String currentIdMsg;
jurzua
parents:
diff changeset
111
jurzua
parents:
diff changeset
112 // used in the new version
jurzua
parents:
diff changeset
113 private Boolean create_error = false;
jurzua
parents:
diff changeset
114 private String selectedWitnessID = "0";
jurzua
parents:
diff changeset
115 private boolean showWitness;
jurzua
parents:
diff changeset
116 private boolean showTitle = false;
jurzua
parents:
diff changeset
117
jurzua
parents:
diff changeset
118 private Map<String, String> attributes = new HashMap<String, String>();
jurzua
parents:
diff changeset
119 protected String defObjectClass = null;
jurzua
parents:
diff changeset
120
jurzua
parents:
diff changeset
121 protected String displayUrl;
jurzua
parents:
diff changeset
122
jurzua
parents:
diff changeset
123 protected Entity entity;
jurzua
parents:
diff changeset
124
jurzua
parents:
diff changeset
125 protected long start;
jurzua
parents:
diff changeset
126
jurzua
parents:
diff changeset
127 public String save(){
jurzua
parents:
diff changeset
128 logger.info("*************** START Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************");
jurzua
parents:
diff changeset
129 this.start = System.currentTimeMillis();
jurzua
parents:
diff changeset
130 return null;
jurzua
parents:
diff changeset
131 }
jurzua
parents:
diff changeset
132
jurzua
parents:
diff changeset
133 protected void saveEnd(){
jurzua
parents:
diff changeset
134 logger.info("*************** END Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************\n");
jurzua
parents:
diff changeset
135 }
jurzua
parents:
diff changeset
136
jurzua
parents:
diff changeset
137 public Entity getEntity() {
jurzua
parents:
diff changeset
138 if (this.entity == null) {
jurzua
parents:
diff changeset
139 this.entity = new Entity();
jurzua
parents:
diff changeset
140 this.entity.setObjectClass(defObjectClass);
jurzua
parents:
diff changeset
141 this.entity.setLightweight(false);
jurzua
parents:
diff changeset
142 this.loadAttributes(this.entity);
jurzua
parents:
diff changeset
143 }
jurzua
parents:
diff changeset
144 return entity;
jurzua
parents:
diff changeset
145 }
jurzua
parents:
diff changeset
146
jurzua
parents:
diff changeset
147 protected void printSuccessSavingEntity(){
jurzua
parents:
diff changeset
148 this.addGeneralMsg("The entity was successfully saved!");
jurzua
parents:
diff changeset
149 this.addGeneralMsg("Its ID is " + this.entity.getId());
jurzua
parents:
diff changeset
150 }
jurzua
parents:
diff changeset
151
jurzua
parents:
diff changeset
152 public void setEntity(Entity entity) {
jurzua
parents:
diff changeset
153 this.entity = entity;
jurzua
parents:
diff changeset
154 }
jurzua
parents:
diff changeset
155
jurzua
parents:
diff changeset
156 public String getSaveButtonLabel(){
jurzua
parents:
diff changeset
157 if(entity.isPersistent())
jurzua
parents:
diff changeset
158 return "Save";
jurzua
parents:
diff changeset
159 return "Create";
jurzua
parents:
diff changeset
160 }
jurzua
parents:
diff changeset
161
jurzua
parents:
diff changeset
162 public boolean isRenderSaveButton(){
jurzua
parents:
diff changeset
163 //#{(CurrentText.entity.id == null and Session.canCreate) || (CurrentText.entity.id != null and Session.canEdit)}
jurzua
parents:
diff changeset
164 if((!entity.isPersistent() && getSessionBean().isCanCreate()) ||
jurzua
parents:
diff changeset
165 entity.isPersistent() && getSessionBean().isCanEdit())
jurzua
parents:
diff changeset
166 return true;
jurzua
parents:
diff changeset
167 return false;
jurzua
parents:
diff changeset
168 }
jurzua
parents:
diff changeset
169
jurzua
parents:
diff changeset
170 public String clearAction(){
jurzua
parents:
diff changeset
171 System.out.println("clearAction");
jurzua
parents:
diff changeset
172 this.entity = new Entity(Node.TYPE_ABOX, this.defObjectClass, false);
jurzua
parents:
diff changeset
173 this.setEntity(this.entity);
jurzua
parents:
diff changeset
174 return PAGE_EDITOR;
jurzua
parents:
diff changeset
175 }
jurzua
parents:
diff changeset
176
jurzua
parents:
diff changeset
177 public String actionReloadEntity(){
jurzua
parents:
diff changeset
178 Long id = null;
jurzua
parents:
diff changeset
179 try{
jurzua
parents:
diff changeset
180 id = new Long(this.getCurrentId());
jurzua
parents:
diff changeset
181 }catch (Exception e) {}
jurzua
parents:
diff changeset
182
jurzua
parents:
diff changeset
183 if(id != null){
jurzua
parents:
diff changeset
184 Entity tmp = getWrapper().getEntityById(id);
jurzua
parents:
diff changeset
185 if(tmp != null && tmp.getObjectClass().equals(this.defObjectClass)){
jurzua
parents:
diff changeset
186 this.setEntity(tmp);
jurzua
parents:
diff changeset
187 }else{
jurzua
parents:
diff changeset
188 this.setCurrentIdMsg("Entity no found!");
jurzua
parents:
diff changeset
189 }
jurzua
parents:
diff changeset
190 }else{
jurzua
parents:
diff changeset
191 this.setCurrentIdMsg("ID is not valid!");
jurzua
parents:
diff changeset
192 }
jurzua
parents:
diff changeset
193 return PAGE_EDITOR;
jurzua
parents:
diff changeset
194 }
jurzua
parents:
diff changeset
195
jurzua
parents:
diff changeset
196 public String getDisplayUrl() {
jurzua
parents:
diff changeset
197 return displayUrl;
jurzua
parents:
diff changeset
198 }
jurzua
parents:
diff changeset
199
jurzua
parents:
diff changeset
200 public void setDisplayUrl(String displayUrl) {
jurzua
parents:
diff changeset
201 this.displayUrl = displayUrl;
jurzua
parents:
diff changeset
202 }
jurzua
parents:
diff changeset
203
jurzua
parents:
diff changeset
204 public static String generateDisplayUrl(Entity author, Entity title, Entity witness, String rootUrl){
jurzua
parents:
diff changeset
205 //example: ?personId=414996&textId=36650&witnessId=66802#witnesses
jurzua
parents:
diff changeset
206 StringBuilder sb = new StringBuilder();
jurzua
parents:
diff changeset
207 if(author != null && author.isPersistent()){
jurzua
parents:
diff changeset
208 sb.append(rootUrl + "/search/displayAuthor.xhtml?");
jurzua
parents:
diff changeset
209 sb.append("personId=" + author.getId());
jurzua
parents:
diff changeset
210 if(title != null && title.isPersistent()){
jurzua
parents:
diff changeset
211 sb.append("&textId=" + title.getId());
jurzua
parents:
diff changeset
212 if(witness != null && witness.isPersistent()){
jurzua
parents:
diff changeset
213 sb.append("&witness=" + witness.getId());
jurzua
parents:
diff changeset
214 sb.append("#witnesses");
jurzua
parents:
diff changeset
215 }else{
jurzua
parents:
diff changeset
216 sb.append("#titles");
jurzua
parents:
diff changeset
217 }
jurzua
parents:
diff changeset
218 }
jurzua
parents:
diff changeset
219 }else if(title != null && title.isPersistent()){
jurzua
parents:
diff changeset
220 sb.append(rootUrl + "/search/displayTitle.xhtml?");
jurzua
parents:
diff changeset
221 sb.append("&textId=" + title.getId());
jurzua
parents:
diff changeset
222 if(witness != null && witness.isPersistent()){
jurzua
parents:
diff changeset
223 sb.append("&witness=" + witness.getId());
jurzua
parents:
diff changeset
224 sb.append("#witnesses");
jurzua
parents:
diff changeset
225 }else{
jurzua
parents:
diff changeset
226 sb.append("#titles");
jurzua
parents:
diff changeset
227 }
jurzua
parents:
diff changeset
228
jurzua
parents:
diff changeset
229 }
jurzua
parents:
diff changeset
230 return sb.toString();
jurzua
parents:
diff changeset
231 }
jurzua
parents:
diff changeset
232
jurzua
parents:
diff changeset
233 //********************************
jurzua
parents:
diff changeset
234 //**** PUBLICATIONS END NOTE *****
jurzua
parents:
diff changeset
235 //********************************
jurzua
parents:
diff changeset
236
jurzua
parents:
diff changeset
237 private ReferenceTable endNoteRefTable = new ReferenceTable();
jurzua
parents:
diff changeset
238
jurzua
parents:
diff changeset
239 protected void loadEndNoteRefs(){
jurzua
parents:
diff changeset
240 this.endNoteRefTable.loadRefs(getEntRefs());
jurzua
parents:
diff changeset
241 }
jurzua
parents:
diff changeset
242
jurzua
parents:
diff changeset
243 public ReferenceTable getEndNoteRefTable() {
jurzua
parents:
diff changeset
244 return endNoteRefTable;
jurzua
parents:
diff changeset
245 }
jurzua
parents:
diff changeset
246
jurzua
parents:
diff changeset
247 public void setEndNoteRefTable(ReferenceTable endNoteRefTable) {
jurzua
parents:
diff changeset
248 this.endNoteRefTable = endNoteRefTable;
jurzua
parents:
diff changeset
249 }
jurzua
parents:
diff changeset
250
jurzua
parents:
diff changeset
251 private List<Entity> getEntRefs(){
jurzua
parents:
diff changeset
252 List<Entity> rs = new ArrayList<Entity>();
jurzua
parents:
diff changeset
253 for (Relation rel : this.entity.getTargetRelations()) {
jurzua
parents:
diff changeset
254 if (rel.getOwnValue().equals(rel_is_reference_of)) {
jurzua
parents:
diff changeset
255 rs.add(getWrapper().getEntityByIdWithContent(rel.getSourceId()));
jurzua
parents:
diff changeset
256 }
jurzua
parents:
diff changeset
257 }
jurzua
parents:
diff changeset
258 return rs;
jurzua
parents:
diff changeset
259 }
jurzua
parents:
diff changeset
260
jurzua
parents:
diff changeset
261 //********************************
jurzua
parents:
diff changeset
262 //**** PUBLICATIONS ESciDOC ******
jurzua
parents:
diff changeset
263 //********************************
jurzua
parents:
diff changeset
264
jurzua
parents:
diff changeset
265 private ESciDocItemDataTable refDataTable = new ESciDocItemDataTable(this);
jurzua
parents:
diff changeset
266 protected SelectedESciDocItems selectedItems = new SelectedESciDocItems();
jurzua
parents:
diff changeset
267
jurzua
parents:
diff changeset
268 public ESciDocItemDataTable getRefDataTable() {
jurzua
parents:
diff changeset
269 return refDataTable;
jurzua
parents:
diff changeset
270 }
jurzua
parents:
diff changeset
271
jurzua
parents:
diff changeset
272 public void setRefDataTable(ESciDocItemDataTable refDataTable) {
jurzua
parents:
diff changeset
273 this.refDataTable = refDataTable;
jurzua
parents:
diff changeset
274 }
jurzua
parents:
diff changeset
275
jurzua
parents:
diff changeset
276 public void listenerRemoveReference(ActionEvent event){
jurzua
parents:
diff changeset
277 List<String> pubIdList = new ArrayList<String>();
jurzua
parents:
diff changeset
278 for(String pubId : this.selectedItems.getMap().keySet()){
jurzua
parents:
diff changeset
279 if(this.selectedItems.getMap().get(pubId)){
jurzua
parents:
diff changeset
280 pubIdList.add(pubId);
jurzua
parents:
diff changeset
281 }
jurzua
parents:
diff changeset
282 }
jurzua
parents:
diff changeset
283 for(String pubId : pubIdList){
jurzua
parents:
diff changeset
284 this.selectedItems.removeById(pubId);
jurzua
parents:
diff changeset
285 }
jurzua
parents:
diff changeset
286 }
jurzua
parents:
diff changeset
287
jurzua
parents:
diff changeset
288 public void loadReferences(Entity currentEntity){
jurzua
parents:
diff changeset
289 this.loadReferences(currentEntity, new ArrayList<String>());
jurzua
parents:
diff changeset
290 }
jurzua
parents:
diff changeset
291
jurzua
parents:
diff changeset
292 public void loadReferences(Entity currentEntity, List<String> idsNoFound){
jurzua
parents:
diff changeset
293 this.selectedItems.setList(new ArrayList<ESciDocItem>());
jurzua
parents:
diff changeset
294 boolean escidocRespondOK = true;
jurzua
parents:
diff changeset
295 try{
jurzua
parents:
diff changeset
296
jurzua
parents:
diff changeset
297 for (Relation rel : currentEntity.getTargetRelations()) {
jurzua
parents:
diff changeset
298 if (rel.getOwnValue().equals(rel_is_reference_of)) {
jurzua
parents:
diff changeset
299 Entity source = getWrapper().getEntityByIdWithContent(rel.getSourceId());
jurzua
parents:
diff changeset
300 ESciDocItem item = getAppBean().getRefCache().getItem(source.getOwnValue());
jurzua
parents:
diff changeset
301 if(item == null){
jurzua
parents:
diff changeset
302 item = new ESciDocItem(source.getOwnValue());
jurzua
parents:
diff changeset
303 item.setErrorLoading(ESciDocItem.ESCIDOC_ERROR_ID_NO_FOUND);
jurzua
parents:
diff changeset
304 idsNoFound.add(source.getOwnValue());
jurzua
parents:
diff changeset
305 }
jurzua
parents:
diff changeset
306
jurzua
parents:
diff changeset
307 /*Publication pub = ESciDocHandler.getPublicationById(source.getOwnValue());
jurzua
parents:
diff changeset
308 if(pub == null){
jurzua
parents:
diff changeset
309 pub = new Publication(source.getOwnValue());
jurzua
parents:
diff changeset
310 pub.setErrorLoading(Publication.ESCIDOC_ERROR_ID_NO_FOUND);
jurzua
parents:
diff changeset
311 idsNoFound.add(source.getOwnValue());
jurzua
parents:
diff changeset
312 }
jurzua
parents:
diff changeset
313 */
jurzua
parents:
diff changeset
314 Attribute att = source.getAttributeByName("additional_information");
jurzua
parents:
diff changeset
315 if(att != null){
jurzua
parents:
diff changeset
316 item.getPublication().setAdditionalInformation(att.getOwnValue());
jurzua
parents:
diff changeset
317 }
jurzua
parents:
diff changeset
318 item.getPublication().setEntity(source);
jurzua
parents:
diff changeset
319 this.selectedItems.addESciDocItem(item);
jurzua
parents:
diff changeset
320 }
jurzua
parents:
diff changeset
321 }
jurzua
parents:
diff changeset
322 }catch (Exception e) {
jurzua
parents:
diff changeset
323 escidocRespondOK = false;
jurzua
parents:
diff changeset
324 }
jurzua
parents:
diff changeset
325 this.reportEscidocError(escidocRespondOK, idsNoFound);
jurzua
parents:
diff changeset
326 }
jurzua
parents:
diff changeset
327
jurzua
parents:
diff changeset
328
jurzua
parents:
diff changeset
329
jurzua
parents:
diff changeset
330 protected void reportEscidocError(boolean escidocRespondOK, List<String> idsNoFound){
jurzua
parents:
diff changeset
331 if(!escidocRespondOK){
jurzua
parents:
diff changeset
332 addGeneralMsg("The references could not be loaded. The server did not respond.");
jurzua
parents:
diff changeset
333 addGeneralMsg("Exception connecting to http://escidoc.mpiwg-berlin.mpg.de:8080 ");
jurzua
parents:
diff changeset
334 }
jurzua
parents:
diff changeset
335
jurzua
parents:
diff changeset
336 if(!idsNoFound.isEmpty()){
jurzua
parents:
diff changeset
337 addGeneralMsg("The following references were not found in Pubman server:");
jurzua
parents:
diff changeset
338 StringBuilder sb = new StringBuilder();
jurzua
parents:
diff changeset
339 int count = 0;
jurzua
parents:
diff changeset
340 for(String id : idsNoFound){
jurzua
parents:
diff changeset
341 if(count > 0){
jurzua
parents:
diff changeset
342 sb.append(", ");
jurzua
parents:
diff changeset
343 }
jurzua
parents:
diff changeset
344 sb.append(id);
jurzua
parents:
diff changeset
345 }
jurzua
parents:
diff changeset
346 addGeneralMsg(sb.toString());
jurzua
parents:
diff changeset
347 }
jurzua
parents:
diff changeset
348
jurzua
parents:
diff changeset
349 }
jurzua
parents:
diff changeset
350
jurzua
parents:
diff changeset
351 protected void prepareEndNoteRefs2Save() throws Exception{
jurzua
parents:
diff changeset
352 //REFERENCE -> is_reference_of -> WITNESS
jurzua
parents:
diff changeset
353 this.entity.removeAllTargetRelationsByName(rel_is_reference_of);
jurzua
parents:
diff changeset
354 for(SelectableObject<Reference> so : this.endNoteRefTable.list){
jurzua
parents:
diff changeset
355 Reference ref = so.getObj();
jurzua
parents:
diff changeset
356
jurzua
parents:
diff changeset
357 Entity entRef = ref.getEnt();
jurzua
parents:
diff changeset
358 getWrapper().saveAssertion(entRef, getUserName());
jurzua
parents:
diff changeset
359 //entity can be no persistent, therefore the assignment of the relation should be done after the save
jurzua
parents:
diff changeset
360 entRef.addSourceRelation(rel_is_reference_of, entity);
jurzua
parents:
diff changeset
361 //new Relation(entRef, entity, rel_is_reference_of);
jurzua
parents:
diff changeset
362 }
jurzua
parents:
diff changeset
363 }
jurzua
parents:
diff changeset
364
jurzua
parents:
diff changeset
365 protected Entity prepareESciDocRefs2Save(Entity currentEntity) throws Exception{
jurzua
parents:
diff changeset
366 //REFERENCE -> is_reference_of -> WITNESS
jurzua
parents:
diff changeset
367 currentEntity.removeAllTargetRelationsByName(rel_is_reference_of);
jurzua
parents:
diff changeset
368 for(ESciDocItem item : this.selectedItems.getList()){
jurzua
parents:
diff changeset
369 Publication pub = item.getPublication();
jurzua
parents:
diff changeset
370 if(pub.getEntity() == null){
jurzua
parents:
diff changeset
371 Entity pubEntity = new Entity(Node.TYPE_ABOX, REFERENCE, false);
jurzua
parents:
diff changeset
372 pubEntity.setOwnValue(pub.getObjid());
jurzua
parents:
diff changeset
373 pubEntity.addAttribute(new Attribute("id", "escidoc-objid", pub.getObjid()));
jurzua
parents:
diff changeset
374 if(StringUtils.isNotEmpty(pub.getAdditionalInformation())){
jurzua
parents:
diff changeset
375 pubEntity.addAttribute(new Attribute("additional_information", "text", pub.getAdditionalInformation()));
jurzua
parents:
diff changeset
376 }
jurzua
parents:
diff changeset
377 pubEntity = getWrapper().saveEntity(pubEntity, getUserName());
jurzua
parents:
diff changeset
378 pub.setEntity(pubEntity);
jurzua
parents:
diff changeset
379 }else{
jurzua
parents:
diff changeset
380 if(pub.getEntity().getAttributeByName("additional_information") != null){
jurzua
parents:
diff changeset
381 pub.getEntity().getAttributeByName("additional_information").setOwnValue(pub.getAdditionalInformation());
jurzua
parents:
diff changeset
382 }else{
jurzua
parents:
diff changeset
383 pub.getEntity().addAttribute(new Attribute("additional_information", "text", pub.getAdditionalInformation()));
jurzua
parents:
diff changeset
384 }
jurzua
parents:
diff changeset
385 pub.setEntity(getWrapper().saveEntity(pub.getEntity(), getUserName()));
jurzua
parents:
diff changeset
386 }
jurzua
parents:
diff changeset
387 Relation rel = new Relation(pub.getEntity(), currentEntity, rel_is_reference_of);
jurzua
parents:
diff changeset
388 }
jurzua
parents:
diff changeset
389 return currentEntity;
jurzua
parents:
diff changeset
390 }
jurzua
parents:
diff changeset
391
jurzua
parents:
diff changeset
392 public static de.mpiwg.itgroup.ismi.util.guiComponents.Calendar updateCalendar(Attribute att){
jurzua
parents:
diff changeset
393 de.mpiwg.itgroup.ismi.util.guiComponents.Calendar calendar = null;
jurzua
parents:
diff changeset
394 if(att != null && StringUtils.isNotEmpty(att.getOwnValue())){
jurzua
parents:
diff changeset
395 calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar(att.getOwnValue());
jurzua
parents:
diff changeset
396 }else{
jurzua
parents:
diff changeset
397 calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar();
jurzua
parents:
diff changeset
398 }
jurzua
parents:
diff changeset
399 return calendar;
jurzua
parents:
diff changeset
400 }
jurzua
parents:
diff changeset
401
jurzua
parents:
diff changeset
402 protected void loadAttributes(Entity entity) {
jurzua
parents:
diff changeset
403 attributes = new HashMap<String, String>();
jurzua
parents:
diff changeset
404 if (entity != null) {
jurzua
parents:
diff changeset
405 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) {
jurzua
parents:
diff changeset
406 Attribute originalAtt = entity.getAttributeByName(defAtt
jurzua
parents:
diff changeset
407 .getOwnValue());
jurzua
parents:
diff changeset
408 String attValue = (originalAtt != null) ? originalAtt
jurzua
parents:
diff changeset
409 .getOwnValue() : "";
jurzua
parents:
diff changeset
410 attributes.put(defAtt.getOwnValue(), attValue);
jurzua
parents:
diff changeset
411 }
jurzua
parents:
diff changeset
412 } else {
jurzua
parents:
diff changeset
413 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) {
jurzua
parents:
diff changeset
414 attributes.put(defAtt.getOwnValue(), "");
jurzua
parents:
diff changeset
415 }
jurzua
parents:
diff changeset
416 }
jurzua
parents:
diff changeset
417 }
jurzua
parents:
diff changeset
418
jurzua
parents:
diff changeset
419 public void reset(){
jurzua
parents:
diff changeset
420 this.setSelectedSaveAsNew(false);
jurzua
parents:
diff changeset
421 this.setCurrentId("");
jurzua
parents:
diff changeset
422 this.setCurrentIdMsg("");
jurzua
parents:
diff changeset
423 this.setAttributes(new HashMap<String, String>());
jurzua
parents:
diff changeset
424 this.selectedItems = new SelectedESciDocItems();
jurzua
parents:
diff changeset
425 this.displayUrl = null;
jurzua
parents:
diff changeset
426 this.endNoteRefTable = new ReferenceTable();
jurzua
parents:
diff changeset
427 }
jurzua
parents:
diff changeset
428
jurzua
parents:
diff changeset
429 public boolean isSelectedSaveAsNew() {
jurzua
parents:
diff changeset
430 return selectedSaveAsNew;
jurzua
parents:
diff changeset
431 }
jurzua
parents:
diff changeset
432
jurzua
parents:
diff changeset
433 public void setSelectedSaveAsNew(boolean selectedSaveAsNew) {
jurzua
parents:
diff changeset
434 this.selectedSaveAsNew = selectedSaveAsNew;
jurzua
parents:
diff changeset
435 }
jurzua
parents:
diff changeset
436
jurzua
parents:
diff changeset
437 /**
jurzua
parents:
diff changeset
438 * <p>
jurzua
parents:
diff changeset
439 * "Entity -> CurrentEntity"
jurzua
parents:
diff changeset
440 * </p>
jurzua
parents:
diff changeset
441 * <p>
jurzua
parents:
diff changeset
442 * This method updates the attributes of the given entity with the
jurzua
parents:
diff changeset
443 * attributes of the attributes Map<String, String>.
jurzua
parents:
diff changeset
444 * </p>
jurzua
parents:
diff changeset
445 *
jurzua
parents:
diff changeset
446 * @return the input's entity with updated attributes.
jurzua
parents:
diff changeset
447 */
jurzua
parents:
diff changeset
448 public Entity updateEntityAttributes(Entity entity) {
jurzua
parents:
diff changeset
449 if (entity == null) {
jurzua
parents:
diff changeset
450 entity = new Entity(Node.TYPE_ABOX, false);
jurzua
parents:
diff changeset
451 //entity.setObjectClass(getDefinition().getOwnValue());
jurzua
parents:
diff changeset
452 entity.setObjectClass(this.defObjectClass);
jurzua
parents:
diff changeset
453 }
jurzua
parents:
diff changeset
454 //for (Attribute defAtt : getDefinition(entity).getAttributes()) {
jurzua
parents:
diff changeset
455 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) {
jurzua
parents:
diff changeset
456 Attribute att = entity.getAttributeByName(defAtt.getOwnValue());
jurzua
parents:
diff changeset
457 if (StringUtils.isNotEmpty(this.attributes
jurzua
parents:
diff changeset
458 .get(defAtt.getOwnValue()))) {
jurzua
parents:
diff changeset
459 if (att == null) {
jurzua
parents:
diff changeset
460 att = new Attribute(defAtt);
jurzua
parents:
diff changeset
461 entity.addAttribute(att);
jurzua
parents:
diff changeset
462 }
jurzua
parents:
diff changeset
463 att.setOwnValue(this.attributes.get(defAtt.getOwnValue()));
jurzua
parents:
diff changeset
464 att.setObjectClass(defAtt.getOwnValue());
jurzua
parents:
diff changeset
465 } else if (att != null) {
jurzua
parents:
diff changeset
466 // the attribute must be deleted.
jurzua
parents:
diff changeset
467 entity.getAttributes().remove(att);
jurzua
parents:
diff changeset
468 }
jurzua
parents:
diff changeset
469 }
jurzua
parents:
diff changeset
470 return entity;
jurzua
parents:
diff changeset
471 }
jurzua
parents:
diff changeset
472
jurzua
parents:
diff changeset
473 protected List<SelectItem> updateSuggestedPersonByRole(String searchWord, String objClass, String attName, String role){
jurzua
parents:
diff changeset
474 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), -1);
jurzua
parents:
diff changeset
475
jurzua
parents:
diff changeset
476 List<SelectItem> suggestedItems = new ArrayList<SelectItem>();
jurzua
parents:
diff changeset
477 if (attList == null)
jurzua
parents:
diff changeset
478 return suggestedItems;
jurzua
parents:
diff changeset
479
jurzua
parents:
diff changeset
480 int count = 0;
jurzua
parents:
diff changeset
481 for (Attribute att : attList) {
jurzua
parents:
diff changeset
482 if(getCache().roleContainsPersonId(role, att.getSourceId())){
jurzua
parents:
diff changeset
483 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]","description: " + att);
jurzua
parents:
diff changeset
484 suggestedItems.add(item);
jurzua
parents:
diff changeset
485 count++;
jurzua
parents:
diff changeset
486 if(count == MAX_SUGGEST)
jurzua
parents:
diff changeset
487 break;
jurzua
parents:
diff changeset
488 }
jurzua
parents:
diff changeset
489 }
jurzua
parents:
diff changeset
490 return suggestedItems;
jurzua
parents:
diff changeset
491 }
jurzua
parents:
diff changeset
492
jurzua
parents:
diff changeset
493 protected List<SelectItem> updateSuggestedItems(ValueChangeEvent event,
jurzua
parents:
diff changeset
494 String objClass, String attName) {
jurzua
parents:
diff changeset
495 return updateSuggestedItems((String) event.getNewValue(), objClass,
jurzua
parents:
diff changeset
496 attName);
jurzua
parents:
diff changeset
497 }
jurzua
parents:
diff changeset
498
jurzua
parents:
diff changeset
499 protected List<SelectItem> updateSuggestedItems(String searchWord,
jurzua
parents:
diff changeset
500 String objClass, String attName) {
jurzua
parents:
diff changeset
501
jurzua
parents:
diff changeset
502 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), MAX_SUGGEST);
jurzua
parents:
diff changeset
503
jurzua
parents:
diff changeset
504 List<SelectItem> suggestedItems = new ArrayList<SelectItem>();
jurzua
parents:
diff changeset
505 if (attList == null)
jurzua
parents:
diff changeset
506 return suggestedItems;
jurzua
parents:
diff changeset
507
jurzua
parents:
diff changeset
508 for (Attribute att : attList) {
jurzua
parents:
diff changeset
509 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]",
jurzua
parents:
diff changeset
510 "description: " + att);
jurzua
parents:
diff changeset
511 suggestedItems.add(item);
jurzua
parents:
diff changeset
512 }
jurzua
parents:
diff changeset
513 return suggestedItems;
jurzua
parents:
diff changeset
514 }
jurzua
parents:
diff changeset
515
jurzua
parents:
diff changeset
516 protected SimpleSearchCache getCache(){
jurzua
parents:
diff changeset
517 return getAppBean().getSimpleSearchCache();
jurzua
parents:
diff changeset
518 }
jurzua
parents:
diff changeset
519
jurzua
parents:
diff changeset
520 protected List<SelectItem> updateSuggestedItems(String objClass,
jurzua
parents:
diff changeset
521 String firstName, String firstValue, String secondName,
jurzua
parents:
diff changeset
522 String secondValue) {
jurzua
parents:
diff changeset
523
jurzua
parents:
diff changeset
524 List<Attribute> attList =
jurzua
parents:
diff changeset
525 getWrapper().
jurzua
parents:
diff changeset
526 searchAttribute(firstName, firstValue, secondName, secondValue, objClass, MAX_SUGGEST);
jurzua
parents:
diff changeset
527
jurzua
parents:
diff changeset
528 List<SelectItem> suggestedItems = new ArrayList<SelectItem>();
jurzua
parents:
diff changeset
529 if (attList == null)
jurzua
parents:
diff changeset
530 return suggestedItems;
jurzua
parents:
diff changeset
531
jurzua
parents:
diff changeset
532 for (Attribute att : attList) {
jurzua
parents:
diff changeset
533 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]");
jurzua
parents:
diff changeset
534 suggestedItems.add(item);
jurzua
parents:
diff changeset
535 }
jurzua
parents:
diff changeset
536 return suggestedItems;
jurzua
parents:
diff changeset
537 }
jurzua
parents:
diff changeset
538
jurzua
parents:
diff changeset
539 public Map<String, String> getAttributes() {
jurzua
parents:
diff changeset
540 return attributes;
jurzua
parents:
diff changeset
541 }
jurzua
parents:
diff changeset
542
jurzua
parents:
diff changeset
543 public void setAttributes(Map<String, String> attributes) {
jurzua
parents:
diff changeset
544 this.attributes = attributes;
jurzua
parents:
diff changeset
545 }
jurzua
parents:
diff changeset
546
jurzua
parents:
diff changeset
547 /**
jurzua
parents:
diff changeset
548 * <p>
jurzua
parents:
diff changeset
549 * This method plays the role of a small cache to get quickly the
jurzua
parents:
diff changeset
550 * definitions.
jurzua
parents:
diff changeset
551 * </p>
jurzua
parents:
diff changeset
552 * TODO this method must be implemented into a bean in session context and
jurzua
parents:
diff changeset
553 * research by every beans.
jurzua
parents:
diff changeset
554 *
jurzua
parents:
diff changeset
555 * @param assertion
jurzua
parents:
diff changeset
556 * @return
jurzua
parents:
diff changeset
557 */
jurzua
parents:
diff changeset
558 public Entity getLWDefinition(Entity assertion) {
jurzua
parents:
diff changeset
559 return getWrapper().getDefinition(assertion.getObjectClass());
jurzua
parents:
diff changeset
560 }
jurzua
parents:
diff changeset
561
jurzua
parents:
diff changeset
562 public Entity getLWDefinition(String objClass) {
jurzua
parents:
diff changeset
563 return getWrapper().getDefinition(objClass);
jurzua
parents:
diff changeset
564 }
jurzua
parents:
diff changeset
565
jurzua
parents:
diff changeset
566 /**
jurzua
parents:
diff changeset
567 * <p>
jurzua
parents:
diff changeset
568 * Returns the target's entity of a relation. The returned target is no
jurzua
parents:
diff changeset
569 * light weight.
jurzua
parents:
diff changeset
570 * <p>
jurzua
parents:
diff changeset
571 *
jurzua
parents:
diff changeset
572 * @param rel
jurzua
parents:
diff changeset
573 * @param target
jurzua
parents:
diff changeset
574 * @return
jurzua
parents:
diff changeset
575 */
jurzua
parents:
diff changeset
576 protected Entity getTargetRelation(Relation rel) {
jurzua
parents:
diff changeset
577 Entity target = rel.getTarget();
jurzua
parents:
diff changeset
578 if (target == null) {
jurzua
parents:
diff changeset
579 target = getWrapper().getEntityById(rel.getTargetId());
jurzua
parents:
diff changeset
580 rel.setTarget(target);
jurzua
parents:
diff changeset
581 } else if (target.isLightweight()) {
jurzua
parents:
diff changeset
582 target = getWrapper().getEntityContent(target);
jurzua
parents:
diff changeset
583 }
jurzua
parents:
diff changeset
584 return target;
jurzua
parents:
diff changeset
585 }
jurzua
parents:
diff changeset
586
jurzua
parents:
diff changeset
587 protected Attribute getTargetAttribute(Entity target, String name) {
jurzua
parents:
diff changeset
588 Attribute att = getWrapper().getAttributeByName(target.getId(), name);
jurzua
parents:
diff changeset
589
jurzua
parents:
diff changeset
590 if (att == null) {
jurzua
parents:
diff changeset
591 att = new Attribute();
jurzua
parents:
diff changeset
592 att.setOwnValue(target.getOwnValue());
jurzua
parents:
diff changeset
593 }
jurzua
parents:
diff changeset
594 return att;
jurzua
parents:
diff changeset
595 }
jurzua
parents:
diff changeset
596
jurzua
parents:
diff changeset
597 protected WrapperService getWrapper() {
jurzua
parents:
diff changeset
598 return getAppBean().getWrapper();
jurzua
parents:
diff changeset
599 }
jurzua
parents:
diff changeset
600
jurzua
parents:
diff changeset
601 /**
jurzua
parents:
diff changeset
602 * <p>
jurzua
parents:
diff changeset
603 * Return the <code>FacesContext</code> instance for the current request.
jurzua
parents:
diff changeset
604 */
jurzua
parents:
diff changeset
605 protected FacesContext context() {
jurzua
parents:
diff changeset
606 return (FacesContext.getCurrentInstance());
jurzua
parents:
diff changeset
607 }
jurzua
parents:
diff changeset
608
jurzua
parents:
diff changeset
609 public void setCreate_error(Boolean create_error) {
jurzua
parents:
diff changeset
610 this.create_error = create_error;
jurzua
parents:
diff changeset
611 }
jurzua
parents:
diff changeset
612
jurzua
parents:
diff changeset
613 public Boolean getCreate_error() {
jurzua
parents:
diff changeset
614 return create_error;
jurzua
parents:
diff changeset
615 }
jurzua
parents:
diff changeset
616
jurzua
parents:
diff changeset
617 /**
jurzua
parents:
diff changeset
618 * Eine Liste <code>toBeRestricted</code> wird so eingeschraenkt, dass nur
jurzua
parents:
diff changeset
619 * noch die jenigen uebrig bleiben, die �ber die Relation
jurzua
parents:
diff changeset
620 * <code>relation</code> mit einem der Elemente aus
jurzua
parents:
diff changeset
621 * <code>contraintIds</code> verbunden sind.
jurzua
parents:
diff changeset
622 *
jurzua
parents:
diff changeset
623 * @param toBeRestricted
jurzua
parents:
diff changeset
624 * @param constraintIds
jurzua
parents:
diff changeset
625 * @param relation
jurzua
parents:
diff changeset
626 * @param mode
jurzua
parents:
diff changeset
627 * @return
jurzua
parents:
diff changeset
628 */
jurzua
parents:
diff changeset
629 protected List<SelectItem> restrictList(List<SelectItem> toBeRestricted,
jurzua
parents:
diff changeset
630 List<String> constraintIds, String relation, String mode) {
jurzua
parents:
diff changeset
631
jurzua
parents:
diff changeset
632 List<SelectItem> newList = new ArrayList<SelectItem>();
jurzua
parents:
diff changeset
633
jurzua
parents:
diff changeset
634 for (SelectItem s : toBeRestricted) {
jurzua
parents:
diff changeset
635 Entity ent = getWrapper().getEntityById(
jurzua
parents:
diff changeset
636 Long.valueOf((String) s.getValue()));
jurzua
parents:
diff changeset
637 if (s.getValue().equals("0")) {
jurzua
parents:
diff changeset
638 newList.add(s);
jurzua
parents:
diff changeset
639 continue;
jurzua
parents:
diff changeset
640 }
jurzua
parents:
diff changeset
641
jurzua
parents:
diff changeset
642 List<Relation> rels;
jurzua
parents:
diff changeset
643 if (mode.equals("target")) {
jurzua
parents:
diff changeset
644 rels = ent.getTargetRelations();
jurzua
parents:
diff changeset
645 } else if (mode.equals("source")) {
jurzua
parents:
diff changeset
646 rels = ent.getSourceRelations();
jurzua
parents:
diff changeset
647 } else {
jurzua
parents:
diff changeset
648 System.err.println("restrict List - mode not defined:" + mode);
jurzua
parents:
diff changeset
649 return null;
jurzua
parents:
diff changeset
650 }
jurzua
parents:
diff changeset
651
jurzua
parents:
diff changeset
652 for (Relation r : rels) {
jurzua
parents:
diff changeset
653 if (r.getObjectClass().equals(relation)) {
jurzua
parents:
diff changeset
654 Long id;
jurzua
parents:
diff changeset
655 if (mode.equals("target")) {
jurzua
parents:
diff changeset
656 id = r.getSource().getId();
jurzua
parents:
diff changeset
657 } else if (mode.equals("source")) {
jurzua
parents:
diff changeset
658 id = r.getTarget().getId();
jurzua
parents:
diff changeset
659 } else {
jurzua
parents:
diff changeset
660 System.err.println("restrict List - mode not defined:"
jurzua
parents:
diff changeset
661 + mode);
jurzua
parents:
diff changeset
662 return null;
jurzua
parents:
diff changeset
663 }
jurzua
parents:
diff changeset
664 if (constraintIds.contains(String.valueOf(id))) {
jurzua
parents:
diff changeset
665 newList.add(s);
jurzua
parents:
diff changeset
666 }
jurzua
parents:
diff changeset
667 }
jurzua
parents:
diff changeset
668 }
jurzua
parents:
diff changeset
669 }
jurzua
parents:
diff changeset
670
jurzua
parents:
diff changeset
671 return newList;
jurzua
parents:
diff changeset
672 }
jurzua
parents:
diff changeset
673
jurzua
parents:
diff changeset
674 public String getSelectedWitnessID() {
jurzua
parents:
diff changeset
675 return selectedWitnessID;
jurzua
parents:
diff changeset
676 }
jurzua
parents:
diff changeset
677
jurzua
parents:
diff changeset
678 public void setShowWitness(boolean showWitness) {
jurzua
parents:
diff changeset
679 this.showWitness = showWitness;
jurzua
parents:
diff changeset
680 }
jurzua
parents:
diff changeset
681
jurzua
parents:
diff changeset
682 public boolean isShowWitness() {
jurzua
parents:
diff changeset
683 return showWitness;
jurzua
parents:
diff changeset
684 }
jurzua
parents:
diff changeset
685
jurzua
parents:
diff changeset
686 public void setShowTitle(boolean showTitle) {
jurzua
parents:
diff changeset
687 this.showTitle = showTitle;
jurzua
parents:
diff changeset
688 }
jurzua
parents:
diff changeset
689
jurzua
parents:
diff changeset
690 public boolean isShowTitle() {
jurzua
parents:
diff changeset
691 return showTitle;
jurzua
parents:
diff changeset
692 }
jurzua
parents:
diff changeset
693 /*
jurzua
parents:
diff changeset
694 public PanelPopup getPopup() {
jurzua
parents:
diff changeset
695 return popup;
jurzua
parents:
diff changeset
696 }
jurzua
parents:
diff changeset
697
jurzua
parents:
diff changeset
698 public void setPopup(PanelPopup popup) {
jurzua
parents:
diff changeset
699 this.popup = popup;
jurzua
parents:
diff changeset
700 }
jurzua
parents:
diff changeset
701
jurzua
parents:
diff changeset
702 public String getPopupText() {
jurzua
parents:
diff changeset
703 return popupText;
jurzua
parents:
diff changeset
704 }
jurzua
parents:
diff changeset
705
jurzua
parents:
diff changeset
706 public void setPopupText(String popupText) {
jurzua
parents:
diff changeset
707 this.popupText = popupText;
jurzua
parents:
diff changeset
708 }*/
jurzua
parents:
diff changeset
709
jurzua
parents:
diff changeset
710
jurzua
parents:
diff changeset
711 public String getUserName(){
jurzua
parents:
diff changeset
712 User user = getSessionUser();
jurzua
parents:
diff changeset
713 if(user == null)
jurzua
parents:
diff changeset
714 return "";
jurzua
parents:
diff changeset
715 else
jurzua
parents:
diff changeset
716 return user.getEmail();
jurzua
parents:
diff changeset
717 }
jurzua
parents:
diff changeset
718
jurzua
parents:
diff changeset
719 public User getSessionUser() {
jurzua
parents:
diff changeset
720 SessionBean bean = getSessionBean();
jurzua
parents:
diff changeset
721 if(bean != null){
jurzua
parents:
diff changeset
722 return bean.getUser();
jurzua
parents:
diff changeset
723 }else{
jurzua
parents:
diff changeset
724 return null;
jurzua
parents:
diff changeset
725 }
jurzua
parents:
diff changeset
726 }
jurzua
parents:
diff changeset
727
jurzua
parents:
diff changeset
728 public void fillList(List<SelectItem> list, String[] array) {
jurzua
parents:
diff changeset
729 list.add(new SelectItem(""));
jurzua
parents:
diff changeset
730 for (int i = 0; i < array.length; i++) {
jurzua
parents:
diff changeset
731 list.add(new SelectItem(array[i]));
jurzua
parents:
diff changeset
732 }
jurzua
parents:
diff changeset
733
jurzua
parents:
diff changeset
734 }
jurzua
parents:
diff changeset
735
jurzua
parents:
diff changeset
736 public boolean isWarning() {
jurzua
parents:
diff changeset
737 return warning;
jurzua
parents:
diff changeset
738 }
jurzua
parents:
diff changeset
739
jurzua
parents:
diff changeset
740 public void setWarning(boolean warning) {
jurzua
parents:
diff changeset
741 this.warning = warning;
jurzua
parents:
diff changeset
742 }
jurzua
parents:
diff changeset
743
jurzua
parents:
diff changeset
744 public void setWarningMessage(String warningMessage) {
jurzua
parents:
diff changeset
745 this.warningMessage = warningMessage;
jurzua
parents:
diff changeset
746 }
jurzua
parents:
diff changeset
747
jurzua
parents:
diff changeset
748 public String getWarningMessage() {
jurzua
parents:
diff changeset
749 return warningMessage;
jurzua
parents:
diff changeset
750 }
jurzua
parents:
diff changeset
751
jurzua
parents:
diff changeset
752 public void setDisplayWarning(boolean displayWarning) {
jurzua
parents:
diff changeset
753 this.displayWarning = displayWarning;
jurzua
parents:
diff changeset
754 }
jurzua
parents:
diff changeset
755
jurzua
parents:
diff changeset
756 public boolean isDisplayWarning() {
jurzua
parents:
diff changeset
757 return displayWarning;
jurzua
parents:
diff changeset
758 }
jurzua
parents:
diff changeset
759
jurzua
parents:
diff changeset
760 public void registerChecker(StatusChecker sc) {
jurzua
parents:
diff changeset
761 statusChecker.add(sc);
jurzua
parents:
diff changeset
762 }
jurzua
parents:
diff changeset
763
jurzua
parents:
diff changeset
764 public void registerChecker(ListenerObject lo, String message) {
jurzua
parents:
diff changeset
765 registerChecker(lo.statusImage, message);
jurzua
parents:
diff changeset
766
jurzua
parents:
diff changeset
767 }
jurzua
parents:
diff changeset
768
jurzua
parents:
diff changeset
769 public void registerChecker(StatusChecker sc, String message) {
jurzua
parents:
diff changeset
770 sc.setMessage(message);
jurzua
parents:
diff changeset
771 statusChecker.add(sc);
jurzua
parents:
diff changeset
772 }
jurzua
parents:
diff changeset
773
jurzua
parents:
diff changeset
774 class CheckResults {
jurzua
parents:
diff changeset
775 List<String> errors = new ArrayList<String>();
jurzua
parents:
diff changeset
776 List<String> warnings = new ArrayList<String>();
jurzua
parents:
diff changeset
777 public boolean hasErrors = false;
jurzua
parents:
diff changeset
778 public boolean hasWarnings = false;
jurzua
parents:
diff changeset
779
jurzua
parents:
diff changeset
780 }
jurzua
parents:
diff changeset
781
jurzua
parents:
diff changeset
782 public CheckResults getCheckResults() {
jurzua
parents:
diff changeset
783 CheckResults cr = new CheckResults();
jurzua
parents:
diff changeset
784
jurzua
parents:
diff changeset
785 for (StatusChecker sc : statusChecker) {
jurzua
parents:
diff changeset
786 if (sc.getStatus().equals("false")) {
jurzua
parents:
diff changeset
787 cr.hasErrors = true;
jurzua
parents:
diff changeset
788 cr.errors.add(sc.getMessage());
jurzua
parents:
diff changeset
789 } else if (sc.getStatus().equals("unset")) {
jurzua
parents:
diff changeset
790 cr.hasWarnings = true;
jurzua
parents:
diff changeset
791 cr.warnings.add(sc.getMessage());
jurzua
parents:
diff changeset
792 }
jurzua
parents:
diff changeset
793 }
jurzua
parents:
diff changeset
794 return cr;
jurzua
parents:
diff changeset
795 }
jurzua
parents:
diff changeset
796
jurzua
parents:
diff changeset
797 protected ListenerObject changeValue(String ownvalue, ListenerObject lo, String suggestType, String suggestAttributeName,
jurzua
parents:
diff changeset
798 List<SelectItem> restrictedItems) {
jurzua
parents:
diff changeset
799 if (restrictedItems != null) {
jurzua
parents:
diff changeset
800 lo.suggestedItems = restrictedItems;}
jurzua
parents:
diff changeset
801
jurzua
parents:
diff changeset
802 if (ownvalue == null || ownvalue.equals(""))
jurzua
parents:
diff changeset
803 lo.statusImage.setStatus("unset");
jurzua
parents:
diff changeset
804 else
jurzua
parents:
diff changeset
805 lo.statusImage.setStatus("false");
jurzua
parents:
diff changeset
806 lo.entity = null;
jurzua
parents:
diff changeset
807 // setze erst mal den Eigenwert auf das eingebene.
jurzua
parents:
diff changeset
808 Attribute at = new Attribute();
jurzua
parents:
diff changeset
809 at.setOwnValue(ownvalue);
jurzua
parents:
diff changeset
810 lo.attribute = at;
jurzua
parents:
diff changeset
811 Entity element = null;
jurzua
parents:
diff changeset
812 if (lo.suggestedItems != null) // schaue in der liste der vorgebenen Ereignisse nach.
jurzua
parents:
diff changeset
813 for (SelectItem item : lo.suggestedItems) {
jurzua
parents:
diff changeset
814 if (item.getLabel().equals(ownvalue)) {
jurzua
parents:
diff changeset
815 if (Attribute.class.isInstance(item.getValue())){ // entweder es ist schon ein attribute
jurzua
parents:
diff changeset
816 lo.attribute = (Attribute) item.getValue();
jurzua
parents:
diff changeset
817 element = getWrapper().getEntityById(
jurzua
parents:
diff changeset
818 lo.attribute.getSourceId());
jurzua
parents:
diff changeset
819 }else{ //oder ein paar wert / id// = (Attribute) item.getValue();
jurzua
parents:
diff changeset
820 element = getWrapper().getEntityById(Long.valueOf((String) item.getValue()));
jurzua
parents:
diff changeset
821 lo.setEntityAndAttribute(element, suggestAttributeName);
jurzua
parents:
diff changeset
822 }
jurzua
parents:
diff changeset
823 if (element != null) {
jurzua
parents:
diff changeset
824 if(element.isLightweight()){
jurzua
parents:
diff changeset
825 element = getWrapper().getEntityByIdWithContent(element.getId());
jurzua
parents:
diff changeset
826 }
jurzua
parents:
diff changeset
827 lo.entity = element;
jurzua
parents:
diff changeset
828 lo.statusImage.setStatus("ok");
jurzua
parents:
diff changeset
829 }
jurzua
parents:
diff changeset
830 break;
jurzua
parents:
diff changeset
831 }
jurzua
parents:
diff changeset
832
jurzua
parents:
diff changeset
833 } else {
jurzua
parents:
diff changeset
834 //juc *** List<Entity> ents = getWrapper().getLightweightConceptsByAttribute(null, suggestType, suggestAttributeName, ownvalue, 1, false);
jurzua
parents:
diff changeset
835 List<Entity> ents = getWrapper().getEntitiesByAtt(suggestType, suggestAttributeName, ownvalue, 1, false);
jurzua
parents:
diff changeset
836 if (ents.size()==1){
jurzua
parents:
diff changeset
837 lo.setEntityAndAttribute(ents.get(0),suggestAttributeName);
jurzua
parents:
diff changeset
838 lo.statusImage.setStatus("ok");
jurzua
parents:
diff changeset
839 }
jurzua
parents:
diff changeset
840
jurzua
parents:
diff changeset
841 }
jurzua
parents:
diff changeset
842 return lo;
jurzua
parents:
diff changeset
843
jurzua
parents:
diff changeset
844 }
jurzua
parents:
diff changeset
845
jurzua
parents:
diff changeset
846
jurzua
parents:
diff changeset
847
jurzua
parents:
diff changeset
848 protected ListenerObject changeValuePersonByRole(ValueChangeEvent event, ListenerObject lo, String role){
jurzua
parents:
diff changeset
849 if (event.getNewValue() == null) {
jurzua
parents:
diff changeset
850 return lo;
jurzua
parents:
diff changeset
851 }else if(StringUtils.isEmpty(event.getNewValue().toString()) && (event.getOldValue() == null || StringUtils.isEmpty(event.getOldValue().toString()))){
jurzua
parents:
diff changeset
852 //if the old and new value are empty, then return
jurzua
parents:
diff changeset
853 return lo;
jurzua
parents:
diff changeset
854 }
jurzua
parents:
diff changeset
855 if (event.getNewValue().equals(event.getOldValue())) {
jurzua
parents:
diff changeset
856 return lo;
jurzua
parents:
diff changeset
857 }
jurzua
parents:
diff changeset
858
jurzua
parents:
diff changeset
859 String ownValue = (String) event.getNewValue();
jurzua
parents:
diff changeset
860
jurzua
parents:
diff changeset
861 if(StringUtils.isEmpty(ownValue))
jurzua
parents:
diff changeset
862 lo.statusImage.setStatus("unset");
jurzua
parents:
diff changeset
863 else
jurzua
parents:
diff changeset
864 lo.statusImage.setStatus("false");
jurzua
parents:
diff changeset
865
jurzua
parents:
diff changeset
866 lo.entity = null;
jurzua
parents:
diff changeset
867 // setze erst mal den Eigenwert auf das eingebene.
jurzua
parents:
diff changeset
868 Attribute at = new Attribute();
jurzua
parents:
diff changeset
869 at.setOwnValue(ownValue);
jurzua
parents:
diff changeset
870 lo.attribute = at;
jurzua
parents:
diff changeset
871 for (SelectItem item : lo.suggestedItems) {
jurzua
parents:
diff changeset
872 if (StringUtils.isNotEmpty(item.getLabel()) &&
jurzua
parents:
diff changeset
873 item.getLabel().equals(ownValue)) {
jurzua
parents:
diff changeset
874 //System.out.println("item.getValue()= " + item.getValue());
jurzua
parents:
diff changeset
875 lo.attribute = (Attribute) item.getValue();
jurzua
parents:
diff changeset
876 Entity element = getWrapper().getEntityById(
jurzua
parents:
diff changeset
877 lo.attribute.getSourceId());
jurzua
parents:
diff changeset
878
jurzua
parents:
diff changeset
879 if (element != null) {
jurzua
parents:
diff changeset
880 if(element.isLightweight()){
jurzua
parents:
diff changeset
881 element = getWrapper().getEntityByIdWithContent(element.getId());
jurzua
parents:
diff changeset
882 }
jurzua
parents:
diff changeset
883 lo.entity = element;
jurzua
parents:
diff changeset
884 lo.statusImage.setStatus(StatusImage.STATUS_OK);
jurzua
parents:
diff changeset
885 }
jurzua
parents:
diff changeset
886 break;
jurzua
parents:
diff changeset
887 }
jurzua
parents:
diff changeset
888
jurzua
parents:
diff changeset
889 }
jurzua
parents:
diff changeset
890
jurzua
parents:
diff changeset
891 //juc lo.suggestedItems = updateSuggestedPersonByRole(ownValue, PERSON, "name", role);
jurzua
parents:
diff changeset
892 lo.suggestedItems = updateSuggestedPersonByRole(ownValue, PERSON, "name_translit", role);
jurzua
parents:
diff changeset
893
jurzua
parents:
diff changeset
894
jurzua
parents:
diff changeset
895 return lo;
jurzua
parents:
diff changeset
896 }
jurzua
parents:
diff changeset
897
jurzua
parents:
diff changeset
898 protected ListenerObject changeValue(String ownvalue, ListenerObject lo,
jurzua
parents:
diff changeset
899 String suggestType, String suggestAttributeName) {
jurzua
parents:
diff changeset
900
jurzua
parents:
diff changeset
901 return changeValue(ownvalue, lo, suggestType, suggestAttributeName,
jurzua
parents:
diff changeset
902 null);
jurzua
parents:
diff changeset
903 }
jurzua
parents:
diff changeset
904
jurzua
parents:
diff changeset
905 protected ListenerObject changeListener(ValueChangeEvent event,
jurzua
parents:
diff changeset
906 ListenerObject lo, String suggestType, String suggestAttributeName,
jurzua
parents:
diff changeset
907 String restrictingAttributeName, String restrictingAttributeValue) {
jurzua
parents:
diff changeset
908 try {
jurzua
parents:
diff changeset
909 if (event.getNewValue() == null) {
jurzua
parents:
diff changeset
910 return lo;
jurzua
parents:
diff changeset
911 }else if(StringUtils.isEmpty(event.getNewValue().toString()) && (event.getOldValue() == null || StringUtils.isEmpty(event.getOldValue().toString()))){
jurzua
parents:
diff changeset
912 //if the old and new value are empty, then return
jurzua
parents:
diff changeset
913 return lo;
jurzua
parents:
diff changeset
914 }
jurzua
parents:
diff changeset
915 if (event.getNewValue().equals(event.getOldValue())) {
jurzua
parents:
diff changeset
916 return lo;
jurzua
parents:
diff changeset
917 }
jurzua
parents:
diff changeset
918
jurzua
parents:
diff changeset
919 String ownvalue = (String) event.getNewValue();
jurzua
parents:
diff changeset
920
jurzua
parents:
diff changeset
921 if(StringUtils.isEmpty(ownvalue))
jurzua
parents:
diff changeset
922 lo.statusImage.setStatus(StatusImage.STATUS_UNSET);
jurzua
parents:
diff changeset
923 else
jurzua
parents:
diff changeset
924 lo.statusImage.setStatus(StatusImage.STATUS_FALSE);
jurzua
parents:
diff changeset
925
jurzua
parents:
diff changeset
926 lo.entity = null;
jurzua
parents:
diff changeset
927 // setze erst mal den Eigenwert auf das eingebene.
jurzua
parents:
diff changeset
928 Attribute at = new Attribute();
jurzua
parents:
diff changeset
929 at.setOwnValue(ownvalue);
jurzua
parents:
diff changeset
930 lo.attribute = at;
jurzua
parents:
diff changeset
931 for (SelectItem item : lo.suggestedItems) {
jurzua
parents:
diff changeset
932 if (StringUtils.isNotEmpty(item.getLabel()) &&
jurzua
parents:
diff changeset
933 item.getLabel().equals(ownvalue)) {
jurzua
parents:
diff changeset
934 //System.out.println("item.getValue()= " + item.getValue());
jurzua
parents:
diff changeset
935 lo.attribute = (Attribute) item.getValue();
jurzua
parents:
diff changeset
936 Entity element = getWrapper().getEntityById(
jurzua
parents:
diff changeset
937 lo.attribute.getSourceId());
jurzua
parents:
diff changeset
938
jurzua
parents:
diff changeset
939 if (element != null) {
jurzua
parents:
diff changeset
940 if(element.isLightweight()){
jurzua
parents:
diff changeset
941 element = getWrapper().getEntityByIdWithContent(element.getId());
jurzua
parents:
diff changeset
942 }
jurzua
parents:
diff changeset
943 lo.entity = element;
jurzua
parents:
diff changeset
944 lo.statusImage.setStatus(StatusImage.STATUS_OK);
jurzua
parents:
diff changeset
945 }
jurzua
parents:
diff changeset
946 break;
jurzua
parents:
diff changeset
947 }
jurzua
parents:
diff changeset
948
jurzua
parents:
diff changeset
949 }
jurzua
parents:
diff changeset
950
jurzua
parents:
diff changeset
951 if (restrictingAttributeName == null) {
jurzua
parents:
diff changeset
952 lo.suggestedItems = this.updateSuggestedItems(event,
jurzua
parents:
diff changeset
953 suggestType, suggestAttributeName);
jurzua
parents:
diff changeset
954 } else {
jurzua
parents:
diff changeset
955 lo.suggestedItems = this.updateSuggestedItems(suggestType,
jurzua
parents:
diff changeset
956 suggestAttributeName, event.getNewValue().toString(),
jurzua
parents:
diff changeset
957 restrictingAttributeName, restrictingAttributeValue);
jurzua
parents:
diff changeset
958 }
jurzua
parents:
diff changeset
959
jurzua
parents:
diff changeset
960 } catch (Exception e) {
jurzua
parents:
diff changeset
961 e.printStackTrace();
jurzua
parents:
diff changeset
962 }
jurzua
parents:
diff changeset
963 return lo;
jurzua
parents:
diff changeset
964 }
jurzua
parents:
diff changeset
965
jurzua
parents:
diff changeset
966 protected void generateSecundaryOW(Entity entity, String user) throws Exception{
jurzua
parents:
diff changeset
967 List<Entity> nodeList = new ArrayList<Entity>();
jurzua
parents:
diff changeset
968
jurzua
parents:
diff changeset
969 long start = System.currentTimeMillis();
jurzua
parents:
diff changeset
970 if(entity.getObjectClass().equals(PLACE)){
jurzua
parents:
diff changeset
971 this.generateOW4City(entity, nodeList, user);
jurzua
parents:
diff changeset
972 long medium = System.currentTimeMillis();
jurzua
parents:
diff changeset
973 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start));
jurzua
parents:
diff changeset
974 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user);
jurzua
parents:
diff changeset
975 System.out.println("Save time: " + (System.currentTimeMillis() - medium));
jurzua
parents:
diff changeset
976 }else if(entity.getObjectClass().equals(REPOSITORY)){
jurzua
parents:
diff changeset
977 this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user);
jurzua
parents:
diff changeset
978 long medium = System.currentTimeMillis();
jurzua
parents:
diff changeset
979 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start));
jurzua
parents:
diff changeset
980 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user);
jurzua
parents:
diff changeset
981 System.out.println("Save time: " + (System.currentTimeMillis() - medium));
jurzua
parents:
diff changeset
982 }else if(entity.getObjectClass().equals(COLLECTION)){
jurzua
parents:
diff changeset
983 this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user);
jurzua
parents:
diff changeset
984 long medium = System.currentTimeMillis();
jurzua
parents:
diff changeset
985 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start));
jurzua
parents:
diff changeset
986 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user);
jurzua
parents:
diff changeset
987 System.out.println("Save time: " + (System.currentTimeMillis() - medium));
jurzua
parents:
diff changeset
988 }else if(entity.getObjectClass().equals(CODEX)){
jurzua
parents:
diff changeset
989 this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user);
jurzua
parents:
diff changeset
990 long medium = System.currentTimeMillis();
jurzua
parents:
diff changeset
991 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start));
jurzua
parents:
diff changeset
992 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user);
jurzua
parents:
diff changeset
993 System.out.println("Save time: " + (System.currentTimeMillis() - medium));
jurzua
parents:
diff changeset
994 }else if(entity.getObjectClass().equals(TEXT)){
jurzua
parents:
diff changeset
995 generateOW4Text(entity, user);
jurzua
parents:
diff changeset
996 long medium = System.currentTimeMillis();
jurzua
parents:
diff changeset
997 System.out.println("Saving witnessList time: " + (medium - start));
jurzua
parents:
diff changeset
998 }
jurzua
parents:
diff changeset
999 //TODO PERSON and TEXT
jurzua
parents:
diff changeset
1000 }
jurzua
parents:
diff changeset
1001
jurzua
parents:
diff changeset
1002 private void generateOW4City(Entity city, List<Entity> nodeList, String user){
jurzua
parents:
diff changeset
1003 Map<String, String> map = new HashMap<String, String>();
jurzua
parents:
diff changeset
1004 map.put(PLACE, city.getOwnValue());
jurzua
parents:
diff changeset
1005
jurzua
parents:
diff changeset
1006 List<Entity> repoList = getWrapper().getSourcesForTargetRelation(city, is_in, REPOSITORY, -1);
jurzua
parents:
diff changeset
1007 for(Entity repo : repoList){
jurzua
parents:
diff changeset
1008 this.generateOW4Repository(repo, nodeList, map, user);
jurzua
parents:
diff changeset
1009 }
jurzua
parents:
diff changeset
1010 }
jurzua
parents:
diff changeset
1011
jurzua
parents:
diff changeset
1012 private void generateOW4Repository(Entity repository, List<Entity> nodeList, Map<String, String> map, String user){
jurzua
parents:
diff changeset
1013 if(map.size() == 0){
jurzua
parents:
diff changeset
1014 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1);
jurzua
parents:
diff changeset
1015 map.put(PLACE, ((placeList.size() > 0) ? placeList.get(0).getOwnValue() : ""));
jurzua
parents:
diff changeset
1016 }
jurzua
parents:
diff changeset
1017
jurzua
parents:
diff changeset
1018 map.put(REPOSITORY, repository.getOwnValue());
jurzua
parents:
diff changeset
1019 List<Entity> collectionList = getWrapper().getSourcesForTargetRelation(repository, is_part_of, COLLECTION, -1);
jurzua
parents:
diff changeset
1020 for(Entity collection : collectionList){
jurzua
parents:
diff changeset
1021 this.generateOW4Collection(collection, nodeList, map, user);
jurzua
parents:
diff changeset
1022 }
jurzua
parents:
diff changeset
1023 }
jurzua
parents:
diff changeset
1024
jurzua
parents:
diff changeset
1025 private void generateOW4Collection(Entity collection, List<Entity> nodeList, Map<String, String> map, String user){
jurzua
parents:
diff changeset
1026 if(map.size() == 0){
jurzua
parents:
diff changeset
1027 List<Entity> repoList = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1);
jurzua
parents:
diff changeset
1028 map.put(REPOSITORY, (repoList.size() > 0) ? repoList.get(0).getOwnValue() : "");
jurzua
parents:
diff changeset
1029 if(repoList.size() > 0){
jurzua
parents:
diff changeset
1030 Entity repository = repoList.get(0);
jurzua
parents:
diff changeset
1031 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1);
jurzua
parents:
diff changeset
1032 map.put(PLACE, (placeList.size() > 0) ? placeList.get(0).getOwnValue() : "");
jurzua
parents:
diff changeset
1033 }else{
jurzua
parents:
diff changeset
1034 map.put(REPOSITORY, "");
jurzua
parents:
diff changeset
1035 map.put(PLACE, "");
jurzua
parents:
diff changeset
1036 }
jurzua
parents:
diff changeset
1037 }
jurzua
parents:
diff changeset
1038
jurzua
parents:
diff changeset
1039 map.put(COLLECTION, collection.getOwnValue());
jurzua
parents:
diff changeset
1040 List<Entity> list = getWrapper().getSourcesForTargetRelation(collection, is_part_of, CODEX, -1);
jurzua
parents:
diff changeset
1041 for(Entity codex : list){
jurzua
parents:
diff changeset
1042 //update ow codex
jurzua
parents:
diff changeset
1043 Attribute att = getWrapper().getAttributeByName(codex.getId(), "identifier");
jurzua
parents:
diff changeset
1044 if(att != null){
jurzua
parents:
diff changeset
1045 codex.setOwnValue(collection.getOwnValue() + "_" + att.getOwnValue());
jurzua
parents:
diff changeset
1046 nodeList.add(codex);
jurzua
parents:
diff changeset
1047 }
jurzua
parents:
diff changeset
1048 this.generateOW4Codex(codex, nodeList, map, user);
jurzua
parents:
diff changeset
1049 }
jurzua
parents:
diff changeset
1050 }
jurzua
parents:
diff changeset
1051
jurzua
parents:
diff changeset
1052 private void generateOW4Codex(Entity codex, List<Entity> nodeList, Map<String, String> map, String user){
jurzua
parents:
diff changeset
1053 if(map.size() == 0){
jurzua
parents:
diff changeset
1054 List<Entity> collList = getWrapper().getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1);
jurzua
parents:
diff changeset
1055 map.put(COLLECTION, (collList.size() > 0 ) ? collList.get(0).getOwnValue() : "");
jurzua
parents:
diff changeset
1056 if(collList.size() > 0){
jurzua
parents:
diff changeset
1057 Entity collection = collList.get(0);
jurzua
parents:
diff changeset
1058 List<Entity> repoList = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1);
jurzua
parents:
diff changeset
1059 map.put(REPOSITORY, (repoList.size() > 0) ? repoList.get(0).getOwnValue() : "");
jurzua
parents:
diff changeset
1060 if(repoList.size() > 0){
jurzua
parents:
diff changeset
1061 Entity repository = repoList.get(0);
jurzua
parents:
diff changeset
1062 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1);
jurzua
parents:
diff changeset
1063 map.put(PLACE, (placeList.size() > 0) ? placeList.get(0).getOwnValue() : "");
jurzua
parents:
diff changeset
1064 }else{
jurzua
parents:
diff changeset
1065 map.put(PLACE, "");
jurzua
parents:
diff changeset
1066 }
jurzua
parents:
diff changeset
1067 }else{
jurzua
parents:
diff changeset
1068 map.put(COLLECTION, "");
jurzua
parents:
diff changeset
1069 map.put(REPOSITORY, "");
jurzua
parents:
diff changeset
1070 map.put(PLACE, "");
jurzua
parents:
diff changeset
1071 }
jurzua
parents:
diff changeset
1072 }
jurzua
parents:
diff changeset
1073 List<Entity> list = getWrapper().getSourcesForTargetRelation(codex, is_part_of, WITNESS, -1);
jurzua
parents:
diff changeset
1074 String placeText = (StringUtils.isNotEmpty(map.get(PLACE))) ? "_" + map.get(PLACE) : "";
jurzua
parents:
diff changeset
1075 String repoText = (StringUtils.isNotEmpty(map.get(REPOSITORY))) ? "_" + map.get(REPOSITORY) : "";
jurzua
parents:
diff changeset
1076 String codexText = (codex != null) ? "_" + codex.getOwnValue() : "";
jurzua
parents:
diff changeset
1077
jurzua
parents:
diff changeset
1078 for(Entity witness : list){
jurzua
parents:
diff changeset
1079 List<Entity> textList = getWrapper().getTargetsForSourceRelation(witness, "is_exemplar_of", TEXT, -1);
jurzua
parents:
diff changeset
1080 String textName = (textList.size() > 0) ? textList.get(0).getOwnValue() : "";
jurzua
parents:
diff changeset
1081 witness.setOwnValue(textName + placeText + repoText + codexText);
jurzua
parents:
diff changeset
1082 nodeList.add(witness);
jurzua
parents:
diff changeset
1083 }
jurzua
parents:
diff changeset
1084 }
jurzua
parents:
diff changeset
1085
jurzua
parents:
diff changeset
1086 private void generateOW4Text(Entity text, String user) throws Exception{
jurzua
parents:
diff changeset
1087 List<Entity> witnessList = getWrapper().getSourcesForTargetRelation(text, "is_exemplar_of", WITNESS, -1);
jurzua
parents:
diff changeset
1088 List<Entity> listToSave = new ArrayList<Entity>();
jurzua
parents:
diff changeset
1089 for(Entity witness : witnessList){
jurzua
parents:
diff changeset
1090 List<Entity> list = getWrapper().getTargetsForSourceRelation(witness, "is_part_of", "CODEX", 1);
jurzua
parents:
diff changeset
1091 if(list.size() > 0){
jurzua
parents:
diff changeset
1092 Entity codex = list.get(0);
jurzua
parents:
diff changeset
1093 list = getWrapper().getTargetsForSourceRelation(codex, "is_part_of", "COLLECTION", 1);
jurzua
parents:
diff changeset
1094 if(list.size() > 0){
jurzua
parents:
diff changeset
1095 Entity collection = list.get(0);
jurzua
parents:
diff changeset
1096 list = getWrapper().getTargetsForSourceRelation(collection, "is_part_of", "REPOSITORY", 1);
jurzua
parents:
diff changeset
1097 if(list.size() > 0){
jurzua
parents:
diff changeset
1098 Entity repository = list.get(0);
jurzua
parents:
diff changeset
1099 list = getWrapper().getTargetsForSourceRelation(repository, "is_in", "PLACE", 1);
jurzua
parents:
diff changeset
1100 if(list.size() > 0){
jurzua
parents:
diff changeset
1101 Entity city = list.get(0);
jurzua
parents:
diff changeset
1102 witness.setOwnValue(text.getOwnValue() + "_" + city.getOwnValue() + "_" + repository.getOwnValue() + "_" + codex.getOwnValue());
jurzua
parents:
diff changeset
1103 listToSave.add(witness);
jurzua
parents:
diff changeset
1104 }
jurzua
parents:
diff changeset
1105 }
jurzua
parents:
diff changeset
1106 }
jurzua
parents:
diff changeset
1107 }
jurzua
parents:
diff changeset
1108 getWrapper().saveEntityListAsNodeWithoutContent(listToSave, user);
jurzua
parents:
diff changeset
1109 }
jurzua
parents:
diff changeset
1110 }
jurzua
parents:
diff changeset
1111
jurzua
parents:
diff changeset
1112 protected SecurityService getSecurityService() {
jurzua
parents:
diff changeset
1113 return getAppBean().getSecurityService();
jurzua
parents:
diff changeset
1114 }
jurzua
parents:
diff changeset
1115
jurzua
parents:
diff changeset
1116 protected ListenerObject changeListener(ValueChangeEvent event,
jurzua
parents:
diff changeset
1117 ListenerObject lo, String suggestType, String suggestAttributeName) {
jurzua
parents:
diff changeset
1118
jurzua
parents:
diff changeset
1119 return changeListener(event, lo, suggestType, suggestAttributeName,
jurzua
parents:
diff changeset
1120 null, null);
jurzua
parents:
diff changeset
1121 }
jurzua
parents:
diff changeset
1122
jurzua
parents:
diff changeset
1123 public String getCurrentId() {
jurzua
parents:
diff changeset
1124 return currentId;
jurzua
parents:
diff changeset
1125 }
jurzua
parents:
diff changeset
1126
jurzua
parents:
diff changeset
1127 public void setCurrentId(String currentId) {
jurzua
parents:
diff changeset
1128 this.currentId = currentId;
jurzua
parents:
diff changeset
1129 }
jurzua
parents:
diff changeset
1130
jurzua
parents:
diff changeset
1131 public String getCurrentIdMsg() {
jurzua
parents:
diff changeset
1132 return currentIdMsg;
jurzua
parents:
diff changeset
1133 }
jurzua
parents:
diff changeset
1134
jurzua
parents:
diff changeset
1135 public void setCurrentIdMsg(String currentIdMsg) {
jurzua
parents:
diff changeset
1136 this.currentIdMsg = currentIdMsg;
jurzua
parents:
diff changeset
1137 }
jurzua
parents:
diff changeset
1138
jurzua
parents:
diff changeset
1139 public SelectedESciDocItems getSelectedItems() {
jurzua
parents:
diff changeset
1140 return selectedItems;
jurzua
parents:
diff changeset
1141 }
jurzua
parents:
diff changeset
1142
jurzua
parents:
diff changeset
1143 public void setSelectedItems(SelectedESciDocItems selectedItems) {
jurzua
parents:
diff changeset
1144 this.selectedItems = selectedItems;
jurzua
parents:
diff changeset
1145 }
jurzua
parents:
diff changeset
1146
jurzua
parents:
diff changeset
1147 public String getDefObjectClass() {
jurzua
parents:
diff changeset
1148 return defObjectClass;
jurzua
parents:
diff changeset
1149 }
jurzua
parents:
diff changeset
1150
jurzua
parents:
diff changeset
1151 public void setDefObjectClass(String defObjectClass) {
jurzua
parents:
diff changeset
1152 this.defObjectClass = defObjectClass;
jurzua
parents:
diff changeset
1153 }
jurzua
parents:
diff changeset
1154 }