Mercurial > hg > ismi-richfaces
view src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java @ 173:aa564b1b5e1f public_by_author
publicByAuthor feature ui for selecting texts ready.
actual changing of public state not yet implemented.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 06 Jun 2018 21:01:05 +0200 |
parents | 50b8103ec85c |
children | 3d8b31508128 |
line wrap: on
line source
package de.mpiwg.itgroup.ismi.merge; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.faces.event.ActionEvent; import org.apache.log4j.Logger; import org.mpi.openmind.repository.bo.Entity; import org.mpi.openmind.repository.bo.Relation; import de.mpiwg.itgroup.ismi.browse.EntityRepositoryBean; import de.mpiwg.itgroup.ismi.browse.FullEntityRepositoryBean; import de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean; public class PublicByAuthorBean extends AbstractISMIBean implements Serializable{ private static Logger logger = Logger.getLogger(PublicByAuthorBean.class); private static final long serialVersionUID = 1L; private String findAuthorName = ""; protected Long selectedPersonId = 0l; protected Entity selectedPerson; protected List<Entity> selectedPersonTexts; protected List<String> selectedPersonSubjects; protected Map<String,List<Entity>> selectedPersonSubjectMap; protected Map<String,List<String>> subjectParents; private FullEntityRepositoryBean browseBean; public PublicByAuthorBean(){ //logger.info("AdvancedSearchBean"); this.reset(); } public void reset(){ //logger.info("AdvancedSearchBean.reset()"); browseBean = new FullEntityRepositoryBean(); browseBean.setObjectClass(PERSON); selectedPersonTexts = new ArrayList<Entity>(); selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); makeSubjectTree(); } protected void makeSubjectTree() { subjectParents = new HashMap<String,List<String>>(); List<Entity> subjects = getWrapper().getEntitiesByDef(SUBJECT); for (Entity subject : subjects) { if (subject.isLightweight()) { subject = getWrapper().getEntityContent(subject); } ArrayList<String> parents = new ArrayList<String>(); Entity parent = subject; int cnt = 0; do { if (parent.isLightweight()) { parent = getWrapper().getEntityContent(parent); } List<Relation> parRels = parent.getSourceRelations(is_part_of, SUBJECT); if (!parRels.isEmpty()) { Long parentId = parRels.get(0).getTargetId(); parent = getWrapper().getEntityById(parentId); parents.add(parent.getOwnValue()); } else { break; } } while (++cnt < 5); subjectParents.put(subject.getOwnValue(), parents); } } /** * @return the subjectParents */ public Map<String, List<String>> getSubjectParents() { return subjectParents; } public void listenerAuthorIdSearch(ActionEvent event) { setSelectedPersonById(); } protected void setSelectedPersonById() { Entity ent = getWrapper().getEntityById(selectedPersonId); if (ent != null) { ent = getWrapper().getEntityContent(ent); selectedPerson = ent; updateSelectedPerson(); } } public void updateSelectedPerson() { // load all texts by this author selectedPersonTexts = new ArrayList<Entity>(); selectedPersonSubjectMap = new HashMap<String,List<Entity>>(); List<Relation> textRels = selectedPerson.getTargetRelations("was_created_by", "TEXT"); for (Relation rel : textRels) { Long textID = rel.getSourceId(); // get text Entity text = getWrapper().getEntityByIdWithContent(textID); selectedPersonTexts.add(text); // get subject List<Relation> subjectRels = text.getSourceRelations("has_subject", "SUBJECT"); if (subjectRels.isEmpty()) { String subject = "NO SUBJECT"; List<Entity> texts = selectedPersonSubjectMap.get(subject); if (texts == null) { texts = new ArrayList<Entity>(); } // add text to list texts.add(text); // add list to subject map selectedPersonSubjectMap.put(subject, texts); } else { for (Relation subjectRel : subjectRels) { Long subjectId = subjectRel.getTargetId(); Entity subject = getWrapper().getEntityByIdWithContent(subjectId); List<Entity> texts = selectedPersonSubjectMap.get(subject.getOwnValue()); if (texts == null) { texts = new ArrayList<Entity>(); } // add text to list texts.add(text); // add list to subject map selectedPersonSubjectMap.put(subject.getOwnValue(), texts); } } } // update list of subjects selectedPersonSubjects = new ArrayList<String>(); for (String sub : selectedPersonSubjectMap.keySet()) { selectedPersonSubjects.add(sub); } } 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"); browseBean.setSortAttributeNumerically(true); try { browseBean.sortByAttributes(); } catch (Exception e) { logger.error(e); } } /** * @return the findAuthorName */ public String getFindAuthorName() { return findAuthorName; } /** * @param findAuthorName the findAuthorName to set */ public void setFindAuthorName(String findAuthorName) { this.findAuthorName = findAuthorName; } /** * @return the browseBean */ public EntityRepositoryBean getBrowseBean() { return browseBean; } /** * @return the selectedPersonId */ public long getSelectedPersonId() { return selectedPersonId; } /** * @param selectedPersonId the selectedPersonId to set */ public void setSelectedPersonId(long selectedPersonId) { this.selectedPersonId = selectedPersonId; } /** * @return the selectedPerson */ public Entity getSelectedPerson() { return selectedPerson; } /** * @return the selectedPersonTexts */ public List<Entity> getSelectedPersonTexts() { return selectedPersonTexts; } /** * @return the selectedPersonSubjects */ public Map<String, List<Entity>> getSelectedPersonSubjectMap() { return selectedPersonSubjectMap; } /** * @param selectedPersonId the selectedPersonId to set */ public void setSelectedPersonId(Long selectedPersonId) { this.selectedPersonId = selectedPersonId; } /** * @return the selectedPersonSubjects */ public List<String> getSelectedPersonSubjects() { return selectedPersonSubjects; } }