コード例 #1
0
  @Override
  public Collection<StaffData> retrieveAllStaff(final String extraCriteria) {

    context.authenticatedUser();

    StaffMapper rm = new StaffMapper();
    String sql = "select " + rm.schema();
    if (StringUtils.isNotBlank(extraCriteria)) {
      sql += " where " + extraCriteria;
    }
    sql = sql + " order by s.lastname";
    return this.jdbcTemplate.query(sql, rm, new Object[] {});
  }
コード例 #2
0
  @Override
  public StaffData retrieveStaff(final Long staffId) {

    try {
      context.authenticatedUser();

      StaffMapper rm = new StaffMapper();
      String sql = "select " + rm.schema() + " where s.id = ?";

      StaffData selectedStaff = this.jdbcTemplate.queryForObject(sql, rm, new Object[] {staffId});

      return selectedStaff;
    } catch (EmptyResultDataAccessException e) {
      throw new StaffNotFoundException(staffId);
    }
  }
コード例 #3
0
  @Transactional
  @Override
  public Long updateRole(RoleCommand command) {

    AppUser currentUser = context.authenticatedUser();

    RoleCommandValidator validator = new RoleCommandValidator(command);
    validator.validateForUpdate();

    List<Permission> selectedPermissions =
        assembleListOfSelectedPermissions(command.getPermissions());

    Role role =
        this.roleRepository.findOne(rolesThatMatch(currentUser.getOrganisation(), command.getId()));
    if (role == null) {
      throw new RoleNotFoundException(command.getId());
    }
    role.update(command.getName(), command.getDescription(), selectedPermissions);

    this.roleRepository.save(role);

    return role.getId();
  }
コード例 #4
0
  @Transactional
  @Override
  public Long createRole(final RoleCommand command) {

    AppUser currentUser = context.authenticatedUser();

    RoleCommandValidator validator = new RoleCommandValidator(command);
    validator.validateForCreate();

    List<Permission> selectedPermissions =
        assembleListOfSelectedPermissions(command.getPermissions());

    Role entity =
        new Role(
            currentUser.getOrganisation(),
            command.getName(),
            command.getDescription(),
            selectedPermissions);

    this.roleRepository.save(entity);

    return entity.getId();
  }