Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Usuario extends DefaultTimeStamped implements Serializable {
- @Transient
- private Double uid;
- @Id
- @GeneratedValue
- private Long id;
- // @NotNull
- @Size(min = 1, max = 100)
- @Column(length = 100, unique = true, nullable = false)
- private String login;
- // @NotNull
- @Size(min = 60, max = 60)
- @Column(name = "password_hash", length = 60)
- private String password;
- @Size(max = 50)
- @Column(name = "first_name", length = 50)
- private String firstName;
- @Size(max = 50)
- @Column(name = "last_name", length = 50)
- private String lastName;
- @Size(max = 100)
- @Column(length = 100, unique = false)
- private String email;
- // @NotNull
- // @Column(nullable = false)
- private boolean activated = false;
- @Size(min = 2, max = 5)
- @Column(name = "lang_key", length = 5)
- private String langKey;
- @Size(max = 20)
- @Column(name = "activation_key", length = 20)
- private String activationKey;
- @Size(max = 20)
- @Column(name = "reset_key", length = 20)
- private String resetKey;
- @Column(name = "reset_date", nullable = true)
- private ZonedDateTime resetDate = null;
- @OneToMany(mappedBy = "cliente", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- @Fetch(FetchMode.SUBSELECT)
- private List<Proposta> propostas = new ArrayList<>();
- @ManyToMany
- @JoinTable(
- name = "user_authority",
- joinColumns = {
- @JoinColumn(name = "user_id", referencedColumnName = "id")},
- inverseJoinColumns = {
- @JoinColumn(name = "authority_id", referencedColumnName = "name")})
- private Set<Authority> authorities = new HashSet<>();
- public Usuario() {
- this.uid = Math.random();
- }
- public class UsuarioDao extends FiltroTimeStampedDao<Usuario> {
- public UsuarioDao() {
- super(Usuario.class);
- }
- @Override
- public Criteria criarCriteriaFiltro(IFiltro filtro) {
- Criteria criteria = iniciarCriteria(null);
- FiltroGeral auxFiltro = (FiltroGeral) filtro;
- if (auxFiltro.getTexto() != null && !auxFiltro.getTexto().isEmpty()) {
- if (auxFiltro.getCampo().equalsIgnoreCase("id")) {
- criteria.add(Restrictions.ilike(auxFiltro.getCampo(), Long.parseLong(auxFiltro.getTexto())));
- } else {
- criteria.add(Restrictions.ilike(auxFiltro.getCampo(), auxFiltro.getTexto() + "%"));
- }
- }
- return criteria;
- }
- public Usuario getByLogin(String login) {
- return (Usuario) iniciarCriteria(null).
- add(Restrictions.eq("login", login)).
- list().stream().findFirst().get();
- }
- public List<Usuario> getByAuthority(String authority) {
- return (List<Usuario>) iniciarCriteria(null).add(Restrictions.eq("authorities", authority.toUpperCase())).list();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement