# HG changeset patch # User Robert Casties # Date 1499787890 -7200 # Node ID b40a84944716bbb1f705f817df0f4b71b2947c11 # Parent 1389c83028ef9a16d67afec38aa97bb94668ac31 add public/private editing to Entity Details. diff -r 1389c83028ef -r b40a84944716 src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java --- 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 saveList = new ArrayList(); + 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 saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper()); + // hide related entities from display + sourceRelations = new HashMap>(); + targetRelations = new HashMap>(); + // save entities + try { + getWrapper().saveEntityListAsNodeWithoutContent(saveList, getUserName()); + } catch (Exception e) { + printInternalError(e); + logger.error(e); + } + return GOTO_ENTITY_DETAILS; + } + /** *

* Show the details page for the current entity. diff -r 1389c83028ef -r b40a84944716 src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java --- 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 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 saveList = new ArrayList(); + + // 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 changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){ List saveList = new ArrayList(); diff -r 1389c83028ef -r b40a84944716 src/main/webapp/browse/entityDetails.xhtml --- 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 @@ -


@@ -73,6 +72,38 @@ + + + + + + + + + + + +