Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java @ 128:aef031e76278
105: MISATTRIBUTION should be deleted when detached
Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/ismi/ticket/105
author | casties |
---|---|
date | Wed, 01 Feb 2017 18:20:04 +0100 |
parents | ca36b24a22f7 |
children | 502ae5b1a07d |
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 /** |
104 * Save all misattributions. | |
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); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
115 // delete old relations |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
116 text.removeAllSourceRelationsByName(Misattribution.HAS_AUTHOR_MISATT); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
117 // create new misattributions |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
118 for (Misattribution misatt : this.getMisattList()) { |
1 | 119 text = misatt.saveAndGetMisattribution(text); |
120 } | |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
121 // check for orphaned old misattributions |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
122 for (Relation rel : oldRels) { |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
123 boolean match = false; |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
124 for (Misattribution mi : this.getMisattList()) { |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
125 Entity miEnt = mi.getMisatt(); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
126 if (miEnt != null && rel.getTargetId() == miEnt.getId()) { |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
127 match = true; |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
128 break; |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
129 } |
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 if (!match) { |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
132 Entity ent = getWrapper().getEntityById(rel.getTargetId()); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
133 logger.warn("Orphaned MISATTRIBUTION will be deleted: " + ent); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
134 getWrapper().removeCurrentVersionEntity(ent, getUserName()); |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
135 } |
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
136 } |
1 | 137 return text; |
128
aef031e76278
105: MISATTRIBUTION should be deleted when detached
casties
parents:
116
diff
changeset
|
138 } |
1 | 139 |
116
ca36b24a22f7
add misattribution to displayAuthor. small cleanups.
casties
parents:
91
diff
changeset
|
140 private List<Misattribution> getMisattList() { |
91 | 141 List<Misattribution> list = new ArrayList<Misattribution>(); |
142 for(SelectableObject<Misattribution> so : this.list){ | |
1 | 143 list.add(so.getObj()); |
144 } | |
145 return list; | |
146 } | |
147 | |
91 | 148 public List<SelectableObject<Misattribution>> getList() { |
1 | 149 return list; |
150 } | |
151 | |
91 | 152 public void setList(List<SelectableObject<Misattribution>> list) { |
1 | 153 this.list = list; |
154 } | |
155 | |
91 | 156 public Misattribution getMisatt() { |
1 | 157 return misatt; |
158 } | |
159 | |
91 | 160 public void setMisatt(Misattribution misatt) { |
1 | 161 this.misatt = misatt; |
162 } | |
163 | |
164 public ListenerObject getLo() { | |
165 return lo; | |
166 } | |
167 | |
168 public void setLo(ListenerObject lo) { | |
169 this.lo = lo; | |
170 } | |
171 } |