No Description

SearchController.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package org.develop.officialjournal.controllers;
  2. import java.util.List;
  3. import org.develop.officialjournal.services.Database;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import dao.DAOEntity;
  8. import dao.DAOJudge;
  9. import dao.DAOLawyer;
  10. import dao.DAOSearch;
  11. import entity.Entity;
  12. import entity.Info;
  13. import entity.Judge;
  14. import entity.Lawyer;
  15. @RestController
  16. public class SearchController {
  17. private DAOLawyer daoLawyer;
  18. private DAOJudge daoJudge;
  19. private DAOEntity daoEntity;
  20. private DAOSearch daoSearch;
  21. public SearchController() {
  22. daoLawyer = Database.get().getDaoLawyer();
  23. daoJudge = Database.get().getDaoJudge();
  24. daoEntity = Database.get().getDaoEntity();
  25. daoSearch = Database.get().getDaoSearch();
  26. }
  27. /**returns lawyer by id*/
  28. @RequestMapping("/search/autocomplete")
  29. public List<Entity> autoComplete(@RequestParam String text ) {
  30. return daoSearch.autoComplete(text);
  31. }
  32. /**returns lawyer by id*/
  33. @RequestMapping("/search")
  34. public Entity getEntity(@RequestParam String text ) {
  35. Lawyer lawyer = new Lawyer(text);
  36. Judge judge = new Judge(text);
  37. Entity entity = new Entity();
  38. entity.setName(text);
  39. if(daoLawyer.contains(lawyer))
  40. {
  41. lawyer = daoLawyer.get(lawyer);
  42. return lawyer;
  43. }
  44. if(daoJudge.contains(judge))
  45. {
  46. judge = daoJudge.get(judge);
  47. return judge;
  48. }
  49. if(daoEntity.contains(entity))
  50. {
  51. entity = daoEntity.get(entity);
  52. return entity;
  53. }
  54. return new Entity();
  55. }
  56. @RequestMapping("/search/info")
  57. public Info getEntityInfo(@RequestParam String type, @RequestParam Integer entityId ) {
  58. return daoSearch.getInfo(type, entityId);
  59. }
  60. }