Mercurial > hg > ismi-richfaces
diff src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java @ 177:af1018d06443
PublicByAuthor feature with new "Select by public and MAMS" works now!
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 08 Jun 2018 17:03:35 +0200 |
parents | c63d39034b60 |
children | ca83d67a2dc9 |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java Fri Jun 08 15:32:27 2018 +0200 +++ b/src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java Fri Jun 08 17:03:35 2018 +0200 @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.faces.event.ActionEvent; @@ -57,6 +58,7 @@ selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); makeSubjectTree(); + updateSubjectTexts(); logger.info("PublicByAuthorBean.reset() Done."); } @@ -70,9 +72,6 @@ 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 */ @@ -107,28 +106,41 @@ } } while (++cnt < 5); 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); } } - + + /** + * update subjectTexts, subjectPublicTexts and subjectPrivateTexts. + * + */ + private void updateSubjectTexts() { + subjectTexts = new HashMap<String,List<Entity>>(); + subjectPublicTexts = new HashMap<String,List<Entity>>(); + subjectPrivateTexts = new HashMap<String,List<Entity>>(); + for (Entry<String, Entity> subjectItem : subjectEntity.entrySet()) { + String subjectName = subjectItem.getKey(); + Entity subject = subjectItem.getValue(); + /* + * 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); + } + } public void actionReset() { reset(); @@ -282,6 +294,7 @@ /* * go through all texts for the subject */ + int pubCnt = 0; List<Entity> texts = subjectTexts.get(subject); for (Entity text : texts) { if (text.isLightweight()) { @@ -316,6 +329,7 @@ List<Entity> entities = PrivacityUtils.setTextAndMorePrivacity(text, true, textMsg, getWrapper()); // save only public state getWrapper().saveEntityListAsNodeWithoutContent(entities, null); + pubCnt += 1; } catch (Exception e) { logger.error(e); } @@ -324,6 +338,12 @@ logger.debug(msg); } } + if (pubCnt == 0) { + addGeneralMsg("No text matched your criteria."); + } else { + addGeneralMsg(pubCnt+" texts with MAMS number < "+maxMamsNr+" were made public!"); + } + updateSubjectTexts(); return null; }