Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java @ 175:3d8b31508128
PublicByAuthor feature works now.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 07 Jun 2018 18:47:18 +0200 |
parents | 29c4b64caad0 |
children | 8aff920ec7c0 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.utils; |
2 | |
3 import java.util.ArrayList; | |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
4 import java.util.Arrays; |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
5 import java.util.HashSet; |
1 | 6 import java.util.List; |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
7 import java.util.Set; |
1 | 8 |
9 import org.mpi.openmind.cache.WrapperService; | |
10 import org.mpi.openmind.repository.bo.Entity; | |
11 import org.mpi.openmind.repository.bo.Relation; | |
12 | |
13 public class PrivacityUtils { | |
14 | |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
15 public static final Set<String> TEXTexcepts = new HashSet<String>(Arrays.asList("TEXT")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
16 public static final Set<String> PERSONexcepts = new HashSet<String>(Arrays.asList("TEXT", "PERSON", "WITNESS", |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
17 "CODEX", "TRANSFER_EVENT", "STUDY_EVENT", "COPY_EVENT", "MISATTRIBUTION", "MISIDENTIFICATION")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
18 public static final Set<String> WITNESSexcepts = new HashSet<String>(Arrays.asList("WITNESS", "TEXT")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
19 public static final Set<String> CODEXexcepts = new HashSet<String>(Arrays.asList("WITNESS")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
20 public static final Set<String> COLLECTIONexcepts = new HashSet<String>(Arrays.asList("CODEX")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
21 public static final Set<String> REPOSITORYexcepts = new HashSet<String>(Arrays.asList("COLLECTION", "STUDY_EVENT", "COPY_EVENT")); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
22 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
23 |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
24 /** |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
25 * Change public state of the given entity. |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
26 * |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
27 * Toggles public state if isPublic == null. |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
28 * |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
29 * Returns the changed Entity (that needs to be saved). |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
30 * |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
31 * @param entity |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
32 * @param isPublic |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
33 * @param wrapper |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
34 * @return |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
35 */ |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
36 public static Entity changeEntityPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper) { |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
37 // make sure attributes are loaded |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
38 if (entity.isLightweight()) { |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
39 entity = wrapper.getEntityContent(entity); |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
40 } |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
41 // toggle public if isPublic == null |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
42 if (isPublic == null) { |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
43 isPublic = !entity.getIsPublic(); |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
44 } |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
45 // set public |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
46 entity.setIsPublic(isPublic); |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
47 return entity; |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
48 } |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
49 |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
50 /** |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
51 * Change public state of all entities directly related to the given entity |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
52 * (does not change the given entity). |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
53 * |
150
29c4b64caad0
small cleanup; add mams_number field for PERSON.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
148
diff
changeset
|
54 * Sets public state to given entity's state if isPublic == null. |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
55 * |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
56 * Does not touch Entities of the types listed in exceptedTypes. |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
57 * |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
58 * Returns a List of Entities that have been changed (and need to be saved). |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
59 * |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
60 * @param entity |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
61 * @param isPublic |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
62 * @param wrapper |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
63 * @param exceptedTypes |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
64 * @return |
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
65 */ |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
66 public static List<Entity> setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper, |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
67 Set<String> exceptedTypes) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
68 List<Entity> saveList = new ArrayList<Entity>(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
69 // make sure relations are loaded |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
70 if (entity.isLightweight()) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
71 entity = wrapper.getEntityContent(entity); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
72 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
73 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
74 // use entity's public if isPublic == null |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
75 if (isPublic == null) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
76 isPublic = entity.getIsPublic(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
77 } |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
78 |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
79 // change source relations |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
80 for (Relation rel : entity.getSourceRelations()) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
81 if (!exceptedTypes.contains(rel.getTargetObjectClass())) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
82 Long entId = rel.getTargetId(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
83 Entity ent = wrapper.getEntityById(entId); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
84 ent.setIsPublic(isPublic); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
85 saveList.add(ent); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
86 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
87 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
88 // change target relations |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
89 for (Relation rel : entity.getTargetRelations()) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
90 if (!exceptedTypes.contains(rel.getSourceObjectClass())) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
91 Long entId = rel.getSourceId(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
92 Entity ent = wrapper.getEntityById(entId); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
93 ent.setIsPublic(isPublic); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
94 saveList.add(ent); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
95 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
96 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
97 return saveList; |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
98 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
99 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
100 /** |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
101 * Change public state of a TEXT and all meaningfully related Entities. |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
102 * |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
103 * Sets public state to given entity's state if isPublic == null. |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
104 * |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
105 * Returns a List of Entities that have been changed (and need to be saved). |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
106 * |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
107 * @param text |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
108 * @param isPublic |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
109 * @param wrapper |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
110 * @return |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
111 * @throws Exception |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
112 */ |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
113 public static List<Entity> setTextAndMorePrivacity(Entity text, Boolean isPublic, List<String> report, |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
114 WrapperService wrapper) throws Exception { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
115 List<Entity> saveList = new ArrayList<Entity>(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
116 // make sure relations are loaded |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
117 if (text.isLightweight()) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
118 text = wrapper.getEntityContent(text); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
119 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
120 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
121 // use entity's public if isPublic == null |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
122 if (isPublic == null) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
123 isPublic = text.getIsPublic(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
124 } |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
125 |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
126 /* |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
127 * mark text public |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
128 */ |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
129 text.setIsPublic(isPublic); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
130 saveList.add(text); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
131 report.add("Set public="+isPublic+" on "+text.getShortString()+"\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
132 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
133 /* |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
134 * mark directly related objects except TEXT |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
135 */ |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
136 List<Entity> relatedEnts = setRelatedEntitiesPrivacity(text, isPublic, wrapper, TEXTexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
137 saveList.addAll(relatedEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
138 report.add("Set public="+isPublic+" on related entities to "+text.getShortString()+" : ["+Entity.getShortStringList(relatedEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
139 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
140 /* |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
141 * follow relations of related objects |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
142 */ |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
143 int cnt = 0; |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
144 do { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
145 List<Entity> nextRelEnts = new ArrayList<Entity>(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
146 for (Entity relEnt : relatedEnts) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
147 String entType = relEnt.getObjectClass(); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
148 if (entType.equals("PERSON")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
149 // PERSON |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
150 List<Entity> persRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, PERSONexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
151 saveList.addAll(persRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
152 nextRelEnts.addAll(persRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
153 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(persRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
154 } else if (entType.equals("WITNESS")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
155 // WITNESS |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
156 List<Entity> witRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, WITNESSexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
157 saveList.addAll(witRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
158 nextRelEnts.addAll(witRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
159 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(witRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
160 } else if (entType.equals("CODEX")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
161 // CODEX |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
162 List<Entity> codRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, CODEXexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
163 saveList.addAll(codRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
164 nextRelEnts.addAll(codRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
165 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(codRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
166 } else if (entType.equals("COLLECTION")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
167 // COLLECTION |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
168 List<Entity> colRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, COLLECTIONexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
169 saveList.addAll(colRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
170 nextRelEnts.addAll(colRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
171 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(colRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
172 } else if (entType.equals("REPOSITORY")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
173 // REPOSITORY |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
174 List<Entity> repRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, REPOSITORYexcepts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
175 saveList.addAll(repRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
176 nextRelEnts.addAll(repRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
177 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(repRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
178 } else if (entType.endsWith("_EVENT")) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
179 // *_EVENT: mark all related entities |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
180 List<Entity> evRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, null); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
181 saveList.addAll(evRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
182 nextRelEnts.addAll(evRelEnts); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
183 report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(evRelEnts)+"]\n"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
184 } else { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
185 // everything else? |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
186 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
187 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
188 // start with next level |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
189 relatedEnts = nextRelEnts; |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
190 } while (!relatedEnts.isEmpty() && ++cnt < 5); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
191 if (cnt == 5) { |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
192 throw new Exception("Relation depth limit exceeded when marking text public!"); |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
193 } |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
194 return saveList; |
148
b40a84944716
add public/private editing to Entity Details.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
195 } |
1 | 196 |
175
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
197 |
3d8b31508128
PublicByAuthor feature works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
150
diff
changeset
|
198 |
1 | 199 public static List<Entity> changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){ |
200 List<Entity> saveList = new ArrayList<Entity>(); | |
201 | |
202 if(person.isLightweight()){ | |
203 person = wrapper.getEntityContent(person); | |
204 } | |
205 | |
206 boolean privacity = false; | |
207 if(isPublic == null){ | |
208 privacity = !person.getIsPublic(); | |
209 }else{ | |
210 privacity = isPublic; | |
211 } | |
212 | |
213 person.setIsPublic(privacity); | |
214 saveList.add(person); | |
215 | |
216 List<Relation> relList = null; | |
217 //loading relations | |
218 if(privacity){ | |
219 relList = new ArrayList<Relation>(person.getSourceRelations()); | |
220 for (Relation rel : relList) { | |
221 String relName = rel.getOwnValue(); | |
222 if (relName.equals("was_born_in") || | |
223 relName.equals("lived_in") || | |
224 relName.equals("was_student_of") || | |
225 relName.equals("has_role") || | |
226 relName.equals("died_in")) { | |
227 Entity target = wrapper.getEntityById(rel.getTargetId()); | |
228 //target = wrapper.getEntityContent(target); | |
229 target.setIsPublic(privacity); | |
230 saveList.add(target); | |
231 } | |
232 } | |
233 } | |
234 | |
235 relList = new ArrayList<Relation>(person.getTargetRelations()); | |
236 for (Relation rel : relList) { | |
237 String relName = rel.getOwnValue(); | |
238 //title were be not included into this list | |
239 if (relName.equals("is_alias_name_of") || relName.equals("is_prime_alias_name_of")) { | |
240 Entity source = wrapper.getEntityById(rel.getSourceId()); | |
241 //source = wrapper.getEntityContent(source); | |
242 source.setIsPublic(privacity); | |
243 saveList.add(source); | |
244 } | |
245 } | |
246 | |
247 return saveList; | |
248 } | |
249 | |
250 public static List<Entity> changePrivacity4Title(Entity title, Boolean isPublic, WrapperService wrapper){ | |
251 List<Entity> saveList = new ArrayList<Entity>(); | |
252 | |
253 /* | |
254 if(title.isLightweight()){ | |
255 title = wrapper.getEntityContent(title); | |
256 }*/ | |
257 | |
258 boolean privacity = false; | |
259 if(isPublic == null){ | |
260 privacity = !title.getIsPublic(); | |
261 }else{ | |
262 privacity = isPublic; | |
263 } | |
264 | |
265 title.setIsPublic(privacity); | |
266 saveList.add(title); | |
267 | |
268 if(privacity){ | |
269 for(Entity ent : wrapper.getTargetsForSourceRelation(title, "has_subject", "SUBJECT", 1)){ | |
270 //if(ent.isLightweight()) | |
271 // ent = wrapper.getEntityContent(ent); | |
272 ent.setIsPublic(privacity); | |
273 saveList.add(ent); | |
274 } | |
275 | |
276 for(Entity ent : wrapper.getTargetsForSourceRelation(title, "was_created_in", "PLACE", 1)){ | |
277 //if(ent.isLightweight()) | |
278 // ent = wrapper.getEntityContent(ent); | |
279 ent.setIsPublic(privacity); | |
280 saveList.add(ent); | |
281 } | |
282 } | |
283 | |
284 for(Entity ent : wrapper.getSourcesForTargetRelation(title, "is_alias_title_of", "ALIAS", -1)){ | |
285 //if(ent.isLightweight()) | |
286 // ent = wrapper.getEntityContent(ent); | |
287 ent.setIsPublic(privacity); | |
288 saveList.add(ent); | |
289 } | |
290 | |
291 return saveList; | |
292 } | |
293 | |
294 | |
295 /** | |
296 * 437080 | |
297 * al-Taḏkiraẗ fī ʿilm al-hayʾaẗ | |
298 * BIT(1) | |
299 * create: | |
300 * ALTER TABLE `openmind`.`node` ADD COLUMN `public` BIT(1) AFTER `possible_value`; | |
301 * modify: | |
302 * ALTER TABLE `openmind`.`node` MODIFY COLUMN `public` BIT(1) NOT NULL DEFAULT false; | |
303 * @param witness | |
304 * @param isPublic | |
305 * @param wrapper | |
306 * @return | |
307 */ | |
308 public static List<Entity> changePrivacity4Witness(Entity witness, Boolean isPublic, WrapperService wrapper){ | |
309 List<Entity> saveList = new ArrayList<Entity>(); | |
310 /* | |
311 if(witness.isLightweight()){ | |
312 witness = wrapper.getEntityContent(witness); | |
313 } | |
314 */ | |
315 boolean privacity = false; | |
316 if(isPublic == null){ | |
317 privacity = !witness.getIsPublic(); | |
318 }else{ | |
319 privacity = isPublic; | |
320 } | |
321 | |
322 witness.setIsPublic(privacity); | |
323 saveList.add(witness); | |
324 | |
325 //changing references | |
326 List<Entity> refEntities = wrapper.getSourcesForTargetRelation(witness.getId(), "is_reference_of", "REFERENCE", -1); | |
327 for(Entity ref : refEntities){ | |
328 if(ref.isLightweight()){ | |
329 ref = wrapper.getEntityContent(ref); | |
330 } | |
331 ref.setIsPublic(privacity); | |
332 saveList.add(ref); | |
333 } | |
334 | |
335 //only if the witness is done public, the related entities will be changed. | |
336 if(privacity){ | |
337 List<Entity> list = | |
338 wrapper.getTargetsForSourceRelation(witness.getId(),"is_part_of", "CODEX", 1); | |
339 if (list.size() > 0) { | |
340 Entity codex = list.get(0); | |
341 codex.setIsPublic(privacity); | |
342 saveList.add(codex); | |
343 | |
344 list = wrapper.getTargetsForSourceRelation(codex.getId(), "is_part_of", "COLLECTION", 1); | |
345 if (list.size() > 0) { | |
346 Entity collection = list.get(0); | |
347 collection.setIsPublic(privacity); | |
348 saveList.add(collection); | |
349 | |
350 list = wrapper.getTargetsForSourceRelation(collection.getId(), "is_part_of", "REPOSITORY", 1); | |
351 if (list.size() > 0) { | |
352 Entity repository = list.get(0); | |
353 repository.setIsPublic(privacity); | |
354 saveList.add(repository); | |
355 | |
356 list = wrapper.getTargetsForSourceRelation(repository.getId(), "is_in", "PLACE", 1); | |
357 if(list.size() > 0){ | |
358 Entity city = list.get(0); | |
359 city.setIsPublic(privacity); | |
360 saveList.add(city); | |
361 | |
362 list = wrapper.getTargetsForSourceRelation(city.getId(), "is_part_of", "PLACE", 1); | |
363 if(list.size() > 0){ | |
364 Entity country = list.get(0); | |
365 country.setIsPublic(privacity); | |
366 saveList.add(country); | |
367 } | |
368 } | |
369 } | |
370 } | |
371 } | |
372 } | |
373 | |
374 return saveList; | |
375 } | |
376 | |
377 } |