annotate src/main/java/org/mpi/openmind/cache/WrapperService.java @ 71:aeb29e362a67

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