PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/org.itbelts.domain/src/main/java/org/itbelts/dao/mongolab/TodoDAOImpl.java

https://bitbucket.org/itbelts/itbelts
Java | 82 lines | 49 code | 20 blank | 13 comment | 2 complexity | 41e89096a1eaf0e8fcbc75476da2ab7a MD5 | raw file
  1. package org.itbelts.dao.mongolab;
  2. import java.lang.reflect.Type;
  3. import java.net.URL;
  4. import java.util.List;
  5. import org.itbelts.dao.ITodoDAO;
  6. import org.itbelts.domain.Todo;
  7. import com.google.gson.reflect.TypeToken;
  8. /**
  9. * MongoDB implementation for the ITodoDAO. <br>
  10. * <br>
  11. * <u><i>Version History</i></u>
  12. *
  13. * <pre>
  14. * v2013.12.0 16-nov.-2013 - DKBR813 - initial release
  15. *
  16. * </pre>
  17. *
  18. * @version v2013.12.0 16-nov.-2013
  19. * @author <a href=\"mailto:koenbruyndonckx@gmail.com\"> Koen Bruyndonckx </a>
  20. */
  21. public class TodoDAOImpl extends AbstractMongoLabDAO implements ITodoDAO {
  22. private static final String PATH = "collections/todos";
  23. @Override
  24. public Todo saveTodo( Todo aTodo ) {
  25. sendTo( buildUrl( PATH ), aTodo );
  26. return aTodo;
  27. }
  28. @Override
  29. public List<Todo> getTodosForTopic( String aTopicId ) {
  30. URL url = buildUrl( PATH, "q={\"topicId\":\"" + aTopicId + "\"}" );
  31. Type theListType = new TypeToken<List<Todo>>(){}.getType();
  32. return readFrom( url, theListType );
  33. }
  34. @Override
  35. public List<Todo> getTodosForCourse( String aCourseId ) {
  36. URL url = buildUrl( PATH, "q={\"courseId\":\"" + aCourseId + "\"}" );
  37. Type theListType = new TypeToken<List<Todo>>(){}.getType();
  38. return readFrom( url, theListType );
  39. }
  40. @Override
  41. public List<Todo> getTodosForExam( String anExamId ) {
  42. URL url = buildUrl( PATH, "q={\"examId\":\"" + anExamId + "\"}" );
  43. Type theListType = new TypeToken<List<Todo>>(){}.getType();
  44. return readFrom( url, theListType );
  45. }
  46. @Override
  47. public Todo getTodo( String aTodoId ) {
  48. URL url = buildUrl( PATH, "q={\"_id\":\"" + aTodoId + "\"}" );
  49. Type theListType = new TypeToken<List<Todo>>(){}.getType();
  50. List<Todo> theList = readFrom( url, theListType );
  51. if ( theList.size() == 0 ) {
  52. return null;
  53. }
  54. return theList.get( 0 );
  55. }
  56. @Override
  57. public List<Todo> getTodos() {
  58. URL url = buildUrl( PATH );
  59. Type theListType = new TypeToken<List<Todo>>(){}.getType();
  60. return readFrom( url, theListType );
  61. }
  62. }