package org.develop.officialjournal.controllers; import java.util.Comparator; import java.util.List; import org.develop.officialjournal.services.Database; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import dao.connection.LuceneConnector; import dao.entity.DOProcess; import dao.entity.Entity; import dao.lucene.search.DAOSearch; import dao.lucene.tables.DAOProcess; @RestController public class ProcessController { private DAOSearch daoSearch; private DAOProcess daoProcess; public ProcessController() { daoSearch = Database.get().getDaoSearch(); daoProcess = Database.get().getDaoProcess(); } /**returns lawyer by id*/ @RequestMapping("/process/{id}") public DOProcess getById(@PathVariable Long id ) { DOProcess process = this.daoProcess.get(id, LuceneConnector.getSearcherDisk()); return process; } @RequestMapping("/process/{id}/all") public DOProcess getAllInfo(@PathVariable Integer id ) { if(daoProcess == null) daoProcess = Database.get().getDaoProcess(); System.out.println("DAOPROCESS " +daoProcess); DOProcess process = this.daoProcess.getAllInfo(id, LuceneConnector.getSearcherDisk()); return process; } @RequestMapping("/process/entity") public List getProcessByEntity(@RequestParam (required = true) Integer entityId, @RequestParam (required = true) String type , @RequestParam (required = false, defaultValue= "0") Integer processId ) { Entity entity = new Entity(); entity.setId(entityId); entity.setType(type); return daoSearch.search(entity); } @RequestMapping("/process/number") public List getProcessByEntity( @RequestParam (required = true) String processNumber , @RequestParam (required = false, defaultValue= "0") Integer processId ) { List searchResults = daoSearch.search(processNumber); searchResults.sort(new Comparator() { public int compare(DOProcess o1, DOProcess o2) { // TODO Auto-generated method stub return (int) (o1.getProcessDate().getTime() - o2.getProcessDate().getTime()); } }); return searchResults; } }