Commit af1a8c38 authored by Mathieu Gicquel's avatar Mathieu Gicquel
Browse files

Participants association - Fix #18

parent 26a4a746
......@@ -188,7 +188,7 @@ public abstract class AbstractProject extends AbstractServerObject implements IP
@Override
public final void setParticipantsList(final List<IParticipant> participantList) {
this.participantsList = participantList;
this.getParticipantsReference().set(participantList);
}
@Override
......
......@@ -17,4 +17,6 @@ public interface IParticipant extends IServerObject {
*/
void setPseudonym(final String pseudo);
MultipleReference<IProject> getProjectReference();
}
......@@ -145,4 +145,6 @@ public interface IProject extends IServerObject {
MultipleReference<ITask> getTaskReference();
MultipleReference<IProject> getSubprojectReference();
MultipleReference<IParticipant> getParticipantsReference();
}
......@@ -14,12 +14,14 @@ public class Project extends AbstractProject implements IProject {
private ReferenceToProjects subprojects;
private ReferenceProjectToTask tasks;
private SingleReference<IParticipant> creator;
private MultipleReference<IParticipant> participants;
public Project() {
super();
this.subprojects = new ReferenceToProjects();
this.tasks = new ReferenceProjectToTask(this);
this.creator = new ReferenceToUser();
this.participants = new ReferenceProjectToUser(this);
}
public Project(IProject autre) {
......@@ -78,7 +80,7 @@ public class Project extends AbstractProject implements IProject {
@Override
public List<IParticipant> getParticipantsList() {
return null;
return this.participants.get();
}
@Override
......@@ -115,4 +117,8 @@ public class Project extends AbstractProject implements IProject {
return this.subprojects;
}
@Override
public MultipleReference<IParticipant> getParticipantsReference() {
return this.participants;
}
}
package fr.alma.gtd.server.main.donnees;
import fr.alma.gtd.server.core.IParticipant;
import fr.alma.gtd.server.core.IProject;
import fr.alma.gtd.server.core.MultipleReference;
import fr.alma.gtd.server.persistence.data.Utilisateur;
import java.util.ArrayList;
import java.util.List;
public class ReferenceProjectToUser implements MultipleReference<IParticipant> {
IProject p;
List<IParticipant> users;
public ReferenceProjectToUser(IProject p) {
this.p=p;
this.users = new ArrayList<>();
}
@Override
public boolean add(IParticipant value) {
value.getProjectReference().basicAdd(this.p);
this.basicAdd(value);
return true;
}
@Override
public void remove(IParticipant value) {
value.getProjectReference().basicRemove(p);
this.basicRemove(value);
}
@Override
public boolean contains(IParticipant value) {
return this.users.contains(value);
}
@Override
public int size() {
return this.users.size();
}
@Override
public void basicAdd(IParticipant value) {
this.users.add(value);
}
@Override
public void basicRemove(IParticipant value) {
this.users.remove(value);
}
@Override
public void removeAll() {
while (this.size()>0) {
this.get().get(0).getProjectReference().remove(this.p);
}
}
@Override
public List<IParticipant> get() {
return this.users;
}
@Override
public void set(List<IParticipant> value) {
this.removeAll();
this.users = value;
for (IParticipant p :
users) {
p.getProjectReference().basicAdd(this.p);
}
}
}
......@@ -89,4 +89,9 @@ public final class Participant extends AbstractParticipant {
public int hashCode() {
return this.serverIdentifier.hashCode();
}
@Override
public MultipleReference<IProject> getProjectReference() {
return null;
}
}
......@@ -237,4 +237,9 @@ public final class Project extends AbstractProject {
public MultipleReference<IProject> getSubprojectReference() {
throw new UnsupportedOperationException();
}
@Override
public MultipleReference<IParticipant> getParticipantsReference() {
throw new UnsupportedOperationException();
}
}
package fr.alma.gtd.server.persistence.data;
import fr.alma.gtd.server.core.IParticipant;
import fr.alma.gtd.server.core.IProject;
import fr.alma.gtd.server.core.ITask;
import fr.alma.gtd.server.core.MultipleReference;
import java.util.ArrayList;
import java.util.List;
public class ReferenceUserToProject implements MultipleReference<IProject> {
IParticipant participant;
List<IProject> projects;
public ReferenceUserToProject(IParticipant participant) {
this.participant = participant;
this.projects = new ArrayList<>();
}
@Override
public boolean add(IProject value) {
value.getParticipantsReference().basicAdd(participant);
this.basicAdd(value);
return true;
}
@Override
public void remove(IProject value) {
value.getParticipantsReference().basicRemove(this.participant);
this.basicRemove(value);
}
@Override
public boolean contains(IProject value) {
return this.projects.contains(value);
}
@Override
public int size() {
return this.projects.size();
}
@Override
public void basicAdd(IProject value) {
this.projects.add(value);
}
@Override
public void basicRemove(IProject value) {
this.projects.remove(value);
}
@Override
public List<IProject> get() {
return this.projects;
}
public void removeAll() {
while (this.size()>0) {
this.projects.get(0).getParticipantsReference().remove(this.participant);
}
}
@Override
public void set(List<IProject> value) {
this.removeAll();
this.projects = value;
for (IProject project :
projects) {
project.getParticipantsReference().basicAdd(this.participant);
}
}
}
package fr.alma.gtd.server.persistence.data;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.Basic;
......@@ -12,6 +13,8 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import fr.alma.gtd.server.core.IParticipant;
import fr.alma.gtd.server.core.IProject;
import fr.alma.gtd.server.core.MultipleReference;
import org.hibernate.annotations.GenericGenerator;
......@@ -66,6 +69,8 @@ public final class Utilisateur implements IParticipant {
private Set<Project> projetsAssocies;
private Date lastModificationDate;
private MultipleReference<IProject> projects;
/**
* Le constructeur par defaut.
......@@ -73,6 +78,7 @@ public final class Utilisateur implements IParticipant {
public Utilisateur() {
super();
this.lastModificationDate = new Date();
this.projects = new ReferenceUserToProject(this);
}
/**
......@@ -91,7 +97,7 @@ public final class Utilisateur implements IParticipant {
public void copier(final Utilisateur u){
this.ideesAssociees = u.getIdeesAssociees();
this.tachesAssociees = u.getTachesAssociees();
this.projetsAssocies = u.getProjetsAssocies();
this.projects = u.getProjectReference();
this.participantAssocie = u.getParticipantAssocie();
this.password = u.getPassword();
this.login = u.getLogin();
......@@ -177,15 +183,15 @@ public final class Utilisateur implements IParticipant {
/**
* @return Sete des projets crees par l'utilisateur.
*/
public Set<Project> getProjetsAssocies() {
return projetsAssocies;
public List<IProject> getProjetsAssocies() {
return (this.projects.get());
}
/**
* @param projetsAssociees Sete des projets crees par l'utilisateur.
*/
public void setProjetsAssocies(final Set<Project> projetsAssocies) {
this.projetsAssocies = projetsAssocies;
public void setProjetsAssocies(final List<IProject> projetsAssocies) {
this.projects.set(projetsAssocies);
}
......@@ -244,4 +250,9 @@ public final class Utilisateur implements IParticipant {
public void setLastModificationDate(Date lastModificationDate) {
this.lastModificationDate = lastModificationDate;
}
@Override
public MultipleReference<IProject> getProjectReference() {
return this.projects;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment