PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/itbelts/itbelts
Java | 63 lines | 38 code | 13 blank | 12 comment | 2 complexity | fce7e4fbe1eef1cfc43fade5ec96ab9c 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.ITopicDAO;
  6. import org.itbelts.domain.Topic;
  7. import com.google.gson.reflect.TypeToken;
  8. /**
  9. * MongoDB implementation for the ITopicDAO.
  10. * <br><br>
  11. * <u><i>Version History</i></u>
  12. * <pre>
  13. * v2013.10.0 20-okt.-2013 - DKBR813 - initial release
  14. *
  15. * </pre>
  16. *
  17. * @version v2013.10.0 20-okt.-2013
  18. * @author <a href=\"mailto:koenbruyndonckx@gmail.com\"> Koen Bruyndonckx </a>
  19. */
  20. public class TopicDAOImpl extends AbstractMongoLabDAO implements ITopicDAO {
  21. private static final String PATH = "collections/topics";
  22. @Override
  23. public List<Topic> getTopics() {
  24. URL url = buildUrl( PATH );
  25. Type theListType = new TypeToken<List<Topic>>(){}.getType();
  26. return readFrom( url, theListType );
  27. }
  28. @Override
  29. public List<Topic> getTopicsForSpecialty( String aSpecialtyId ) {
  30. URL url = buildUrl( PATH, "q={\"specialtyId\":\"" + aSpecialtyId + "\"}" );
  31. Type theListType = new TypeToken<List<Topic>>(){}.getType();
  32. return readFrom( url, theListType );
  33. }
  34. @Override
  35. public List<Topic> getTopicsForCommunity( String aCommunityId ) {
  36. URL url = buildUrl( PATH, "q={\"specialtyId\":{$regex:\"^" + aCommunityId + ".*\"}}" );
  37. Type theListType = new TypeToken<List<Topic>>(){}.getType();
  38. return readFrom( url, theListType );
  39. }
  40. @Override
  41. public Topic getTopic( String aTopicId ) {
  42. URL url = buildUrl( PATH, "q={\"_id\":\"" + aTopicId + "\"}}" );
  43. Type theListType = new TypeToken<List<Topic>>(){}.getType();
  44. List<Topic> theList = readFrom( url, theListType );
  45. if ( theList == null ) {
  46. return null;
  47. }
  48. return theList.get( 0 );
  49. }
  50. }