# HG changeset patch # User Robert Casties # Date 1528390038 -7200 # Node ID 3d8b315081281fb8bc16102c838f410a37451018 # Parent 4961820373d056e57d4af64cb6e8a7df12bd3064 PublicByAuthor feature works now. diff -r 4961820373d0 -r 3d8b31508128 src/main/java/de/mpiwg/itgroup/ismi/browse/EntityDetailsBean.java --- 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 saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper()); + List saveList = PrivacityUtils.setRelatedEntitiesPrivacity(this.entity, null, getWrapper(), null); // hide related entities from display sourceRelations = new HashMap>(); targetRelations = new HashMap>(); diff -r 4961820373d0 -r 3d8b31508128 src/main/java/de/mpiwg/itgroup/ismi/entry/utils/PrivacityUtils.java --- 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 TEXTexcepts = new HashSet(Arrays.asList("TEXT")); + public static final Set PERSONexcepts = new HashSet(Arrays.asList("TEXT", "PERSON", "WITNESS", + "CODEX", "TRANSFER_EVENT", "STUDY_EVENT", "COPY_EVENT", "MISATTRIBUTION", "MISIDENTIFICATION")); + public static final Set WITNESSexcepts = new HashSet(Arrays.asList("WITNESS", "TEXT")); + public static final Set CODEXexcepts = new HashSet(Arrays.asList("WITNESS")); + public static final Set COLLECTIONexcepts = new HashSet(Arrays.asList("CODEX")); + public static final Set REPOSITORYexcepts = new HashSet(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 setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper) { - // make sure relations are loaded - if (entity.isLightweight()) { - entity = wrapper.getEntityContent(entity); - } + public static List setRelatedEntitiesPrivacity(Entity entity, Boolean isPublic, WrapperService wrapper, + Set exceptedTypes) { + List saveList = new ArrayList(); + // 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 saveList = new ArrayList(); + // 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 setTextAndMorePrivacity(Entity text, Boolean isPublic, List report, + WrapperService wrapper) throws Exception { + List saveList = new ArrayList(); + // 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 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 nextRelEnts = new ArrayList(); + for (Entity relEnt : relatedEnts) { + String entType = relEnt.getObjectClass(); + if (entType.equals("PERSON")) { + // PERSON + List 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 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 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 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 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 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 changePrivacity4Person(Entity person, Boolean isPublic, WrapperService wrapper){ List saveList = new ArrayList(); diff -r 4961820373d0 -r 3d8b31508128 src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java --- 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 textMsg = new ArrayList(); + try { + List 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 texts = selectedPersonSubjectMap.get(subject); + for (Entity text : texts) { + List textMsg = new ArrayList(); + try { + List 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 */ diff -r 4961820373d0 -r 3d8b31508128 src/main/webapp/clean/components/publicShowSubjects.xhtml --- 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"> -

+

#{subject} < #{parent}

- + + var="text"> #{text.ownValue} @@ -56,6 +57,11 @@ #{text.privacity} + + +
diff -r 4961820373d0 -r 3d8b31508128 src/main/webapp/templates/main_template.xhtml --- 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 @@ -
+
@@ -38,11 +38,13 @@ - + +
+