package com.linstid.energydashws.rest;

import java.util.Date;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import com.linstid.energydashws.entities.HoursEntity;
import com.linstid.energydashws.persistence.MongodbPersistence;

import org.jboss.logging.Logger;

@Path("/hours")
public class Hours {
	@Context
	private UriInfo context;

	private Logger logger;
	
	public Hours() {
		this.logger = Logger.getLogger(this.getClass());
	}

	@GET
	@Path("/{start}&{end}")
	@Produces(MediaType.APPLICATION_JSON)
	public List<HoursEntity> getHoursRange(@PathParam("start") String start, @PathParam("end") String end) {
		logger.info("getting hours for " + start + " --> " + end);
		
		Date startDate = new Date();
		Date endDate = new Date();
		
		try {
			startDate.setTime(Long.parseLong(start) * 1000);
		} catch (NumberFormatException e) {
			logger.error("Failed to parse start date of " + start + ": " + e);
		}
		try {
			endDate.setTime(Long.parseLong(end) * 1000);
		} catch (NumberFormatException e) {
			logger.error("Failed to parse end date of " + end + ": " + e);
		}
		
		MongodbPersistence db = new MongodbPersistence();
		return db.getRangeOfHours(startDate, endDate);
	}

}

@@ -188,16 +188,60 @@
 oduces;%0A
+import javax.ws.rs.WebApplicationException;%0A
 import j
@@ -300,16 +300,50 @@
 iaType;%0A
+import javax.ws.rs.core.Response;%0A
 import j
@@ -1094,37 +1094,37 @@
 ion e) %7B%0A%09%09%09
-logger.error(
+String err = 
 %22Failed to p
@@ -1154,32 +1154,120 @@
 start + %22: %22 + e
+;%0A%09%09%09logger.error(err);%0A%09%09%09throw new WebApplicationException(Response.Status.BAD_REQUEST
 );%0A%09%09%7D%0A%09%09try %7B%0A%09
@@ -1354,29 +1354,29 @@
 e) %7B%0A%09%09%09
-logger.error(
+String err = 
 %22Failed 
@@ -1414,16 +1414,104 @@
 %22: %22 + e
+;%0A%09%09%09logger.error(err);%0A%09%09%09throw new WebApplicationException(Response.Status.BAD_REQUEST
 );%0A%09%09%7D%0A%09

Add some extra error handling for invalid input.