All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 38s
123 lines
3.2 KiB
Java
Executable File
123 lines
3.2 KiB
Java
Executable File
package io.gmss.fiscad.entities.user;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
|
|
import io.gmss.fiscad.entities.BaseEntity;
|
|
import io.gmss.fiscad.entities.decoupage.Secteur;
|
|
import io.gmss.fiscad.entities.infocad.metier.Enquete;
|
|
import io.gmss.fiscad.entities.infocad.parametre.Structure;
|
|
import io.gmss.fiscad.entities.rfu.parametre.Participer;
|
|
import io.gmss.fiscad.enums.UserRole;
|
|
import jakarta.persistence.*;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.Setter;
|
|
import org.hibernate.annotations.SQLDelete;
|
|
import org.hibernate.annotations.Where;
|
|
|
|
import java.io.Serializable;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
@Entity
|
|
@Getter
|
|
@Setter
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
@SQLDelete(sql =
|
|
"UPDATE users " +
|
|
"SET deleted = true " +
|
|
"WHERE id = ?")
|
|
@Where(clause = " deleted = false")
|
|
@Table(name = "users")
|
|
public class User extends BaseEntity implements Serializable {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
private String nom;
|
|
private String prenom;
|
|
private String tel;
|
|
private String email;
|
|
@Column(
|
|
name = "username",
|
|
nullable = false,
|
|
unique = true,
|
|
length = 200
|
|
)
|
|
private String username;
|
|
@JsonIgnore
|
|
private String password;
|
|
@Column(columnDefinition = "boolean default true")
|
|
private boolean active;
|
|
@Column(columnDefinition = "boolean default false")
|
|
private boolean resetPassword;
|
|
|
|
private String token;
|
|
|
|
private LocalDateTime tokenDate;
|
|
|
|
|
|
@OneToMany(mappedBy = "user")
|
|
private Set<AvoirFonction> avoirFonctions= new HashSet<>();
|
|
|
|
@ManyToOne
|
|
private Structure structure;
|
|
|
|
|
|
@JsonIgnore
|
|
@OneToMany(mappedBy = "user")
|
|
private List<Participer> participers;
|
|
|
|
|
|
|
|
@Transient
|
|
private Long idCampagneCourant;
|
|
@Transient
|
|
private Long idSecteurCourant;
|
|
|
|
public boolean isAdmin() {
|
|
// for (Role r : this.roles) {
|
|
// if (r.getNom().equals(UserRole.ROLE_ADMIN)) {
|
|
// return true;
|
|
// }
|
|
// }
|
|
return false;
|
|
}
|
|
|
|
|
|
public Long getIdCampagneCourant() {
|
|
if(participers!=null) {
|
|
for (Participer p : participers) {
|
|
if (p.getDateFin() == null) {
|
|
if (p.getEquipe()!= null && p.getEquipe().getCampagne() != null) {
|
|
return p.getEquipe().getCampagne().getId();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Long getIdSecteurCourant() {
|
|
if(participers!=null){
|
|
for (Participer p : participers) {
|
|
if (p.getDateFin() == null) {
|
|
if(p.getEquipe()!=null && p.getEquipe().getSecteur()!=null) {
|
|
return p.getEquipe().getSecteur().getId();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null ;
|
|
}
|
|
|
|
|
|
}
|