Commit ace183b74ee419ce38468fb5a6706faa4fa1aef5
Exists in
master
Merge branch 'tarefa-4207' into adm-1.12.0
Showing
1 changed file
with
34 additions
and
0 deletions
Show diff stats
cit-tabelas-corp-web/src/main/java/br/com/centralit/controller/ComissaoController.java
@@ -2,8 +2,11 @@ package br.com.centralit.controller; | @@ -2,8 +2,11 @@ package br.com.centralit.controller; | ||
2 | 2 | ||
3 | import java.util.List; | 3 | import java.util.List; |
4 | 4 | ||
5 | +import org.apache.commons.lang3.SerializationUtils; | ||
6 | +import org.hibernate.exception.ConstraintViolationException; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
6 | import org.springframework.stereotype.Controller; | 8 | import org.springframework.stereotype.Controller; |
9 | +import org.springframework.web.bind.annotation.RequestBody; | ||
7 | import org.springframework.web.bind.annotation.RequestMapping; | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
8 | import org.springframework.web.bind.annotation.RequestMethod; | 11 | import org.springframework.web.bind.annotation.RequestMethod; |
9 | import org.springframework.web.bind.annotation.RequestParam; | 12 | import org.springframework.web.bind.annotation.RequestParam; |
@@ -76,6 +79,37 @@ public class ComissaoController extends GenericController<Comissao> { | @@ -76,6 +79,37 @@ public class ComissaoController extends GenericController<Comissao> { | ||
76 | return responseBody; | 79 | return responseBody; |
77 | } | 80 | } |
78 | 81 | ||
82 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
83 | + @ResponseBody | ||
84 | + public ResponseBodyWrapper save(@RequestBody Comissao entity) throws Exception{ | ||
85 | + boolean uniqueConstraintViolate = true; | ||
86 | + | ||
87 | + Comissao comissao = new Comissao(); | ||
88 | + | ||
89 | + //TODO Solução temporária para evitar que sejam criados registros com o código duplicado. Alterar solução quando for implementado o cache compartilhado | ||
90 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
91 | + try{ | ||
92 | + comissao = this.comissaoService.save(SerializationUtils.clone(entity)); | ||
93 | + uniqueConstraintViolate = false; | ||
94 | + }catch(Throwable e){ | ||
95 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
96 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
97 | + if(ex.getSQLException().getMessage().contains("codigo_unico_comissao")){ | ||
98 | + uniqueConstraintViolate = true; | ||
99 | + }else{ | ||
100 | + throw e; | ||
101 | + } | ||
102 | + }else{ | ||
103 | + throw e; | ||
104 | + } | ||
105 | + } | ||
106 | + } | ||
107 | + | ||
108 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(comissao, getEditView()); | ||
109 | + | ||
110 | + return responseBody; | ||
111 | + } | ||
112 | + | ||
79 | /** | 113 | /** |
80 | * Método responsável por listar <code>Comissao</code> por nome e <code>Organizacao</code> e <code>Dominio</code> | 114 | * Método responsável por listar <code>Comissao</code> por nome e <code>Organizacao</code> e <code>Dominio</code> |
81 | * | 115 | * |