Commit b02298220c919903c93614afc3f16007d4e2e03a

Authored by erick.sato
1 parent 203d693e
Exists in master

[Redmine Atendimento #4863]Validação null rascunho

cit-portal-api/src/main/java/br/com/centralit/api/service/impl/RascunhoServiceImpl.java
@@ -40,9 +40,14 @@ public class RascunhoServiceImpl extends GenericServiceImpl<Rascunho, Long> impl @@ -40,9 +40,14 @@ public class RascunhoServiceImpl extends GenericServiceImpl<Rascunho, Long> impl
40 40
41 @Override 41 @Override
42 public Rascunho merge(Rascunho entity) { 42 public Rascunho merge(Rascunho entity) {
  43 + boolean rascunhoNull = false;
43 if(!UtilObjeto.isReferencia(entity.getAutor()) && !UtilObjeto.isReferencia(entity.getEditor()) && UtilObjeto.isReferencia(entity.getDetentor())){ 44 if(!UtilObjeto.isReferencia(entity.getAutor()) && !UtilObjeto.isReferencia(entity.getEditor()) && UtilObjeto.isReferencia(entity.getDetentor())){
44 Rascunho rascunho = this.find(entity.getId()); 45 Rascunho rascunho = this.find(entity.getId());
45 - entity.setAutor(rascunho.getAutor()); 46 + if(rascunho != null){
  47 + entity.setAutor(rascunho.getAutor());
  48 + }else{
  49 + rascunhoNull = true;
  50 + }
46 }else{ 51 }else{
47 Usuario usuario = null; 52 Usuario usuario = null;
48 if (SecurityContextHolder.getContext().getAuthentication() != null) { 53 if (SecurityContextHolder.getContext().getAuthentication() != null) {
@@ -52,12 +57,15 @@ public class RascunhoServiceImpl extends GenericServiceImpl<Rascunho, Long> impl @@ -52,12 +57,15 @@ public class RascunhoServiceImpl extends GenericServiceImpl<Rascunho, Long> impl
52 } 57 }
53 entity.setDetentor(usuario); 58 entity.setDetentor(usuario);
54 } 59 }
55 - return salvar(entity); 60 + return !rascunhoNull ? salvar(entity) : null;
56 } 61 }
57 62
58 private Rascunho salvar(Rascunho entity) { 63 private Rascunho salvar(Rascunho entity) {
59 - validarEntidade(entity, this.validator);  
60 - return super.save(entity); 64 + if(entity != null){
  65 + validarEntidade(entity, this.validator);
  66 + return super.save(entity);
  67 + }
  68 + return null;
61 } 69 }
62 70
63 @Override 71 @Override