1
|
1 package org.mpi.openmind.scripts;
|
|
2
|
|
3 import java.text.SimpleDateFormat;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.Date;
|
|
6 import java.util.List;
|
|
7
|
|
8 import org.apache.log4j.ConsoleAppender;
|
|
9 import org.apache.log4j.Level;
|
|
10 import org.apache.log4j.Logger;
|
|
11 import org.apache.log4j.PatternLayout;
|
|
12 import org.mpi.openmind.cache.WrapperService;
|
|
13 import org.mpi.openmind.repository.bo.Attribute;
|
|
14 import org.mpi.openmind.repository.bo.Entity;
|
|
15 import org.mpi.openmind.repository.bo.Node;
|
|
16 import org.mpi.openmind.repository.services.PersistenceService;
|
|
17 import org.mpi.openmind.repository.services.ServiceRegistry;
|
|
18 import org.mpi.openmind.repository.utils.OMUtils;
|
|
19
|
|
20 public class CodexOwnValueGenerator {
|
|
21
|
|
22 private static Logger logger = Logger.getLogger(CodexOwnValueGenerator.class);
|
|
23
|
|
24 private WrapperService ot;
|
|
25 private PersistenceService ss;
|
|
26
|
|
27 public CodexOwnValueGenerator(WrapperService ot){
|
|
28 this.ot = ot;
|
|
29 this.ss = ot.getPS();
|
|
30 }
|
|
31
|
|
32
|
|
33 public void execute(){
|
|
34 try {
|
|
35 logger.info("Starting CodexOwnValueGenerator");
|
|
36 List<Entity> codexList = ot.getLightweightAssertions("CODEX", null, -1);
|
|
37 logger.info("Codices="+ codexList.size());
|
|
38 List<Node> dirtyEntities = new ArrayList<Node>();
|
|
39 int count = 0;
|
|
40 int countCodicesNonCollection = 0;
|
|
41 for(Entity codex : codexList){
|
|
42
|
|
43 Attribute codexIdAtt = ss.getAttributeByName(codex, "identifier");
|
|
44 if(codexIdAtt == null){
|
|
45 throw new Exception("identifier is null for " + codex);
|
|
46 }
|
|
47 String ov = new String();
|
|
48
|
|
49 List<Entity> list0 = this.ss.getTargetsForSourceRelation(codex, "is_part_of", "COLLECTION", 1);
|
|
50
|
|
51
|
|
52 Entity collection;
|
|
53 if(list0.size() > 0){
|
|
54 collection = list0.get(0);
|
|
55 if(collection != null){
|
|
56 ov = collection.getOwnValue() + "_" + codexIdAtt.getValue();
|
|
57 }else{
|
|
58 ov = "empty_" + codexIdAtt.getValue();
|
|
59 countCodicesNonCollection++;
|
|
60 }
|
|
61 if(count % 100 == 0){
|
|
62 int size = codexList.size();
|
|
63
|
|
64 logger.info("* " + OMUtils.percentage(count, size) + " %");
|
|
65 }
|
|
66 count++;
|
|
67 codex.setOwnValue(ov);
|
|
68 dirtyEntities.add(codex);
|
|
69 }
|
|
70 }
|
|
71 ot.saveNodeListOnlyForScripts(dirtyEntities);
|
|
72
|
|
73 logger.info("Summary");
|
|
74 logger.info("Codices without collection=" + countCodicesNonCollection);
|
|
75 logger.info("Total=" + count);
|
|
76
|
|
77
|
|
78 } catch (Exception e) {
|
|
79 e.printStackTrace();
|
|
80 }
|
|
81 }
|
|
82
|
|
83 public static void main(String[] args) {
|
|
84 ServiceRegistry services = new ServiceRegistry();
|
|
85 CodexOwnValueGenerator script = new CodexOwnValueGenerator(services.getWrapper());
|
|
86 script.execute();
|
|
87 System.exit(0);
|
|
88 }
|
|
89 }
|