mirror of
https://github.com/ArenMg/aren.git
synced 2024-11-16 05:30:51 +00:00
Merge pull request #7 from Arimihanta/main
Regler problème rang sur vote majoritaire
This commit is contained in:
commit
2abb350ccd
7 changed files with 31 additions and 104 deletions
|
@ -137,15 +137,6 @@ public class User extends AbstractEntEntity implements Serializable {
|
||||||
@SortNatural
|
@SortNatural
|
||||||
private SortedSet<Team> teams = new TreeSet<>();
|
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")
|
@OneToMany(mappedBy = "owner")
|
||||||
@SortNatural
|
@SortNatural
|
||||||
private SortedSet<Notification> notifications = new TreeSet<>();
|
private SortedSet<Notification> notifications = new TreeSet<>();
|
||||||
|
@ -383,40 +374,6 @@ public class User extends AbstractEntEntity implements Serializable {
|
||||||
team.getUsers().remove(this);
|
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
|
* @return
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package fr.lirmm.aren.model.vm;
|
package fr.lirmm.aren.model.vm;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
import fr.lirmm.aren.model.AbstractEntity;
|
import fr.lirmm.aren.model.AbstractEntity;
|
||||||
import org.hibernate.annotations.SortNatural;
|
import org.hibernate.annotations.SortNatural;
|
||||||
|
@ -73,6 +75,10 @@ public class VMChoice extends AbstractEntity implements Serializable {
|
||||||
@SortNatural
|
@SortNatural
|
||||||
private SortedSet<VMVote> votes = new TreeSet<>();
|
private SortedSet<VMVote> votes = new TreeSet<>();
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@JsonProperty
|
||||||
|
private int rank ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
@ -297,6 +303,22 @@ public class VMChoice extends AbstractEntity implements Serializable {
|
||||||
this.votes = votes;
|
this.votes = votes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getRank() {
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param rank
|
||||||
|
*/
|
||||||
|
public void setRank(int rank) {
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVoted(){
|
public boolean isVoted(){
|
||||||
if(this.getRejected()!=0 ||
|
if(this.getRejected()!=0 ||
|
||||||
this.getInsufficient()!=0 ||
|
this.getInsufficient()!=0 ||
|
||||||
|
|
|
@ -10,8 +10,6 @@ import org.hibernate.annotations.Where;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ANDRIAMBOLAHARIMIHANTA Havana on 11/07/2021
|
* @author ANDRIAMBOLAHARIMIHANTA Havana on 11/07/2021
|
||||||
|
@ -25,10 +23,6 @@ public class VMTeam extends AbstractEntity implements Serializable {
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "vmTeams")
|
|
||||||
@SortNatural
|
|
||||||
private SortedSet<User> members = new TreeSet<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
@ -44,38 +38,4 @@ public class VMTeam extends AbstractEntity implements Serializable {
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import javax.persistence.*;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ public class VMTheme extends AbstractEntity implements Serializable {
|
||||||
private ZonedDateTime expiracyDate;
|
private ZonedDateTime expiracyDate;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "themeId")
|
@OneToMany(mappedBy = "themeId")
|
||||||
private Set<VMChoice> choices = new LinkedHashSet<>();
|
private Set<VMChoice> choices = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -79,16 +79,4 @@ public class VMTeamService extends AbstractService<VMTeam> {
|
||||||
}
|
}
|
||||||
return teams.get(0);
|
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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,7 @@ public class VMTeamRESTFacade extends AbstractRESTFacade<VMTeam>{
|
||||||
@Override
|
@Override
|
||||||
@PermitAll
|
@PermitAll
|
||||||
public VMTeam create(VMTeam team){
|
public VMTeam create(VMTeam team){
|
||||||
SortedSet<User> members=team.getMembers() ;
|
|
||||||
VMTeam teamRes= teamService.insert(team) ;
|
VMTeam teamRes= teamService.insert(team) ;
|
||||||
members.forEach(member->{
|
|
||||||
teamRes.addUser(userService.getReference(member.getId()));
|
|
||||||
teamService.edit(teamRes);
|
|
||||||
});
|
|
||||||
return teamRes ;
|
return teamRes ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,16 +119,20 @@ public class VMThemeRESTFacade extends AbstractRESTFacade<VMTheme>{
|
||||||
|
|
||||||
int index=0 ;
|
int index=0 ;
|
||||||
for(ProposalResultInterface item : result.getProposalResults()){
|
for(ProposalResultInterface item : result.getProposalResults()){
|
||||||
newChoices[item.getRank()-1]=(VMChoice) choices[index] ;
|
VMChoice vmChoice=(VMChoice) choices[index] ;
|
||||||
|
vmChoice.setRank(item.getRank());
|
||||||
|
newChoices[item.getRank()-1]=vmChoice ;
|
||||||
System.out.println(item.getRank()+" - "+newChoices[item.getRank()-1].getTitle());
|
System.out.println(item.getRank()+" - "+newChoices[item.getRank()-1].getTitle());
|
||||||
index++ ;
|
index++ ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0 ; i<choicesNotVoted.size() ; i++){
|
for(int i=0 ; i<choicesNotVoted.size() ; i++){
|
||||||
newChoices[newChoices.length-(i+1)]= choicesNotVoted.get(i) ;
|
VMChoice vmChoice=choicesNotVoted.get(i) ;
|
||||||
|
vmChoice.setRank(newChoices.length-i);
|
||||||
|
newChoices[newChoices.length-(i+1)]= vmChoice ;
|
||||||
}
|
}
|
||||||
LinkedHashSet<VMChoice> setChoices = new LinkedHashSet<>();
|
HashSet<VMChoice> setChoices = new HashSet<>();
|
||||||
System.out.println("Rang : ") ;
|
System.out.println("Rang : ") ;
|
||||||
for(int i=0 ; i<newChoices.length ; i++){
|
for(int i=0 ; i<newChoices.length ; i++){
|
||||||
System.out.println(i+" - "+newChoices[i].getTitle());
|
System.out.println(i+" - "+newChoices[i].getTitle());
|
||||||
|
|
Loading…
Reference in a new issue