Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/merge/NonpublicEntitiesBean.java @ 188:34ac2e1b323a
new Clean UI to find non-public digitalizations of public codices and make them public.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 06 Nov 2018 20:05:49 +0100 |
parents | |
children | b36a57a452a6 |
comparison
equal
deleted
inserted
replaced
187:be6bc580b137 | 188:34ac2e1b323a |
---|---|
1 package de.mpiwg.itgroup.ismi.merge; | |
2 | |
3 import java.io.Serializable; | |
4 import java.util.ArrayList; | |
5 import java.util.List; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 import org.mpi.openmind.repository.bo.Entity; | |
9 import org.mpi.openmind.repository.bo.Relation; | |
10 import org.mpi.openmind.repository.services.utils.RelationFilter; | |
11 import org.richfaces.event.ItemChangeEvent; | |
12 | |
13 import de.mpiwg.itgroup.ismi.browse.EntityRepositoryBean; | |
14 import de.mpiwg.itgroup.ismi.browse.FullEntityRepositoryBean; | |
15 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; | |
16 import de.mpiwg.itgroup.ismi.entry.utils.PrivacityUtils; | |
17 | |
18 public class NonpublicEntitiesBean extends AbstractISMIBean implements Serializable{ | |
19 | |
20 private static Logger logger = Logger.getLogger(NonpublicEntitiesBean.class); | |
21 | |
22 private static final long serialVersionUID = 1L; | |
23 | |
24 protected FullEntityRepositoryBean browseBean; | |
25 | |
26 protected String selectedTab = "aut"; | |
27 | |
28 | |
29 public NonpublicEntitiesBean(){ | |
30 //logger.info("AdvancedSearchBean"); | |
31 this.reset(); | |
32 } | |
33 | |
34 public synchronized void reset(){ | |
35 logger.info("MissingRelationsBean.reset()"); | |
36 browseBean = new FullEntityRepositoryBean(); | |
37 logger.info("MissingRelationsBean.reset() Done."); | |
38 } | |
39 | |
40 | |
41 public void actionFindNonpublicDigitalizations() { | |
42 logger.debug("Start findNonpublicDigitalizations..."); | |
43 List<RelationFilter> relFilters = new ArrayList<RelationFilter>(); | |
44 /* | |
45 * find DIGITALIZATION is_digitalization_of CODEX relation | |
46 */ | |
47 browseBean = new FullEntityRepositoryBean(); | |
48 browseBean.setObjectClass(DIGITALIZATION); | |
49 RelationFilter relFilter = new RelationFilter(); | |
50 relFilter.relObjectClass = "is_digitalization_of"; | |
51 relFilter.tarObjectClass = "CODEX"; | |
52 relFilters.add(relFilter); | |
53 try { | |
54 // search all digitalizations | |
55 browseBean.searchByRelations(relFilters); | |
56 // filter out non-public DIGITALIZATIONs of public CODEXs | |
57 List<Entity> entities = browseBean.getEntities(); | |
58 List<Entity> nonpublicEntities = new ArrayList<Entity>(); | |
59 for (Entity ent : entities) { | |
60 if (!ent.getIsPublic()) { | |
61 List<Relation> rels = ent.getSourceRelations("is_digitalization_of", CODEX); | |
62 for (Relation rel : rels) { | |
63 Entity tar = getWrapper().getEntityById(rel.getTargetId()); | |
64 if (tar.getIsPublic()) { | |
65 nonpublicEntities.add(ent); | |
66 break; | |
67 } | |
68 } | |
69 } | |
70 } | |
71 browseBean.updateEntities(nonpublicEntities); | |
72 | |
73 } catch (Exception e) { | |
74 logger.error(e); | |
75 } | |
76 logger.debug("Done findNonpublicDigitalizations."); | |
77 } | |
78 | |
79 /** | |
80 * Makes the selected digitalizations public. | |
81 * Uses PrivacityUtils.setTextAndMorePrivacity(). | |
82 * @return | |
83 */ | |
84 public String actionMakeDigitalizationsPublic() { | |
85 logger.info("MAKE DIGITALIZATIONS PUBLIC"); | |
86 List<String> textMsg = new ArrayList<String>(); | |
87 try { | |
88 List<Entity> entities = browseBean.getEntities(); | |
89 if (entities.size() == 0) return null; | |
90 for (Entity ent : entities) { | |
91 PrivacityUtils.changeEntityPrivacity(ent, true, getWrapper()); | |
92 textMsg.add("Set public=true on "+ent.getShortString()+"\n"); | |
93 } | |
94 // save only public state | |
95 getWrapper().saveEntityListAsNodeWithoutContent(entities, null); | |
96 } catch (Exception e) { | |
97 logger.error(e); | |
98 } | |
99 for (String msg : textMsg) { | |
100 this.addGeneralMsg(msg); | |
101 logger.debug(msg); | |
102 } | |
103 addGeneralMsg(browseBean.getEntities().size() + " DIGITALIZATIONS were made public!"); | |
104 return null; | |
105 } | |
106 | |
107 | |
108 public EntityRepositoryBean getBrowseBean() { | |
109 return browseBean; | |
110 } | |
111 | |
112 public void listenerTabChange(ItemChangeEvent event) { | |
113 reset(); | |
114 String url = "?formIndex=" + selectedTab; | |
115 redirect(null, url); | |
116 } | |
117 | |
118 public String getSelectedTab() { | |
119 return selectedTab; | |
120 } | |
121 | |
122 public void setSelectedTab(String selectedMissingRelationsTab) { | |
123 selectedTab = selectedMissingRelationsTab; | |
124 } | |
125 | |
126 | |
127 } |