Commit a32ab114 authored by Peter Harrison's avatar Peter Harrison

Task #15.

Adding methods and controller REST call to get tasks for a user. 
parent dacb363f
...@@ -22,12 +22,15 @@ ...@@ -22,12 +22,15 @@
package nz.net.orcon.kanban.controllers; package nz.net.orcon.kanban.controllers;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.jcr.Session; import javax.jcr.Session;
import nz.net.orcon.kanban.model.CardTask;
import nz.net.orcon.kanban.model.User; import nz.net.orcon.kanban.model.User;
import nz.net.orcon.kanban.tools.CardTools;
import nz.net.orcon.kanban.tools.IdentifierTools; import nz.net.orcon.kanban.tools.IdentifierTools;
import nz.net.orcon.kanban.tools.ListTools; import nz.net.orcon.kanban.tools.ListTools;
import nz.net.orcon.kanban.tools.OcmMapperFactory; import nz.net.orcon.kanban.tools.OcmMapperFactory;
...@@ -53,6 +56,9 @@ public class UserController { ...@@ -53,6 +56,9 @@ public class UserController {
@Autowired @Autowired
private ListTools listTools; private ListTools listTools;
@Autowired
CardTools cardTools;
@Resource(name="ocmFactory") @Resource(name="ocmFactory")
OcmMapperFactory ocmFactory; OcmMapperFactory ocmFactory;
...@@ -96,6 +102,19 @@ public class UserController { ...@@ -96,6 +102,19 @@ public class UserController {
return user; return user;
} }
@RequestMapping(value = "/{userId}/tasks", method=RequestMethod.GET)
public @ResponseBody List<CardTask> getUserTasks(@PathVariable String userId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
List<CardTask> taskList;
try{
taskList = cardTools.getCardTasksByUser(userId, ocm);
} finally {
ocm.logout();
}
return taskList;
}
@RequestMapping(value = "/{userId}", method=RequestMethod.DELETE) @RequestMapping(value = "/{userId}", method=RequestMethod.DELETE)
public @ResponseBody void deleteUser(@PathVariable String userId) throws Exception { public @ResponseBody void deleteUser(@PathVariable String userId) throws Exception {
Session session = ocmFactory.getOcm().getSession(); Session session = ocmFactory.getOcm().getSession();
......
...@@ -69,6 +69,11 @@ public interface CardTools { ...@@ -69,6 +69,11 @@ public interface CardTools {
String cardId, String cardId,
String taskId, String taskId,
ObjectContentManager ocm ) throws ResourceNotFoundException; ObjectContentManager ocm ) throws ResourceNotFoundException;
public List<CardTask> getCardTasksByUser(
String userId,
ObjectContentManager ocm)
throws ResourceNotFoundException;
public List<Card> getCardList( public List<Card> getCardList(
String boardId, String boardId,
......
...@@ -23,6 +23,7 @@ package nz.net.orcon.kanban.tools; ...@@ -23,6 +23,7 @@ package nz.net.orcon.kanban.tools;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -132,6 +133,28 @@ public class CardToolsImpl implements CardTools{ ...@@ -132,6 +133,28 @@ public class CardToolsImpl implements CardTools{
return cardTask; return cardTask;
} }
@Override
public List<CardTask> getCardTasksByUser(
String user,
ObjectContentManager ocm)
throws ResourceNotFoundException {
QueryManager qm = ocm.getQueryManager();
Filter filter = qm.createFilter(CardTask.class);
filter.setScope("//");
filter.addEqualTo("user", user);
filter.addEqualTo("complete", "false");
Query query = qm.createQuery(filter);
Collection objects = ocm.getObjects(query);
List<CardTask> returnList = new ArrayList<CardTask>();
for( Object object : objects){
returnList.add((CardTask)object);
}
return returnList;
}
public Map<String, Object> getFieldsForCard(Card card, public Map<String, Object> getFieldsForCard(Card card,
ObjectContentManager ocm) throws RepositoryException { ObjectContentManager ocm) throws RepositoryException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment