Guest User

Untitled

a guest
Nov 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.31 KB | None | 0 0
  1. Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to fr.alteca.outilindicateurs.entityRedmine.Issues
  2. at fr.alteca.outilindicateurs.controller.IssuesRESTController.init(IssuesRESTController.java:68)
  3. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  4. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  5. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  6. at java.lang.reflect.Method.invoke(Method.java:498)
  7. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365)
  8. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:310)
  9. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
  10. ... 44 more
  11.  
  12. SELECT issues.id,
  13. max(CASE WHEN custom_fields.name='Date de résolution'
  14. THEN custom_values.value
  15. ELSE '-'
  16. END) AS date_resolution ,
  17. max(CASE WHEN custom_fields.name='Date d'ouverture'
  18. THEN custom_values.value
  19. ELSE '-'
  20. END ) AS date_ouverture
  21. FROM redmine_tma_ibp.issues
  22. join custom_values
  23. on issues.id = custom_values.customized_id
  24. join custom_fields
  25. on custom_values.custom_field_id = custom_fields.id
  26. join enumerations
  27. on enumerations.id=issues.priority_id
  28.  
  29. where (enumerations.type="IssuePriority" and (enumerations.position=1 or enumerations.position=2))
  30. and (status_id=3 or status_id=5)
  31. and (custom_fields.name = "Date d'ouverture" or custom_fields.name="Date de résolution")
  32. and str_to_date(custom_values.value, '%d/%m/%Y %H:%i') > date('2016-01-01')
  33. group by issues.id
  34.  
  35. public static String GET_RECORDS_FOR_M1 =
  36. "Select i, max(case when cf.name=:date_denom then cv.value else null end) as date_ouverture FROM Issues i, CustomValues cv, CustomFields cf, Enumerations e "
  37. + "join fetch i.values "
  38. + "where i.id=cv.issue "
  39. + "and cv.customFields=cf.id "
  40. + "and e.id=i.priority "
  41. + "and (e.type=:priority and (e.position=:position1 or e.position=:position2)) "
  42. + "and (i.issueStatus.id=:status1 or i.issueStatus.id=:status2) "
  43. + "and cf.name = :date_denom "
  44. + "and str_to_date(cv.value, :date_format) > date(:date_ouverture)"
  45. + "and i.projects.name=:pole "
  46. //+ "and :value member of i.values "
  47. + "group by i.id";
  48.  
  49. @RestController
  50. @RequestMapping("/issues")
  51. public class IssuesRESTController extends GenericRestController<Issues> {
  52.  
  53. private List<Issues> listeM1;
  54. private List<Issues> trashBin;
  55.  
  56. @Autowired
  57. IssuesRepository issuesRepository;
  58.  
  59. @Autowired
  60. DataM1Repository dataM1Repository;
  61.  
  62. @Autowired
  63. AuteurRepository auteurRepository;
  64.  
  65. @Autowired
  66. PoleRepository poleRepository;
  67.  
  68. @Autowired
  69. public IssuesRESTController(IssuesRepository repository, DataM1Repository dataM1Repository, AuteurRepository auteurRepository, PoleRepository poleRepository) {
  70. super(repository);
  71. }
  72.  
  73. @PostConstruct
  74. public void init() {
  75. Param.poles=new HashMap<>();
  76. int i=0;
  77. for(String s : issuesRepository.getPolesNames()) {
  78. Param.poles.put(i, s);
  79. i++;
  80. }
  81. listeM1= new ArrayList<>();
  82. trashBin = new ArrayList<>();
  83. listeM1 = issuesRepository.getM1Issues();
  84. System.out.println(listeM1.size()+" Enregistrements récupérés dans la variable listeM1");
  85.  
  86. /**
  87. * On regarde si les tuples remontés sont déjà présent dans la base,
  88. * si oui, on les enlève de la liste à traiter.
  89. */
  90.  
  91. System.out.println(listeM1.get(0).toString());
  92.  
  93. for(Issues issue : listeM1) {
  94. for(DataM1 d : dataM1Repository.list()) {
  95.  
  96. if(issue.getId()==d.getId_ticket()) {
  97. System.out.println("Ticket trouvé correspondant au tuple"+issue + "n suppression du tuple de la liste à traiter");
  98. trashBin.add(issue);
  99. };
  100. }
  101. }
  102.  
  103. for (Issues issue : trashBin) { // on évite java-util concurrentmodificationexception
  104. listeM1.remove(issue);
  105. }
  106. trashBin.clear();
  107.  
  108. /**
  109. * On crée les tickets manquants, les poles et les auteurs suivant le besoin
  110. */
  111. for(Issues issue : listeM1) {
  112.  
  113. System.out.println("Création dans la table outil des tickets manquants");
  114.  
  115. DataM1 ticket = new DataM1();
  116. ticket.setId(Integer.SIZE);
  117. ticket.setId_ticket(issue.getId());
  118.  
  119. System.out.println("*********n Ticket : "+issue.getId()+"n**********");
  120. System.out.println("Recherche l'auteur "+ issue.getAuthor().getLastname()+" "+issue.getAuthor().getFirstname()+" dans la base ...");
  121. System.out.println(issue.getValues());
  122.  
  123. try {
  124. Auteur a = auteurRepository.findbyName(issue.getAuthor().getLastname(), issue.getAuthor().getFirstname());
  125. System.out.println("Auteur trouvé :"+a.getNom() + " "+a.getPrenom());
  126. ticket.setAuteur(a);
  127.  
  128. }catch(NullPointerException e){
  129. System.out.println("Cet auteur n'est pas en base .. création ...");
  130. ticket.setAuteur(new Auteur(issue.getAuthor().getLastname(), issue.getAuthor().getFirstname()));
  131. }
  132.  
  133. System.out.println("Recherche du pole "+issue.getProjects().getName()+" dans la base ...");
  134.  
  135. try {
  136. Pole p = poleRepository.findbyName(issue.getProjects().getName());
  137. System.out.println("Pole trouvé : "+p.getNom_pole());
  138. ticket.setPole(p);
  139. }catch(NullPointerException e) {
  140. System.out.println("Ce pole n'est pas en base... création...");
  141. ticket.setPole(new Pole(issue.getProjects().getName()));
  142. }
  143.  
  144.  
  145. System.out.println("Création du ticket...");
  146. dataM1Repository.create(ticket);
  147. System.out.println("Ticket crée");
  148.  
  149.  
  150. }
  151.  
  152. }
  153.  
  154. @Override
  155. @RequestMapping("/all")
  156. public ResponseEntity<List<Issues>> list(){
  157. List<Issues> list = issuesRepository.getAll();
  158. return new ResponseEntity<List<Issues>> (list, HttpStatus.OK);
  159. }
  160.  
  161. @RequestMapping("/M1/list")
  162. public ResponseEntity<List<Issues>> listM1(){
  163. List<Issues> list = issuesRepository.getM1Issues();
  164. return new ResponseEntity<List<Issues>> (list, HttpStatus.OK);
  165. }
  166.  
  167. @RequestMapping("/M1/count")
  168. public ResponseEntity<Long> countM1(){
  169. Long nbIssues = issuesRepository.countM1Issues();
  170. return new ResponseEntity<Long>(nbIssues, HttpStatus.OK);
  171. }
  172.  
  173. @RequestMapping("/M1/poles") // recherche la liste des poles dans la base
  174. public ResponseEntity<List<String>> getPolesNames(){
  175. List<String> poles = issuesRepository.getPolesNames();
  176. return new ResponseEntity<List<String>>(poles, HttpStatus.OK);
  177. }
  178.  
  179. @RequestMapping("/M1/pole")
  180. public ResponseEntity<List<Issues>> getPoleByName(@RequestParam(value="pole") int polekey){
  181. List<Issues> poles = issuesRepository.getPoleByName(polekey);
  182.  
  183.  
  184.  
  185. return new ResponseEntity<List<Issues>>(poles, HttpStatus.OK);
  186. }
  187.  
  188. @RequestMapping("/M1/pole/count")
  189. public ResponseEntity<Long> countPoleByName(@RequestParam(value="pole") int polekey){
  190. Long poles = issuesRepository.CountPoleByName(polekey);
  191. return new ResponseEntity<Long>(poles, HttpStatus.OK);
  192. }
  193.  
  194. @RequestMapping("/M1/pole/count/all")
  195. public ResponseEntity<HashMap<String, Long>> getAllInformationOnPoles(){
  196. HashMap<String, Long> tabl = new HashMap<>();
  197. int i=0;
  198. for(String s :issuesRepository.getPolesNames()) {
  199. tabl.put(Param.poles.get(i), issuesRepository.CountPoleByName(i));
  200. i++;
  201. }
  202.  
  203. return new ResponseEntity<HashMap<String, Long>>(tabl, HttpStatus.OK);
  204. }
  205.  
  206. @RequestMapping("/M1/pole/count/red")
  207. public ResponseEntity<HashMap<String, Long>> getAllRedInformationOnPoles(){
  208. HashMap<String, Long> tabl = new HashMap<>();
  209. int i=0;
  210. for(String s :issuesRepository.getPolesNames()) {
  211. tabl.put(Param.poles.get(i), issuesRepository.CountRedPoleByName(i));
  212. i++;
  213. }
  214.  
  215. return new ResponseEntity<HashMap<String, Long>>(tabl, HttpStatus.OK);
  216. }
  217.  
  218.  
  219. @RequestMapping("/test/issue")
  220. public ResponseEntity<Issues> listIssueFields(@RequestParam(value="issue") int id_issue){
  221. Issues list = issuesRepository.getIssueById(id_issue);
  222. return new ResponseEntity<Issues>(list, HttpStatus.OK);
  223. }
  224.  
  225.  
  226. }
  227.  
  228. @Entity
  229. @Table(name = "issues")
  230. public class Issues {
  231.  
  232. public Issues() {}
  233.  
  234. /*
  235. * Primary key
  236. */
  237. @Id
  238. @Column(name = "id", unique = true, nullable = false)
  239. private int id;
  240.  
  241. /*
  242. * Foreign keys
  243. */
  244.  
  245. @JoinColumn(name = "project_id")
  246. @ManyToOne(targetEntity = Projects.class)
  247. private Projects projects;
  248.  
  249. @JoinColumn(name = "status_id")
  250. @ManyToOne(targetEntity = IssueStatuses.class)
  251. private IssueStatuses issueStatus;
  252.  
  253. @JoinColumn(name = "author_id", referencedColumnName = "id")
  254. @ManyToOne(targetEntity = Users.class)
  255. private Users author;
  256.  
  257. @JoinColumn(name = "priority_id")
  258. @ManyToOne(targetEntity = Enumerations.class)
  259. private Enumerations priority;
  260.  
  261.  
  262. /*
  263. * Fields
  264. */
  265. @Column(name = "subject", nullable = false)
  266. private String subject;
  267.  
  268. @Column(name = "description", nullable = true)
  269. private String description;
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. @OneToMany(mappedBy = "issue", targetEntity = CustomValues.class, fetch = FetchType.LAZY)
  277. private List<CustomValues> values;
  278.  
  279. @Transient
  280. private Map<CustomFields, String> mapValeurs;
  281.  
  282. @Transient
  283. private IssueStatuses status;
  284.  
  285. //getters & setters
Add Comment
Please, Sign In to add comment