package com.etherios.gae.connector.tank;

import java.io.IOException;

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

import com.etherios.gae.connector.tank.datastore.UserData;

@SuppressWarnings("serial")
public class TankServlet extends BaseServlet {
	// Constants.
	public static final String MAC_PATTERN = "([0-9a-fA-F]{2}:){7}[0-9a-fA-F]{2}";
	
	/*
	 * (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {
		clearErrorMessage();
		
		UserData user = getUserFromSession(req);
		if (user == null) {
			req.setAttribute("error", errorMessage);
			loginDispatcher.forward(req, resp);
			return;
		}
		
		if (user.getSelectedDevice() == null) {
			req.setAttribute("error", "You need to select and save a device first.");
			devicesDispatcher.forward(req, resp);
			return;
		}
		
		tanksDispatcher.forward(req, resp);
	}
}
