changeset 175:3d8b31508128

PublicByAuthor feature works now.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Thu, 07 Jun 2018 18:47:18 +0200
parents 4961820373d0
children c63d39034b60
files src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java src/main/webapp/clean/components/publicShowSubjects.xhtml src/main/webapp/templates/main_template.xhtml
diffstat 5 files changed, 215 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java	Wed Jun 06 21:02:30 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java	Thu Jun 07 18:47:18 2018 +0200
@@ -260,7 +260,7 @@
 	 */
 	public String actionChangeRelatedEntitiesPrivacity() {
 		// set publication state
-		List<Entity> saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper());
+		List<Entity> saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper(), null);
 		// hide related entities from display
 		sourceRelations = new HashMap<String, List<Relation>>();
 		targetRelations = new HashMap<String, List<Relation>>();
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java	Wed Jun 06 21:02:30 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java	Thu Jun 07 18:47:18 2018 +0200
@@ -1,7 +1,10 @@
 package de.mpiwg.itgroup.ismi.entry.utils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.mpi.openmind.cache.WrapperService;
 import org.mpi.openmind.repository.bo.Entity;
@@ -9,11 +12,22 @@
 
 public class PrivacityUtils {
 
+    public static final Set<String> TEXTexcepts = new HashSet<String>(Arrays.asList("TEXT"));
+    public static final Set<String> PERSONexcepts = new HashSet<String>(Arrays.asList("TEXT", "PERSON", "WITNESS",
+            "CODEX", "TRANSFER_EVENT", "STUDY_EVENT", "COPY_EVENT", "MISATTRIBUTION", "MISIDENTIFICATION"));
+    public static final Set<String> WITNESSexcepts = new HashSet<String>(Arrays.asList("WITNESS", "TEXT"));
+    public static final Set<String> CODEXexcepts = new HashSet<String>(Arrays.asList("WITNESS"));
+    public static final Set<String> COLLECTIONexcepts = new HashSet<String>(Arrays.asList("CODEX"));
+    public static final Set<String> REPOSITORYexcepts = new HashSet<String>(Arrays.asList("COLLECTION", "STUDY_EVENT", "COPY_EVENT"));
+
+    
 	/**
 	 * Change public state of the given entity.
 	 * 
 	 * Toggles public state if isPublic == null.
 	 * 
+	 * Returns the changed Entity (that needs to be saved).
+	 * 
 	 * @param entity
 	 * @param isPublic
 	 * @param wrapper
@@ -34,44 +48,154 @@
 	}
 	
 	/**
-	 * Change public state of all entities related to the given entity.
+	 * Change public state of all entities directly related to the given entity 
+	 * (does not change the given entity).
 	 * 
 	 * Sets public state to given entity's state if isPublic == null.
 	 * 
+	 * Does not touch Entities of the types listed in exceptedTypes.
+	 * 
+	 * Returns a List of Entities that have been changed (and need to be saved).
+	 * 
 	 * @param entity
 	 * @param isPublic
 	 * @param wrapper
+	 * @param exceptedTypes
 	 * @return
 	 */
-	public static List<Entity> setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper) {
-		// make sure relations are loaded
-		if (entity.isLightweight()) {
-			entity = wrapper.getEntityContent(entity);
-		}
+    public static List<Entity> setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper,
+            Set<String> exceptedTypes) {
+        List<Entity> saveList = new ArrayList<Entity>();
+        // make sure relations are loaded
+        if (entity.isLightweight()) {
+            entity = wrapper.getEntityContent(entity);
+        }
+
+        // use entity's public if isPublic == null
+        if (isPublic == null) {
+            isPublic = entity.getIsPublic();
+        }
 
-		// use entity's public if isPublic == null
-		if (isPublic == null) {
-			isPublic = entity.getIsPublic();
-		}
-		List<Entity> saveList = new ArrayList<Entity>();
+        // change source relations
+        for (Relation rel : entity.getSourceRelations()) {
+            if (!exceptedTypes.contains(rel.getTargetObjectClass())) {
+                Long entId = rel.getTargetId();
+                Entity ent = wrapper.getEntityById(entId);
+                ent.setIsPublic(isPublic);
+                saveList.add(ent);
+            }
+        }
+        // change target relations
+        for (Relation rel : entity.getTargetRelations()) {
+            if (!exceptedTypes.contains(rel.getSourceObjectClass())) {
+                Long entId = rel.getSourceId();
+                Entity ent = wrapper.getEntityById(entId);
+                ent.setIsPublic(isPublic);
+                saveList.add(ent);
+            }
+        }
+        return saveList;
+    }
+	
+	/**
+	 * Change public state of a TEXT and all meaningfully related Entities.
+	 * 
+     * Sets public state to given entity's state if isPublic == null.
+     * 
+     * Returns a List of Entities that have been changed (and need to be saved).
+     * 
+	 * @param text
+	 * @param isPublic
+	 * @param wrapper
+	 * @return
+	 * @throws Exception 
+	 */
+    public static List<Entity> setTextAndMorePrivacity(Entity text, Boolean isPublic, List<String> report,
+            WrapperService wrapper) throws Exception {
+        List<Entity> saveList = new ArrayList<Entity>();
+        // make sure relations are loaded
+        if (text.isLightweight()) {
+            text = wrapper.getEntityContent(text);
+        }
+
+        // use entity's public if isPublic == null
+        if (isPublic == null) {
+            isPublic = text.getIsPublic();
+        }
 
-		// change source relations
-		for (Relation rel : entity.getSourceRelations()) {
-			Long entId = rel.getTargetId();
-			Entity ent = wrapper.getEntityById(entId);
-			ent.setIsPublic(isPublic);
-			saveList.add(ent);
-		}
-		// change target relations
-		for (Relation rel : entity.getTargetRelations()) {
-			Long entId = rel.getSourceId();
-			Entity ent = wrapper.getEntityById(entId);
-			ent.setIsPublic(isPublic);
-			saveList.add(ent);
-		}
-		return saveList;
+        /*
+         * mark text public
+         */
+        text.setIsPublic(isPublic);
+        saveList.add(text);
+        report.add("Set public="+isPublic+" on "+text.getShortString()+"\n");
+        
+        /*
+         * mark directly related objects except TEXT
+         */
+        List<Entity> relatedEnts = setRelatedEntitiesPrivacity(text, isPublic, wrapper, TEXTexcepts);
+        saveList.addAll(relatedEnts);
+        report.add("Set public="+isPublic+" on related entities to "+text.getShortString()+" : ["+Entity.getShortStringList(relatedEnts)+"]\n");
+       
+        /*
+         * follow relations of related objects
+         */
+        int cnt = 0;
+        do {
+            List<Entity> nextRelEnts = new ArrayList<Entity>();
+            for (Entity relEnt : relatedEnts) {
+                String entType = relEnt.getObjectClass();
+                if (entType.equals("PERSON")) {
+                    // PERSON
+                    List<Entity> persRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, PERSONexcepts);
+                    saveList.addAll(persRelEnts);
+                    nextRelEnts.addAll(persRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(persRelEnts)+"]\n");
+                } else if (entType.equals("WITNESS")) {
+                    // WITNESS
+                    List<Entity> witRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, WITNESSexcepts);
+                    saveList.addAll(witRelEnts);
+                    nextRelEnts.addAll(witRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(witRelEnts)+"]\n");
+                } else if (entType.equals("CODEX")) {
+                    // CODEX
+                    List<Entity> codRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, CODEXexcepts);
+                    saveList.addAll(codRelEnts);
+                    nextRelEnts.addAll(codRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(codRelEnts)+"]\n");
+                } else if (entType.equals("COLLECTION")) {
+                    // COLLECTION
+                    List<Entity> colRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, COLLECTIONexcepts);
+                    saveList.addAll(colRelEnts);
+                    nextRelEnts.addAll(colRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(colRelEnts)+"]\n");
+                } else if (entType.equals("REPOSITORY")) {
+                    // REPOSITORY
+                    List<Entity> repRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, REPOSITORYexcepts);
+                    saveList.addAll(repRelEnts);
+                    nextRelEnts.addAll(repRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(repRelEnts)+"]\n");
+                } else if (entType.endsWith("_EVENT")) {
+                    // *_EVENT: mark all related entities
+                    List<Entity> evRelEnts = setRelatedEntitiesPrivacity(relEnt, isPublic, wrapper, null);
+                    saveList.addAll(evRelEnts);
+                    nextRelEnts.addAll(evRelEnts);
+                    report.add("Set public="+isPublic+" on related entities to "+relEnt.getShortString()+" : ["+Entity.getShortStringList(evRelEnts)+"]\n");
+                } else {
+                    // everything else?
+                }
+            }
+            // start with next level
+            relatedEnts = nextRelEnts;
+        } while (!relatedEnts.isEmpty() && ++cnt < 5);
+        if (cnt == 5) {
+            throw new Exception("Relation depth limit exceeded when marking text public!");
+        }
+        return saveList;
 	}
 	
