Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java @ 1:2e911857a759
(none)
author | jurzua |
---|---|
date | Wed, 29 Oct 2014 14:00:28 +0000 |
parents | |
children | b40a84944716 |
comparison
equal
deleted
inserted
replaced
0:74df02964906 | 1:2e911857a759 |
---|---|
1 package de.mpiwg.itgroup.ismi.entry.utils; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.mpi.openmind.cache.WrapperService; | |
7 import org.mpi.openmind.repository.bo.Entity; | |
8 import org.mpi.openmind.repository.bo.Relation; | |
9 | |
10 public class PrivacityUtils { | |
11 | |
12 | |
13 public static List<Entity> changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){ | |
14 List<Entity> saveList = new ArrayList<Entity>(); | |
15 | |
16 if(person.isLightweight()){ | |
17 person = wrapper.getEntityContent(person); | |
18 } | |
19 | |
20 boolean privacity = false; | |
21 if(isPublic == null){ | |
22 privacity = !person.getIsPublic(); | |
23 }else{ | |
24 privacity = isPublic; | |
25 } | |
26 | |
27 person.setIsPublic(privacity); | |
28 saveList.add(person); | |
29 | |
30 List<Relation> relList = null; | |
31 //loading relations | |
32 if(privacity){ | |
33 relList = new ArrayList<Relation>(person.getSourceRelations()); | |
34 for (Relation rel : relList) { | |
35 String relName = rel.getOwnValue(); | |
36 if (relName.equals("was_born_in") || | |
37 relName.equals("lived_in") || | |
38 relName.equals("was_student_of") || | |
39 relName.equals("has_role") || | |
40 relName.equals("died_in")) { | |
41 Entity target = wrapper.getEntityById(rel.getTargetId()); | |
42 //target = wrapper.getEntityContent(target); | |
43 target.setIsPublic(privacity); | |
44 saveList.add(target); | |
45 } | |
46 } | |
47 } | |
48 | |
49 relList = new ArrayList<Relation>(person.getTargetRelations()); | |
50 for (Relation rel : relList) { | |
51 String relName = rel.getOwnValue(); | |
52 //title were be not included into this list | |
53 if (relName.equals("is_alias_name_of") || relName.equals("is_prime_alias_name_of")) { | |
54 Entity source = wrapper.getEntityById(rel.getSourceId()); | |
55 //source = wrapper.getEntityContent(source); | |
56 source.setIsPublic(privacity); | |
57 saveList.add(source); | |
58 } | |
59 } | |
60 | |
61 return saveList; | |
62 } | |
63 | |
64 public static List<Entity> changePrivacity4Title(Entity title, Boolean isPublic, WrapperService wrapper){ | |
65 List<Entity> saveList = new ArrayList<Entity>(); | |
66 | |
67 /* | |
68 if(title.isLightweight()){ | |
69 title = wrapper.getEntityContent(title); | |
70 }*/ | |
71 | |
72 boolean privacity = false; | |
73 if(isPublic == null){ | |
74 privacity = !title.getIsPublic(); | |
75 }else{ | |
76 privacity = isPublic; | |
77 } | |
78 | |
79 title.setIsPublic(privacity); | |
80 saveList.add(title); | |
81 | |
82 if(privacity){ | |
83 for(Entity ent : wrapper.getTargetsForSourceRelation(title, "has_subject", "SUBJECT", 1)){ | |
84 //if(ent.isLightweight()) | |
85 // ent = wrapper.getEntityContent(ent); | |
86 ent.setIsPublic(privacity); | |
87 saveList.add(ent); | |
88 } | |
89 | |
90 for(Entity ent : wrapper.getTargetsForSourceRelation(title, "was_created_in", "PLACE", 1)){ | |
91 //if(ent.isLightweight()) | |
92 // ent = wrapper.getEntityContent(ent); | |
93 ent.setIsPublic(privacity); | |
94 saveList.add(ent); | |
95 } | |
96 } | |
97 | |
98 for(Entity ent : wrapper.getSourcesForTargetRelation(title, "is_alias_title_of", "ALIAS", -1)){ | |
99 //if(ent.isLightweight()) | |
100 // ent = wrapper.getEntityContent(ent); | |
101 ent.setIsPublic(privacity); | |
102 saveList.add(ent); | |
103 } | |
104 | |
105 return saveList; | |
106 } | |
107 | |
108 | |
109 /** | |
110 * 437080 | |
111 * al-Taḏkiraẗ fī ʿilm al-hayʾaẗ | |
112 * BIT(1) | |
113 * create: | |
114 * ALTER TABLE `openmind`.`node` ADD COLUMN `public` BIT(1) AFTER `possible_value`; | |
115 * modify: | |
116 * ALTER TABLE `openmind`.`node` MODIFY COLUMN `public` BIT(1) NOT NULL DEFAULT false; | |
117 * @param witness | |
118 * @param isPublic | |
119 * @param wrapper | |
120 * @return | |
121 */ | |
122 public static List<Entity> changePrivacity4Witness(Entity witness, Boolean isPublic, WrapperService wrapper){ | |
123 List<Entity> saveList = new ArrayList<Entity>(); | |
124 /* | |
125 if(witness.isLightweight()){ | |
126 witness = wrapper.getEntityContent(witness); | |
127 } | |
128 */ | |
129 boolean privacity = false; | |
130 if(isPublic == null){ | |
131 privacity = !witness.getIsPublic(); | |
132 }else{ | |
133 privacity = isPublic; | |
134 } | |
135 | |
136 witness.setIsPublic(privacity); | |
137 saveList.add(witness); | |
138 | |
139 //changing references | |
140 List<Entity> refEntities = wrapper.getSourcesForTargetRelation(witness.getId(), "is_reference_of", "REFERENCE", -1); | |
141 for(Entity ref : refEntities){ | |
142 if(ref.isLightweight()){ | |
143 ref = wrapper.getEntityContent(ref); | |
144 } | |
145 ref.setIsPublic(privacity); | |
146 saveList.add(ref); | |
147 } | |
148 | |
149 //only if the witness is done public, the related entities will be changed. | |
150 if(privacity){ | |
151 List<Entity> list = | |
152 wrapper.getTargetsForSourceRelation(witness.getId(),"is_part_of", "CODEX", 1); | |
153 if (list.size() > 0) { | |
154 Entity codex = list.get(0); | |
155 codex.setIsPublic(privacity); | |
156 saveList.add(codex); | |
157 | |
158 list = wrapper.getTargetsForSourceRelation(codex.getId(), "is_part_of", "COLLECTION", 1); | |
159 if (list.size() > 0) { | |
160 Entity collection = list.get(0); | |
161 collection.setIsPublic(privacity); | |
162 saveList.add(collection); | |
163 | |
164 list = wrapper.getTargetsForSourceRelation(collection.getId(), "is_part_of", "REPOSITORY", 1); | |
165 if (list.size() > 0) { | |
166 Entity repository = list.get(0); | |
167 repository.setIsPublic(privacity); | |
168 saveList.add(repository); | |
169 | |
170 list = wrapper.getTargetsForSourceRelation(repository.getId(), "is_in", "PLACE", 1); | |
171 if(list.size() > 0){ | |
172 Entity city = list.get(0); | |
173 city.setIsPublic(privacity); | |
174 saveList.add(city); | |
175 | |
176 list = wrapper.getTargetsForSourceRelation(city.getId(), "is_part_of", "PLACE", 1); | |
177 if(list.size() > 0){ | |
178 Entity country = list.get(0); | |
179 country.setIsPublic(privacity); | |
180 saveList.add(country); | |
181 } | |
182 } | |
183 } | |
184 } | |
185 } | |
186 } | |
187 | |
188 return saveList; | |
189 } | |
190 | |
191 } |