Mercurial > hg > ismi-richfaces
changeset 176:c63d39034b60
PublicByAuthor feature with new "Select by public and MAMS" text-UI.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 08 Jun 2018 15:32:27 +0200 |
parents | 3d8b31508128 |
children | af1018d06443 |
files | src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java src/main/webapp/clean/components/publicAuthorSubjects.xhtml src/main/webapp/clean/components/publicMamsSubjects.xhtml src/main/webapp/clean/components/publicShowSubjects.xhtml src/main/webapp/clean/makeTextsPublic.xhtml src/main/webapp/clean/publicByAuthor.xhtml src/main/webapp/templates/main_template.xhtml |
diffstat | 7 files changed, 379 insertions(+), 141 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java Thu Jun 07 18:47:18 2018 +0200 +++ b/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java Fri Jun 08 15:32:27 2018 +0200 @@ -9,6 +9,7 @@ import javax.faces.event.ActionEvent; import org.apache.log4j.Logger; +import org.mpi.openmind.repository.bo.Attribute; import org.mpi.openmind.repository.bo.Entity; import org.mpi.openmind.repository.bo.Relation; @@ -23,16 +24,21 @@ private static final long serialVersionUID = 1L; - private String findAuthorName = ""; + protected String findAuthorName = ""; protected Long selectedPersonId = 0l; + protected Integer maxMamsNr = 0; protected Entity selectedPerson; protected List<Entity> selectedPersonTexts; protected List<String> selectedPersonSubjects; protected Map<String,List<Entity>> selectedPersonSubjectMap; + protected List<String> subjectList; protected Map<String,List<String>> subjectParents; - + protected Map<String,List<Entity>> subjectTexts; + protected Map<String,List<Entity>> subjectPublicTexts; + protected Map<String,List<Entity>> subjectPrivateTexts; + protected Map<String,Entity> subjectEntity; private FullEntityRepositoryBean browseBean; @@ -43,25 +49,50 @@ } public void reset(){ - //logger.info("AdvancedSearchBean.reset()"); + logger.info("PublicByAuthorBean.reset()"); browseBean = new FullEntityRepositoryBean(); browseBean.setObjectClass(PERSON); selectedPersonTexts = new ArrayList<Entity>(); selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); + makeSubjectTree(); + logger.info("PublicByAuthorBean.reset() Done."); } + /** + * Creates the subjectParents Map with all subject names as keys and + * a List with their parents as values. + * + * Also creates the subjectList List of subject names. + */ protected void makeSubjectTree() { + subjectList = new ArrayList<String>(); + subjectEntity = new HashMap<String,Entity>(); subjectParents = new HashMap<String,List<String>>(); + subjectTexts = new HashMap<String,List<Entity>>(); + subjectPublicTexts = new HashMap<String,List<Entity>>(); + subjectPrivateTexts = new HashMap<String,List<Entity>>(); + /* + * get all subjects + */ List<Entity> subjects = getWrapper().getEntitiesByDef(SUBJECT); for (Entity subject : subjects) { if (subject.isLightweight()) { subject = getWrapper().getEntityContent(subject); } + /* + * add subject + */ + String subjectName = subject.getOwnValue(); + subjectList.add(subjectName); + subjectEntity.put(subjectName, subject); ArrayList<String> parents = new ArrayList<String>(); Entity parent = subject; int cnt = 0; + /* + * find subject's parents + */ do { if (parent.isLightweight()) { parent = getWrapper().getEntityContent(parent); @@ -75,18 +106,34 @@ break; } } while (++cnt < 5); - subjectParents.put(subject.getOwnValue(), parents); + subjectParents.put(subjectName, parents); + /* + * find subject's texts + */ + ArrayList<Entity> textList = new ArrayList<Entity>(); + ArrayList<Entity> pubTextList = new ArrayList<Entity>(); + ArrayList<Entity> privTextList = new ArrayList<Entity>(); + for (Relation textRel : subject.getTargetRelations(has_subject, TEXT)) { + Long textId = textRel.getSourceId(); + Entity text = getWrapper().getEntityByIdWithContent(textId); + textList.add(text); + if (text.getIsPublic()) { + pubTextList.add(text); + } else { + privTextList.add(text); + } + } + subjectTexts.put(subjectName, textList); + subjectPublicTexts.put(subjectName, pubTextList); + subjectPrivateTexts.put(subjectName, privTextList); } } - /** - * @return the subjectParents - */ - public Map<String, List<String>> getSubjectParents() { - return subjectParents; - } - + public void actionReset() { + reset(); + } + public void listenerAuthorIdSearch(ActionEvent event) { setSelectedPersonById(); } @@ -100,8 +147,10 @@ } } - - + /** + * Updates the information in selectedPersonTexts, selectedPersonSubjects + * and selectedPersonSubjectMap. + */ public void updateSelectedPerson() { // load all texts by this author selectedPersonTexts = new ArrayList<Entity>(); @@ -164,11 +213,16 @@ selectedPersonId = entity.getId(); setSelectedPersonById(); // switch tab - getSessionBean().setSelectedPublicByAuthorTab("sub"); + getSessionBean().setSelectedPublicByAuthorTab("autsub"); return null; } + /** + * Makes the selected text and its related objects public. + * Uses PrivacityUtils.setTextAndMorePrivacity(). + * @return + */ public String actionMakeTextAndRelatedPublic() { Entity text = (Entity) getRequestBean("text"); List<String> textMsg = new ArrayList<String>(); @@ -187,6 +241,11 @@ return null; } + /** + * Makes the selected subject and its texts and related objects public. + * Uses PrivacityUtils.setTextAndMorePrivacity(). + * @return + */ public String actionMakePersonSubjectAndRelatedPublic() { String subject = (String) getRequestBean("subject"); logger.debug("MAKE SUBJECT PUBLIC"); @@ -208,6 +267,66 @@ return null; } + /** + * Makes the selected subject and its texts and related objects public. + * Uses PrivacityUtils.setTextAndMorePrivacity(). + * @return + */ + public String actionMakeMamsSubjectAndRelatedPublic() { + String subject = (String) getRequestBean("subject"); + logger.debug("MAKE PUBLIC BY MAMS AND SUBJECT"); + if (maxMamsNr < 1) { + addErrorMsg("MAMS number too small!"); + return null; + } + /* + * go through all texts for the subject + */ + List<Entity> texts = subjectTexts.get(subject); + for (Entity text : texts) { + if (text.isLightweight()) { + text = getWrapper().getEntityContent(text); + } + /* + * check author's MAMS number + */ + List<Relation> authorRels = text.getSourceRelations(rel_was_created_by, PERSON); + if (authorRels.isEmpty()) { + // skip text with no author + continue; + } + long authorId = authorRels.get(0).getTargetId(); + Entity author = getWrapper().getEntityByIdWithContent(authorId); + try { + Attribute mamsAtt = author.getAttributeByName("mams_number"); + int mamsNr = Integer.parseInt(mamsAtt.getValue()); + if (mamsNr > maxMamsNr) { + // skip if MAMS number too big + continue; + } + } catch (Exception e) { + // attribute missing or wrong + continue; + } + /* + * make text and related objects public + */ + 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 */ @@ -237,12 +356,6 @@ } /** - * @param selectedPersonId the selectedPersonId to set - */ - public void setSelectedPersonId(long selectedPersonId) { - this.selectedPersonId = selectedPersonId; - } - /** * @return the selectedPerson */ public Entity getSelectedPerson() { @@ -276,5 +389,61 @@ public List<String> getSelectedPersonSubjects() { return selectedPersonSubjects; } + + /** + * @return the subjectParents + */ + public Map<String, List<String>> getSubjectParents() { + return subjectParents; + } + + /** + * @return the subjectList + */ + public List<String> getSubjectList() { + return subjectList; + } + + /** + * @return the maxMamsNr + */ + public Integer getMaxMamsNr() { + return maxMamsNr; + } + + /** + * @param maxMamsNr the maxMamsNr to set + */ + public void setMaxMamsNr(Integer maxMamsNr) { + this.maxMamsNr = maxMamsNr; + } + + /** + * @return the subjectTexts + */ + public Map<String, List<Entity>> getSubjectTexts() { + return subjectTexts; + } + + /** + * @return the subjectPublicTexts + */ + public Map<String, List<Entity>> getSubjectPublicTexts() { + return subjectPublicTexts; + } + + /** + * @return the subjectPrivateTexts + */ + public Map<String, List<Entity>> getSubjectPrivateTexts() { + return subjectPrivateTexts; + } + + /** + * @return the subjectEntity + */ + public Map<String, Entity> getSubjectEntity() { + return subjectEntity; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/clean/components/publicAuthorSubjects.xhtml Fri Jun 08 15:32:27 2018 +0200 @@ -0,0 +1,80 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:c="http://java.sun.com/jsp/jstl/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:a4j="http://richfaces.org/a4j" + xmlns:rich="http://richfaces.org/rich"> + +<body> + <ui:composition> + + <!-- <h:outputStylesheet name="/css/ismi-db/repository.css" /> --> + + <h:panelGrid id="setAuthorPanel" columns="1"> + + <h2 style="color:black; text-align:left">Author: #{Session.publicByAuthor.selectedPerson.ownValue}"</h2> + + <h:panelGrid columns="3" styleClass="displayPanel" + columnClasses="displayPanelColumn01,displayPanelColumn02"> + + <h:outputLabel value="Person ID" /> + <h:inputText value="#{Session.publicByAuthor.selectedPersonId}" /> + + <a4j:commandButton value="search" + actionListener="#{Session.publicByAuthor.listenerAuthorIdSearch}" + render="setAuthorPanel,selectSubjectPanel" /> + + </h:panelGrid> + </h:panelGrid> + + <h:panelGrid id="selectSubjectPanel" columns="1" + style="margin-left:auto; margin-right:auto; text-align:left; width:100%;"> + <rich:dataTable + value="#{Session.publicByAuthor.selectedPersonSubjects}" + var="subject" styleClass="select"> + <rich:column> + <h2 style="margin-top:1em"> + #{subject} + <ui:repeat + value="#{Session.publicByAuthor.subjectParents.get(subject)}" + var="parent"> < #{parent}</ui:repeat> + </h2> + + <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"> + <rich:column> + #{text.ownValue} + </rich:column> + <rich:column> + <h:outputLink + value="#{ApplicationBean1.root}/browse/entityDetails.xhtml?eid=#{text.id}" + target="_blank">[#{text.id}]</h:outputLink> + </rich:column> + <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> + </rich:dataTable> + + + </h:panelGrid> + + + + </ui:composition> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/clean/components/publicMamsSubjects.xhtml Fri Jun 08 15:32:27 2018 +0200 @@ -0,0 +1,57 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:c="http://java.sun.com/jsp/jstl/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:a4j="http://richfaces.org/a4j" + xmlns:rich="http://richfaces.org/rich"> + +<body> + <ui:composition> + + <!-- <h:outputStylesheet name="/css/ismi-db/repository.css" /> --> + + <h:panelGrid columns="2" styleClass="displayPanel" + columnClasses="displayPanelColumn01,displayPanelColumn02"> + + <h:outputLabel value="Maximum MAMS number" /> + <h:inputText value="#{Session.publicByAuthor.maxMamsNr}" /> + + </h:panelGrid> + + <h:panelGrid id="selectSubjectPanel2" columns="1" + style="margin-left:auto; margin-right:auto; text-align:left; width:100%;"> + <rich:dataTable + value="#{Session.publicByAuthor.subjectList}" + var="subject" styleClass="select"> + <rich:column> + <h2 style="margin-top:1em"> + #{subject} + <ui:repeat + value="#{Session.publicByAuthor.subjectParents.get(subject)}" + var="parent"> < #{parent}</ui:repeat> + </h2> + + <a4j:commandButton value="make all texts up to given MAMS number and their witnesses public" + actionListener="#{Session.publicByAuthor.NoactionMakeMamsSubjectAndRelatedPublic}" + render="selectSubjectPanel" style="margin-bottom:0.5em"/> + + <div> + #{Session.publicByAuthor.subjectPublicTexts.get(subject).size()} + public texts, + #{Session.publicByAuthor.subjectPrivateTexts.get(subject).size()} + private texts on + <h:outputLink + value="#{ApplicationBean1.root}/browse/entityDetails.xhtml?eid=#{Session.publicByAuthor.subjectEntity.get(subject).getId()}" + target="_blank">this subject</h:outputLink> (regardless of MAMS number). + </div> + </rich:column> + </rich:dataTable> + + + </h:panelGrid> + + </ui:composition> +</body> +</html>
--- a/src/main/webapp/clean/components/publicShowSubjects.xhtml Thu Jun 07 18:47:18 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" - xmlns:c="http://java.sun.com/jsp/jstl/core" - xmlns:h="http://java.sun.com/jsf/html" - xmlns:f="http://java.sun.com/jsf/core" - xmlns:ui="http://java.sun.com/jsf/facelets" - xmlns:a4j="http://richfaces.org/a4j" - xmlns:rich="http://richfaces.org/rich"> - -<body> - <ui:composition> - - <!-- <h:outputStylesheet name="/css/ismi-db/repository.css" /> --> - - <h2 style="color:black; text-align:left">Author: #{Session.publicByAuthor.selectedPerson.ownValue}"</h2> - - <h:panelGrid columns="3" styleClass="displayPanel" - columnClasses="displayPanelColumn01,displayPanelColumn02"> - - <h:outputLabel value="Person ID" /> - <h:inputText value="#{Session.publicByAuthor.selectedPersonId}" /> - - <a4j:commandButton value="search" - actionListener="#{Session.publicByAuthor.listenerAuthorIdSearch}" - render="selectSubjectPanel" /> - - </h:panelGrid> - - <h:panelGrid id="selectSubjectPanel" columns="1" - style="margin-left:auto; margin-right:auto; text-align:left; width:100%;"> - <rich:dataTable - value="#{Session.publicByAuthor.selectedPersonSubjects}" - var="subject" styleClass="select"> - <rich:column> - <h2 style="margin-top:1em"> - #{subject} - <ui:repeat - value="#{Session.publicByAuthor.subjectParents.get(subject)}" - var="parent"> < #{parent}</ui:repeat> - </h2> - - <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"> - <rich:column> - #{text.ownValue} - </rich:column> - <rich:column> - <h:outputLink - value="#{ApplicationBean1.root}/browse/entityDetails.xhtml?eid=#{text.id}" - target="_blank">[#{text.id}]</h:outputLink> - </rich:column> - <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> - </rich:dataTable> - - - </h:panelGrid> - - - - </ui:composition> -</body> -</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/clean/makeTextsPublic.xhtml Fri Jun 08 15:32:27 2018 +0200 @@ -0,0 +1,51 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:a4j="http://richfaces.org/a4j" + xmlns:rich="http://richfaces.org/rich"> + +<body> + <ui:composition template="/templates/privateTemplate.xhtml"> + + <h:outputStylesheet name="/css/ismi-db/repository.css" /> + + <ui:define name="privateContent"> + + <div id="pageTitle"> + <h:outputText value="Make Texts Public" /> + </div> + + <h:panelGrid columns="1" + styleClass="mainPanel"> + + <rich:tabPanel id="tabPanel" + activeItem="#{Session.selectedPublicByAuthorTab}"> + + <rich:tab header="Find Author" name="aut"> + <ui:include src="components/publicFindAuthor.xhtml" /> + </rich:tab> + + <rich:tab header="Select by Author and Subject" name="autsub"> + <ui:include src="components/publicAuthorSubjects.xhtml" /> + </rich:tab> + + <rich:tab header="Select by Subject and MAMS" name="mamssub"> + <ui:include src="components/publicMamsSubjects.xhtml" /> + </rich:tab> + </rich:tabPanel> + + <a4j:commandButton value="reload all texts" + actionListener="#{Session.publicByAuthor.actionReset}" + render="mainPanel" /> + + + </h:panelGrid> + + + </ui:define> + </ui:composition> + +</body> +</html> \ No newline at end of file
--- a/src/main/webapp/clean/publicByAuthor.xhtml Thu Jun 07 18:47:18 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" - xmlns:h="http://java.sun.com/jsf/html" - xmlns:f="http://java.sun.com/jsf/core" - xmlns:ui="http://java.sun.com/jsf/facelets" - xmlns:a4j="http://richfaces.org/a4j" - xmlns:rich="http://richfaces.org/rich"> - -<body> - <ui:composition template="/templates/privateTemplate.xhtml"> - - <h:outputStylesheet name="/css/ismi-db/repository.css" /> - - <ui:define name="privateContent"> - - <div id="pageTitle"> - <h:outputText value="Public by Author Form" /> - </div> - - <h:panelGrid columns="1" - styleClass="mainPanel"> - - <rich:tabPanel id="tabPanel" - activeItem="#{Session.selectedPublicByAuthorTab}"> - - <rich:tab header="Find Author" name="src"> - <ui:include src="components/publicFindAuthor.xhtml" /> - </rich:tab> - - <rich:tab header="Select by Subject" name="sub"> - <ui:include src="components/publicShowSubjects.xhtml" /> - </rich:tab> - </rich:tabPanel> - - </h:panelGrid> - - - </ui:define> - </ui:composition> - -</body> -</html> \ No newline at end of file
--- a/src/main/webapp/templates/main_template.xhtml Thu Jun 07 18:47:18 2018 +0200 +++ b/src/main/webapp/templates/main_template.xhtml Fri Jun 08 15:32:27 2018 +0200 @@ -176,8 +176,8 @@ </h:panelGroup> </f:facet> - <rich:menuItem label="Public by author" - onclick="document.location.href='#{ApplicationBean1.root}/clean/publicByAuthor.xhtml'"> + <rich:menuItem label="Make Texts Public" + onclick="document.location.href='#{ApplicationBean1.root}/clean/makeTextsPublic.xhtml'"> </rich:menuItem> </rich:dropDownMenu>