view src/main/java/de/mpiwg/web/jsp/HomePage.java @ 31:c8d367a4bbcd

new: user updates label in branch
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 24 Sep 2015 13:35:39 +0200
parents 3b3e2963c8f7
children 74fe1518bc5c
line wrap: on
line source

package de.mpiwg.web.jsp;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;




import de.mpiwg.gazetteer.bo.LGBranch;
import de.mpiwg.gazetteer.utils.DataProvider;

public class HomePage  extends AbstractJSPPage{
	
	private static Logger logger = Logger.getLogger(HomePage.class);
	
	public static String bean = "homeBean";
	public static String page = "pages/home.jsp";
	
	
	private List<LGBranch> branches;
	private Long branchId;
	
	
	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
		this.request = request;
		this.response = response;
		
		this.branchId = getLongParameter("branchId");
	}
	
	public void reloadBranches(){
		
		logger.debug("reloadBranches");
		
		this.branches = new ArrayList<LGBranch>();
		if(getSessionBean().getUser() != null){
			for(LGBranch branch : DataProvider.getInstance().getBranches(getSessionBean().getUser().getId())){
				branch.loadTransientData();
				// section of this branch may be deleted. In this case, we don't add the branch to branches list
				// TODO might let user to delete the branch?
				if (branch.isEmpty()) {
					logger.debug("section of the branch doesn't exist anymore.");
				} else {
					this.branches.add(branch);
				}
			}	
		}
	}
	
	public void deleteBranch(){
		
		logger.debug("deleteBranch " + branchId);
		
		if(branchId != null){
			LGBranch branch = DataProvider.getInstance().getBranch(branchId);
			if(branch != null){
				DataProvider.getInstance().deleteBranch(branch);
				this.reloadBranches();
			}	
		}
	}
	
	public List<LGBranch> getBranches() {
		return branches;
	}


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

	public Long getBranchId() {
		return branchId;
	}

	public void setBranchId(Long branchId) {
		this.branchId = branchId;
	}	
}