# HG changeset patch # User Robert Casties # Date 1528464747 -7200 # Node ID c63d39034b600fabbe7c908cd4fdf2d44c592097 # Parent 3d8b315081281fb8bc16102c838f410a37451018 PublicByAuthor feature with new "Select by public and MAMS" text-UI. diff -r 3d8b31508128 -r c63d39034b60 src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java --- 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 selectedPersonTexts; protected List selectedPersonSubjects; protected Map> selectedPersonSubjectMap; + protected List subjectList; protected Map> subjectParents; - + protected Map> subjectTexts; + protected Map> subjectPublicTexts; + protected Map> subjectPrivateTexts; + protected Map 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(); selectedPersonSubjectMap = new HashMap>(); + 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(); + subjectEntity = new HashMap(); subjectParents = new HashMap>(); + subjectTexts = new HashMap>(); + subjectPublicTexts = new HashMap>(); + subjectPrivateTexts = new HashMap>(); + /* + * get all subjects + */ List 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 parents = new ArrayList(); 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 textList = new ArrayList(); + ArrayList pubTextList = new ArrayList(); + ArrayList privTextList = new ArrayList(); + 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> 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(); @@ -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 textMsg = new ArrayList(); @@ -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 texts = subjectTexts.get(subject); + for (Entity text : texts) { + if (text.isLightweight()) { + text = getWrapper().getEntityContent(text); + } + /* + * check author's MAMS number + */ + List 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 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 */ @@ -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 getSelectedPersonSubjects() { return selectedPersonSubjects; } + + /** + * @return the subjectParents + */ + public Map> getSubjectParents() { + return subjectParents; + } + + /** + * @return the subjectList + */ + public List 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> getSubjectTexts() { + return subjectTexts; + } + + /** + * @return the subjectPublicTexts + */ + public Map> getSubjectPublicTexts() { + return subjectPublicTexts; + } + + /** + * @return the subjectPrivateTexts + */ + public Map> getSubjectPrivateTexts() { + return subjectPrivateTexts; + } + + /** + * @return the subjectEntity + */ + public Map getSubjectEntity() { + return subjectEntity; + } } diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/clean/components/publicAuthorSubjects.xhtml --- /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 @@ + + + + + + + + + + +

Author: #{Session.publicByAuthor.selectedPerson.ownValue}"

+ + + + + + + + + +
+ + + + +

+ #{subject} + < #{parent} +

+ + + + + + #{text.ownValue} + + + [#{text.id}] + + + #{text.privacity} + + + + + + +
+
+ + +
+ + + +
+ + diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/clean/components/publicMamsSubjects.xhtml --- /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 @@ + + + + + + + + + + + + + + + + + + +

+ #{subject} + < #{parent} +

+ + + +
+ #{Session.publicByAuthor.subjectPublicTexts.get(subject).size()} + public texts, + #{Session.publicByAuthor.subjectPrivateTexts.get(subject).size()} + private texts on + this subject (regardless of MAMS number). +
+
+
+ + +
+ +
+ + diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/clean/components/publicShowSubjects.xhtml --- 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 @@ - - - - - - - - -

Author: #{Session.publicByAuthor.selectedPerson.ownValue}"

- - - - - - - - - - - - - -

- #{subject} - < #{parent} -

- - - - - - #{text.ownValue} - - - [#{text.id}] - - - #{text.privacity} - - - - - - -
-
- - -
- - - -
- - diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/clean/makeTextsPublic.xhtml --- /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 @@ + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/clean/publicByAuthor.xhtml --- 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 @@ - - - - - - - - - - -
- -
- - - - - - - - - - - - - - - - - -
-
- - - \ No newline at end of file diff -r 3d8b31508128 -r c63d39034b60 src/main/webapp/templates/main_template.xhtml --- 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 @@ - +