annotate src/main/java/org/mpi/openmind/cache/WrapperService.java @ 73:ab61cd3ad0e0

cleanup.
author casties
date Thu, 02 Feb 2017 19:02:05 +0100
parents aeb29e362a67
children 68e3e4b569f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
jurzua
parents:
diff changeset
1 package org.mpi.openmind.cache;
jurzua
parents:
diff changeset
2
jurzua
parents:
diff changeset
3 import java.io.Serializable;
jurzua
parents:
diff changeset
4 import java.lang.management.ManagementFactory;
jurzua
parents:
diff changeset
5 import java.util.ArrayList;
jurzua
parents:
diff changeset
6 import java.util.Collection;
jurzua
parents:
diff changeset
7 import java.util.Collections;
jurzua
parents:
diff changeset
8 import java.util.HashMap;
jurzua
parents:
diff changeset
9 import java.util.List;
jurzua
parents:
diff changeset
10 import java.util.Map;
jurzua
parents:
diff changeset
11
jurzua
parents:
diff changeset
12 import org.apache.commons.lang.StringUtils;
jurzua
parents:
diff changeset
13 import org.apache.log4j.Logger;
65
74cd973f6ece more work on stale entity update problem. cache compare function works now.
casties
parents: 64
diff changeset
14 import org.mpi.openmind.cache.CacheService.EntityDiff;
1
jurzua
parents:
diff changeset
15 import org.mpi.openmind.repository.bo.Attribute;
jurzua
parents:
diff changeset
16 import org.mpi.openmind.repository.bo.Entity;
jurzua
parents:
diff changeset
17 import org.mpi.openmind.repository.bo.Node;
jurzua
parents:
diff changeset
18 import org.mpi.openmind.repository.bo.Relation;
jurzua
parents:
diff changeset
19 import org.mpi.openmind.repository.bo.ViewerAttribute;
jurzua
parents:
diff changeset
20 import org.mpi.openmind.repository.bo.ViewerPage;
jurzua
parents:
diff changeset
21 import org.mpi.openmind.repository.bo.utils.EntitySortByNormalizedOwnValue;
jurzua
parents:
diff changeset
22 import org.mpi.openmind.repository.bo.utils.EntitySortByVersion;
jurzua
parents:
diff changeset
23 import org.mpi.openmind.repository.bo.utils.RelationSortBySourceOW;
jurzua
parents:
diff changeset
24 import org.mpi.openmind.repository.bo.utils.RelationSortByTargetOW;
jurzua
parents:
diff changeset
25 import org.mpi.openmind.repository.services.PersistenceService;
jurzua
parents:
diff changeset
26 import org.mpi.openmind.repository.services.utils.AttributeFilter;
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
27 import org.mpi.openmind.repository.services.utils.EditIntent;
1
jurzua
parents:
diff changeset
28 import org.mpi.openmind.repository.utils.ImportOM3Util;
jurzua
parents:
diff changeset
29 import org.mpi.openmind.repository.utils.NormalizerUtils;
7
jurzua
parents: 1
diff changeset
30 import org.mpi.openmind.repository.utils.RomanizationLoC;
1
jurzua
parents:
diff changeset
31
jurzua
parents:
diff changeset
32 public class WrapperService implements Serializable{
jurzua
parents:
diff changeset
33
jurzua
parents:
diff changeset
34 private static final long serialVersionUID = 2578074607841626396L;
jurzua
parents:
diff changeset
35
jurzua
parents:
diff changeset
36 public static final String IS_TYPE_OF = "is_type_of";
jurzua
parents:
diff changeset
37
jurzua
parents:
diff changeset
38 private static Logger logger = Logger.getLogger(WrapperService.class);
jurzua
parents:
diff changeset
39
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
40 private static Logger txLog = Logger.getLogger(PersistenceService.TRANSACTION_LOGGER);
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
41
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
42 private transient CacheService cache;
1
jurzua
parents:
diff changeset
43
jurzua
parents:
diff changeset
44 public long getSourceRelationsCount(Entity entity, String relationName,
jurzua
parents:
diff changeset
45 String tarObjClass) {
jurzua
parents:
diff changeset
46 return this.getPS().getSourceRelationsCount(entity, relationName,
jurzua
parents:
diff changeset
47 tarObjClass);
jurzua
parents:
diff changeset
48 }
jurzua
parents:
diff changeset
49
jurzua
parents:
diff changeset
50 public Long getTargetRelationsCount(Entity entity, String relationName,
jurzua
parents:
diff changeset
51 String srcObjClass) {
jurzua
parents:
diff changeset
52 return this.getPS().getTargetRelationsCount(entity, relationName,
jurzua
parents:
diff changeset
53 srcObjClass);
jurzua
parents:
diff changeset
54 }
jurzua
parents:
diff changeset
55
35
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
56 /**
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
57 * Search entities matching a list of attribute filters.
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
58 *
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
59 * Returns a Map of Entities and Attributes.
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
60 *
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
61 * @param filters
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
62 * @param maxResult
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
63 * @return
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
64 */
1cd9d9a67cad added regular expression match option to AttributeFilter and searchEntityByAttribute.
casties
parents: 33
diff changeset
65 public Map<Entity, Attribute> searchEntityByAttributeFilter (
1
jurzua
parents:
diff changeset
66 List<AttributeFilter> filters, int maxResult) {
jurzua
parents:
diff changeset
67 return this.getPS().searchEntityByAttributeFilter(filters, maxResult);
jurzua
parents:
diff changeset
68 }
jurzua
parents:
diff changeset
69
jurzua
parents:
diff changeset
70 public Map<Attribute, Entity> searchAttEntityByAttributeFilter(
jurzua
parents:
diff changeset
71 List<AttributeFilter> filters, int maxResult) {
jurzua
parents:
diff changeset
72 return this.getPS()
jurzua
parents:
diff changeset
73 .searchAttEntityByAttributeFilter(filters, maxResult);
jurzua
parents:
diff changeset
74 }
jurzua
parents:
diff changeset
75
jurzua
parents:
diff changeset
76 public List<Entity> searchEntityByOwnValue(String oc, String term){
jurzua
parents:
diff changeset
77 List<Entity> rs = new ArrayList<Entity>();
jurzua
parents:
diff changeset
78 if(StringUtils.isEmpty(term))
jurzua
parents:
diff changeset
79 return rs;
jurzua
parents:
diff changeset
80
37
3485498af8c3 small comments and refactoring.
casties
parents: 36
diff changeset
81 List<Entity> entList = this.cache.loadEntitiesByDef(oc);
1
jurzua
parents:
diff changeset
82 term = NormalizerUtils.normalize(term);
jurzua
parents:
diff changeset
83
jurzua
parents:
diff changeset
84 for(Entity ent : entList){
jurzua
parents:
diff changeset
85 if(StringUtils.isNotEmpty(ent.getNormalizedOwnValue()) &&
jurzua
parents:
diff changeset
86 StringUtils.contains(ent.getNormalizedOwnValue(), term)){
jurzua
parents:
diff changeset
87 rs.add(ent);
jurzua
parents:
diff changeset
88 }
jurzua
parents:
diff changeset
89 }
jurzua
parents:
diff changeset
90 return rs;
jurzua
parents:
diff changeset
91 }
jurzua
parents:
diff changeset
92
jurzua
parents:
diff changeset
93 // ************************************************************
jurzua
parents:
diff changeset
94 // ************************************************************
jurzua
parents:
diff changeset
95 // ************************************************************
jurzua
parents:
diff changeset
96 // ************************************************************
jurzua
parents:
diff changeset
97
jurzua
parents:
diff changeset
98 public List<Entity> getPreviousEntitiesById(Long id) {
jurzua
parents:
diff changeset
99 List<Entity> list = this.getPS().getEntities(id,
jurzua
parents:
diff changeset
100 Node.SYS_STATUS_PREVIOUS_VERSION, null, null);
jurzua
parents:
diff changeset
101 Collections.sort(list, new EntitySortByVersion());
jurzua
parents:
diff changeset
102 return list;
jurzua
parents:
diff changeset
103 }
jurzua
parents:
diff changeset
104
jurzua
parents:
diff changeset
105 public void initCache() {
jurzua
parents:
diff changeset
106 logger.info("##### Initializing Cache #####");
jurzua
parents:
diff changeset
107 logger.info(ManagementFactory.getRuntimeMXBean().getName());
jurzua
parents:
diff changeset
108
jurzua
parents:
diff changeset
109 try {
jurzua
parents:
diff changeset
110 int mb = 1024 * 1024;
jurzua
parents:
diff changeset
111
jurzua
parents:
diff changeset
112 // Getting the runtime reference from system
jurzua
parents:
diff changeset
113 Runtime runtime = Runtime.getRuntime();
jurzua
parents:
diff changeset
114
jurzua
parents:
diff changeset
115 logger.info("##### Heap utilization statistics [MB] #####");
jurzua
parents:
diff changeset
116
jurzua
parents:
diff changeset
117 // Print used memory
jurzua
parents:
diff changeset
118 logger.info("Used Memory:"
jurzua
parents:
diff changeset
119 + (runtime.totalMemory() - runtime.freeMemory()) / mb);
jurzua
parents:
diff changeset
120
jurzua
parents:
diff changeset
121 // Print free memory
jurzua
parents:
diff changeset
122 logger.info("Free Memory:" + runtime.freeMemory() / mb);
jurzua
parents:
diff changeset
123
jurzua
parents:
diff changeset
124 // Print total available memory
jurzua
parents:
diff changeset
125 logger.info("Total Memory:" + runtime.totalMemory() / mb);
jurzua
parents:
diff changeset
126
jurzua
parents:
diff changeset
127 // Print Maximum available memory
jurzua
parents:
diff changeset
128 logger.info("Max Memory:" + runtime.maxMemory() / mb + "\n");
jurzua
parents:
diff changeset
129 } catch (Exception e) {
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
130 logger.error(e);
1
jurzua
parents:
diff changeset
131 }
jurzua
parents:
diff changeset
132
jurzua
parents:
diff changeset
133 if (!this.cache.areDefsLoaded()) {
jurzua
parents:
diff changeset
134 try {
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
135 this.cache.initDefinitions(getPS().getLWDefinitions(),
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
136 getPS().getDefAttributes(),
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
137 getPS().getDefRelations());
1
jurzua
parents:
diff changeset
138 } catch (Exception e) {
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
139 logger.error(e);
1
jurzua
parents:
diff changeset
140 }
jurzua
parents:
diff changeset
141 }
jurzua
parents:
diff changeset
142 }
jurzua
parents:
diff changeset
143
51
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
144 public void removeCurrentVersionEntity(Entity entity, String user) throws Exception {
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
145 logger.info("removeCurrentVersionEntity ("+ user + ") " + entity);
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
146 txLog.debug("** START remove entity: user="+user+" entity="+entity.toSmallString());
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
147 // delete entity from cache
1
jurzua
parents:
diff changeset
148 this.cache.deleteEntity(entity.getId(), entity.getObjectClass());
51
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
149 // delete entity from DB
1
jurzua
parents:
diff changeset
150 this.getPS().removeEntCurrentVersion(entity.getId(), entity.getType());
51
d2833ab25c54 better logging of entity deletion.
casties
parents: 45
diff changeset
151 txLog.debug("** END remove entity: user="+user+" entity="+entity.toSmallString());
1
jurzua
parents:
diff changeset
152 }
jurzua
parents:
diff changeset
153
69
bde6212babfd 106: translit normalization should ignore all '-equivalent chars
casties
parents: 68
diff changeset
154 public Map<Entity, Attribute> searchEntityByAttributeFilter(String term, List<AttributeFilter> filters,
bde6212babfd 106: translit normalization should ignore all '-equivalent chars
casties
parents: 68
diff changeset
155 int maxResults) {
1
jurzua
parents:
diff changeset
156 Map<Entity, Attribute> map = new HashMap<Entity, Attribute>();
jurzua
parents:
diff changeset
157 List<Long> usedIds = new ArrayList<Long>();
jurzua
parents:
diff changeset
158
jurzua
parents:
diff changeset
159 boolean mustBreak = false;
jurzua
parents:
diff changeset
160 int count = 0;
jurzua
parents:
diff changeset
161 if (StringUtils.isNotEmpty(term)) {
71
aeb29e362a67 New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents: 69
diff changeset
162 String normalizedTerm = NormalizerUtils.normalize(term);
1
jurzua
parents:
diff changeset
163 for (AttributeFilter filter : filters) {
jurzua
parents:
diff changeset
164 if (mustBreak) {
jurzua
parents:
diff changeset
165 break;
jurzua
parents:
diff changeset
166 }
69
bde6212babfd 106: translit normalization should ignore all '-equivalent chars
casties
parents: 68
diff changeset
167 for (Attribute att : getAttributesByDefByAttName(filter.getEntObjectClass(), filter.getName(), -1)) {
bde6212babfd 106: translit normalization should ignore all '-equivalent chars
casties
parents: 68
diff changeset
168 if (!usedIds.contains(att.getSourceId()) && StringUtils.isNotEmpty(att.getNormalizedOwnValue())
bde6212babfd 106: translit normalization should ignore all '-equivalent chars
casties
parents: 68
diff changeset
169 && att.getNormalizedOwnValue().contains(normalizedTerm)) {
1
jurzua
parents:
diff changeset
170 map.put(getEntityById(att.getSourceId()), att);
jurzua
parents:
diff changeset
171 usedIds.add(att.getSourceId());
jurzua
parents:
diff changeset
172 count++;
jurzua
parents:
diff changeset
173 if (maxResults > 0 && count == maxResults) {
jurzua
parents:
diff changeset
174 mustBreak = true;
jurzua
parents:
diff changeset
175 break;
jurzua
parents:
diff changeset
176 }
jurzua
parents:
diff changeset
177 }
jurzua
parents:
diff changeset
178 }
jurzua
parents:
diff changeset
179 }
jurzua
parents:
diff changeset
180 }
jurzua
parents:
diff changeset
181 return map;
jurzua
parents:
diff changeset
182 }
jurzua
parents:
diff changeset
183
jurzua
parents:
diff changeset
184 public int getEntitiesCount(String def) {
jurzua
parents:
diff changeset
185 int count = this.cache.getEntitiesCount(def);
jurzua
parents:
diff changeset
186 return count;
jurzua
parents:
diff changeset
187 }
jurzua
parents:
diff changeset
188
53
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
189 /**
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
190 * Returns a List of Entities of the given definition (object_class).
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
191 *
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
192 * All Entities are sorted by normalized own-value first. Then the
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
193 * part between fromIndex and toIndex is returned.
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
194 *
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
195 * @param def
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
196 * @param fromIndex
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
197 * @param toIndex
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
198 * @return
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
199 */
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
200 public List<Entity> getEntityByDefSubList(String def, int fromIndex, int toIndex) {
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
201 List<Entity> list = new ArrayList<Entity>();
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
202 List<Entity> all = getEntitiesByDef(def);
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
203 if (all != null && all.size() >= toIndex) {
1
jurzua
parents:
diff changeset
204
53
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
205 long start = System.currentTimeMillis();
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
206 Collections.sort(list, new EntitySortByNormalizedOwnValue());
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
207 long diff = System.currentTimeMillis() - start;
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
208 logger.debug("Sorting entities time[ms] " + diff);
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
209
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
210 for (Entity ent : all.subList(fromIndex, toIndex)) {
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
211 list.add(ent);
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
212 }
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
213 }
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
214 return list;
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
215 }
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
216
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
217 /**
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
218 * Returns a List of all Entities of the given definition (object_class).
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
219 *
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
220 * @param def
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
221 * @return
3a3362f78d48 small cleanup.
casties
parents: 51
diff changeset
222 */
1
jurzua
parents:
diff changeset
223 public List<Entity> getEntitiesByDef(String def) {
37
3485498af8c3 small comments and refactoring.
casties
parents: 36
diff changeset
224 List<Entity> list = this.cache.loadEntitiesByDef(def);
1
jurzua
parents:
diff changeset
225 return list;
jurzua
parents:
diff changeset
226 }
jurzua
parents:
diff changeset
227
jurzua
parents:
diff changeset
228 public List<Entity> getEntityByDefAndOW(String def, String ow,
jurzua
parents:
diff changeset
229 int maxResults) {
jurzua
parents:
diff changeset
230 List<Entity> result = new ArrayList<Entity>();
jurzua
parents:
diff changeset
231 if (StringUtils.isNotEmpty(ow)) {
37
3485498af8c3 small comments and refactoring.
casties
parents: 36
diff changeset
232 List<Entity> list = this.cache.loadEntitiesByDef(def);
1
jurzua
parents:
diff changeset
233
jurzua
parents:
diff changeset
234 int count = 0;
jurzua
parents:
diff changeset
235 ow = NormalizerUtils.normalize(ow);
jurzua
parents:
diff changeset
236 for (Entity e : list) {
jurzua
parents:
diff changeset
237 // String eow = (StringUtils.isNotEmpty(e.getOwnValue())) ?
jurzua
parents:
diff changeset
238 // e.getOwnValue().toLowerCase() : "";
jurzua
parents:
diff changeset
239 if (StringUtils.isNotBlank(e.getNormalizedOwnValue())
jurzua
parents:
diff changeset
240 && e.getNormalizedOwnValue().contains(ow)) {
jurzua
parents:
diff changeset
241 result.add((Entity) e.clone());
jurzua
parents:
diff changeset
242 count++;
jurzua
parents:
diff changeset
243 }
jurzua
parents:
diff changeset
244
jurzua
parents:
diff changeset
245 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
246 break;
jurzua
parents:
diff changeset
247 }
jurzua
parents:
diff changeset
248 }
jurzua
parents:
diff changeset
249 }
jurzua
parents:
diff changeset
250 return result;
jurzua
parents:
diff changeset
251 }
jurzua
parents:
diff changeset
252
jurzua
parents:
diff changeset
253 /**
jurzua
parents:
diff changeset
254 * this method does not execute: - ownValue generation - new version
jurzua
parents:
diff changeset
255 * generation This method only save the entity in the current state.
jurzua
parents:
diff changeset
256 *
jurzua
parents:
diff changeset
257 * @param nodeList
jurzua
parents:
diff changeset
258 * @param user
jurzua
parents:
diff changeset
259 */
jurzua
parents:
diff changeset
260 public void saveEntityListAsNode(List<Entity> entList, String user) {
jurzua
parents:
diff changeset
261 for (Entity ent : entList) {
jurzua
parents:
diff changeset
262 ent.setUser(user);
jurzua
parents:
diff changeset
263 }
jurzua
parents:
diff changeset
264 getPS().saveEntityListAsNode(entList);
jurzua
parents:
diff changeset
265 for (Entity ent : entList) {
jurzua
parents:
diff changeset
266 cache.saveEntity(ent);
jurzua
parents:
diff changeset
267 }
jurzua
parents:
diff changeset
268 }
jurzua
parents:
diff changeset
269
jurzua
parents:
diff changeset
270 public void saveEntityListAsNodeWithoutContent(List<Entity> nodeList,
jurzua
parents:
diff changeset
271 String user) throws Exception {
jurzua
parents:
diff changeset
272 this.cache.saveEntityListAsNodeWithoutContent(nodeList);
jurzua
parents:
diff changeset
273 }
jurzua
parents:
diff changeset
274
jurzua
parents:
diff changeset
275 public boolean existEntity(Long entId) {
jurzua
parents:
diff changeset
276 return getCache().getEntityByIdReadOnly(entId) != null;
jurzua
parents:
diff changeset
277 }
jurzua
parents:
diff changeset
278
jurzua
parents:
diff changeset
279 public boolean existRelation(Long srcId, Long tarId, String relName) {
jurzua
parents:
diff changeset
280
jurzua
parents:
diff changeset
281 try {
jurzua
parents:
diff changeset
282 if (srcId == null || tarId == null) {
jurzua
parents:
diff changeset
283 throw new Exception("srcId and tarId can not be null.");
jurzua
parents:
diff changeset
284 }
jurzua
parents:
diff changeset
285
jurzua
parents:
diff changeset
286 List<Relation> relList = this.cache.getRelsBySrcId(srcId);
jurzua
parents:
diff changeset
287
jurzua
parents:
diff changeset
288 for (Relation rel : relList) {
jurzua
parents:
diff changeset
289 if (rel.getTargetId().equals(tarId)
jurzua
parents:
diff changeset
290 && rel.getOwnValue().equals(relName))
jurzua
parents:
diff changeset
291 return true;
jurzua
parents:
diff changeset
292 }
jurzua
parents:
diff changeset
293 } catch (Exception e) {
jurzua
parents:
diff changeset
294 e.printStackTrace();
jurzua
parents:
diff changeset
295 }
jurzua
parents:
diff changeset
296
jurzua
parents:
diff changeset
297 return false;
jurzua
parents:
diff changeset
298 }
jurzua
parents:
diff changeset
299
jurzua
parents:
diff changeset
300 public void saveRelationAsNode(Relation rel, String user) throws Exception {
jurzua
parents:
diff changeset
301
jurzua
parents:
diff changeset
302 if (rel.getAttributes() != null && rel.getAttributes().size() > 0) {
jurzua
parents:
diff changeset
303 throw new Exception(
jurzua
parents:
diff changeset
304 "This method can be only used if the relation does not contains attributes, this is not the case.");
jurzua
parents:
diff changeset
305 }
jurzua
parents:
diff changeset
306
jurzua
parents:
diff changeset
307 rel.setUser(user);
jurzua
parents:
diff changeset
308 this.getPS().saveNode(rel);
jurzua
parents:
diff changeset
309 this.cache.updateRelationAsNode(rel);
jurzua
parents:
diff changeset
310 }
jurzua
parents:
diff changeset
311
jurzua
parents:
diff changeset
312 public List<Entity> searchEntityByAttributeOfTarRelation(String objClass,
jurzua
parents:
diff changeset
313 String relName, String objClassSrc, String attName,
jurzua
parents:
diff changeset
314 String attValue, int maxResults) throws Exception {
jurzua
parents:
diff changeset
315 List<Entity> list = new ArrayList<Entity>();
jurzua
parents:
diff changeset
316
jurzua
parents:
diff changeset
317 List<Attribute> attList = getAttributesByDefByAttName(objClassSrc,
jurzua
parents:
diff changeset
318 attName, attValue, -1);
jurzua
parents:
diff changeset
319 int count = 0;
jurzua
parents:
diff changeset
320 for (Attribute att : attList) {
jurzua
parents:
diff changeset
321 Relation rel = getFirstRelationByTargetOCByName(
jurzua
parents:
diff changeset
322 cache.getRelsBySrcId(att.getSourceId()), objClass, relName);
jurzua
parents:
diff changeset
323 if (rel != null) {
jurzua
parents:
diff changeset
324 list.add(getEntityById(rel.getTargetId()));
jurzua
parents:
diff changeset
325 count++;
jurzua
parents:
diff changeset
326 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
327 break;
jurzua
parents:
diff changeset
328 }
jurzua
parents:
diff changeset
329 }
jurzua
parents:
diff changeset
330 }
jurzua
parents:
diff changeset
331
jurzua
parents:
diff changeset
332 return list;
jurzua
parents:
diff changeset
333 }
jurzua
parents:
diff changeset
334
jurzua
parents:
diff changeset
335 private static Relation getFirstRelationByTargetOCByName(
jurzua
parents:
diff changeset
336 List<Relation> list, String tarOC, String name) {
jurzua
parents:
diff changeset
337 if (StringUtils.isNotEmpty(name)) {
jurzua
parents:
diff changeset
338 name = name.toLowerCase();
jurzua
parents:
diff changeset
339 for (Relation rel : list) {
jurzua
parents:
diff changeset
340 if (rel.getTargetObjectClass().equals(tarOC)) {
jurzua
parents:
diff changeset
341 if (StringUtils.isNotEmpty(rel.getOwnValue())
jurzua
parents:
diff changeset
342 && name.equals(rel.getOwnValue().toLowerCase())) {
jurzua
parents:
diff changeset
343 return rel;
jurzua
parents:
diff changeset
344 }
jurzua
parents:
diff changeset
345 }
jurzua
parents:
diff changeset
346 }
jurzua
parents:
diff changeset
347 }
jurzua
parents:
diff changeset
348 return null;
jurzua
parents:
diff changeset
349 }
jurzua
parents:
diff changeset
350
jurzua
parents:
diff changeset
351 public List<Attribute> getAttributeByEntId(Long entId) {
jurzua
parents:
diff changeset
352 List<Attribute> list = cache.getAttsBySrcId(entId);
jurzua
parents:
diff changeset
353 return list;
jurzua
parents:
diff changeset
354 }
jurzua
parents:
diff changeset
355
jurzua
parents:
diff changeset
356 public Attribute getAttributeByName(Long entId, String name) {
jurzua
parents:
diff changeset
357 List<Attribute> list = cache.getAttsBySrcId(entId);
jurzua
parents:
diff changeset
358
jurzua
parents:
diff changeset
359 for (Attribute att : list) {
jurzua
parents:
diff changeset
360 if (att.getName().equals(name)) {
jurzua
parents:
diff changeset
361 return (Attribute) att.clone();
jurzua
parents:
diff changeset
362 }
jurzua
parents:
diff changeset
363 }
jurzua
parents:
diff changeset
364 return null;
jurzua
parents:
diff changeset
365 }
jurzua
parents:
diff changeset
366
7
jurzua
parents: 1
diff changeset
367 public String getAttributeOVByName(Long entId, String name, boolean useRomanization){
jurzua
parents: 1
diff changeset
368 Attribute att = getAttributeByName(entId, name);
jurzua
parents: 1
diff changeset
369 if(att != null){
jurzua
parents: 1
diff changeset
370 return (useRomanization) ? RomanizationLoC.convert(att.getOwnValue()) : att.getOwnValue();
jurzua
parents: 1
diff changeset
371 }
jurzua
parents: 1
diff changeset
372 return "";
jurzua
parents: 1
diff changeset
373 }
jurzua
parents: 1
diff changeset
374
1
jurzua
parents:
diff changeset
375 public List<Attribute> searchAttribute(String firstName, String firstValue,
jurzua
parents:
diff changeset
376 String secondName, String secondValue, String def, int maxResults) {
jurzua
parents:
diff changeset
377 List<Attribute> list = new ArrayList<Attribute>();
jurzua
parents:
diff changeset
378
jurzua
parents:
diff changeset
379 List<Attribute> firstAttList = cache.getAttsByOCAndName(def, firstName);
jurzua
parents:
diff changeset
380
jurzua
parents:
diff changeset
381 firstValue = StringUtils.isNotEmpty(firstValue) ? NormalizerUtils
jurzua
parents:
diff changeset
382 .normalize(firstValue) : null;
jurzua
parents:
diff changeset
383 secondValue = StringUtils.isNotEmpty(secondValue) ? NormalizerUtils
jurzua
parents:
diff changeset
384 .normalize(secondValue) : null;
jurzua
parents:
diff changeset
385
jurzua
parents:
diff changeset
386 if (StringUtils.isNotEmpty(firstValue)) {
jurzua
parents:
diff changeset
387 for (Attribute firstAtt : firstAttList) {
jurzua
parents:
diff changeset
388 String attValue1 = (StringUtils.isNotEmpty(firstAtt
jurzua
parents:
diff changeset
389 .getNormalizedOwnValue())) ? firstAtt
jurzua
parents:
diff changeset
390 .getNormalizedOwnValue() : "";
jurzua
parents:
diff changeset
391 // (StringUtils.isNotEmpty(firstAtt.getValue())) ?
jurzua
parents:
diff changeset
392 // firstAtt.getValue().toLowerCase() : "";
jurzua
parents:
diff changeset
393 if (StringUtils.isNotEmpty(firstValue)
jurzua
parents:
diff changeset
394 && attValue1.contains(firstValue)) {
jurzua
parents:
diff changeset
395 Attribute secondAtt = getAttributeByName(
jurzua
parents:
diff changeset
396 firstAtt.getSourceId(), secondName);
jurzua
parents:
diff changeset
397 if (secondAtt != null) {
jurzua
parents:
diff changeset
398 String attValue2 = (StringUtils.isNotEmpty(secondAtt
jurzua
parents:
diff changeset
399 .getNormalizedOwnValue())) ? secondAtt
jurzua
parents:
diff changeset
400 .getNormalizedOwnValue() : "";
jurzua
parents:
diff changeset
401 // (StringUtils.isNotEmpty(secondAtt.getValue())) ?
jurzua
parents:
diff changeset
402 // secondAtt.getValue().toLowerCase() : "";
jurzua
parents:
diff changeset
403 if (StringUtils.isNotEmpty(secondValue)
jurzua
parents:
diff changeset
404 && attValue2.contains(attValue2)) {
jurzua
parents:
diff changeset
405 list.add((Attribute) firstAtt.clone());
jurzua
parents:
diff changeset
406 }
jurzua
parents:
diff changeset
407 }
jurzua
parents:
diff changeset
408 }
jurzua
parents:
diff changeset
409 }
jurzua
parents:
diff changeset
410 }
jurzua
parents:
diff changeset
411
jurzua
parents:
diff changeset
412 return list;
jurzua
parents:
diff changeset
413 }
jurzua
parents:
diff changeset
414
jurzua
parents:
diff changeset
415 private List<Attribute> getAttributesByDefByAttName(String def,
jurzua
parents:
diff changeset
416 String attName, int maxResults) {
jurzua
parents:
diff changeset
417 List<Attribute> list = cache.getAttsByOCAndName(def, attName);
jurzua
parents:
diff changeset
418 return list;
jurzua
parents:
diff changeset
419 }
jurzua
parents:
diff changeset
420
jurzua
parents:
diff changeset
421 /**
58
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
422 * Returns a sorted list of attributes by def (=objectClass) of the entity, the att Name
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
423 * and its (normalized) value.
1
jurzua
parents:
diff changeset
424 *
jurzua
parents:
diff changeset
425 * @param def
jurzua
parents:
diff changeset
426 * @param attName
jurzua
parents:
diff changeset
427 * @param attValue
58
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
428 * case insensitive sub string match.
1
jurzua
parents:
diff changeset
429 * @param maxResults
jurzua
parents:
diff changeset
430 * @return
jurzua
parents:
diff changeset
431 */
jurzua
parents:
diff changeset
432 public List<Attribute> getAttributesByDefByAttName(String def,
jurzua
parents:
diff changeset
433 String attName, String attValue, int maxResults) {
jurzua
parents:
diff changeset
434
jurzua
parents:
diff changeset
435 List<Attribute> list = getAttributesByDefByAttName0(def, attName, attValue, maxResults);
jurzua
parents:
diff changeset
436 Collections.sort(list);
jurzua
parents:
diff changeset
437 return list;
jurzua
parents:
diff changeset
438 }
jurzua
parents:
diff changeset
439
jurzua
parents:
diff changeset
440 public List<Attribute> getAttributes(String oc, String attName){
jurzua
parents:
diff changeset
441 return cache.getAttsByOCAndName(oc, attName);
jurzua
parents:
diff changeset
442 }
jurzua
parents:
diff changeset
443
jurzua
parents:
diff changeset
444 /**
jurzua
parents:
diff changeset
445 *
jurzua
parents:
diff changeset
446 * @param attName
jurzua
parents:
diff changeset
447 * @param attValue
jurzua
parents:
diff changeset
448 * @return
jurzua
parents:
diff changeset
449 */
jurzua
parents:
diff changeset
450 public List<Attribute> getAttributesByExactValue(String attName, String attValue){
jurzua
parents:
diff changeset
451 List<Attribute> list = new ArrayList<Attribute>();
jurzua
parents:
diff changeset
452
jurzua
parents:
diff changeset
453 if(StringUtils.isNotEmpty(attValue)){
jurzua
parents:
diff changeset
454 for(Entity def : cache.getLWDefinitions()){
jurzua
parents:
diff changeset
455
jurzua
parents:
diff changeset
456 List<Attribute> attList = cache.getAttsByOCAndName(def.getOwnValue(), attName);
jurzua
parents:
diff changeset
457 attValue = NormalizerUtils.normalize(attValue);
jurzua
parents:
diff changeset
458
jurzua
parents:
diff changeset
459 for(Attribute att : attList){
jurzua
parents:
diff changeset
460 if(StringUtils.equals(attValue, att.getNormalizedOwnValue())){
jurzua
parents:
diff changeset
461 list.add(att);
jurzua
parents:
diff changeset
462 }
jurzua
parents:
diff changeset
463 }
jurzua
parents:
diff changeset
464
jurzua
parents:
diff changeset
465 }
jurzua
parents:
diff changeset
466 Collections.sort(list);
jurzua
parents:
diff changeset
467 }
jurzua
parents:
diff changeset
468 return list;
jurzua
parents:
diff changeset
469 }
jurzua
parents:
diff changeset
470
58
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
471 /**
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
472 * Returns a list of attributes by def (=objectClass) of the entity, the att Name
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
473 * and its (normalized) value.
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
474 *
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
475 * @param def
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
476 * @param attName
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
477 * @param attValue
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
478 * @param maxResults
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
479 * @return
153a0232270b cleanup and better comments.
casties
parents: 55
diff changeset
480 */
1
jurzua
parents:
diff changeset
481 private List<Attribute> getAttributesByDefByAttName0(String def,
jurzua
parents:
diff changeset
482 String attName, String attValue, int maxResults) {
jurzua
parents:
diff changeset
483 List<Attribute> list = new ArrayList<Attribute>();
jurzua
parents:
diff changeset
484 List<Attribute> attList = cache.getAttsByOCAndName(def, attName);
jurzua
parents:
diff changeset
485 attValue = NormalizerUtils.normalize(attValue);
jurzua
parents:
diff changeset
486 int count = 0;
jurzua
parents:
diff changeset
487 if (StringUtils.isEmpty(attValue)) {
jurzua
parents:
diff changeset
488 for (Attribute att : attList) {
jurzua
parents:
diff changeset
489 list.add((Attribute) att.clone());
jurzua
parents:
diff changeset
490 count++;
jurzua
parents:
diff changeset
491 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
492 break;
jurzua
parents:
diff changeset
493 }
jurzua
parents:
diff changeset
494 }
jurzua
parents:
diff changeset
495 } else {
jurzua
parents:
diff changeset
496 for (Attribute att : attList) {
jurzua
parents:
diff changeset
497 String attValue0 = StringUtils.isNotEmpty(att
jurzua
parents:
diff changeset
498 .getNormalizedOwnValue()) ? att.getNormalizedOwnValue()
jurzua
parents:
diff changeset
499 : "";
jurzua
parents:
diff changeset
500 if (StringUtils.isNotEmpty(attValue)
jurzua
parents:
diff changeset
501 && attValue0.contains(attValue)) {
jurzua
parents:
diff changeset
502 list.add((Attribute) att.clone());
jurzua
parents:
diff changeset
503 count++;
jurzua
parents:
diff changeset
504 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
505 break;
jurzua
parents:
diff changeset
506 }
jurzua
parents:
diff changeset
507 }
jurzua
parents:
diff changeset
508 }
jurzua
parents:
diff changeset
509 }
jurzua
parents:
diff changeset
510 return list;
jurzua
parents:
diff changeset
511 }
jurzua
parents:
diff changeset
512
jurzua
parents:
diff changeset
513 /**
jurzua
parents:
diff changeset
514 * Returns a list of entities.
jurzua
parents:
diff changeset
515 *
jurzua
parents:
diff changeset
516 * @param def
jurzua
parents:
diff changeset
517 * @param attName
jurzua
parents:
diff changeset
518 * @param attValue
jurzua
parents:
diff changeset
519 * ignores case sensitive
jurzua
parents:
diff changeset
520 * @param maxResults
jurzua
parents:
diff changeset
521 * @param subString
jurzua
parents:
diff changeset
522 * if true the attValue is searching as substring
jurzua
parents:
diff changeset
523 * @return
jurzua
parents:
diff changeset
524 */
jurzua
parents:
diff changeset
525 public List<Entity> getEntitiesByAtt(String def, String attName,
jurzua
parents:
diff changeset
526 String attValue, int maxResults, boolean subString) {
jurzua
parents:
diff changeset
527 List<Entity> list = new ArrayList<Entity>();
jurzua
parents:
diff changeset
528
jurzua
parents:
diff changeset
529 List<Attribute> attList = cache.getAttsByOCAndName(def, attName);
jurzua
parents:
diff changeset
530
jurzua
parents:
diff changeset
531 int count = 0;
jurzua
parents:
diff changeset
532 if (StringUtils.isEmpty(attValue)) {
jurzua
parents:
diff changeset
533 for (Attribute att : attList) {
jurzua
parents:
diff changeset
534 list.add(getEntityById(att.getSourceId()));
jurzua
parents:
diff changeset
535 count++;
jurzua
parents:
diff changeset
536 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
537 break;
jurzua
parents:
diff changeset
538 }
jurzua
parents:
diff changeset
539 }
jurzua
parents:
diff changeset
540 } else {
jurzua
parents:
diff changeset
541 attValue = (StringUtils.isNotEmpty(attValue)) ? NormalizerUtils
jurzua
parents:
diff changeset
542 .normalize(attValue) : "";
jurzua
parents:
diff changeset
543 for (Attribute att : attList) {
jurzua
parents:
diff changeset
544 String attValue0 = (StringUtils.isNotEmpty(att
jurzua
parents:
diff changeset
545 .getNormalizedOwnValue())) ? att
jurzua
parents:
diff changeset
546 .getNormalizedOwnValue() : "";
jurzua
parents:
diff changeset
547 if ((subString && attValue0.contains(attValue))
jurzua
parents:
diff changeset
548 || (!subString && attValue.equals(attValue0))) {
jurzua
parents:
diff changeset
549 list.add(getEntityById(att.getSourceId()));
jurzua
parents:
diff changeset
550 count++;
jurzua
parents:
diff changeset
551 if (maxResults > 0 && maxResults == count) {
jurzua
parents:
diff changeset
552 break;
jurzua
parents:
diff changeset
553 }
jurzua
parents:
diff changeset
554 }
jurzua
parents:
diff changeset
555 }
jurzua
parents:
diff changeset
556 }
jurzua
parents:
diff changeset
557 return list;
jurzua
parents:
diff changeset
558 }
jurzua
parents:
diff changeset
559
jurzua
parents:
diff changeset
560 public void removeDefAttribute(Attribute att) throws Exception {
jurzua
parents:
diff changeset
561 this.cache.deleteDefAttribute(att);
jurzua
parents:
diff changeset
562 att.setSystemStatus(Node.SYS_STATUS_PREVIOUS_VERSION);
jurzua
parents:
diff changeset
563 this.getPS().saveNode(att);
jurzua
parents:
diff changeset
564 }
jurzua
parents:
diff changeset
565
jurzua
parents:
diff changeset
566 public void removeDefRelation(Relation rel) throws Exception {
jurzua
parents:
diff changeset
567 this.cache.deleteDefRelation(rel);
jurzua
parents:
diff changeset
568 rel.setSystemStatus(Node.SYS_STATUS_PREVIOUS_VERSION);
jurzua
parents:
diff changeset
569 this.getPS().saveNode(rel);
jurzua
parents:
diff changeset
570 }
jurzua
parents:
diff changeset
571
jurzua
parents:
diff changeset
572 public Entity saveLWDefinition(Entity def, String user) throws Exception {
jurzua
parents:
diff changeset
573 boolean isNew = !def.isPersistent();
jurzua
parents:
diff changeset
574 def.setUser(user);
jurzua
parents:
diff changeset
575 def.increaseVersion();
jurzua
parents:
diff changeset
576 def.setModificationTime(System.currentTimeMillis());
jurzua
parents:
diff changeset
577 def.setType(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
578 def.setObjectClass(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
579 def.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION);
jurzua
parents:
diff changeset
580 this.getPS().saveNode(def);
jurzua
parents:
diff changeset
581
jurzua
parents:
diff changeset
582 if (isNew) {
jurzua
parents:
diff changeset
583 this.cache.createLWDefinition(def);
jurzua
parents:
diff changeset
584 } else {
jurzua
parents:
diff changeset
585 this.cache.saveLWDefinition(def);
jurzua
parents:
diff changeset
586 }
jurzua
parents:
diff changeset
587
jurzua
parents:
diff changeset
588 return def;
jurzua
parents:
diff changeset
589 }
jurzua
parents:
diff changeset
590
jurzua
parents:
diff changeset
591 public Attribute saveDefAttribute(Attribute att, String user)
jurzua
parents:
diff changeset
592 throws Exception {
jurzua
parents:
diff changeset
593 att.setUser(user);
jurzua
parents:
diff changeset
594 att.increaseVersion();
jurzua
parents:
diff changeset
595 att.setModificationTime(System.currentTimeMillis());
jurzua
parents:
diff changeset
596 att.setObjectClass(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
597 att.setType(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
598 att.getPossibleValues();
jurzua
parents:
diff changeset
599 this.getPS().saveNode(att);
jurzua
parents:
diff changeset
600 this.cache.saveDefAttribute(att);
jurzua
parents:
diff changeset
601 return att;
jurzua
parents:
diff changeset
602 }
jurzua
parents:
diff changeset
603
jurzua
parents:
diff changeset
604 public Relation saveDefRelation(Relation rel, String user) throws Exception {
jurzua
parents:
diff changeset
605 rel.setUser(user);
jurzua
parents:
diff changeset
606 rel.increaseVersion();
jurzua
parents:
diff changeset
607 rel.setModificationTime(System.currentTimeMillis());
jurzua
parents:
diff changeset
608 rel.setObjectClass(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
609 rel.setType(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
610 this.getPS().saveNode(rel);
jurzua
parents:
diff changeset
611 this.cache.saveDefRelation(rel);
jurzua
parents:
diff changeset
612 return rel;
jurzua
parents:
diff changeset
613 }
jurzua
parents:
diff changeset
614
33
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
615 /**
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
616 * Save the given entity as a separate new entity with a new ID.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
617 *
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
618 * Keeps attributes and relations as copies.
1
jurzua
parents:
diff changeset
619 *
33
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
620 * @param entity
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
621 * @param user
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
622 * @return
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
623 * @throws Exception
1
jurzua
parents:
diff changeset
624 */
jurzua
parents:
diff changeset
625 public Entity saveEntityAsNew(Entity entity, String user) throws Exception {
jurzua
parents:
diff changeset
626 long start = System.currentTimeMillis();
jurzua
parents:
diff changeset
627 entity.resetRowId();
jurzua
parents:
diff changeset
628 entity.resetId();
jurzua
parents:
diff changeset
629 entity.setType(Node.TYPE_ABOX);
jurzua
parents:
diff changeset
630 entity.setUser(user);
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
631
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
632 txLog.debug("** START save entity as new: user="+user+" entity="+entity.toSmallString());
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
633 // save in database
1
jurzua
parents:
diff changeset
634 this.getPS().saveEntity(entity);
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
635 // save in cache
1
jurzua
parents:
diff changeset
636 cache.saveEntity(entity);
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
637 txLog.debug("** END save entity as new: user="+user+" entity="+entity.toSmallString());
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
638
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
639 logger.debug("[U=" + user + "] SaveEntityAsNew - execution time[ms]: " + (System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
640 return (Entity) entity.clone();
jurzua
parents:
diff changeset
641 }
jurzua
parents:
diff changeset
642
36
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
643 /**
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
644 * Save the given entity to the database.
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
645 *
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
646 * Creates a new version of the entity.
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
647 *
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
648 * @param entity
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
649 * @param user
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
650 * @param intent TODO
36
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
651 * @return
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
652 * @throws Exception
63fe33172397 more comments, less log messages.
casties
parents: 35
diff changeset
653 */
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
654 public Entity saveEntity(Entity entity, String user, EditIntent intent) throws Exception {
1
jurzua
parents:
diff changeset
655 long start = System.currentTimeMillis();
jurzua
parents:
diff changeset
656 if (StringUtils.isEmpty(entity.getType())) {
jurzua
parents:
diff changeset
657 entity.setType(Node.TYPE_ABOX);
jurzua
parents:
diff changeset
658 }
jurzua
parents:
diff changeset
659 entity.setUser(user);
jurzua
parents:
diff changeset
660
jurzua
parents:
diff changeset
661 entity = removeWrongRelations(entity);
jurzua
parents:
diff changeset
662 entity = removeEmptyAttributes(entity);
jurzua
parents:
diff changeset
663
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
664 txLog.debug("** START save entity: user="+user+" entity="+entity.toSmallString());
64
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
665 // check if entity is up to date with cache
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
666 if (!cache.isEntityCurrent(entity)) {
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
667 logger.warn("Possible collision: Entity to save not current!");
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
668 // create differences from cache
65
74cd973f6ece more work on stale entity update problem. cache compare function works now.
casties
parents: 64
diff changeset
669 EntityDiff diff = cache.diffEntityCache(entity, true);
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
670 if (diff != null) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
671 if (intent != null) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
672 /*
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
673 * check if diff was intended
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
674 */
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
675 if (!intent.isEntModificationIntended(entity.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
676 logger.error("unintended modification of entity: "+entity);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
677 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
678 for (Attribute a : diff.addedAttributes) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
679 if (!intent.isAttModificationIntended(a.getName())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
680 logger.error("unintended addition: "+a);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
681 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
682 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
683 for (Attribute a : diff.modifiedAttributes) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
684 if (!intent.isAttModificationIntended(a.getName())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
685 logger.error("unintended modification: "+a);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
686 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
687 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
688 for (Attribute a : diff.removedAttributes) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
689 if (!intent.isAttModificationIntended(a.getName())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
690 logger.error("unintended removal prevented: "+a);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
691 entity.addAttribute(a);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
692 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
693 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
694 for (Relation r : diff.addedSrcRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
695 if (!intent.isSrcRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
696 logger.error("unintended addition: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
697 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
698 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
699 for (Relation r : diff.modifiedSrcRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
700 if (!intent.isSrcRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
701 logger.error("unintended modification: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
702 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
703 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
704 for (Relation r : diff.removedSrcRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
705 if (!intent.isSrcRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
706 logger.error("unintended removal prevented: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
707 // re-add
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
708 entity.addSourceRelation(r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
709 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
710 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
711 for (Relation r : diff.addedTarRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
712 if (!intent.isTarRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
713 logger.error("unintended addition: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
714 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
715 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
716 for (Relation r : diff.modifiedTarRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
717 if (!intent.isTarRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
718 logger.error("unintended modification: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
719 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
720 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
721 for (Relation r : diff.removedTarRels) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
722 if (!intent.isTarRelModificationIntended(r.getObjectClass())) {
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
723 logger.error("unintended removal prevented: "+r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
724 // re-add
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
725 entity.addTargetRelation(r);
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
726 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
727 }
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
728 } else {
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
729 logger.warn("Save with missing EditIntent!");
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
730 }
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
731 } else {
68
677492395dc0 Cleaner log messages.
casties
parents: 67
diff changeset
732 logger.warn("No difference to cache found.");
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
733 }
64
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
734 }
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
735
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
736 // save in database
1
jurzua
parents:
diff changeset
737 this.getPS().saveEntity(entity);
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
738 // save in cache
1
jurzua
parents:
diff changeset
739 cache.saveEntity(entity);
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
740 txLog.debug("** END save entity: user="+user+" entity="+entity.toSmallString());
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
741
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
742 logger.debug("[U=" + user + "] SaveEntity - execution time[ms]: " + (System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
743 Entity clone = (Entity) entity.clone();
jurzua
parents:
diff changeset
744 return clone;
jurzua
parents:
diff changeset
745 }
jurzua
parents:
diff changeset
746
jurzua
parents:
diff changeset
747 public void saveEntityList(List<Entity> list, String user) throws Exception{
jurzua
parents:
diff changeset
748 long start = System.currentTimeMillis();
jurzua
parents:
diff changeset
749 for(Entity entity : list){
jurzua
parents:
diff changeset
750 if (StringUtils.isEmpty(entity.getType())) {
jurzua
parents:
diff changeset
751 entity.setType(Node.TYPE_ABOX);
jurzua
parents:
diff changeset
752 }
jurzua
parents:
diff changeset
753 entity.setUser(user);
jurzua
parents:
diff changeset
754
jurzua
parents:
diff changeset
755 entity = removeWrongRelations(entity);
jurzua
parents:
diff changeset
756 entity = removeEmptyAttributes(entity);
jurzua
parents:
diff changeset
757 }
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
758 txLog.debug("** START save entity list: user="+user+" list="+list);
1
jurzua
parents:
diff changeset
759 this.getPS().saveEntityList(list);
jurzua
parents:
diff changeset
760 for(Entity entity : list){
jurzua
parents:
diff changeset
761 cache.saveEntity(entity);
jurzua
parents:
diff changeset
762 }
45
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
763 txLog.debug("** END save entity list: user="+user+" list="+list);
fd98c31371cb better transaction logging.
casties
parents: 39
diff changeset
764 logger.debug("[U=" + user + "] SaveEntityList - execution time[ms]: " + (System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
765 }
jurzua
parents:
diff changeset
766
jurzua
parents:
diff changeset
767 private Entity removeEmptyAttributes(Entity ent){
jurzua
parents:
diff changeset
768
jurzua
parents:
diff changeset
769 for(Attribute att : new ArrayList<Attribute>(ent.getAttributes())){
jurzua
parents:
diff changeset
770 if(StringUtils.isEmpty(att.getValue())){
jurzua
parents:
diff changeset
771 ent.getAttributes().remove(att);
jurzua
parents:
diff changeset
772 }
jurzua
parents:
diff changeset
773 }
jurzua
parents:
diff changeset
774 return ent;
jurzua
parents:
diff changeset
775
jurzua
parents:
diff changeset
776 }
jurzua
parents:
diff changeset
777
33
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
778 /**
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
779 * Returns if this entity has wrong relations.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
780 *
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
781 * Wrong are source relations whose target doesn't exist.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
782 * Similarly for target relations.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
783 *
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
784 * @param ent
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
785 * @return
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
786 */
1
jurzua
parents:
diff changeset
787 private boolean hasWrongRelations(Entity ent) {
jurzua
parents:
diff changeset
788 for (Relation srcRel : ent.getSourceRelations()) {
jurzua
parents:
diff changeset
789 if (getEntityById(srcRel.getTargetId()) == null) {
jurzua
parents:
diff changeset
790 return true;
jurzua
parents:
diff changeset
791 }
jurzua
parents:
diff changeset
792 }
jurzua
parents:
diff changeset
793
jurzua
parents:
diff changeset
794 for (Relation tarRel : ent.getTargetRelations()) {
jurzua
parents:
diff changeset
795 if (getEntityById(tarRel.getSourceId()) == null) {
jurzua
parents:
diff changeset
796 return true;
jurzua
parents:
diff changeset
797 }
jurzua
parents:
diff changeset
798 }
jurzua
parents:
diff changeset
799 return false;
jurzua
parents:
diff changeset
800 }
jurzua
parents:
diff changeset
801
33
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
802 /**
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
803 * Remove wrong relations from this entity.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
804 *
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
805 * Wrong are source relations whose target is null or doesn't exist.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
806 * Similarly for target relations.
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
807 *
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
808 * @param ent
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
809 * @return
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
810 */
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
811 private Entity removeWrongRelations(Entity ent) {
1
jurzua
parents:
diff changeset
812
33
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
813 for (Relation srcRel : new ArrayList<Relation>(ent.getSourceRelations())) {
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
814 if (srcRel.getTargetId() == null || getEntityByIdReadOnly(srcRel.getTargetId()) == null) {
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
815 ent.getSourceRelations().remove(srcRel);
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
816 logger.error("Inconsistency detected saving entity [" + ent.getId() + "] " + srcRel.toString());
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
817 }
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
818 }
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
819
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
820 for (Relation tarRel : new ArrayList<Relation>(ent.getTargetRelations())) {
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
821 if (tarRel.getSourceId() == null || getEntityByIdReadOnly(tarRel.getSourceId()) == null) {
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
822 ent.getTargetRelations().remove(tarRel);
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
823 logger.error("Inconsistency detected saving entity [" + ent.getId() + "] " + tarRel.toString());
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
824 }
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
825 }
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
826
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
827 return ent;
e52f593f9e0d new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents: 7
diff changeset
828 }
1
jurzua
parents:
diff changeset
829
jurzua
parents:
diff changeset
830 public Attribute getDefAttributeByOwnValue(String defOC, String attOW) {
jurzua
parents:
diff changeset
831 for (Attribute att : this.cache.getDefAttributes(defOC)) {
jurzua
parents:
diff changeset
832 if (att.getOwnValue().equals(attOW)) {
jurzua
parents:
diff changeset
833 return att;
jurzua
parents:
diff changeset
834 }
jurzua
parents:
diff changeset
835 }
jurzua
parents:
diff changeset
836 return null;
jurzua
parents:
diff changeset
837 }
jurzua
parents:
diff changeset
838
jurzua
parents:
diff changeset
839 public List<Attribute> getDefRelationAttributes(Long id) {
jurzua
parents:
diff changeset
840 return this.cache.getDefAttributesById(id);
jurzua
parents:
diff changeset
841 }
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
842
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
843 /**
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
844 * Returns the attributes of the definition of the given type.
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
845 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
846 * @param objectClass
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
847 * @return
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
848 */
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
849 public List<Attribute> getDefAttributes(String objectClass) {
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
850 return this.cache.getDefAttributes(objectClass);
1
jurzua
parents:
diff changeset
851 }
jurzua
parents:
diff changeset
852
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
853 /**
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
854 * Returns the source relations of the definition of the given type.
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
855 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
856 * @param objectClass
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
857 * @return
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
858 */
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
859 public List<Relation> getDefSourceRelations(String objectClass) {
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
860 return this.cache.getDefSourceRelations(objectClass);
1
jurzua
parents:
diff changeset
861 }
jurzua
parents:
diff changeset
862
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
863 /**
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
864 * Returns the target relations of the definition of the given type.
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
865 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
866 * @param objectClass
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
867 * @return
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
868 */
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
869 public List<Relation> getDefTargetRelations(String objectClass) {
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
870 return this.cache.getDefTargetRelations(objectClass);
1
jurzua
parents:
diff changeset
871 }
jurzua
parents:
diff changeset
872
jurzua
parents:
diff changeset
873 public Entity getDefinitionById(Long id) {
jurzua
parents:
diff changeset
874 return this.cache.getLWDefinitionById(id);
jurzua
parents:
diff changeset
875 }
jurzua
parents:
diff changeset
876
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
877 /**
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
878 * Returns all (lightweight) definition entities.
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
879 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
880 * @return
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
881 */
1
jurzua
parents:
diff changeset
882 public List<Entity> getLWDefinitions() {
jurzua
parents:
diff changeset
883 return this.cache.getLWDefinitions();
jurzua
parents:
diff changeset
884 }
jurzua
parents:
diff changeset
885
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
886 /**
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
887 * Returns the (lightweight) definition entity for the given type.
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
888 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
889 * @param objectClass
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
890 * @return
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
891 */
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
892 public Entity getDefinition(String objectClass) {
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
893 return this.cache.getLWDefinition(objectClass);
1
jurzua
parents:
diff changeset
894 }
jurzua
parents:
diff changeset
895
jurzua
parents:
diff changeset
896 public List<Relation> getRelation(String name, String srcOC, String tarOC)
jurzua
parents:
diff changeset
897 throws Exception {
jurzua
parents:
diff changeset
898 // TODO read only???
jurzua
parents:
diff changeset
899 List<Relation> list = new ArrayList<Relation>();
jurzua
parents:
diff changeset
900 if (StringUtils.isNotEmpty(name)) {
jurzua
parents:
diff changeset
901 List<Relation> list0 = cache.getRelsByName(name);
jurzua
parents:
diff changeset
902 if (StringUtils.isEmpty(srcOC) && StringUtils.isEmpty(tarOC)) {
jurzua
parents:
diff changeset
903 list = list0;
jurzua
parents:
diff changeset
904 } else {
jurzua
parents:
diff changeset
905 for (Relation rel : list0) {
jurzua
parents:
diff changeset
906 if ((StringUtils.isEmpty(srcOC) || srcOC.equals(rel
jurzua
parents:
diff changeset
907 .getSourceObjectClass()))
jurzua
parents:
diff changeset
908 && (StringUtils.isEmpty(tarOC) || tarOC.equals(rel
jurzua
parents:
diff changeset
909 .getTargetObjectClass()))) {
jurzua
parents:
diff changeset
910 list.add(rel);
jurzua
parents:
diff changeset
911 }
jurzua
parents:
diff changeset
912 }
jurzua
parents:
diff changeset
913 }
jurzua
parents:
diff changeset
914 }
jurzua
parents:
diff changeset
915
jurzua
parents:
diff changeset
916 return list;
jurzua
parents:
diff changeset
917 }
jurzua
parents:
diff changeset
918
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
919 /**
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
920 * Returns the Entities that are the sources of the target relations of the given Entity.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
921 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
922 * Filters relations by relationName and tarObjClass.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
923 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
924 * @param tar
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
925 * @param relationName
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
926 * @param srcObjClass
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
927 * @param maxResult
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
928 * @return
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
929 */
1
jurzua
parents:
diff changeset
930 public List<Entity> getSourcesForTargetRelation(Entity tar,
jurzua
parents:
diff changeset
931 String relationName, String srcObjClass, int maxResult) {
jurzua
parents:
diff changeset
932 return getSourcesForTargetRelation(tar.getId(), relationName,
jurzua
parents:
diff changeset
933 srcObjClass, maxResult);
jurzua
parents:
diff changeset
934 }
jurzua
parents:
diff changeset
935
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
936 /**
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
937 * Returns the Entities that are the sources of the target relations of the Entity with the given tarId.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
938 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
939 * Filters relations by relationName and tarObjClass.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
940 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
941 * @param tarId
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
942 * @param relationName
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
943 * @param srcObjClass
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
944 * @param maxResult
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
945 * @return
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
946 */
1
jurzua
parents:
diff changeset
947 public List<Entity> getSourcesForTargetRelation(Long tarId,
jurzua
parents:
diff changeset
948 String relationName, String srcObjClass, int maxResult) {
jurzua
parents:
diff changeset
949 List<Entity> rs = new ArrayList<Entity>();
jurzua
parents:
diff changeset
950
jurzua
parents:
diff changeset
951 List<Relation> tarRelList = this.cache.getRelsByTarId(tarId);
jurzua
parents:
diff changeset
952
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
953 //long start = System.currentTimeMillis();
1
jurzua
parents:
diff changeset
954 int count = 0;
jurzua
parents:
diff changeset
955 for (Relation rel : tarRelList) {
jurzua
parents:
diff changeset
956 if (stringEquals(relationName, rel.getOwnValue())
jurzua
parents:
diff changeset
957 && stringEquals(srcObjClass, rel.getSourceObjectClass())) {
jurzua
parents:
diff changeset
958 Entity ent = getEntityByIdReadOnly(rel.getSourceId());
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
959 if (ent == null) {
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
960 logger.error("Relation source id does not exist! id="+rel.getSourceId()+" relation: "+rel);
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
961 } else {
1
jurzua
parents:
diff changeset
962 rs.add(ent);
jurzua
parents:
diff changeset
963 count++;
jurzua
parents:
diff changeset
964 if (maxResult > 0 && count == maxResult) {
jurzua
parents:
diff changeset
965 break;
jurzua
parents:
diff changeset
966 }
jurzua
parents:
diff changeset
967 }
jurzua
parents:
diff changeset
968 }
jurzua
parents:
diff changeset
969 }
64
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
970 //logger.debug("getSourcesForTargetRelation (loading sources) - execution time[ms]: "+(System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
971 Collections.sort(rs, new EntitySortByNormalizedOwnValue());
jurzua
parents:
diff changeset
972 return rs;
jurzua
parents:
diff changeset
973 }
jurzua
parents:
diff changeset
974
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
975 /**
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
976 * Returns the Entities that are the targets of the source relations of the given Entity.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
977 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
978 * Filters relations by relationName and tarObjClass.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
979 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
980 * @param src
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
981 * @param relationName
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
982 * @param tarObjClass
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
983 * @param maxResult
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
984 * @return
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
985 */
1
jurzua
parents:
diff changeset
986 public List<Entity> getTargetsForSourceRelation(Entity src,
jurzua
parents:
diff changeset
987 String relationName, String tarObjClass, int maxResult) {
jurzua
parents:
diff changeset
988 return getTargetsForSourceRelation(src.getId(), relationName,
jurzua
parents:
diff changeset
989 tarObjClass, maxResult);
jurzua
parents:
diff changeset
990 }
jurzua
parents:
diff changeset
991
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
992 /**
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
993 * Returns the Entities that are the targets of the source relations of the Entity with the given srcId.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
994 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
995 * Filters relations by relationName and tarObjClass.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
996 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
997 * @param srcId
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
998 * @param relationName
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
999 * @param tarObjClass
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1000 * @param maxResult
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1001 * @return
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1002 */
1
jurzua
parents:
diff changeset
1003 public List<Entity> getTargetsForSourceRelation(Long srcId,
jurzua
parents:
diff changeset
1004 String relationName, String tarObjClass, int maxResult) {
jurzua
parents:
diff changeset
1005 List<Entity> rs = new ArrayList<Entity>();
jurzua
parents:
diff changeset
1006
jurzua
parents:
diff changeset
1007 try {
jurzua
parents:
diff changeset
1008 Collection<Relation> srcRelList = this.cache.getRelsBySrcId(srcId);
jurzua
parents:
diff changeset
1009
jurzua
parents:
diff changeset
1010 int count = 0;
jurzua
parents:
diff changeset
1011 for (Relation rel : srcRelList) {
jurzua
parents:
diff changeset
1012 if (stringEquals(relationName, rel.getOwnValue())
jurzua
parents:
diff changeset
1013 && stringEquals(tarObjClass, rel.getTargetObjectClass())) {
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1014 Entity ent = getEntityByIdReadOnly(rel.getTargetId());
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1015 if (ent == null) {
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1016 logger.error("Relation target id does not exist! id="+rel.getTargetId()+" relation: "+rel);
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1017 } else {
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1018 rs.add(ent);
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1019 count++;
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1020 if (maxResult > 0 && count == maxResult) {
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1021 break;
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1022 }
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1023 }
1
jurzua
parents:
diff changeset
1024 }
jurzua
parents:
diff changeset
1025 }
jurzua
parents:
diff changeset
1026 Collections.sort(rs, new EntitySortByNormalizedOwnValue());
jurzua
parents:
diff changeset
1027 } catch (Exception e) {
jurzua
parents:
diff changeset
1028 logger.error(e.getMessage(), e);
jurzua
parents:
diff changeset
1029 }
jurzua
parents:
diff changeset
1030
jurzua
parents:
diff changeset
1031 return rs;
jurzua
parents:
diff changeset
1032 }
jurzua
parents:
diff changeset
1033
jurzua
parents:
diff changeset
1034 public List<Relation> getTargetRelations(Entity target,
jurzua
parents:
diff changeset
1035 String relationName, String srcObjClass, int maxResult) {
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
1036 //long start = System.currentTimeMillis();
1
jurzua
parents:
diff changeset
1037 List<Relation> list = new ArrayList<Relation>();
jurzua
parents:
diff changeset
1038
jurzua
parents:
diff changeset
1039 List<Relation> tarRelList = this.cache.getRelsByTarId(target.getId());
jurzua
parents:
diff changeset
1040
jurzua
parents:
diff changeset
1041 int count = 0;
jurzua
parents:
diff changeset
1042 for (Relation rel : tarRelList) {
jurzua
parents:
diff changeset
1043 if (stringEquals(relationName, rel.getOwnValue())
jurzua
parents:
diff changeset
1044 && stringEquals(srcObjClass, rel.getSourceObjectClass())) {
jurzua
parents:
diff changeset
1045 Entity source = getEntityById(rel.getSourceId());
jurzua
parents:
diff changeset
1046 if (source != null) {
jurzua
parents:
diff changeset
1047 rel.setTarget(target);
jurzua
parents:
diff changeset
1048 rel.setSource(source);
jurzua
parents:
diff changeset
1049 list.add(rel);
jurzua
parents:
diff changeset
1050 count++;
jurzua
parents:
diff changeset
1051 if (maxResult > 0 && count == maxResult) {
jurzua
parents:
diff changeset
1052 break;
jurzua
parents:
diff changeset
1053 }
jurzua
parents:
diff changeset
1054 } else {
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
1055 logger.error("Relation without source: "+ rel.toString());
1
jurzua
parents:
diff changeset
1056 }
jurzua
parents:
diff changeset
1057
jurzua
parents:
diff changeset
1058 }
jurzua
parents:
diff changeset
1059 }
jurzua
parents:
diff changeset
1060 Collections.sort(list, new RelationSortBySourceOW());
64
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
1061 //logger.debug("getTargetRelations - execution time[ms]: "+ (System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
1062 return list;
jurzua
parents:
diff changeset
1063 }
jurzua
parents:
diff changeset
1064
jurzua
parents:
diff changeset
1065 /**
jurzua
parents:
diff changeset
1066 * Returns a list of relations found by entity source.
jurzua
parents:
diff changeset
1067 *
jurzua
parents:
diff changeset
1068 * @param source
jurzua
parents:
diff changeset
1069 * @param relationName
jurzua
parents:
diff changeset
1070 * @param tarObjClass
jurzua
parents:
diff changeset
1071 * @param maxResult
jurzua
parents:
diff changeset
1072 * @return
jurzua
parents:
diff changeset
1073 */
jurzua
parents:
diff changeset
1074 public List<Relation> getSourceRelations(Entity source,
jurzua
parents:
diff changeset
1075 String relationName, String tarObjClass, int maxResult)
jurzua
parents:
diff changeset
1076 throws Exception {
jurzua
parents:
diff changeset
1077
67
ae732119447f small fixes.
casties
parents: 66
diff changeset
1078 //long start = System.currentTimeMillis();
1
jurzua
parents:
diff changeset
1079 List<Relation> list = new ArrayList<Relation>();
jurzua
parents:
diff changeset
1080
jurzua
parents:
diff changeset
1081 // the collection coll should not be modified
jurzua
parents:
diff changeset
1082 // otherwise java.util.ConcurrentModificationException will be thrown.
jurzua
parents:
diff changeset
1083 // be carefully using getEntityContent, cause it changes the cache
jurzua
parents:
diff changeset
1084
jurzua
parents:
diff changeset
1085 List<Relation> srcRelList = this.cache.getRelsBySrcId(source.getId());
jurzua
parents:
diff changeset
1086
jurzua
parents:
diff changeset
1087 int count = 0;
jurzua
parents:
diff changeset
1088 for (Relation rel : srcRelList) {
jurzua
parents:
diff changeset
1089 if (stringEquals(relationName, rel.getOwnValue())
jurzua
parents:
diff changeset
1090 && stringEquals(tarObjClass, rel.getTargetObjectClass())) {
jurzua
parents:
diff changeset
1091 rel.setSource(source);
jurzua
parents:
diff changeset
1092 rel.setTarget(getEntityById(rel.getTargetId()));
jurzua
parents:
diff changeset
1093 list.add(rel);
jurzua
parents:
diff changeset
1094 count++;
jurzua
parents:
diff changeset
1095 if (maxResult > 0 && count == maxResult) {
jurzua
parents:
diff changeset
1096 break;
jurzua
parents:
diff changeset
1097 }
jurzua
parents:
diff changeset
1098 }
jurzua
parents:
diff changeset
1099 }
jurzua
parents:
diff changeset
1100 Collections.sort(list, new RelationSortByTargetOW());
64
83b209aa4226 working on stale entity update problem.
casties
parents: 62
diff changeset
1101 //logger.debug("getSourceRelations - execution time[ms]: "+ (System.currentTimeMillis() - start));
1
jurzua
parents:
diff changeset
1102
jurzua
parents:
diff changeset
1103 return list;
jurzua
parents:
diff changeset
1104 }
jurzua
parents:
diff changeset
1105
jurzua
parents:
diff changeset
1106 /**
54
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1107 * Load and attach the Attributes and Relations of the given Entity.
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1108 *
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1109 * Tries to loads from cache first and then from DB, saving to cache.
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1110 *
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1111 * Returns a cloned Entity.
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1112 *
1
jurzua
parents:
diff changeset
1113 * This method should not be used inside this Wrapper class, because it
54
7f9033d44a87 small cleanup.
casties
parents: 53
diff changeset
1114 * could throw a java.util.ConcurrentModificationException.
1
jurzua
parents:
diff changeset
1115 *
jurzua
parents:
diff changeset
1116 * @param ent
jurzua
parents:
diff changeset
1117 * @return
jurzua
parents:
diff changeset
1118 */
jurzua
parents:
diff changeset
1119 public Entity getEntityContent(Entity ent) {
jurzua
parents:
diff changeset
1120 try {
jurzua
parents:
diff changeset
1121 if (ent.isLightweight()) {
jurzua
parents:
diff changeset
1122 Entity e = this.cache.getEntityContent(ent);
jurzua
parents:
diff changeset
1123 if (e == null) {
jurzua
parents:
diff changeset
1124 e = this.getPS().getEntityContent(ent);
jurzua
parents:
diff changeset
1125 this.cache.saveEntity(e);
jurzua
parents:
diff changeset
1126 } else {
jurzua
parents:
diff changeset
1127 ent = e;
jurzua
parents:
diff changeset
1128 }
jurzua
parents:
diff changeset
1129 }
jurzua
parents:
diff changeset
1130 return (Entity) ent.clone();
jurzua
parents:
diff changeset
1131 } catch (Exception e) {
jurzua
parents:
diff changeset
1132 logger.error(e.getMessage(), e);
jurzua
parents:
diff changeset
1133 }
jurzua
parents:
diff changeset
1134 return null;
jurzua
parents:
diff changeset
1135 }
jurzua
parents:
diff changeset
1136
jurzua
parents:
diff changeset
1137 public Entity getEntityContentReadOnly(Entity ent) throws Exception {
jurzua
parents:
diff changeset
1138 if (ent.isLightweight()) {
jurzua
parents:
diff changeset
1139 Entity e = this.cache.getEntityContent(ent);
jurzua
parents:
diff changeset
1140 if (e == null) {
jurzua
parents:
diff changeset
1141 e = this.getPS().getEntityContent(ent);
jurzua
parents:
diff changeset
1142 this.cache.saveEntity(e);
jurzua
parents:
diff changeset
1143 } else {
jurzua
parents:
diff changeset
1144 ent = e;
jurzua
parents:
diff changeset
1145 }
jurzua
parents:
diff changeset
1146 }
jurzua
parents:
diff changeset
1147 return ent;
jurzua
parents:
diff changeset
1148 }
jurzua
parents:
diff changeset
1149
jurzua
parents:
diff changeset
1150 /**
39
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1151 * Return an entity with the given id from the cache.
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1152 *
1
jurzua
parents:
diff changeset
1153 * The entity returned could be LW or not, it depends on the cache.
jurzua
parents:
diff changeset
1154 * additionally, it will be always a clone of the version in cache,
jurzua
parents:
diff changeset
1155 * therefore it method is thought for editing's issues.
jurzua
parents:
diff changeset
1156 *
jurzua
parents:
diff changeset
1157 * @param id
jurzua
parents:
diff changeset
1158 * @return
jurzua
parents:
diff changeset
1159 */
jurzua
parents:
diff changeset
1160 public Entity getEntityById(Long id) {
jurzua
parents:
diff changeset
1161 Entity ent = this.cache.getEntityById(id);
jurzua
parents:
diff changeset
1162 return ent;
jurzua
parents:
diff changeset
1163 }
jurzua
parents:
diff changeset
1164
39
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1165 /**
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1166 * Return an entity with the given id from the cache.
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1167 *
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1168 * Do not modify the entity!
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1169 *
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1170 * @param id
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1171 * @return
86c343109257 more comments and cleanup.
casties
parents: 38
diff changeset
1172 */
1
jurzua
parents:
diff changeset
1173 public Entity getEntityByIdReadOnly(Long id) {
jurzua
parents:
diff changeset
1174 Entity ent = this.cache.getEntityByIdReadOnly(id);
jurzua
parents:
diff changeset
1175 return ent;
jurzua
parents:
diff changeset
1176 }
jurzua
parents:
diff changeset
1177
jurzua
parents:
diff changeset
1178 public Entity getClonedEntityById(Long id) {
jurzua
parents:
diff changeset
1179 return (Entity) getEntityById(id).clone();
jurzua
parents:
diff changeset
1180 }
jurzua
parents:
diff changeset
1181
jurzua
parents:
diff changeset
1182 /**
jurzua
parents:
diff changeset
1183 * This method should not be used inside this Wrapper class, because it
jurzua
parents:
diff changeset
1184 * could throws an java.util.ConcurrentModificationException.
jurzua
parents:
diff changeset
1185 *
jurzua
parents:
diff changeset
1186 * @param id
jurzua
parents:
diff changeset
1187 * @return
jurzua
parents:
diff changeset
1188 */
jurzua
parents:
diff changeset
1189 public Entity getEntityByIdWithContent(Long id) {
jurzua
parents:
diff changeset
1190 try {
jurzua
parents:
diff changeset
1191 Entity ent = getEntityById(id);
jurzua
parents:
diff changeset
1192 if (ent != null && ent.isLightweight()) {
jurzua
parents:
diff changeset
1193 ent = getEntityContent(ent);
jurzua
parents:
diff changeset
1194 }
jurzua
parents:
diff changeset
1195 return ent;
jurzua
parents:
diff changeset
1196 } catch (Exception e) {
jurzua
parents:
diff changeset
1197 logger.error(e.getMessage(), e);
jurzua
parents:
diff changeset
1198 }
jurzua
parents:
diff changeset
1199 return null;
jurzua
parents:
diff changeset
1200 }
jurzua
parents:
diff changeset
1201
jurzua
parents:
diff changeset
1202 public Entity getEntityByIdWithContentReadOnly(Long id) throws Exception {
jurzua
parents:
diff changeset
1203 Entity ent = getEntityByIdReadOnly(id);
jurzua
parents:
diff changeset
1204 if (ent.isLightweight()) {
jurzua
parents:
diff changeset
1205 ent = getEntityContentReadOnly(ent);
jurzua
parents:
diff changeset
1206 }
jurzua
parents:
diff changeset
1207 return ent;
jurzua
parents:
diff changeset
1208 }
jurzua
parents:
diff changeset
1209
55
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1210 /**
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1211 * Returns if ow equals term if term is not empty. Returns true if term is empty.
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1212 *
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1213 * @param term
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1214 * @param ow
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1215 * @return
b7a8db041f68 cleanup and fix when target_id doesn't exist.
casties
parents: 54
diff changeset
1216 */
1
jurzua
parents:
diff changeset
1217 public static boolean stringEquals(String term, String ow) {
jurzua
parents:
diff changeset
1218 if (StringUtils.isEmpty(term))
jurzua
parents:
diff changeset
1219 return true;
jurzua
parents:
diff changeset
1220 return term.equals(ow);
jurzua
parents:
diff changeset
1221 }
jurzua
parents:
diff changeset
1222
jurzua
parents:
diff changeset
1223 // ////****
jurzua
parents:
diff changeset
1224 public Entity getLightweightEntityById(Long id) {
jurzua
parents:
diff changeset
1225 Entity entity = null;
jurzua
parents:
diff changeset
1226 if (id != null) {
jurzua
parents:
diff changeset
1227 List<Entity> list = this.getPS().getLightweightEntities(
jurzua
parents:
diff changeset
1228 Node.SYS_STATUS_CURRENT_VERSION, id, null, null, null,
jurzua
parents:
diff changeset
1229 true, -1);
jurzua
parents:
diff changeset
1230 if (list.size() > 0) {
jurzua
parents:
diff changeset
1231 entity = list.get(0);
jurzua
parents:
diff changeset
1232 }
jurzua
parents:
diff changeset
1233 }
jurzua
parents:
diff changeset
1234 return entity;
jurzua
parents:
diff changeset
1235 }
jurzua
parents:
diff changeset
1236
jurzua
parents:
diff changeset
1237 public List<Entity> getLightweightAssertions(String objectClass,
jurzua
parents:
diff changeset
1238 String ownValue, int maxResult) {
jurzua
parents:
diff changeset
1239 return getPS().getLightweightEntities(Node.SYS_STATUS_CURRENT_VERSION,
jurzua
parents:
diff changeset
1240 null, Node.TYPE_ABOX, objectClass, ownValue, true, maxResult);
jurzua
parents:
diff changeset
1241 }
jurzua
parents:
diff changeset
1242
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1243 /**
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
1244 * Save the entity. Calls {@link #saveEntity(String, String, EditIntent)}.
38
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1245 *
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1246 * @param entity
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1247 * @param user
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1248 * @throws Exception
cb25e343e317 more comments and refactorings.
casties
parents: 37
diff changeset
1249 */
1
jurzua
parents:
diff changeset
1250 public void saveAssertion(Entity entity, String user) throws Exception {
66
3e4b05a6cb47 new EditIntent for saveEntity().
casties
parents: 65
diff changeset
1251 this.saveEntity(entity, user, null);
1
jurzua
parents:
diff changeset
1252 }
jurzua
parents:
diff changeset
1253
jurzua
parents:
diff changeset
1254 /**
jurzua
parents:
diff changeset
1255 * <p>
jurzua
parents:
diff changeset
1256 * This method saves a non-persistent entity.
jurzua
parents:
diff changeset
1257 * </p>
jurzua
parents:
diff changeset
1258 * <p>
jurzua
parents:
diff changeset
1259 * The reason of this is that nodes are stored only in the DB and not in the
jurzua
parents:
diff changeset
1260 * cache.
jurzua
parents:
diff changeset
1261 * </p>
jurzua
parents:
diff changeset
1262 * <p>
jurzua
parents:
diff changeset
1263 * Later, when the nodes are required, they will be loaded from the BD to
jurzua
parents:
diff changeset
1264 * the cache automatically. However there are some structures like
jurzua
parents:
diff changeset
1265 * attributes by entId that become inconsistent using this method.
jurzua
parents:
diff changeset
1266 * </p>
jurzua
parents:
diff changeset
1267 *
jurzua
parents:
diff changeset
1268 * @param node
jurzua
parents:
diff changeset
1269 * non-persistent node.
jurzua
parents:
diff changeset
1270 * @param user
jurzua
parents:
diff changeset
1271 * @throws Exception
jurzua
parents:
diff changeset
1272 */
jurzua
parents:
diff changeset
1273 public void saveNodeOnlyForScripts(Node node, String user) throws Exception {
jurzua
parents:
diff changeset
1274 if (node.isPersistent()) {
jurzua
parents:
diff changeset
1275 throw new Exception(
jurzua
parents:
diff changeset
1276 "This method can save only non-persistent nodes. Because the nodes are stored only in the DB in not in the Cache.");
jurzua
parents:
diff changeset
1277 }
jurzua
parents:
diff changeset
1278 if (StringUtils.isEmpty(node.getType())) {
jurzua
parents:
diff changeset
1279 throw new Exception("The type of the node can not be empty");
jurzua
parents:
diff changeset
1280 }
jurzua
parents:
diff changeset
1281 node.setUser(user);
jurzua
parents:
diff changeset
1282 this.getPS().saveNode(node);
jurzua
parents:
diff changeset
1283
jurzua
parents:
diff changeset
1284 // if(StringUtils.isNotEmpty(node.getType())){
jurzua
parents:
diff changeset
1285 // if(node.getType().equals(Node.TYPE_ABOX)){
jurzua
parents:
diff changeset
1286 //
jurzua
parents:
diff changeset
1287 // }else if(node.getType().equals(Node.TYPE_TBOX)){
jurzua
parents:
diff changeset
1288 //
jurzua
parents:
diff changeset
1289 // }
jurzua
parents:
diff changeset
1290 // }
jurzua
parents:
diff changeset
1291 }
jurzua
parents:
diff changeset
1292
jurzua
parents:
diff changeset
1293 public void removeNode(Node node) {
jurzua
parents:
diff changeset
1294 this.getPS().removeNode(node);
jurzua
parents:
diff changeset
1295 }
jurzua
parents:
diff changeset
1296
jurzua
parents:
diff changeset
1297 public Map<Long, Long> saveEntityListAsNew(List<Entity> entities, String user,
jurzua
parents:
diff changeset
1298 boolean testWrongRelations) throws Exception {
jurzua
parents:
diff changeset
1299 logger.info("\n ### Making persistent Entities size total "
jurzua
parents:
diff changeset
1300 + entities.size() + " ### \n");
jurzua
parents:
diff changeset
1301 int sizePart = 1000;
jurzua
parents:
diff changeset
1302 List<Entity> tmpList = null;
jurzua
parents:
diff changeset
1303
jurzua
parents:
diff changeset
1304 Map<Long, Long> idMap = new HashMap<Long, Long>();
jurzua
parents:
diff changeset
1305
jurzua
parents:
diff changeset
1306 for (int j = 0; j <= (entities.size() / sizePart); j++) {
jurzua
parents:
diff changeset
1307 tmpList = new ArrayList<Entity>(sizePart);
jurzua
parents:
diff changeset
1308 for (int i = (j * sizePart); i < ((j + 1) * sizePart); i++) {
jurzua
parents:
diff changeset
1309
jurzua
parents:
diff changeset
1310 if (i < entities.size()) {
jurzua
parents:
diff changeset
1311 if (StringUtils.isNotEmpty(user)) {
jurzua
parents:
diff changeset
1312 entities.get(i).setUser(user);
jurzua
parents:
diff changeset
1313 }
jurzua
parents:
diff changeset
1314
jurzua
parents:
diff changeset
1315 if (testWrongRelations
jurzua
parents:
diff changeset
1316 && hasWrongRelations(entities.get(i))) {
jurzua
parents:
diff changeset
1317 throw new Exception("Wrong relations "
jurzua
parents:
diff changeset
1318 + entities.get(i));
jurzua
parents:
diff changeset
1319 }
jurzua
parents:
diff changeset
1320
jurzua
parents:
diff changeset
1321 tmpList.add(entities.get(i));
jurzua
parents:
diff changeset
1322 } else {
jurzua
parents:
diff changeset
1323 break;
jurzua
parents:
diff changeset
1324 }
jurzua
parents:
diff changeset
1325 }
jurzua
parents:
diff changeset
1326
jurzua
parents:
diff changeset
1327 logger.info("\nMaking persistent Entities part " + (j + 1) + " of "
jurzua
parents:
diff changeset
1328 + ((entities.size() / sizePart) + 1) + " size="
jurzua
parents:
diff changeset
1329 + tmpList.size());
jurzua
parents:
diff changeset
1330 idMap = this.getPS().saveEntityListAsNew(tmpList, idMap);
jurzua
parents:
diff changeset
1331 }
jurzua
parents:
diff changeset
1332 return idMap;
jurzua
parents:
diff changeset
1333 }
jurzua
parents:
diff changeset
1334
jurzua
parents:
diff changeset
1335 /*
jurzua
parents:
diff changeset
1336 public void saveEntityList(List<Entity> entities, String user,
jurzua
parents:
diff changeset
1337 boolean testWrongRelations) throws Exception {
jurzua
parents:
diff changeset
1338 logger.info("\n ### Making persistent Entities size total "
jurzua
parents:
diff changeset
1339 + entities.size() + " ### \n");
jurzua
parents:
diff changeset
1340 int sizePart = 1000;
jurzua
parents:
diff changeset
1341 List<Entity> tmpList = null;
jurzua
parents:
diff changeset
1342
jurzua
parents:
diff changeset
1343 for (int j = 0; j <= (entities.size() / sizePart); j++) {
jurzua
parents:
diff changeset
1344 tmpList = new ArrayList<Entity>(sizePart);
jurzua
parents:
diff changeset
1345 for (int i = (j * sizePart); i < ((j + 1) * sizePart); i++) {
jurzua
parents:
diff changeset
1346
jurzua
parents:
diff changeset
1347 if (i < entities.size()) {
jurzua
parents:
diff changeset
1348 if (StringUtils.isNotEmpty(user)) {
jurzua
parents:
diff changeset
1349 entities.get(i).setUser(user);
jurzua
parents:
diff changeset
1350 }
jurzua
parents:
diff changeset
1351
jurzua
parents:
diff changeset
1352 if (testWrongRelations
jurzua
parents:
diff changeset
1353 && hasWrongRelations(entities.get(i))) {
jurzua
parents:
diff changeset
1354 throw new Exception("Wrong relations "
jurzua
parents:
diff changeset
1355 + entities.get(i));
jurzua
parents:
diff changeset
1356 }
jurzua
parents:
diff changeset
1357
jurzua
parents:
diff changeset
1358 tmpList.add(entities.get(i));
jurzua
parents:
diff changeset
1359 } else {
jurzua
parents:
diff changeset
1360 break;
jurzua
parents:
diff changeset
1361 }
jurzua
parents:
diff changeset
1362 }
jurzua
parents:
diff changeset
1363
jurzua
parents:
diff changeset
1364 logger.info("\nMaking persistent Entities part " + (j + 1) + " of "
jurzua
parents:
diff changeset
1365 + ((entities.size() / sizePart) + 1) + " size="
jurzua
parents:
diff changeset
1366 + tmpList.size());
jurzua
parents:
diff changeset
1367 this.getPS().saveEntityList(tmpList);
jurzua
parents:
diff changeset
1368
jurzua
parents:
diff changeset
1369 for(Entity ent : tmpList){
jurzua
parents:
diff changeset
1370 logger.info("[U=" + user + "] SaveEntity " + ent.toSmallString());
jurzua
parents:
diff changeset
1371 }
jurzua
parents:
diff changeset
1372
jurzua
parents:
diff changeset
1373 }
jurzua
parents:
diff changeset
1374 }*/
jurzua
parents:
diff changeset
1375
jurzua
parents:
diff changeset
1376 public void saveConcept(Entity entity) throws Exception {
jurzua
parents:
diff changeset
1377 entity.setType(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
1378 entity.setObjectClass(Node.TYPE_TBOX);
jurzua
parents:
diff changeset
1379 this.getPS().saveEntity(entity);
jurzua
parents:
diff changeset
1380 }
jurzua
parents:
diff changeset
1381
jurzua
parents:
diff changeset
1382 public void saveNodeListOnlyForScripts(List<Node> nodeList, String user)
jurzua
parents:
diff changeset
1383 throws Exception {
jurzua
parents:
diff changeset
1384 logger.debug("### Making persistent Nodes size total "
jurzua
parents:
diff changeset
1385 + nodeList.size() + " ###");
jurzua
parents:
diff changeset
1386 List<Node> list = null;
jurzua
parents:
diff changeset
1387 int sizePart = 1000;
jurzua
parents:
diff changeset
1388 for (int j = 0; j <= (nodeList.size() / sizePart); j++) {
jurzua
parents:
diff changeset
1389 list = new ArrayList<Node>();
jurzua
parents:
diff changeset
1390 for (int i = (j * sizePart); i < ((j + 1) * sizePart); i++) {
jurzua
parents:
diff changeset
1391 if (i < nodeList.size()) {
jurzua
parents:
diff changeset
1392 nodeList.get(i).setUser(user);
jurzua
parents:
diff changeset
1393 list.add(nodeList.get(i));
jurzua
parents:
diff changeset
1394 }
jurzua
parents:
diff changeset
1395 }
jurzua
parents:
diff changeset
1396 logger.debug("Making persistent Nodes part " + (j + 1) + " of "
jurzua
parents:
diff changeset
1397 + ((nodeList.size() / sizePart) + 1) + " size="
jurzua
parents:
diff changeset
1398 + list.size());
jurzua
parents:
diff changeset
1399 this.getPS().saveNodeList(list);
jurzua
parents:
diff changeset
1400 }
jurzua
parents:
diff changeset
1401 }
jurzua
parents:
diff changeset
1402
jurzua
parents:
diff changeset
1403 public void saveNodeListOnlyForScripts(List<Node> nodeList)
jurzua
parents:
diff changeset
1404 throws Exception {
jurzua
parents:
diff changeset
1405 logger.info("\n ### Making persistent Nodes size total "
jurzua
parents:
diff changeset
1406 + nodeList.size() + " ### \n");
jurzua
parents:
diff changeset
1407 int sizePart = 1000;
jurzua
parents:
diff changeset
1408 List<Node> list = null;
jurzua
parents:
diff changeset
1409 for (int j = 0; j <= (nodeList.size() / sizePart); j++) {
jurzua
parents:
diff changeset
1410 list = new ArrayList<Node>();
jurzua
parents:
diff changeset
1411 for (int i = (j * sizePart); i < ((j + 1) * sizePart); i++) {
jurzua
parents:
diff changeset
1412 if (i < nodeList.size()) {
jurzua
parents:
diff changeset
1413 list.add(nodeList.get(i));
jurzua
parents:
diff changeset
1414 }
jurzua
parents:
diff changeset
1415 }
jurzua
parents:
diff changeset
1416 logger.info("Making persistent Nodes part " + (j + 1) + " of "
jurzua
parents:
diff changeset
1417 + ((nodeList.size() / sizePart) + 1) + " size="
jurzua
parents:
diff changeset
1418 + list.size());
jurzua
parents:
diff changeset
1419 this.getPS().saveNodeList(list);
jurzua
parents:
diff changeset
1420 }
jurzua
parents:
diff changeset
1421 // this.persistenceService.saveNodeList(nodeList);
jurzua
parents:
diff changeset
1422 }
jurzua
parents:
diff changeset
1423
jurzua
parents:
diff changeset
1424 public List<Entity> getConcepts() {
jurzua
parents:
diff changeset
1425 return this.getPS().getEntities(null, Node.SYS_STATUS_CURRENT_VERSION,
jurzua
parents:
diff changeset
1426 Node.TYPE_TBOX, null);
jurzua
parents:
diff changeset
1427 }
jurzua
parents:
diff changeset
1428
jurzua
parents:
diff changeset
1429 public List<Entity> getAssertion() {
jurzua
parents:
diff changeset
1430 return this.getPS().getEntities(null, Node.SYS_STATUS_CURRENT_VERSION,
jurzua
parents:
diff changeset
1431 Node.TYPE_ABOX, null);
jurzua
parents:
diff changeset
1432 }
jurzua
parents:
diff changeset
1433
jurzua
parents:
diff changeset
1434 public List<Entity> getLightweightAssertionsByExactOwnValue(
jurzua
parents:
diff changeset
1435 String objectClass, String ownValue, int maxResult) {
jurzua
parents:
diff changeset
1436 return getPS().getLightweightEntities(Node.SYS_STATUS_CURRENT_VERSION,
jurzua
parents:
diff changeset
1437 null, Node.TYPE_ABOX, objectClass, ownValue, false, maxResult);
jurzua
parents:
diff changeset
1438 }
jurzua
parents:
diff changeset
1439
jurzua
parents:
diff changeset
1440 public void removeNodeList(List<Node> nodeList) {
62
58659e865279 less System.out.println. less logging.
casties
parents: 58
diff changeset
1441 //System.out.println("\n ### Deleting Nodes size total "+ nodeList.size() + " ### \n");
1
jurzua
parents:
diff changeset
1442 this.getPS().removeNodeList(nodeList);
jurzua
parents:
diff changeset
1443 }
jurzua
parents:
diff changeset
1444
jurzua
parents:
diff changeset
1445 public void deleteAllConcepts() {
jurzua
parents:
diff changeset
1446 // persistenceService.deleteEntities(null, Node.TYPE_TBOX, true);
jurzua
parents:
diff changeset
1447 getPS().dropDefinitions();
jurzua
parents:
diff changeset
1448 }
jurzua
parents:
diff changeset
1449
jurzua
parents:
diff changeset
1450 public void importOM3Concepts(String fileName, Boolean dropConcepts) {
jurzua
parents:
diff changeset
1451 getPS().setImportModus(true);
jurzua
parents:
diff changeset
1452 ImportOM3Util.importConcepts(this, fileName, dropConcepts);
jurzua
parents:
diff changeset
1453 getPS().setImportModus(false);
jurzua
parents:
diff changeset
1454 }
jurzua
parents:
diff changeset
1455
jurzua
parents:
diff changeset
1456 // ///
jurzua
parents:
diff changeset
1457
jurzua
parents:
diff changeset
1458 public PersistenceService getPS() {
jurzua
parents:
diff changeset
1459 return this.cache.getPs();
jurzua
parents:
diff changeset
1460 }
jurzua
parents:
diff changeset
1461
jurzua
parents:
diff changeset
1462 public CacheService getCache() {
jurzua
parents:
diff changeset
1463 return cache;
jurzua
parents:
diff changeset
1464 }
jurzua
parents:
diff changeset
1465
jurzua
parents:
diff changeset
1466 public void setCache(CacheService cache) {
jurzua
parents:
diff changeset
1467 this.cache = cache;
jurzua
parents:
diff changeset
1468 }
jurzua
parents:
diff changeset
1469
jurzua
parents:
diff changeset
1470 public List<ViewerAttribute> getViewerAttributes(Long page){
jurzua
parents:
diff changeset
1471 List<ViewerAttribute> list = cache.getViewerAttributes(page);
jurzua
parents:
diff changeset
1472 Collections.sort(list);
jurzua
parents:
diff changeset
1473 return list;
jurzua
parents:
diff changeset
1474 }
jurzua
parents:
diff changeset
1475
jurzua
parents:
diff changeset
1476 public List<ViewerAttribute> getViewerAttributes4Edition(Long page) throws CloneNotSupportedException{
jurzua
parents:
diff changeset
1477 List<ViewerAttribute> list = new ArrayList<ViewerAttribute>();
jurzua
parents:
diff changeset
1478 for(ViewerAttribute att : cache.getViewerAttributes(page)){
jurzua
parents:
diff changeset
1479 list.add((ViewerAttribute)att.clone());
jurzua
parents:
diff changeset
1480 }
jurzua
parents:
diff changeset
1481 Collections.sort(list);
jurzua
parents:
diff changeset
1482 return list;
jurzua
parents:
diff changeset
1483 }
jurzua
parents:
diff changeset
1484
jurzua
parents:
diff changeset
1485 public Collection<ViewerPage> getViewerPages(){
jurzua
parents:
diff changeset
1486 return cache.getViewerPages();
jurzua
parents:
diff changeset
1487 }
jurzua
parents:
diff changeset
1488
jurzua
parents:
diff changeset
1489 public ViewerPage getViewerPage(Long id){
jurzua
parents:
diff changeset
1490 return cache.getViewerPageMap().get(id);
jurzua
parents:
diff changeset
1491 }
jurzua
parents:
diff changeset
1492
jurzua
parents:
diff changeset
1493 public ViewerPage getViewerPage(String definition){
jurzua
parents:
diff changeset
1494 for(ViewerPage page : cache.getViewerPages()){
jurzua
parents:
diff changeset
1495 if(page.getDefinition().equals(definition)){
jurzua
parents:
diff changeset
1496 return page;
jurzua
parents:
diff changeset
1497 }
jurzua
parents:
diff changeset
1498 }
jurzua
parents:
diff changeset
1499 return null;
jurzua
parents:
diff changeset
1500 }
jurzua
parents:
diff changeset
1501
jurzua
parents:
diff changeset
1502 public ViewerPage getViewerPage4Edition(Long id) throws CloneNotSupportedException{
jurzua
parents:
diff changeset
1503 ViewerPage page = cache.getViewerPageMap().get(id);
jurzua
parents:
diff changeset
1504 return (page != null) ? (ViewerPage) page.clone() : null;
jurzua
parents:
diff changeset
1505 }
jurzua
parents:
diff changeset
1506
jurzua
parents:
diff changeset
1507 public ViewerPage saveViewerPage(ViewerPage page, String user){
jurzua
parents:
diff changeset
1508 page.setUser(user);
jurzua
parents:
diff changeset
1509 return cache.saveViewerPage(page);
jurzua
parents:
diff changeset
1510
jurzua
parents:
diff changeset
1511 }
jurzua
parents:
diff changeset
1512
jurzua
parents:
diff changeset
1513 public ViewerAttribute saveViewerAttribute(ViewerPage page, ViewerAttribute att, String user) throws Exception{
jurzua
parents:
diff changeset
1514 att.setUser(user);
jurzua
parents:
diff changeset
1515 return cache.saveViewerAttribute(page, att);
jurzua
parents:
diff changeset
1516 }
jurzua
parents:
diff changeset
1517
jurzua
parents:
diff changeset
1518 /**
jurzua
parents:
diff changeset
1519 * Removes a page and all attributes associated with it.
jurzua
parents:
diff changeset
1520 * @param page
jurzua
parents:
diff changeset
1521 * @return
jurzua
parents:
diff changeset
1522 */
jurzua
parents:
diff changeset
1523 public int removeViewerPage(ViewerPage page){
jurzua
parents:
diff changeset
1524
jurzua
parents:
diff changeset
1525 return (page.getId() != null) ? cache.removeViewerPage(page.getId()) : 0;
jurzua
parents:
diff changeset
1526 }
jurzua
parents:
diff changeset
1527
jurzua
parents:
diff changeset
1528 public boolean removeViewerAnttribute(ViewerAttribute att){
jurzua
parents:
diff changeset
1529 return (att.getId() != null) ? cache.removeAtt(att.getId()) : false;
jurzua
parents:
diff changeset
1530 }
jurzua
parents:
diff changeset
1531 }