+	
+	
 	public static List<Entity> changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){
 		List<Entity> saveList = new ArrayList<Entity>();
 		
--- a/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java	Wed Jun 06 21:02:30 2018 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java	Thu Jun 07 18:47:18 2018 +0200
@@ -15,6 +15,7 @@
 import de.mpiwg.itgroup.ismi.browse.EntityRepositoryBean;
 import de.mpiwg.itgroup.ismi.browse.FullEntityRepositoryBean;
 import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean;
+import de.mpiwg.itgroup.ismi.entry.utils.PrivacityUtils;
 
 public class PublicByAuthorBean extends AbstractISMIBean implements Serializable{
 	
@@ -147,15 +148,6 @@
 	}
 	
 
-	public String actionSelectPerson() {
-       Entity entity = (Entity) getRequestBean("entity");
-       selectedPersonId = entity.getId();
-       setSelectedPersonById();
-       // switch tab
-       getSessionBean().setSelectedPublicByAuthorTab("sub");
-       return null;
-	}
-	
 	public void actionAllAuthors() {
 	    browseBean.setObjectClass(PERSON);
 	    browseBean.setSortAttributeName("mams_number");
@@ -167,6 +159,55 @@
         }
 	}
 	
+    public String actionSelectPerson() {
+        Entity entity = (Entity) getRequestBean("entity");
+        selectedPersonId = entity.getId();
+        setSelectedPersonById();
+        // switch tab
+        getSessionBean().setSelectedPublicByAuthorTab("sub");
+        return null;
+     }
+
+    
+    public String actionMakeTextAndRelatedPublic() {
+        Entity text = (Entity) getRequestBean("text");
+        List<String> textMsg = new ArrayList<String>();
+        try {
+            List<Entity> entities = PrivacityUtils.setTextAndMorePrivacity(text, true, textMsg, getWrapper());
+            // save only public state
+            getWrapper().saveEntityListAsNodeWithoutContent(entities, null);
+        } catch (Exception e) {
+            logger.error(e);
+        }
+        logger.debug("MAKE TEXT PUBLIC");
+        for (String msg : textMsg) {
+            this.addGeneralMsg(msg);
+            logger.debug(msg);
+        }
+        return null;
+    }
+    
+    public String actionMakePersonSubjectAndRelatedPublic() {
+        String subject = (String) getRequestBean("subject");
+        logger.debug("MAKE SUBJECT PUBLIC");
+        List<Entity> texts = selectedPersonSubjectMap.get(subject);
+        for (Entity text : texts) {
+            List<String> textMsg = new ArrayList<String>();
+            try {
+                List<Entity> entities = PrivacityUtils.setTextAndMorePrivacity(text, true, textMsg, getWrapper());
+                // save only public state
+                getWrapper().saveEntityListAsNodeWithoutContent(entities, null);
+            } catch (Exception e) {
+                logger.error(e);
+            }
+            for (String msg : textMsg) {
+                this.addGeneralMsg(msg);
+                logger.debug(msg);
+            }
+        }
+        return null;
+    }
+    
 	/**
 	 * @return the findAuthorName
 	 */
--- a/src/main/webapp/clean/components/publicShowSubjects.xhtml	Wed Jun 06 21:02:30 2018 +0200
+++ b/src/main/webapp/clean/components/publicShowSubjects.xhtml	Thu Jun 07 18:47:18 2018 +0200
@@ -32,19 +32,20 @@
 				value="#{Session.publicByAuthor.selectedPersonSubjects}"
 				var="subject" styleClass="select">
 				<rich:column>
-					<h2 style="margin-top: 1em">
+					<h2 style="margin-top:1em">
 						#{subject}
 						<ui:repeat
 							value="#{Session.publicByAuthor.subjectParents.get(subject)}"
 							var="parent"> &lt; #{parent}</ui:repeat>
 					</h2>
 
-					<a4j:commandButton value="make these texts and their witnesses public"
-						/>
+					<a4j:commandButton value="make all these texts and their witnesses public"
+						actionListener="#{Session.publicByAuthor.actionMakePersonSubjectAndRelatedPublic}"
+						render="selectSubjectPanel" style="margin-bottom:0.5em"/>
 
 					<rich:dataTable
 						value="#{Session.publicByAuthor.selectedPersonSubjectMap.get(subject)}"
-						var="text" styleClass="select">
+						var="text">
 						<rich:column>
 							    #{text.ownValue}
 					    </rich:column>
@@ -56,6 +57,11 @@
 						<rich:column>
 							    #{text.privacity}
 						</rich:column>
+						<rich:column>
+		                  <a4j:commandButton value="make this text and its witnesses public"
+                                actionListener="#{Session.publicByAuthor.actionMakeTextAndRelatedPublic}"
+                                render="selectSubjectPanel"/>
+						</rich:column>
 					</rich:dataTable>
 
 				</rich:column>
--- a/src/main/webapp/templates/main_template.xhtml	Wed Jun 06 21:02:30 2018 +0200
+++ b/src/main/webapp/templates/main_template.xhtml	Thu Jun 07 18:47:18 2018 +0200
@@ -25,7 +25,7 @@
 
 
 				<h:panelGroup rendered="#{!empty Session.generalMsgList}">
-					<div style="z-index: 100;" class="rf-pp-shade">
+					<div style="z-index:100;" class="rf-pp-shade">
 						<button class="rf-pp-btn" tabindex="-1" accesskey="" />
 					</div>
 
@@ -38,11 +38,13 @@
 						<h:panelGrid columns="1" styleClass="ismi-pp-main-panel">
 							<h:panelGrid columns="2">
 								<h:graphicImage url="/resources/images/info_32.png" />
-								<h:panelGrid style="text-align:left">
+								<h:panelGrid style="text-align:left; min-width:60em">
 									<h:dataTable value="#{Session.generalMsgList}" var="msg"
 										rows="10">
 										<h:column>
+										  <div style="overflow:scroll;max-height:300px">
 											<h:outputText value="#{msg}" />
+										  </div>
 										</h:column>
 									</h:dataTable>
 								</h:panelGrid>