view src/main/java/de/mpiwg/web/SessionBean.java @ 0:7682c04c63a8

First commit of the source code!
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Tue, 10 Mar 2015 14:50:41 +0100
parents
children
line wrap: on
line source

package de.mpiwg.web;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;

import org.apache.log4j.Logger;
import org.dom4j.Branch;

import de.mpiwg.gazetteer.bo.LGBranch;
import de.mpiwg.gazetteer.bo.LGFile;
import de.mpiwg.gazetteer.dataverse.DataverseUtils;
import de.mpiwg.gazetteer.dataverse.bo.VDCUser;
import de.mpiwg.gazetteer.utils.DBService;
import de.mpiwg.gazetteer.utils.DataProvider;
import de.mpiwg.gazetteer.utils.SelectableObject;

public class SessionBean extends AbstractBean {

	private static Logger logger = Logger.getLogger(SessionBean.class);
	public static final String BEAN_NAME = "sessionBean";
	
	private List<String> msgList = new ArrayList<String>();
	
	private List<SelectableObject<LGBranch>> branches;
	
	private VDCUser user;
	private String userName;
	private String password;
	
	private String currentSectionId = "5190882";
	
	private FileCreator fileCreator = new FileCreator();
	private BranchEditor branchEditor = new BranchEditor();
	private SearchBean searchPage = new SearchBean();
	
	public SessionBean(){
		logger.info("#### SessionBean #####");
	}
	
	public void reset(){
		this.user = null;
		this.branches = null;
		this.fileCreator = new FileCreator();
		this.branchEditor = new BranchEditor();
		this.searchPage = new SearchBean();
	}
	
	public List<String> getMsgList() {
		return msgList;
	}

	public void setMsgList(List<String> msgList) {
		this.msgList = msgList;
	}
	
	public void listenerCloseMsgPopup(ActionEvent event){
		getSessionBean().setMsgList(null);
	}
	
	public void listenerReloadBranches(ActionEvent event){
		this.reloadBranches();
	}
	
	public void listenerLogin(ActionEvent event){
		login0();
	}
	
	public void ajaxLogin(AjaxBehaviorEvent event){
		login0();
	}
	
	private void login0(){
		try {
			this.user = DataverseUtils.login(userName, password);
			if(user != null){
				reloadBranches();	
				
			}else{
				addMsg("User account no found or userName and password do not match!");
			}
						
		} catch (Exception e) {
			internalError(e);
		}
	}
	
	public void listenerDeleteBranch(ActionEvent event){
		System.out.println("listenerDeleteBranch");
		try {
			for(SelectableObject<LGBranch> so : new ArrayList<SelectableObject<LGBranch>>(this.branches)){
				if(so.isSelected()){
					this.branches.remove(so);
					DataProvider.getInstance().deleteBranch(so.getObj());
				}
			}
			
		} catch (Exception e) {
			internalError(e);
		}
	}
	
	public void reloadBranches(){
		this.branches = new ArrayList<SelectableObject<LGBranch>>();
		if(user != null){
			for(LGBranch branch : DataProvider.getInstance().getBranches(this.user.getId())){
				if(!branch.isTransientDataLoaded()){
					branch.loadTransientData();
				}	
				this.branches.add(new SelectableObject<LGBranch>(branch));
			}	
		}
	}
	
	public void listenerLogout(ActionEvent event){
		this.reset();
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public VDCUser getUser() {
		return user;
	}

	public void setUser(VDCUser user) {
		this.user = user;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}	
	
	public List<SelectableObject<LGBranch>> getBranches() {
		return branches;
	}

	public void setBranches(List<SelectableObject<LGBranch>> branches) {
		this.branches = branches;
	}

	public String getCurrentSectionId() {
		return currentSectionId;
	}

	public void setCurrentSectionId(String currentSectionId) {
		this.currentSectionId = currentSectionId;
	}

	public FileCreator getFileCreator() {
		return fileCreator;
	}

	public void setFileCreator(FileCreator fileCreator) {
		this.fileCreator = fileCreator;
	}

	public BranchEditor getBranchEditor() {
		return branchEditor;
	}

	public void setBranchEditor(BranchEditor branchEditor) {
		this.branchEditor = branchEditor;
	}

	public SearchBean getSearchPage() {
		return searchPage;
	}

	public void setSearchPage(SearchBean searchPage) {
		this.searchPage = searchPage;
	}
	
	
}