Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java @ 216:93d33f138c9e default tip
update medeniyet image server URL.
author | casties |
---|---|
date | Wed, 26 Jan 2022 16:39:32 +0100 |
parents | 502ae5b1a07d |
children |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.util.guiComponents; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import javax.faces.event.ActionEvent; | |
7 | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
8 import org.apache.log4j.Logger; |
1 | 9 import org.mpi.openmind.repository.bo.Entity; |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
10 import org.mpi.openmind.repository.bo.Relation; |
1 | 11 |
12 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; | |
13 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; | |
14 import de.mpiwg.itgroup.ismi.utils.SelectableObject; | |
15 | |
116
ca36b24a22f7
add misattribution to displayAuthor. small cleanups.
casties
parents:
91
diff
changeset
|
16 public class MisattributionTable extends AbstractISMIBean { |
1 | 17 private static final long serialVersionUID = -2756216426560705499L; |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
18 private static Logger logger = Logger.getLogger(MisattributionTable.class); |
1 | 19 |
91 | 20 private List<SelectableObject<Misattribution>> list = new ArrayList<SelectableObject<Misattribution>>(); |
1 | 21 |
91 | 22 private Misattribution misatt; |
1 | 23 |
24 private ListenerObject lo = new ListenerObject(PERSON, "name_translit"); | |
25 //private String attName; | |
26 //private String oc; | |
27 | |
91 | 28 public MisattributionTable(){ |
1 | 29 /* |
30 this.attName = attName; | |
31 this.oc = oc; | |
32 */ | |
33 } | |
34 | |
35 public void listenerRemove(ActionEvent event){ | |
91 | 36 List<SelectableObject<Misattribution>> toDelete = new ArrayList<SelectableObject<Misattribution>>(); |
1 | 37 |
91 | 38 for(SelectableObject<Misattribution> so : this.list){ |
1 | 39 if(so.isSelected()){ |
40 toDelete.add(so); | |
41 } | |
42 } | |
91 | 43 for(SelectableObject<Misattribution> so : toDelete){ |
1 | 44 this.list.remove(so); |
45 } | |
46 } | |
47 | |
48 public void listenerEditRef(ActionEvent event){ | |
91 | 49 SelectableObject<Misattribution> so = |
50 (SelectableObject<Misattribution>)getRequestBean("item"); | |
1 | 51 if(so != null){ |
52 this.misatt = so.getObj(); | |
53 } | |
54 } | |
55 | |
56 public void listenerSaveRef(ActionEvent event){ | |
57 this.misatt = null; | |
58 } | |
59 | |
60 public void listenerCancel(ActionEvent event){ | |
61 //@TODO | |
62 } | |
63 | |
64 public void listenerCreate(ActionEvent event){ | |
65 if(this.lo.entity != null & this.lo.entity.isPersistent()){ | |
66 this.create(this.lo.entity); | |
67 } | |
68 } | |
69 | |
70 public void load(Entity misattEntity){ | |
71 if(!containsEntity(misattEntity)){ | |
72 //TODO sort | |
73 //Collections.sort(this.misattList); | |
74 try { | |
91 | 75 this.list.add(new SelectableObject<Misattribution>(Misattribution.load(misattEntity, getWrapper(), getUserName()))); |
1 | 76 } catch (Exception e) { |
77 addErrorMsg(e.getMessage()); | |
78 e.printStackTrace(); | |
79 } | |
80 }else{ | |
81 addGeneralMsg("This entity has been already inserted!"); | |
82 } | |
83 } | |
84 | |
85 public void create(Entity person){ | |
86 try { | |
91 | 87 this.list.add(new SelectableObject<Misattribution>(Misattribution.create(person, getWrapper(), getUserName()))); |
1 | 88 } catch (Exception e) { |
89 addErrorMsg(e.getMessage()); | |
90 e.printStackTrace(); | |
91 } | |
92 } | |
93 | |
94 private boolean containsEntity(Entity ent){ | |
91 | 95 for(SelectableObject<Misattribution> so : this.list){ |
1 | 96 if(so.getObj().getPerson() != null && so.getObj().getPerson().getId().equals(ent.getId())){ |
97 return true; | |
98 } | |
99 } | |
100 return false; | |
101 } | |
102 | |
91 | 103 /** |
136 | 104 * Save all misattributions on this text. |
91 | 105 * |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
106 * Deletes removed misattributions. |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
107 * |
91 | 108 * @param text |
109 * @return | |
110 * @throws Exception | |
111 */ | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
112 public Entity saveMisattributions(Entity text) throws Exception { |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
113 // remember old misattributions |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
114 List<Relation> oldRels = text.getSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT); |
136 | 115 List<Entity> misatts = new ArrayList<Entity>(); |
116 // save new misattributions | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
117 for (Misattribution misatt : this.getMisattList()) { |
136 | 118 misatt.saveMisattribution(text); |
119 misatts.add(misatt.getMisatt()); | |
1 | 120 } |
136 | 121 // update relations |
122 this.replaceMultipleSourceRelations(text, misatts, Misattribution.MISATT, Misattribution.HAS_AUTHOR_MISATT); | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
123 // check for orphaned old misattributions |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
124 for (Relation rel : oldRels) { |
136 | 125 boolean found = false; |
126 for (Entity miEnt : misatts) { | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
127 if (miEnt != null && rel.getTargetId() == miEnt.getId()) { |
136 | 128 found = true; |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
129 break; |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
130 } |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
131 } |
136 | 132 if (!found) { |
133 Entity miEnt = getWrapper().getEntityById(rel.getTargetId()); | |
134 logger.warn("Orphaned MISATTRIBUTION will be deleted: " + miEnt); | |
135 getWrapper().removeCurrentVersionEntity(miEnt, getUserName()); | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
136 } |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
137 } |
1 | 138 return text; |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
139 } |
1 | 140 |
116
ca36b24a22f7
add misattribution to displayAuthor. small cleanups.
casties
parents:
91
diff
changeset
|
141 private List<Misattribution> getMisattList() { |
91 | 142 List<Misattribution> list = new ArrayList<Misattribution>(); |
143 for(SelectableObject<Misattribution> so : this.list){ | |
1 | 144 list.add(so.getObj()); |
145 } | |
146 return list; | |
147 } | |
148 | |
91 | 149 public List<SelectableObject<Misattribution>> getList() { |
1 | 150 return list; |
151 } | |
152 | |
91 | 153 public void setList(List<SelectableObject<Misattribution>> list) { |
1 | 154 this.list = list; |
155 } | |
156 | |
91 | 157 public Misattribution getMisatt() { |
1 | 158 return misatt; |
159 } | |
160 | |
91 | 161 public void setMisatt(Misattribution misatt) { |
1 | 162 this.misatt = misatt; |
163 } | |
164 | |
165 public ListenerObject getLo() { | |
166 return lo; | |
167 } | |
168 | |
169 public void setLo(ListenerObject lo) { | |
170 this.lo = lo; | |
171 } | |
172 } |