Exemplo n.º 1
0
  public void createUser(GenericRequestParam genericRequestParam) {

    if (genericRequestParam != null && MapUtils.isNotEmpty(genericRequestParam.getParams())) {

      Map<String, Object> params = genericRequestParam.getParams();

      String username = null;
      {
        if (params.containsKey("username")) {
          username = params.get("username").toString();
        }
      }

      String courierCode = null;
      {
        if (params.containsKey("courier")) {
          courierCode = params.get("courier").toString();
        }
      }

      String wirelessCenterCode = null;
      {
        if (params.containsKey("wireless")) {
          wirelessCenterCode = params.get("wireless").toString();
        }
      }

      if (username != null) {
        User user =
            ObjectUtils.defaultIfNull(
                userRepository.findOne(User_.username(username)), new User(username));

        if (StringUtils.isNotBlank(courierCode)) {
          Courier courier = courierService.findOneByCode(courierCode);
          if (courier != null) {
            user.setCourier(courier);
          }
        }

        if (StringUtils.isNotBlank(wirelessCenterCode)) {
          WirelessCenter wirelessCenter = wirelessCenterService.findOneByCode(wirelessCenterCode);
          if (wirelessCenter != null) {
            user.setWirelessCenter(wirelessCenter);
          }
        }

        userRepository.save(user);
      }
    }
  }
Exemplo n.º 2
0
  public void updateUser(GenericRequestParam genericRequestParam) {
    final Map<String, User> users = getUsers();
    final Set<User> forUpdateOrCreate = Sets.newHashSet();

    for (Map.Entry<String, Object> entry : genericRequestParam.getParams().entrySet()) {
      final String[] n = entry.getKey().split(":");

      if (n.length == 2) {
        String username = n[0];
        final User user = ObjectUtils.defaultIfNull(users.get(username), new User(username));
        final String roleAsString = n[1];
        final String code = entry.getValue().toString();

        if ("courier".equalsIgnoreCase(roleAsString)) {
          Courier courier = courierService.findOneByCode(code);
          user.setCourier(courier);
        } else if ("wireless".equalsIgnoreCase(roleAsString)) {
          WirelessCenter wc = wirelessCenterService.findOneByCode(code);
          user.setWirelessCenter(wc);
        }

        forUpdateOrCreate.add(user);
      }
    }

    userRepository.save(forUpdateOrCreate);
  }
Exemplo n.º 3
0
  public Map<String, User> getUsers() {
    final List<User> users = userRepository.findAll();
    final Map<String, User> userMap = Maps.newHashMap();
    for (User user : users) {
      userMap.put(user.getUsername(), user);
    }

    return userMap;
  }
Exemplo n.º 4
0
 public User getLoggedInPrincipalAsUserDomain() {
   return userRepository.findOne(User_.username(authorizationService.getUsername()));
 }