// should be private, but public because of unit test visibility
  public void detachWeekdaysFromWeekends(List<ParkingEvent> parkingEvents) {

    totalHours = 0; // for weekday hours

    weekends = new HashSet<String>(); // storing weekend days

    // iterating over events
    for (ParkingEvent parkingEvent : parkingEvents) {

      LocalDateTime startDateTime = new LocalDateTime(parkingEvent.getStartTime());
      LocalDateTime endDateTime = new LocalDateTime(parkingEvent.getEndTime());

      // iterating over event hours
      for (LocalDateTime date = startDateTime;
          date.isBefore(endDateTime);
          date = date.plusHours(1)) {
        if (date.getDayOfWeek() == DateTimeConstants.SATURDAY
            || date.getDayOfWeek() == DateTimeConstants.SUNDAY) {
          weekends.add(date.toLocalDate().toString());
        } else {
          totalHours++;
        }
      }
    }
  }
示例#2
0
  @Override
  public int compare(LogEvent o1, LogEvent o2) {
    LocalDateTime t1 = o1.getTime();
    LocalDateTime t2 = o2.getTime();

    if (t1.isBefore(t2)) return 1;
    else if (t1.isAfter(t2)) return -1;
    return 0;
  }
  @Override
  public List<UnidadeIndiceOEE> gerarUnidadesIndiceOEE(
      IndiceOEEPorHoraFilter filter, LocalDateTime dtHrInicio, LocalDateTime dtHrFim) {
    if (dtHrFim == null) {
      LocalTime horaAtual = new LocalTime();
      dtHrFim =
          new LocalDate()
              .toLocalDateTime(
                  new LocalTime(horaAtual.getHourOfDay(), horaAtual.getMinuteOfHour(), 0, 0));
    }
    List<UnidadeIndiceOEE> result = new ArrayList<UnidadeIndiceOEE>();

    int year = dtHrInicio.getYear();
    int month = dtHrInicio.getMonthOfYear();
    int day = dtHrInicio.getDayOfMonth();
    int hour = dtHrInicio.getHourOfDay();

    LocalDateTime dtHr = new LocalDateTime(year, month, day, hour, 0, 0, 0);

    while (dtHr.isBefore(dtHrFim)) {
      if (dtHr.toLocalDate().equals(filter.getDt())) {

        UnidadeIndiceOEE unidade = new UnidadeIndiceOEE();
        unidade.setInicio(dtHr);
        unidade.setFim(dtHr.plusMinutes(59));
        updateId(unidade);

        LocalDateTime inicio = dtHrInicio.isAfter(dtHr) ? dtHrInicio : unidade.getInicio();
        LocalDateTime fim = dtHr.plusHours(1);
        fim = dtHrFim.isAfter(fim) ? fim : dtHrFim;
        Integer tempoUtilMinutos = DateUtils.getDiferencaEmMinutos(inicio, fim);
        unidade.setTempoUtilMinutos(tempoUtilMinutos);

        result.add(unidade);
      }
      dtHr = dtHr.plusHours(1);
    }

    return result;
  }
  @Override
  public UserClientResource toResource(UserClient user) {
    if (user == null) {
      return null;
    }
    Set<String> perms = new HashSet<>();
    for (GrantedAuthority grantedAuthority : user.getAuthorities()) {
      // strip off the client and team specifics on the authorities
      Matcher matcher = specializedPermissions.matcher(grantedAuthority.getAuthority());
      if (matcher.matches()) {
        perms.add(matcher.replaceAll("$1"));
      } else {
        perms.add(grantedAuthority.getAuthority());
      }
    }

    if (user.isSuperUser()) {
      // give the super user all team permissions (not necessary but nice for the UI)
      user.setTeamRoles(superUserTeamRoleGenerator.allPermissionsOnAllTeams(user.getClient()));
    }

    // add the teams to which this user has access
    Set<TeamResource> teams = new HashSet<>();
    for (UserClientUserClientTeamRole userClientUserClientTeamRole : user.getTeamRoles()) {
      teams.add(roleTeamResourceResourceAssembler.toResource(userClientUserClientTeamRole));
    }

    boolean interruptFlow = false;

    if (user.getNotNowExpirationTime() != null) {
      LocalDateTime dateTime = LocalDateTime.now(DateTimeZone.UTC);
      interruptFlow = dateTime.isBefore(user.getNotNowExpirationTime());
    }

    UserClientResource ret =
        new UserClientResource(
            user.getId(),
            user.getVersion(),
            user.getLogin(),
            user.getFirstName(),
            user.getLastName(),
            user.getEmail(),
            user.isActive(),
            user.isAccountNonExpired(),
            user.isAccountNonLocked(),
            user.isCredentialsNonExpired(),
            user.isEmailValidated(),
            user.isSecretQuestionCreated(),
            clientResourceAssembler.toResource(user.getClient()),
            new ArrayList<>(perms),
            user.isImpersonated(),
            user.getNotNowExpirationTime(),
            user.getPasswordExpireationDateTime(),
            user.getPasswordSavedDateTime(),
            interruptFlow);

    ret.setSecurityQuestionsNotRequiredForReset(user.isSecurityQuestionsNotRequiredForReset());

    ret.add(linkTo(methodOn(UserClientsResource.class).authenticated()).withRel("authenticated"));

    if (!CollectionUtils.isEmpty(teams)) {
      ret.setTeams(teams);
    }

    if (!user.isImpersonated()) {
      // non-impersonation users only
      ret.add(linkTo(methodOn(UserClientsResource.class).getById(user.getId())).withSelfRel());
      ret.add(updateUserClientLink(user));
      ret.add(createVerifyPasswordLink(user));

      Link link =
          linkTo(
                  methodOn(UserClientSecretQuestionResponsesResource.class)
                      .secretQuestionResponses(user.getId(), null, null, null))
              .withRel("secretQuestionResponses");
      ret.add(new Link(createUriTemplate("password", link), link.getRel()));

      Link updateUserClientSecretQuestion =
          linkTo(methodOn(UserClientsResource.class).updateUserClient(user.getId(), null))
              .withRel("updateUserClientSecretQuestionFlag");
      ret.add(
          new Link(
              createUriTemplate("secretQuestionsCreated", updateUserClientSecretQuestion),
              updateUserClientSecretQuestion.getRel()));

      ret.add(
          linkTo(
                  methodOn(UserClientSecretQuestionResponsesResource.class)
                      .secretQuestionAsteriskResponse(user.getId(), null, null))
              .withRel("secretQuestionAsteriskResponses"));
      ret.add(
          linkTo(methodOn(UserClientsResource.class).sendValidationEmail(user.getId()))
              .withRel("sendValidationEmail"));
      ret.add(
          linkTo(methodOn(UserClientsPasswordResource.class).changePassword(null, null, null))
              .withRel("changePassword"));
      ret.add(linkTo(methodOn(UserClientsResource.class).notNow(user.getId())).withRel("notNow"));
    } else {
      // impersonation users
      ret.add(
          new Link(
              UriComponentsBuilder.fromHttpUrl(
                      linkTo(methodOn(UserClientsResource.class).getById(1l))
                          .withSelfRel()
                          .getHref())
                  .replacePath(adminEntryPoint)
                  .build(false)
                  .toUriString(),
              "adminApp"));
    }

    return ret;
  }