package org.owasp.appsensor.handler.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.GregorianCalendar;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.owasp.appsensor.Attack;
import org.owasp.appsensor.Event;
import org.owasp.appsensor.RequestHandler;
import org.owasp.appsensor.Response;
import org.owasp.appsensor.ServerObjectFactory;

/**
 * This is the restful endpoint that handles requests on the server-side. 
 * 
 * @author John Melton (jtmelton@gmail.com) http://www.jtmelton.com/
 */
@Path("/api/v1.0")
@Produces("application/json")
public class RestRequestHandler implements RequestHandler {

	//TODO: add rest server-side handlers here 
	
	@Override
	@POST
	@Path("/events")
	public void addEvent(Event event) {
		ServerObjectFactory.getEventStore().addEvent(event);
	}

	@Override
	@POST
	@Path("/attacks")
	public void addAttack(Attack attack) {
		ServerObjectFactory.getAttackStore().addAttack(attack);
	}

	@Override
	@GET
	@Path("/responses")
	@Produces(MediaType.APPLICATION_JSON)
	public Collection<Response> getResponses(@QueryParam("detectionSystemId") String detectionSystemId, @QueryParam("earliest") long earliest) {
		Collection<Response> responses = new ArrayList<Response>();
		
		Response response1 = new Response();
		response1.setAction("log");
		response1.setDetectionSystemId("server1");
		response1.setTimestamp(new GregorianCalendar().getTimeInMillis() - 30);
		responses.add(response1);
		
		Response response2 = new Response();
		response2.setAction("logout");
		response2.setDetectionSystemId("server2");
		response2.setTimestamp(new GregorianCalendar().getTimeInMillis() - 15);
		responses.add(response2);
		
		Response response3 = new Response();
		response3.setAction("disable");
		response3.setDetectionSystemId("server2");
		response3.setTimestamp(new GregorianCalendar().getTimeInMillis() + 10);
		responses.add(response3);
		
		return responses;
//		return ServerObjectFactory.getResponseStore().findResponses(detectionSystemId, earliest);
	}
}

@@ -57,82 +57,18 @@
 til.
-ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.GregorianCalendar
+Collection
 ;%0A%0Ai
@@ -706,52 +706,33 @@
 %0A%0A%09/
-/TODO: add rest server-side handlers here %0A%09
+**%0A%09 * %7B@inheritDoc%7D%0A%09 */
 %0A%09@O
@@ -856,24 +856,52 @@
 event);%0A%09%7D%0A%0A
+%09/**%0A%09 * %7B@inheritDoc%7D%0A%09 */%0A
 %09@Override%0A%09
@@ -1027,16 +1027,44 @@
 k);%0A%09%7D%0A%0A
+%09/**%0A%09 * %7B@inheritDoc%7D%0A%09 */%0A
 %09@Overri
@@ -1278,759 +1278,8 @@
 ) %7B%0A
-%09%09Collection%3CResponse%3E responses = new ArrayList%3CResponse%3E();%0A%09%09%0A%09%09Response response1 = new Response();%0A%09%09response1.setAction(%22log%22);%0A%09%09response1.setDetectionSystemId(%22server1%22);%0A%09%09response1.setTimestamp(new GregorianCalendar().getTimeInMillis() - 30);%0A%09%09responses.add(response1);%0A%09%09%0A%09%09Response response2 = new Response();%0A%09%09response2.setAction(%22logout%22);%0A%09%09response2.setDetectionSystemId(%22server2%22);%0A%09%09response2.setTimestamp(new GregorianCalendar().getTimeInMillis() - 15);%0A%09%09responses.add(response2);%0A%09%09%0A%09%09Response response3 = new Response();%0A%09%09response3.setAction(%22disable%22);%0A%09%09response3.setDetectionSystemId(%22server2%22);%0A%09%09response3.setTimestamp(new GregorianCalendar().getTimeInMillis() + 10);%0A%09%09responses.add(response3);%0A%09%09%0A%09%09return responses;%0A//
 %09%09re

Clean up class - moving hardcoded results to mock objects - and adding javadoc.