view src/main/java/de/mpiwg/itgroup/ismi/merge/PublicByAuthorBean.java @ 169:0b5d02012299 public_by_author

more work on publicByAuthor feature.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Thu, 31 May 2018 20:26:10 +0200
parents e9ab943ec528
children 8604b368ec19
line wrap: on
line source

package de.mpiwg.itgroup.ismi.merge;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

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<Entity> selectedPersonSubjects;
	
	
	private EntityRepositoryBean 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>();
	}
	
	public void listenerAuthorIdSearch(ActionEvent event) {
        setSelectedPersonById();
	}

    private 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>();
	    List<Relation> textRels = selectedPerson.getTargetRelations("was_created_by", "TEXT");
	    for (Relation rel : textRels) {
	        Long textID = rel.getSourceId();
	        Entity text = getWrapper().getEntityByIdWithContent(textID);
	        selectedPersonTexts.add(text);
	    }
	}
	

	public String actionSelectPerson() {
       Entity entity = (Entity) getRequestBean("entity");
       selectedPersonId = entity.getId();
       setSelectedPersonById();
       // switch tab
       getSessionBean().setSelectedPublicByAuthorTab("02");
       return null;
	}
	
    public String actionSearch(){
		this.search();
		return null;
	}
	
	public void search(){
		long start = System.currentTimeMillis();
		
		long end = System.currentTimeMillis();
		logger.info("execution time [ms] = " + (end - start));
	}

	
	/**
	 * @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 List<Entity> getSelectedPersonSubjects() {
        return selectedPersonSubjects;
    }

    /**
     * @param selectedPersonId the selectedPersonId to set
     */
    public void setSelectedPersonId(Long selectedPersonId) {
        this.selectedPersonId = selectedPersonId;
    }

}