Commit bfc2ddfcff0101d9d6add7c4752381ed51f9a2a5
1 parent
82308a03
Exists in
master
Redmine #4207
Showing
9 changed files
with
218 additions
and
18 deletions
Show diff stats
citgrp-patrimonio-api/src/main/java/br/com/centralit/api/model/SaidaTemporaria.java
1 | package br.com.centralit.api.model; | 1 | package br.com.centralit.api.model; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
3 | import java.util.Calendar; | 4 | import java.util.Calendar; |
4 | import java.util.Collection; | 5 | import java.util.Collection; |
5 | 6 | ||
@@ -17,6 +18,7 @@ import javax.persistence.Temporal; | @@ -17,6 +18,7 @@ import javax.persistence.Temporal; | ||
17 | import javax.persistence.TemporalType; | 18 | import javax.persistence.TemporalType; |
18 | import javax.persistence.UniqueConstraint; | 19 | import javax.persistence.UniqueConstraint; |
19 | 20 | ||
21 | +import org.apache.commons.beanutils.BeanUtilsBean2; | ||
20 | import org.hibernate.envers.Audited; | 22 | import org.hibernate.envers.Audited; |
21 | import org.hibernate.envers.NotAudited; | 23 | import org.hibernate.envers.NotAudited; |
22 | 24 | ||
@@ -406,5 +408,15 @@ public class SaidaTemporaria extends PersistentObjectAuditOrganizacao { | @@ -406,5 +408,15 @@ public class SaidaTemporaria extends PersistentObjectAuditOrganizacao { | ||
406 | 408 | ||
407 | this.saidaTemporariaItens = saidaTemporariaItens; | 409 | this.saidaTemporariaItens = saidaTemporariaItens; |
408 | } | 410 | } |
411 | + | ||
412 | + public static SaidaTemporaria clone(SaidaTemporaria objeto) throws Exception{ | ||
413 | + SaidaTemporaria saidaTempoaria = (SaidaTemporaria) BeanUtilsBean2.getInstance().cloneBean(objeto); | ||
414 | + | ||
415 | + saidaTempoaria.setSaidaTemporariaItens(new ArrayList<SaidaTemporariaItem>()); | ||
416 | + for(SaidaTemporariaItem item : objeto.getSaidaTemporariaItens()){ | ||
417 | + saidaTempoaria.getSaidaTemporariaItens().add((SaidaTemporariaItem) BeanUtilsBean2.getInstance().cloneBean(item)); | ||
418 | + } | ||
419 | + return saidaTempoaria; | ||
420 | + } | ||
409 | 421 | ||
410 | } | 422 | } |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/AdicaoBemPrincipalController.java
@@ -2,6 +2,8 @@ package br.com.centralit.controller; | @@ -2,6 +2,8 @@ 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; |
7 | import org.springframework.web.bind.annotation.RequestBody; | 9 | import org.springframework.web.bind.annotation.RequestBody; |
@@ -66,6 +68,37 @@ public class AdicaoBemPrincipalController extends GenericController<AdicaoBemPri | @@ -66,6 +68,37 @@ public class AdicaoBemPrincipalController extends GenericController<AdicaoBemPri | ||
66 | 68 | ||
67 | return responseBody; | 69 | return responseBody; |
68 | } | 70 | } |
71 | + | ||
72 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
73 | + @ResponseBody | ||
74 | + public ResponseBodyWrapper save(@RequestBody AdicaoBemPrincipal entity) throws Exception{ | ||
75 | + boolean uniqueConstraintViolate = true; | ||
76 | + | ||
77 | + AdicaoBemPrincipal adicaoBemPrincipal = new AdicaoBemPrincipal(); | ||
78 | + | ||
79 | + //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 | ||
80 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
81 | + try{ | ||
82 | + adicaoBemPrincipal = this.adicaoBemPrincipalService.save(SerializationUtils.clone(entity)); | ||
83 | + uniqueConstraintViolate = false; | ||
84 | + }catch(Throwable e){ | ||
85 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
86 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
87 | + if(ex.getSQLException().getMessage().contains("codigo_unico_adicaobemprincipal")){ | ||
88 | + uniqueConstraintViolate = true; | ||
89 | + }else{ | ||
90 | + throw e; | ||
91 | + } | ||
92 | + }else{ | ||
93 | + throw e; | ||
94 | + } | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(adicaoBemPrincipal, getEditView()); | ||
99 | + | ||
100 | + return responseBody; | ||
101 | + } | ||
69 | 102 | ||
70 | /** | 103 | /** |
71 | * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> | 104 | * <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p> |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/BaixaController.java
1 | package br.com.centralit.controller; | 1 | package br.com.centralit.controller; |
2 | 2 | ||
3 | +import org.apache.commons.lang3.SerializationUtils; | ||
4 | +import org.hibernate.exception.ConstraintViolationException; | ||
3 | import org.springframework.beans.factory.annotation.Autowired; | 5 | import org.springframework.beans.factory.annotation.Autowired; |
4 | import org.springframework.stereotype.Controller; | 6 | import org.springframework.stereotype.Controller; |
7 | +import org.springframework.web.bind.annotation.RequestBody; | ||
5 | import org.springframework.web.bind.annotation.RequestMapping; | 8 | import org.springframework.web.bind.annotation.RequestMapping; |
6 | import org.springframework.web.bind.annotation.RequestMethod; | 9 | import org.springframework.web.bind.annotation.RequestMethod; |
7 | import org.springframework.web.bind.annotation.RequestParam; | 10 | import org.springframework.web.bind.annotation.RequestParam; |
@@ -9,7 +12,6 @@ import org.springframework.web.bind.annotation.ResponseBody; | @@ -9,7 +12,6 @@ import org.springframework.web.bind.annotation.ResponseBody; | ||
9 | 12 | ||
10 | import br.com.centralit.api.model.BaixaPatrimonio; | 13 | import br.com.centralit.api.model.BaixaPatrimonio; |
11 | import br.com.centralit.api.service.BaixaService; | 14 | import br.com.centralit.api.service.BaixaService; |
12 | -import br.com.centralit.api.service.InventarioService; | ||
13 | import br.com.centralit.framework.controller.GenericController; | 15 | import br.com.centralit.framework.controller.GenericController; |
14 | import br.com.centralit.framework.json.ResponseBodyWrapper; | 16 | import br.com.centralit.framework.json.ResponseBodyWrapper; |
15 | import br.com.centralit.framework.json.Views; | 17 | import br.com.centralit.framework.json.Views; |
@@ -77,6 +79,37 @@ public class BaixaController extends GenericController<BaixaPatrimonio> { | @@ -77,6 +79,37 @@ public class BaixaController extends GenericController<BaixaPatrimonio> { | ||
77 | 79 | ||
78 | return Views.BaixaListView.class; | 80 | return Views.BaixaListView.class; |
79 | } | 81 | } |
82 | + | ||
83 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
84 | + @ResponseBody | ||
85 | + public ResponseBodyWrapper save(@RequestBody BaixaPatrimonio entity) throws Exception{ | ||
86 | + boolean uniqueConstraintViolate = true; | ||
87 | + | ||
88 | + BaixaPatrimonio baixa = new BaixaPatrimonio(); | ||
89 | + | ||
90 | + //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 | ||
91 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
92 | + try{ | ||
93 | + baixa = this.baixaService.save(SerializationUtils.clone(entity)); | ||
94 | + uniqueConstraintViolate = false; | ||
95 | + }catch(Throwable e){ | ||
96 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
97 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
98 | + if(ex.getSQLException().getMessage().contains("codigo_unico_baixapatrimonio")){ | ||
99 | + uniqueConstraintViolate = true; | ||
100 | + }else{ | ||
101 | + throw e; | ||
102 | + } | ||
103 | + }else{ | ||
104 | + throw e; | ||
105 | + } | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(baixa, getEditView()); | ||
110 | + | ||
111 | + return responseBody; | ||
112 | + } | ||
80 | 113 | ||
81 | @RequestMapping(value = "/findIdsBemPatrimonialPorData", method = RequestMethod.GET, produces = "application/json") | 114 | @RequestMapping(value = "/findIdsBemPatrimonialPorData", method = RequestMethod.GET, produces = "application/json") |
82 | @ResponseBody | 115 | @ResponseBody |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/DefinicaoDetentorController.java
@@ -23,9 +23,12 @@ import net.sf.jasperreports.engine.JasperReport; | @@ -23,9 +23,12 @@ import net.sf.jasperreports.engine.JasperReport; | ||
23 | import net.sf.jasperreports.engine.design.JasperDesign; | 23 | import net.sf.jasperreports.engine.design.JasperDesign; |
24 | import net.sf.jasperreports.engine.xml.JRXmlLoader; | 24 | import net.sf.jasperreports.engine.xml.JRXmlLoader; |
25 | 25 | ||
26 | +import org.apache.commons.lang3.SerializationUtils; | ||
27 | +import org.hibernate.exception.ConstraintViolationException; | ||
26 | import org.springframework.beans.factory.annotation.Autowired; | 28 | import org.springframework.beans.factory.annotation.Autowired; |
27 | import org.springframework.security.core.context.SecurityContextHolder; | 29 | import org.springframework.security.core.context.SecurityContextHolder; |
28 | import org.springframework.stereotype.Controller; | 30 | import org.springframework.stereotype.Controller; |
31 | +import org.springframework.web.bind.annotation.RequestBody; | ||
29 | import org.springframework.web.bind.annotation.RequestMapping; | 32 | import org.springframework.web.bind.annotation.RequestMapping; |
30 | import org.springframework.web.bind.annotation.RequestMethod; | 33 | import org.springframework.web.bind.annotation.RequestMethod; |
31 | import org.springframework.web.bind.annotation.RequestParam; | 34 | import org.springframework.web.bind.annotation.RequestParam; |
@@ -40,6 +43,7 @@ import br.com.centralit.api.service.InternacionalizacaoService; | @@ -40,6 +43,7 @@ import br.com.centralit.api.service.InternacionalizacaoService; | ||
40 | import br.com.centralit.api.service.UsuarioService; | 43 | import br.com.centralit.api.service.UsuarioService; |
41 | import br.com.centralit.framework.controller.GenericController; | 44 | import br.com.centralit.framework.controller.GenericController; |
42 | import br.com.centralit.framework.controller.ReportController; | 45 | import br.com.centralit.framework.controller.ReportController; |
46 | +import br.com.centralit.framework.json.ResponseBodyWrapper; | ||
43 | import br.com.centralit.framework.json.Views; | 47 | import br.com.centralit.framework.json.Views; |
44 | import br.com.centralit.framework.model.Dominio; | 48 | import br.com.centralit.framework.model.Dominio; |
45 | import br.com.centralit.framework.model.Usuario; | 49 | import br.com.centralit.framework.model.Usuario; |
@@ -222,6 +226,37 @@ public class DefinicaoDetentorController extends GenericController<DefinicaoDete | @@ -222,6 +226,37 @@ public class DefinicaoDetentorController extends GenericController<DefinicaoDete | ||
222 | } | 226 | } |
223 | 227 | ||
224 | } | 228 | } |
229 | + | ||
230 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
231 | + @ResponseBody | ||
232 | + public ResponseBodyWrapper save(@RequestBody DefinicaoDetentor entity) throws Exception{ | ||
233 | + boolean uniqueConstraintViolate = true; | ||
234 | + | ||
235 | + DefinicaoDetentor definicaoDetentor = new DefinicaoDetentor(); | ||
236 | + | ||
237 | + //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 | ||
238 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
239 | + try{ | ||
240 | + definicaoDetentor = this.definicaoDetentorService.save(SerializationUtils.clone(entity)); | ||
241 | + uniqueConstraintViolate = false; | ||
242 | + }catch(Throwable e){ | ||
243 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
244 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
245 | + if(ex.getSQLException().getMessage().contains("codigo_unico_definicaodetentor")){ | ||
246 | + uniqueConstraintViolate = true; | ||
247 | + }else{ | ||
248 | + throw e; | ||
249 | + } | ||
250 | + }else{ | ||
251 | + throw e; | ||
252 | + } | ||
253 | + } | ||
254 | + } | ||
255 | + | ||
256 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(definicaoDetentor, getEditView()); | ||
257 | + | ||
258 | + return responseBody; | ||
259 | + } | ||
225 | 260 | ||
226 | @Override | 261 | @Override |
227 | public Class<Views.DefinicaoDetentorListView> getListView() { | 262 | public Class<Views.DefinicaoDetentorListView> getListView() { |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/EntradaController.java
1 | package br.com.centralit.controller; | 1 | package br.com.centralit.controller; |
2 | 2 | ||
3 | -import java.math.BigDecimal; | ||
4 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
5 | import java.util.List; | 4 | import java.util.List; |
6 | 5 | ||
6 | +import org.apache.commons.lang3.SerializationUtils; | ||
7 | +import org.hibernate.exception.ConstraintViolationException; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Controller; | 9 | import org.springframework.stereotype.Controller; |
9 | import org.springframework.web.bind.annotation.PathVariable; | 10 | import org.springframework.web.bind.annotation.PathVariable; |
@@ -22,7 +23,6 @@ import br.com.centralit.api.service.EntradaService; | @@ -22,7 +23,6 @@ import br.com.centralit.api.service.EntradaService; | ||
22 | import br.com.centralit.framework.controller.GenericController; | 23 | import br.com.centralit.framework.controller.GenericController; |
23 | import br.com.centralit.framework.json.ResponseBodyWrapper; | 24 | import br.com.centralit.framework.json.ResponseBodyWrapper; |
24 | import br.com.centralit.framework.json.Views; | 25 | import br.com.centralit.framework.json.Views; |
25 | -import br.com.centralit.framework.util.UtilObjeto; | ||
26 | import br.com.centralit.framework.view.ResultResponseVH; | 26 | import br.com.centralit.framework.view.ResultResponseVH; |
27 | 27 | ||
28 | /** | 28 | /** |
@@ -115,6 +115,38 @@ public class EntradaController extends GenericController<EntradaPatrimonio> { | @@ -115,6 +115,38 @@ public class EntradaController extends GenericController<EntradaPatrimonio> { | ||
115 | this.entradaService.uploadAnexoCaracteristica(file, idEntradaItem); | 115 | this.entradaService.uploadAnexoCaracteristica(file, idEntradaItem); |
116 | 116 | ||
117 | } | 117 | } |
118 | + | ||
119 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
120 | + @ResponseBody | ||
121 | + public ResponseBodyWrapper save(@RequestBody EntradaPatrimonio entity) throws Exception{ | ||
122 | + boolean uniqueConstraintViolate = true; | ||
123 | + | ||
124 | + EntradaPatrimonio entrada = new EntradaPatrimonio(); | ||
125 | + | ||
126 | + //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 | ||
127 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
128 | + try{ | ||
129 | + entrada = this.entradaService.save(SerializationUtils.clone(entity)); | ||
130 | + uniqueConstraintViolate = false; | ||
131 | + }catch(Throwable e){ | ||
132 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
133 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
134 | + if(ex.getSQLException().getMessage().contains("codigo_unico_entrada")){ | ||
135 | + uniqueConstraintViolate = true; | ||
136 | + }else{ | ||
137 | + throw e; | ||
138 | + } | ||
139 | + }else{ | ||
140 | + throw e; | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(entrada, getEditView()); | ||
146 | + | ||
147 | + return responseBody; | ||
148 | + } | ||
149 | + | ||
118 | 150 | ||
119 | /** | 151 | /** |
120 | * Método responsável por listar <code>Entrada</code> por codigo e <code>Organizacao</code> | 152 | * Método responsável por listar <code>Entrada</code> por codigo e <code>Organizacao</code> |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/InventarioController.java
@@ -2,6 +2,8 @@ package br.com.centralit.controller; | @@ -2,6 +2,8 @@ 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; |
7 | import org.springframework.web.bind.annotation.RequestBody; | 9 | import org.springframework.web.bind.annotation.RequestBody; |
@@ -120,8 +122,30 @@ public class InventarioController extends GenericController<Inventario> { | @@ -120,8 +122,30 @@ public class InventarioController extends GenericController<Inventario> { | ||
120 | @RequestMapping(method = RequestMethod.POST, value = "/saveInventario") | 122 | @RequestMapping(method = RequestMethod.POST, value = "/saveInventario") |
121 | @ResponseBody | 123 | @ResponseBody |
122 | public ResponseBodyWrapper saveInventario(@RequestBody InventarioVH inventarioVH) throws Exception { | 124 | public ResponseBodyWrapper saveInventario(@RequestBody InventarioVH inventarioVH) throws Exception { |
123 | - | ||
124 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(this.inventarioService.save(inventarioVH), getEditView()); | 125 | + boolean uniqueConstraintViolate = true; |
126 | + | ||
127 | + Inventario inventario = new Inventario(); | ||
128 | + | ||
129 | + //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 | ||
130 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
131 | + try{ | ||
132 | + inventario = this.inventarioService.save(SerializationUtils.clone(inventarioVH)); | ||
133 | + uniqueConstraintViolate = false; | ||
134 | + }catch(Throwable e){ | ||
135 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
136 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
137 | + if(ex.getSQLException().getMessage().contains("codigo_unico_inventario")){ | ||
138 | + uniqueConstraintViolate = true; | ||
139 | + }else{ | ||
140 | + throw e; | ||
141 | + } | ||
142 | + }else{ | ||
143 | + throw e; | ||
144 | + } | ||
145 | + } | ||
146 | + } | ||
147 | + | ||
148 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(inventario, getEditView()); | ||
125 | 149 | ||
126 | return responseBody; | 150 | return responseBody; |
127 | } | 151 | } |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/SaidaTemporariaController.java
@@ -2,7 +2,6 @@ package br.com.centralit.controller; | @@ -2,7 +2,6 @@ package br.com.centralit.controller; | ||
2 | 2 | ||
3 | import java.util.Collection; | 3 | import java.util.Collection; |
4 | 4 | ||
5 | -import org.apache.commons.beanutils.BeanUtilsBean; | ||
6 | import org.hibernate.exception.ConstraintViolationException; | 5 | import org.hibernate.exception.ConstraintViolationException; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Controller; | 7 | import org.springframework.stereotype.Controller; |
@@ -112,22 +111,21 @@ public class SaidaTemporariaController extends GenericController<SaidaTemporaria | @@ -112,22 +111,21 @@ public class SaidaTemporariaController extends GenericController<SaidaTemporaria | ||
112 | 111 | ||
113 | SaidaTemporaria saidaTemporaria = new SaidaTemporaria(); | 112 | SaidaTemporaria saidaTemporaria = new SaidaTemporaria(); |
114 | 113 | ||
115 | - //TODO Solução temporária para evitar que sejam criadas transferencias com o código duplicado. Alterar solução quando for implementado o cache compartilhado | 114 | + //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 |
116 | for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | 115 | for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ |
117 | try{ | 116 | try{ |
118 | - saidaTemporaria = (SaidaTemporaria) BeanUtilsBean.getInstance().cloneBean(entity); | ||
119 | - saidaTemporaria = this.saidaTemporariaService.save(saidaTemporaria); | 117 | + saidaTemporaria = this.saidaTemporariaService.save(SaidaTemporaria.clone(entity)); |
120 | uniqueConstraintViolate = false; | 118 | uniqueConstraintViolate = false; |
121 | }catch(Throwable e){ | 119 | }catch(Throwable e){ |
122 | if(e.getCause() instanceof ConstraintViolationException){ | 120 | if(e.getCause() instanceof ConstraintViolationException){ |
123 | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | 121 | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
124 | - if(ex.getSQLException().getMessage().contains("saidatemp_codigo_organizacao_id_key")){ | 122 | + if(ex.getSQLException().getMessage().contains("codigo_unico_saidatemporaria")){ |
125 | uniqueConstraintViolate = true; | 123 | uniqueConstraintViolate = true; |
126 | }else{ | 124 | }else{ |
127 | - uniqueConstraintViolate = false; | 125 | + throw e; |
128 | } | 126 | } |
129 | }else{ | 127 | }else{ |
130 | - uniqueConstraintViolate = false; | 128 | + throw e; |
131 | } | 129 | } |
132 | } | 130 | } |
133 | } | 131 | } |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/SelecaoBemPatrimonialController.java
@@ -2,14 +2,16 @@ package br.com.centralit.controller; | @@ -2,14 +2,16 @@ package br.com.centralit.controller; | ||
2 | 2 | ||
3 | import java.util.Collection; | 3 | import java.util.Collection; |
4 | 4 | ||
5 | +import org.apache.commons.beanutils.BeanUtilsBean; | ||
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; |
10 | import org.springframework.web.bind.annotation.ResponseBody; | 13 | import org.springframework.web.bind.annotation.ResponseBody; |
11 | 14 | ||
12 | -import br.com.centralit.api.model.ContaContabil; | ||
13 | import br.com.centralit.api.model.SelecaoBemPatrimonial; | 15 | import br.com.centralit.api.model.SelecaoBemPatrimonial; |
14 | import br.com.centralit.api.service.DominioService; | 16 | import br.com.centralit.api.service.DominioService; |
15 | import br.com.centralit.api.service.SelecaoBemPatrimonialService; | 17 | import br.com.centralit.api.service.SelecaoBemPatrimonialService; |
@@ -107,6 +109,38 @@ public class SelecaoBemPatrimonialController extends GenericController<SelecaoBe | @@ -107,6 +109,38 @@ public class SelecaoBemPatrimonialController extends GenericController<SelecaoBe | ||
107 | 109 | ||
108 | return responseBody; | 110 | return responseBody; |
109 | } | 111 | } |
112 | + | ||
113 | + @RequestMapping(method = RequestMethod.POST, value = "") | ||
114 | + @ResponseBody | ||
115 | + public ResponseBodyWrapper save(@RequestBody SelecaoBemPatrimonial objeto) throws Exception { | ||
116 | + boolean uniqueConstraintViolate = true; | ||
117 | + SelecaoBemPatrimonial selecaoBemPatrimonial = new SelecaoBemPatrimonial(); | ||
118 | + | ||
119 | + //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 | ||
120 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | ||
121 | + try{ | ||
122 | + selecaoBemPatrimonial = (SelecaoBemPatrimonial) BeanUtilsBean.getInstance().cloneBean(objeto); | ||
123 | + selecaoBemPatrimonial = this.selecaoBemPatrimonialService.save(selecaoBemPatrimonial); | ||
124 | + uniqueConstraintViolate = false; | ||
125 | + }catch(Throwable e){ | ||
126 | + if(e.getCause() instanceof ConstraintViolationException){ | ||
127 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | ||
128 | + if(ex.getSQLException().getMessage().contains("codigo_unico_selecaobempatrimonial")){ | ||
129 | + uniqueConstraintViolate = true; | ||
130 | + }else{ | ||
131 | + throw e; | ||
132 | + } | ||
133 | + }else{ | ||
134 | + throw e; | ||
135 | + } | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(selecaoBemPatrimonial, getEditView()); | ||
140 | + | ||
141 | + return responseBody; | ||
142 | + } | ||
143 | + | ||
110 | 144 | ||
111 | @Override | 145 | @Override |
112 | public Class<Views.SelecaoBemPatrimonialListView> getListView() { | 146 | public Class<Views.SelecaoBemPatrimonialListView> getListView() { |
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/TransferenciaController.java
@@ -339,7 +339,7 @@ public class TransferenciaController extends GenericController<Transferencia>{ | @@ -339,7 +339,7 @@ public class TransferenciaController extends GenericController<Transferencia>{ | ||
339 | boolean uniqueConstraintViolate = true; | 339 | boolean uniqueConstraintViolate = true; |
340 | List<Transferencia> transferencias = new LinkedList<Transferencia>(); | 340 | List<Transferencia> transferencias = new LinkedList<Transferencia>(); |
341 | 341 | ||
342 | - //TODO Solução temporária para evitar que sejam criadas transferencias com o código duplicado. Alterar solução quando for implementado o cache compartilhado | 342 | + //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 |
343 | for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | 343 | for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ |
344 | try{ | 344 | try{ |
345 | Transferencia transferencia = (Transferencia) BeanUtilsBean.getInstance().cloneBean(objeto); | 345 | Transferencia transferencia = (Transferencia) BeanUtilsBean.getInstance().cloneBean(objeto); |
@@ -348,14 +348,13 @@ public class TransferenciaController extends GenericController<Transferencia>{ | @@ -348,14 +348,13 @@ public class TransferenciaController extends GenericController<Transferencia>{ | ||
348 | }catch(PersistenceException e){ | 348 | }catch(PersistenceException e){ |
349 | if(e.getCause() instanceof ConstraintViolationException){ | 349 | if(e.getCause() instanceof ConstraintViolationException){ |
350 | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | 350 | ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
351 | - if(ex.getSQLException().getMessage().contains("trans_codigo_organizacao_id_key") | ||
352 | - || ex.getSQLException().getMessage().contains("trans_codigo_organizacao_codigoasi_id_key")){ | 351 | + if(ex.getSQLException().getMessage().contains("codigo_unico")){ |
353 | uniqueConstraintViolate = true; | 352 | uniqueConstraintViolate = true; |
354 | }else{ | 353 | }else{ |
355 | - uniqueConstraintViolate = false; | 354 | + throw e; |
356 | } | 355 | } |
357 | }else{ | 356 | }else{ |
358 | - uniqueConstraintViolate = false; | 357 | + throw e; |
359 | } | 358 | } |
360 | } | 359 | } |
361 | } | 360 | } |