mirror of
https://github.com/ArenMg/aren.git
synced 2024-11-13 04:00:53 +00:00
Groupe pour l'envoie d'email
This commit is contained in:
parent
c1e8f2b058
commit
d203235530
5 changed files with 329 additions and 0 deletions
|
@ -25,6 +25,8 @@ import java.time.ZonedDateTime;
|
|||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import javax.persistence.JoinTable;
|
||||
|
||||
import fr.lirmm.aren.model.vm.VMTeam;
|
||||
import org.hibernate.annotations.Filter;
|
||||
import org.hibernate.annotations.Filters;
|
||||
import org.hibernate.annotations.SortNatural;
|
||||
|
@ -135,6 +137,15 @@ public class User extends AbstractEntEntity implements Serializable {
|
|||
@SortNatural
|
||||
private SortedSet<Team> teams = new TreeSet<>();
|
||||
|
||||
@JoinTable(name = "vm_teams_users",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "user_id", referencedColumnName = "id")},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "team_id", referencedColumnName = "id")})
|
||||
@ManyToMany
|
||||
@SortNatural
|
||||
private SortedSet<VMTeam> vmTeams = new TreeSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "owner")
|
||||
@SortNatural
|
||||
private SortedSet<Notification> notifications = new TreeSet<>();
|
||||
|
@ -372,6 +383,40 @@ public class User extends AbstractEntEntity implements Serializable {
|
|||
team.getUsers().remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SortedSet<VMTeam> getVmTeams() {
|
||||
return vmTeams;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vmTeams
|
||||
*/
|
||||
public void setVmTeams(SortedSet<VMTeam> vmTeams) {
|
||||
this.vmTeams = vmTeams;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param team
|
||||
*/
|
||||
public void addMember(VMTeam team) {
|
||||
vmTeams.add(team);
|
||||
team.getMembers().add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param team
|
||||
*/
|
||||
public void removeMember(VMTeam team) {
|
||||
vmTeams.remove(team);
|
||||
team.getMembers().remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
|
81
src/main/java/fr/lirmm/aren/model/vm/VMTeam.java
Normal file
81
src/main/java/fr/lirmm/aren/model/vm/VMTeam.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package fr.lirmm.aren.model.vm;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import fr.lirmm.aren.model.AbstractEntity;
|
||||
import fr.lirmm.aren.model.User;
|
||||
import org.hibernate.annotations.SortNatural;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* @author ANDRIAMBOLAHARIMIHANTA Havana on 11/07/2021
|
||||
* @project aren-1
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "vm_teams")
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = VMTheme.class)
|
||||
public class VMTeam extends AbstractEntity implements Serializable {
|
||||
@Size(max = 255)
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ManyToMany(mappedBy = "vmTeams")
|
||||
@SortNatural
|
||||
private SortedSet<User> members = new TreeSet<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SortedSet<User> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param members
|
||||
*/
|
||||
public void setMembers(SortedSet<User> members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
public void addUser(User user) {
|
||||
this.members.add(user);
|
||||
user.getVmTeams().add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
public void removeUser(User user) {
|
||||
this.members.remove(user);
|
||||
user.getVmTeams().remove(this);
|
||||
}
|
||||
}
|
|
@ -29,6 +29,9 @@ public class VMTheme extends AbstractEntity implements Serializable {
|
|||
@ManyToOne
|
||||
private User author;
|
||||
|
||||
@JoinColumn(name = "team", referencedColumnName = "id")
|
||||
@ManyToOne
|
||||
private VMTeam team;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "title")
|
||||
|
@ -64,6 +67,22 @@ public class VMTheme extends AbstractEntity implements Serializable {
|
|||
this.author = author;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public VMTeam getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param team
|
||||
*/
|
||||
public void setTeam(VMTeam team) {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
|
94
src/main/java/fr/lirmm/aren/service/vm/VMTeamService.java
Normal file
94
src/main/java/fr/lirmm/aren/service/vm/VMTeamService.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package fr.lirmm.aren.service.vm;
|
||||
|
||||
import fr.lirmm.aren.model.Debate;
|
||||
import fr.lirmm.aren.model.Team;
|
||||
import fr.lirmm.aren.model.vm.VMTeam;
|
||||
import fr.lirmm.aren.service.AbstractService;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ANDRIAMBOLAHARIMIHANTA Havana on 11/07/2021
|
||||
* @project aren-1
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class VMTeamService extends AbstractService<VMTeam> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public VMTeamService(){
|
||||
super(VMTeam.class) ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param teamId
|
||||
* @return
|
||||
*/
|
||||
private TypedQuery<VMTeam> generateQuery(Long teamId){
|
||||
TypedQuery<VMTeam> query = getEntityManager().createQuery("SELECT vmt "
|
||||
+"FROM VMTeam vmt "
|
||||
+"LEFT JOIN FETCH vmt.members m "
|
||||
+ (teamId != null
|
||||
? "WHERE vmt.id = :teamId "
|
||||
: "WHERE vmt.id IS NOT NULL ")
|
||||
, VMTeam.class
|
||||
) ;
|
||||
if (teamId != null) {
|
||||
query.setParameter("teamId", teamId);
|
||||
}
|
||||
return query ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<VMTeam> findAll() {
|
||||
return new HashSet<VMTeam>(generateQuery(null).getResultList());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param team
|
||||
*/
|
||||
@Override
|
||||
public void edit(VMTeam team) {
|
||||
super.edit(team);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMTeam insert(VMTeam team) {
|
||||
return super.insert(team) ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param teamId
|
||||
* @return
|
||||
*/
|
||||
public VMTeam find(Long teamId) {
|
||||
List<VMTeam> teams = generateQuery(teamId).getResultList();
|
||||
if (teams.isEmpty()) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return teams.get(0);
|
||||
}
|
||||
|
||||
public void updateExternaleTables(VMTeam team) {
|
||||
super.transactionBegin();
|
||||
team.getMembers().forEach(member->{
|
||||
System.out.println(team.getId()+" --- "+member.getId());
|
||||
getEntityManager().createNativeQuery("INSERT INTO vm_teams_users(vmteam_id,members_id) VALUES(?,?) ")
|
||||
.setParameter(1, team.getId())
|
||||
.setParameter(2, member.getId())
|
||||
.executeUpdate();
|
||||
super.commit();
|
||||
});
|
||||
}
|
||||
}
|
90
src/main/java/fr/lirmm/aren/ws/rest/VMTeamRESTFacade.java
Normal file
90
src/main/java/fr/lirmm/aren/ws/rest/VMTeamRESTFacade.java
Normal file
|
@ -0,0 +1,90 @@
|
|||
package fr.lirmm.aren.ws.rest;
|
||||
|
||||
import fr.lirmm.aren.model.Team;
|
||||
import fr.lirmm.aren.model.User;
|
||||
import fr.lirmm.aren.model.vm.VMTeam;
|
||||
import fr.lirmm.aren.service.UserService;
|
||||
import fr.lirmm.aren.service.vm.VMTeamService;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* @author ANDRIAMBOLAHARIMIHANTA Havana on 11/07/2021
|
||||
* @project aren-1
|
||||
*/
|
||||
@RequestScoped
|
||||
@Path("vm/teams")
|
||||
public class VMTeamRESTFacade extends AbstractRESTFacade<VMTeam>{
|
||||
@Inject
|
||||
VMTeamService teamService ;
|
||||
|
||||
@Inject
|
||||
UserService userService ;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected VMTeamService getService(){
|
||||
return teamService ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param team
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@PermitAll
|
||||
public VMTeam create(VMTeam team){
|
||||
SortedSet<User> members=team.getMembers() ;
|
||||
VMTeam teamRes= teamService.insert(team) ;
|
||||
members.forEach(member->{
|
||||
teamRes.addUser(userService.getReference(member.getId()));
|
||||
teamService.edit(teamRes);
|
||||
});
|
||||
return teamRes ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id of the Entity to update
|
||||
* @param team
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public VMTeam edit(Long id, VMTeam team){
|
||||
return super.edit(id,team) ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@PermitAll
|
||||
public Set<VMTeam> findAll() {
|
||||
Set<VMTeam> teams= teamService.findAll();
|
||||
return teams ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id of the Entity to fetch
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@PermitAll
|
||||
public VMTeam find(Long id) {
|
||||
return teamService.find(id);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue