Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Cliente update(Cliente t) throws Exception {
- LocalDate now = LocalDate.now();
- LocalDate date1 = t.getDataCadastro().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
- long numberOfYears = Period.between(now, date1).getYears();
- if(numberOfYears >=1 &&
- numberOfYears < 5 &&
- !(t.getPerfil().equals("Standard") || t.getPerfil().equals("Premium"))) {
- throw new Exception ("So é permitido os perfis Standard e Premium entre 1 e 5 anos");
- }
- else if(numberOfYears >1 && !(t.getPerfil().equals("Standard")) ) {
- throw new Exception ("So é permitido os perfis Standard com menos de 1 ano");
- }
- else if(numberOfYears >=5 && !(t.getPerfil().equals("Gold") || t.getPerfil().equals("Premium") || t.getPerfil().equals("Standard"))) {
- throw new Exception ("So é permitido os perfis Standard, premium e gold");
- };
- log.info("Atualizando " + t);
- return em.merge(t);
- /*LocalDate now = LocalDate.now();
- LocalDate date1 = t.getDataCadastro().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
- Duration joDuration = Duration.between(date1, now);
- long tempo = duration.toDays();
- if(duration.get(ChronoUnit.YEARS) >=1 &&
- duration.get(ChronoUnit.YEARS) < 5 &&
- !(t.getPerfil().equals("Standard") || t.getPerfil().equals("Premium"))) {
- throw new Exception ("So é permitido os perfis Standard e Premium entre 1 e 5 anos");
- }
- else if(duration.get(ChronoUnit.YEARS) <1 && !(t.getPerfil().equals("Standard")) ) {
- throw new Exception ("So é permitido os perfis Standard com menos de 1 ano");
- }
- else if(duration.get(ChronoUnit.YEARS) >=5 && !(t.getPerfil().equals("Gold") || t.getPerfil().equals("Premium") || t.getPerfil().equals("Standard"))) {
- throw new Exception ("So é permitido os perfis Standard, premium e gold");
- };
- log.info("Atualizando " + t);
- return em.merge(t);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement