changeset 148:b40a84944716

add public/private editing to Entity Details.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 11 Jul 2017 17:44:50 +0200
parents 1389c83028ef
children a279d80fae42
files src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java src/main/webapp/browse/entityDetails.xhtml
diffstat 3 files changed, 138 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java	Mon Jul 10 20:41:19 2017 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java	Tue Jul 11 17:44:50 2017 +0200
@@ -14,6 +14,7 @@
 import org.mpi.openmind.repository.bo.Relation;
 
 import de.mpiwg.itgroup.ismi.entry.beans.SessionBean;
+import de.mpiwg.itgroup.ismi.entry.utils.PrivacityUtils;
 import de.mpiwg.itgroup.ismi.event.beans.CopyEvent;
 import de.mpiwg.itgroup.ismi.event.beans.StudyEvent;
 import de.mpiwg.itgroup.ismi.event.beans.TransferEvent;
@@ -221,8 +222,9 @@
 			getSessionBean().editEntity(this.entity);
 			
 		} catch (Exception e) {
-			e.printStackTrace();
-		}	
+			logger.error(e);
+		}
+		
 		if(entity.getObjectClass().equals(StudyEvent.OC) ||
 				entity.getObjectClass().equals(CopyEvent.OC) ||
 				entity.getObjectClass().equals(TransferEvent.OC)){
@@ -232,6 +234,46 @@
 		}
 	}
 
+	
+	/**
+	 * Toggle this entity's public state.
+	 * @return
+	 */
+	public String actionChangeEntityPrivacity() {
+		// toggle publication state
+		PrivacityUtils.changeEntityPrivacity(this.entity, null, getWrapper());
+		ArrayList<Entity> saveList = new ArrayList<Entity>();
+		saveList.add(entity);
+		try {
+			getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName());
+		} catch (Exception e) {
+			printInternalError(e);
+			logger.error(e);
+		}
+		return GOTO_ENTITY_DETAILS;
+	}
+	
+	/**
+	 * Change all related entities' public state to match this entity.
+	 * 
+	 * @return
+	 */
+	public String actionChangeRelatedEntitiesPrivacity() {
+		// set publication state
+		List<Entity> saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper());
+		// hide related entities from display
+		sourceRelations = new HashMap<String, List<Relation>>();
+		targetRelations = new HashMap<String, List<Relation>>();
+		// save entities
+		try {
+			getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName());
+		} catch (Exception e) {
+			printInternalError(e);
+			logger.error(e);
+		}
+		return GOTO_ENTITY_DETAILS;
+	}
+	
 	/**
 	 * <p>
 	 * Show the details page for the current entity.
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java	Mon Jul 10 20:41:19 2017 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java	Tue Jul 11 17:44:50 2017 +0200
@@ -9,6 +9,68 @@
 
 public class PrivacityUtils {
 
+	/**
+	 * Change public state of the given entity.
+	 * 
+	 * Toggles public state if isPublic == null.
+	 * 
+	 * @param entity
+	 * @param isPublic
+	 * @param wrapper
+	 * @return
+	 */
+	public static Entity changeEntityPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper) {
+		// make sure attributes are loaded
+		if (entity.isLightweight()) {
+			entity = wrapper.getEntityContent(entity);
+		}
+		// toggle public if isPublic == null
+		if (isPublic == null) {
+			isPublic = !entity.getIsPublic();
+		}
+		// set public
+		entity.setIsPublic(isPublic);
+		return entity;
+	}
+	
+	/**
+	 * Change public state of all entities related to the given entity.
+	 * 
+	 * Sets public state to entity's state if isPublic == null.
+	 * 
+	 * @param entity
+	 * @param isPublic
+	 * @param wrapper
+	 * @return
+	 */
+	public static List<Entity> setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper) {
+		// 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();
+		}
+		List<Entity> saveList = new ArrayList<Entity>();
+
+		// 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;
+	}
 	
 	public static List<Entity> changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){
 		List<Entity> saveList = new ArrayList<Entity>();
--- a/src/main/webapp/browse/entityDetails.xhtml	Mon Jul 10 20:41:19 2017 +0200
+++ b/src/main/webapp/browse/entityDetails.xhtml	Tue Jul 11 17:44:50 2017 +0200
@@ -20,7 +20,6 @@
 			<h:panelGrid columns="1"
 				style="margin-left: auto; margin-right: auto; text-align: center; width: 700px">
 
-
 				<hr/>
 				
 				<h:panelGrid columns="3" styleClass="controlPanel">
@@ -73,6 +72,38 @@
 					<h:panelGrid id="entityDetailsPanel" columns="1"
 						styleClass="entityDetailsPanel" columnClasses="createPanelFirstColumn">
 
+                        <h:outputText value="Publication state: #{Session.entDetailsForm.entity.privacity}" styleClass="titlePanel"/>
+                        
+                        <h:panelGroup
+                            rendered="#{Session.canEdit}"
+                            style="display:block; margin-left:auto; margin-right:auto;">
+                            
+                            <a4j:commandButton value="Make entity public" title="Change publication state of this entity"
+                                rendered="#{!Session.entDetailsForm.entity.isPublic}"
+                                style="margin-right:10px;"
+                                onclick="if(!confirm('Do you really want to make this entity public?')){ return; };"
+                                action="#{Session.entDetailsForm.actionChangeEntityPrivacity}"/>
+                            <a4j:commandButton value="Make entity private" title="Change publication state of this entity"
+                                rendered="#{Session.entDetailsForm.entity.isPublic}"
+                                style="margin-right:10px;"
+                                onclick="if(!confirm('Do you really want to make this entity private?')){ return; };"
+                                action="#{Session.entDetailsForm.actionChangeEntityPrivacity}"/>
+                            
+                            <a4j:commandButton value="Make related entities public" 
+                                title="Change publication state of directly related entities"
+                                rendered="#{Session.entDetailsForm.entity.isPublic}"
+                                style="margin-right:10px;"
+                                onclick="if(!confirm('Do you really want to make all related entities public?')){ return; };"
+                                action="#{Session.entDetailsForm.actionChangeRelatedEntitiesPrivacity}"/>
+                            <a4j:commandButton value="Make related entities private" 
+                                title="Change publication state of directly related entities"
+                                rendered="#{!Session.entDetailsForm.entity.isPublic}"
+                                style="margin-right:10px;"
+                                onclick="if(!confirm('Do you really want to make all related entities private?')){ return; };"
+                                action="#{Session.entDetailsForm.actionChangeRelatedEntitiesPrivacity}"/>
+                            
+                        </h:panelGroup>
+
 						<h:outputText value="Attributes" styleClass="titlePanel"/>
 						
 						<rich:dataTable id="entity"