package com.translationdata.messenger.resources;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.translationdata.messenger.model.Message;
import com.translationdata.messenger.service.MessageService;

// Maps to http://localhost:8080/Messenger/webapi/messages, case sensitive application name.
@Path("/messages")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class MessageResource {
	MessageService messageService = new MessageService();
	// Uncomment the JSON support, <artifactId>jersey-media-moxy</artifactId>, in the pom.xml to get JSON support working...
	@GET
	public List<Message> getMessages(@QueryParam("year") int year, 
									 @QueryParam("start") int start, 
									 @QueryParam("size") int size ) {
		if(year > 0) {
			return messageService.getAllMessagesForYear(year);
		}
		if(start > 0 && size > 0) {
			return messageService.getAllMessagesPaginated(start, size);
		}
		return messageService.getAllMessages();
	}
	
	@POST
	public Message postMessage(Message message) {
		return messageService.addMessage(message);
	}
	
	@PUT
	@Path("/{messageId}")
	public Message updateMessage(@PathParam("messageId") long id, 
								 Message message) {
		message.setId(id);
		return messageService.updateMessage(message);
	}
	
	@GET
	@Path("/{messageId}")
	// Jersey will cast the String to long...
	public Message getMessage(@PathParam("messageId") long id) {
		return messageService.getMessage(id);
	}
	
	@DELETE
	@Path("/{messageId}")
	public void deleteMessage(@PathParam("messageId") long id) {
		messageService.removeMessage(id);
	}
}

@@ -67,16 +67,46 @@
 .List;%0A%0A
+import javax.ws.rs.BeanParam;%0A
 import j
@@ -429,16 +429,88 @@
 essage;%0A
+import com.translationdata.messenger.resources.beans.MessageFilterBean;%0A
 import c
@@ -1004,133 +1004,76 @@
 es(@
-QueryParam(%22year%22) int year, %0A%09%09%09%09%09%09%09%09%09 @QueryParam(%22start%22) int start, %0A%09%09%09%09%09%09%09%09%09 @QueryParam(%22size%22) int size ) %7B%0A%09%09if(y
+BeanParam MessageFilterBean filterBean ) %7B%0A%09%09if(filterBean.getY
 ear
+()
  %3E 0
@@ -1127,12 +1127,28 @@
 ear(
-y
+filterBean.getY
 ear
+()
 );%0A%09
@@ -1159,21 +1159,37 @@
 %09if(
-s
+filterBean.getS
 tart
+()
  %3E 0 && 
 size
@@ -1184,20 +1184,36 @@
  %3E 0 && 
-s
+filterBean.getS
 ize
+()
  %3E 0) %7B%0A
@@ -1265,19 +1265,51 @@
 ted(
-start, s
+filterBean.getStart(), filterBean.getS
 ize
+()
 );%0A%09

Add @BeanParam function