Advertisement
Guest User

Untitled

a guest
May 16th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. public Cliente update(Cliente t) throws Exception {
  2.  
  3.  
  4. LocalDate now = LocalDate.now();
  5.  
  6.  
  7. LocalDate date1 = t.getDataCadastro().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  8.  
  9. long numberOfYears = Period.between(now, date1).getYears();
  10.  
  11. if(numberOfYears >=1 &&
  12. numberOfYears < 5 &&
  13. !(t.getPerfil().equals("Standard") || t.getPerfil().equals("Premium"))) {
  14. throw new Exception ("So é permitido os perfis Standard e Premium entre 1 e 5 anos");
  15. }
  16.  
  17. else if(numberOfYears >1 && !(t.getPerfil().equals("Standard")) ) {
  18. throw new Exception ("So é permitido os perfis Standard com menos de 1 ano");
  19. }
  20.  
  21.  
  22. else if(numberOfYears >=5 && !(t.getPerfil().equals("Gold") || t.getPerfil().equals("Premium") || t.getPerfil().equals("Standard"))) {
  23. throw new Exception ("So é permitido os perfis Standard, premium e gold");
  24. };
  25.  
  26. log.info("Atualizando " + t);
  27. return em.merge(t);
  28.  
  29.  
  30. /*LocalDate now = LocalDate.now();
  31. LocalDate date1 = t.getDataCadastro().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  32. Duration joDuration = Duration.between(date1, now);
  33. long tempo = duration.toDays();
  34.  
  35. if(duration.get(ChronoUnit.YEARS) >=1 &&
  36. duration.get(ChronoUnit.YEARS) < 5 &&
  37. !(t.getPerfil().equals("Standard") || t.getPerfil().equals("Premium"))) {
  38. throw new Exception ("So é permitido os perfis Standard e Premium entre 1 e 5 anos");
  39. }
  40.  
  41. else if(duration.get(ChronoUnit.YEARS) <1 && !(t.getPerfil().equals("Standard")) ) {
  42. throw new Exception ("So é permitido os perfis Standard com menos de 1 ano");
  43. }
  44.  
  45.  
  46. else if(duration.get(ChronoUnit.YEARS) >=5 && !(t.getPerfil().equals("Gold") || t.getPerfil().equals("Premium") || t.getPerfil().equals("Standard"))) {
  47. throw new Exception ("So é permitido os perfis Standard, premium e gold");
  48. };
  49.  
  50. log.info("Atualizando " + t);
  51. return em.merge(t);*/
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement