package dk.statsbiblioteket.newpaper.processmonitor.backend;

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

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/")
public class Batches {

    private List<Batch> dummyBatches; 
    
    public Batches() {
        Event e1 = new Event();
        e1.setEventID("foo");
        e1.setSuccess(true);
        
        Event e2 = new Event();
        e2.setEventID("bar");
        e2.setSuccess(false);
        
        Event e3 = new Event();
        e3.setEventID("baz");
        e3.setSuccess(true);
        List<Event> b1Events = new ArrayList<Event>();
        b1Events.add(e1);
        b1Events.add(e2);
        b1Events.add(e3);
        
        Batch b1 = new Batch();
        b1.setBatchID("hans");
        
        Event e4 = new Event();
        e4.setEventID("foo");
        e4.setSuccess(true);
        
        Event e5 = new Event();
        e5.setEventID("bar");
        e5.setSuccess(false);
        
        Event e6 = new Event();
        e6.setEventID("baz");
        e6.setSuccess(false);
        
        List<Event> b2Events = new ArrayList<Event>();
        b2Events.add(e4);
        b2Events.add(e5);
        b2Events.add(e6);
        
        Batch b2 = new Batch();
        b2.setBatchID("bjarne");
        
        dummyBatches = new ArrayList<Batch>();
        dummyBatches.add(b1);
        dummyBatches.add(b2);
    } 
    
    
    @GET
    @Path("/")
    public List<Batch> getBatches() {
        return dummyBatches;
    }
    
    @GET
    @Path("{batchID}")
    public Batch getSpecificBatch(@PathParam("batchID") String batchID) {
        Batch batch = null;
        for(Batch b : dummyBatches) {
            if(b.getBatchID().equals(batchID)) {
                batch = b;
            }
        }
        return batch;
    }
    
    @GET
    @Path("{batchID}/{eventID}")
    public Event getSpecificBatchEvent(@PathParam("batchID") String batchID, @PathParam("eventID") String eventID) {
        Event event = null;
        for(Batch b : dummyBatches) {
            if(b.getBatchID().equals(batchID)) {
                for(Event e : b.getEvents()) {
                    if(e.getEventID().equals(eventID)) {
                        event = e;
                    }
                }
            }
        }       
        return event;
    }
    

}

@@ -107,16 +107,49 @@
 .List;%0A%0A
+import javax.ws.rs.DefaultValue;%0A
 import j
@@ -218,16 +218,248 @@
 thParam;
+%0Aimport javax.ws.rs.Produces;%0Aimport javax.ws.rs.QueryParam;%0Aimport javax.ws.rs.core.MediaType;%0A%0A%0A/**%0A * Service class to expose retrieval of Batch (@see Batch) and Events (@see Event) objects for monitoring progress and state  %0A */
 %0A%0A@Path(
@@ -1705,456 +1705,1503 @@
     
-%0A    @GET%0A    @Path(%22/%22)%0A    public List%3CBatch%3E getBatches() %7B%0A        return dummyBatches;%0A    %7D%0A    %0A    @GET%0A    @Path(%22%7BbatchID%7D%22)%0A    public Batch getSpecificBatch(@PathParam(%22batchID%22) String batchID) %7B%0A        Batch batch = null;%0A        for(Batch b : dummyBatches) %7B%0A            if(b.getBatchID().equals(batchID)) %7B%0A                batch = b;%0A            %7D%0A        %7D%0A        return batch;%0A    %7D%0A    %0A    @GET%0A    @Path(%22%7BbatchID%7D/%7BeventID%7D%22
+/**%0A     * Retrieves a list of all known Batch objects (@see Batch).%0A     * @param details If true, will also include the available details for each event in the Batch objects. Defaults to false.%0A     * @return List%3CBatch%3E as JSON data.   %0A     */%0A    @GET%0A    @Path(%22/%22)%0A    @Produces(MediaType.APPLICATION_JSON)%0A    public List%3CBatch%3E getBatches(@QueryParam(%22details%22) @DefaultValue(%22false%22) boolean details) %7B%0A        return dummyBatches;%0A    %7D%0A    %0A    /**%0A     * Retrieves a specific batch given it's ID. %0A     * @param batchID The ID of the specific batch%0A     * @param details If true, will also include the available details for each event in the Batch. Defaults to false.%0A     * @return Batch as JSON Object%0A     */%0A    @GET%0A    @Path(%22%7BbatchID%7D%22)%0A    @Produces(MediaType.APPLICATION_JSON)%0A    public Batch getSpecificBatch(@PathParam(%22batchID%22) String batchID, %0A            @QueryParam(%22details%22) @DefaultValue(%22false%22) boolean details) %7B%0A        Batch batch = null;%0A        for(Batch b : dummyBatches) %7B%0A            if(b.getBatchID().equals(batchID)) %7B%0A                batch = b;%0A            %7D%0A        %7D%0A        return batch;%0A    %7D%0A    %0A    /**%0A     * Retrieves a specific Event for a specific Batch.%0A     * @param batchID The ID of the specific batch%0A     * @param eventID The ID of the specific event%0A     * @param details If true, will also include the available details. Defaults to false.%0A     */%0A    @GET%0A    @Path(%22%7BbatchID%7D/%7BeventID%7D%22)%0A    @Produces(MediaType.APPLICATION_JSON
 )%0A  
@@ -3311,16 +3311,92 @@
  eventID
+, %0A            @QueryParam(%22details%22) @DefaultValue(%22false%22) boolean details
 ) %7B%0A    

Add javadoc for rest service, add details query param to methods (default to false)