Commit 02e0d8ee authored by sunye's avatar sunye
Browse files

Several refactorings

parent bc6f10bf
package fr.alma.gtd.commande;
import fr.alma.gtd.donneespartagees.IContexte;
import fr.alma.gtd.donneesserveur.Utilisateur;
import fr.alma.gtd.interfacedistante.CallBack;
import fr.alma.gtd.isessions.IContexteServiceRemote;
import fr.alma.gtd.isessions.IUtilisateurServiceRemote;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Commande de creation d'un contexte.
* author Nobody
* @version 1.0.0
*/
public final class CommandeCreerContexte implements Commande {
/**
* L'identifiant de l'utilisateur.
*/
private final String identification;
/**
* Le contexte.
*/
private final IContexte contexte;
/**
* Le callback.
*/
private final CallBack<IContexte> callback;
/**
* Le service de gestion des contextes.
*/
private IContexteServiceRemote contexteServiceRemote;
/**
* Le service de gestion d'utilisateurs.
*/
private IUtilisateurServiceRemote utilisateurServiceRemote;
/**
* Le constructeur.
* @param i L'identifiant de l'utilisateur.
* @param co Le contexte.
* @param ca Le callback.
*/
public CommandeCreerContexte(final String i, final IContexte co, final CallBack<IContexte> ca) {
super();
this.identification = i;
this.contexte = co;
this.callback = ca;
final Properties env = new Properties();
env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
env.setProperty("java.naming.provider.url", "localhost:1099");
env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
try {
final Context context = new InitialContext(env);
this.contexteServiceRemote = (IContexteServiceRemote) context.lookup("ContexteService/local");
this.utilisateurServiceRemote = (IUtilisateurServiceRemote) context.lookup("UtilisateurService/local");
} catch (NamingException e) {
e.printStackTrace();
}
}
@Override
public void execute() throws RemoteException {
final IContexte ctx = this.contexteServiceRemote.getContexteById(this.contexte.getIdentifiantServeur());
final Utilisateur uti = this.utilisateurServiceRemote.getUtilisateurById(this.contexte.getCreateur().getIdentifiantServeur());
if ((ctx == null) && (uti != null) && (this.identification.equalsIgnoreCase(uti.getIdentifiantServeur()))) {
this.callback.onSucces(this.contexteServiceRemote.creerContexte(this.contexte));
} else {
if (ctx != null) {
this.callback.onFailure(new Exception("Contexte deja existant"));
} else {
this.callback.onFailure(new Exception("Identifiant utilisateur invalide"));
}
}
}
}
package fr.alma.gtd.commande;
import fr.alma.gtd.donneespartagees.IContexte;
import fr.alma.gtd.donneesserveur.Utilisateur;
import fr.alma.gtd.interfacedistante.CallBack;
import fr.alma.gtd.isessions.IContexteServiceRemote;
import fr.alma.gtd.isessions.IUtilisateurServiceRemote;
import java.rmi.RemoteException;
import java.util.List;
/**
* Commande de telechargement d'un contexte.
* author Nobody
* @version 1.0.0
*/
public final class CommandeTelechargeContextes implements Commande {
/**
* L'identifiant de l'utilisateur.
*/
private final String identification;
/**
* Le nom d'utilisateur.
*/
private final String username;
/**
* Le callback.
*/
private final CallBack<List<IContexte>> callback;
/**
* Le service de gestion de contexte.
*/
private IContexteServiceRemote contexteServiceRemote;
/**
* Le service de gestion d'utilisateurs.
*/
private IUtilisateurServiceRemote utilisateurServiceRemote;
/**
* Le constructeur.
* @param i L'identifiant de l'utilisateur.
* @param c Le callback.
*/
public CommandeTelechargeContextes(final String i, final CallBack<List<IContexte>> c) {
super();
this.identification = i;
this.callback = c;
this.username = "";
}
/**
* Le constructeur.
* @param i L'identifiant de l'utilisateur.
* @param u Le nom d'utilisateur.
* @param c Le callback.
*/
public CommandeTelechargeContextes(final String i, final String u, final CallBack<List<IContexte>> c) {
super();
this.identification = i;
this.username = u;
this.callback = c;
}
@Override
public void execute() throws RemoteException {
if ("".equalsIgnoreCase(this.username)) {
//TODO
} else {
final Utilisateur uti = this.utilisateurServiceRemote.getUtilisateurById(this.identification);
if (uti != null) {
this.callback.onSucces(this.contexteServiceRemote.getContexteByCreateur(uti.getIdentifiantServeur()));
} else {
this.callback.onFailure(new Exception("Identifiant utilisateur invalide"));
}
}
}
}
package fr.alma.gtd.donneesserveur;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.GenericGenerator;
import fr.alma.gtd.donneespartagees.AbstractProjet;
import fr.alma.gtd.donneespartagees.Avancement;
import fr.alma.gtd.donneespartagees.IContact;
import fr.alma.gtd.donneespartagees.IContexte;
import fr.alma.gtd.donneespartagees.IParticipant;
import fr.alma.gtd.donneespartagees.IProjet;
import fr.alma.gtd.donneespartagees.ITache;
/**
* Bean Entite representant un Projet et charge de gerer sa persistance.
* author Nobody
* @version 1.0.0
*/
@Entity
@Table(name = "PROJET")
public final class Projet extends AbstractProjet {
/**
* L'ID.
*/
private static final long serialVersionUID = 4820282979269181082L;
/**
* Le constructeur par defaut.
*/
public Projet() {
super();
}
/**
* Le constructeur avec initialisation du nom, du contexte par defaut et du createur.
* @param n Le nom choisi.
* @param contexte Le contexte choisi.
* @param c Le createur du projet.
*/
public Projet(final String n, final IContexte contexte,
final IParticipant c) {
super(n, contexte, c);
}
/**
* Constructeur de recopie d'un projet.
* @param p Projet a recopier
*/
public Projet(final IProjet p) {
super(p);
this.avancement = p.getAvancement();
this.contacts = p.getListeContacts();
this.contexteParDefaut = p.getContexteParDefaut();
this.createur = p.getCreateur();
this.dateDeDerniereModification = p.getDateDeDerniereModification();
this.nom = p.getNom();
this.dansArchive = p.isDansArchive();
this.dansLaPoubelle = p.isDansLaPoubelle();
this.listeDesParticipants = p.getListeDeParticipants();
this.listeDesSousProjets = p.getListeDeSousProjets();
this.listeDesTaches = p.getListeDeTaches();
}
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Override
public String getIdentifiantServeur() {
return this.identifiantServeur;
}
@Override
@ManyToOne
public Participant getCreateur() {
return (Participant) this.createur;
}
@Override
@Basic
public Date getDateDeDerniereModification() {
return this.dateDeDerniereModification;
}
@Override
@Basic
public String getNom() {
return this.nom;
}
@Override
@Basic
public Avancement getAvancement() {
return this.avancement;
}
@Override
@ManyToOne
public Contexte getContexteParDefaut() {
return (Contexte) this.contexteParDefaut;
}
@Transient
@Override
public List<IParticipant> getListeDeParticipants() {
return this.listeDesParticipants;
}
@Transient
@Override
public List<ITache> getListeDeTaches() {
return this.listeDesTaches;
}
@Override
@Basic
public boolean isDansLaPoubelle() {
return dansLaPoubelle;
}
@Override
@Basic
public boolean isDansArchive() {
return this.dansArchive;
}
@Transient
@Override
public List<IContact> getListeContacts() {
return contacts;
}
@Transient
@Override
public List<IProjet> getListeDeSousProjets() {
return this.listeDesSousProjets;
}
/*
* Methodes privees appelees uniquement par Hibernate :
* getters et setters permettant d'assurer la persistance des listes :
* - de Sous-Projets
* - de Participants
* - de Tags
*/
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Projet> getListeDesSousProjets() {
Set<Projet> listeElem = new HashSet<Projet>();
for(IProjet iElem : listeDesSousProjets){
listeElem.add((Projet)iElem);
}
return listeElem;
}
private void setListeDesSousProjets(Set<Projet> ssprojets) {
listeDesSousProjets.clear();
for(IProjet t : ssprojets){
listeDesSousProjets.add(t);
}
}
@ManyToMany(fetch = FetchType.EAGER)
private Set<Participant> getListeDesParticipants() {
Set<Participant> listeElem = new HashSet<Participant>();
for(IParticipant iElem : listeDesParticipants){
listeElem.add((Participant)iElem);
}
return listeElem;
}
private void setListeDesParticipants(Set<Participant> Participants) {
listeDesParticipants.clear();
for(Participant t : Participants){
listeDesParticipants.add(t);
}
}
@OneToMany(mappedBy = "projetConteneur", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Tache> getListeDesTaches() {
Set<Tache> listeElem = new HashSet<Tache>();
for(ITache iElem : listeDesTaches){
listeElem.add((Tache)iElem);
}
return listeElem;
}
private void setListeDesTaches(Set<Tache> listedesTaches) {
listeDesTaches.clear();
for(Tache t : listedesTaches){
listeDesTaches.add(t);
t.setProjetConteneur(this);
}
}
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Contact> getContacts() {
Set<Contact> listeElem = new HashSet<Contact>();
for(IContact iElem : contacts){
listeElem.add((Contact)iElem);
}
return listeElem;
}
private void setContacts(Set<Contact> listedescontacts) {
contacts.clear();
for(Contact t : listedescontacts){
contacts.add(t);
}
}
}
package fr.alma.gtd.donneesserveur;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import fr.alma.gtd.donneespartagees.AbstractTag;
import fr.alma.gtd.donneespartagees.IParticipant;
import fr.alma.gtd.donneespartagees.ITag;
/**
* Bean Entite representant un Tag et charge de gerer sa persistance.
* author Nobody
* @version 1.0.0
*/
@Entity
@Table(name = "TAG")
public final class Tag extends AbstractTag {
/**
* Identifiant de serialisation.
*/
private static final long serialVersionUID = 636415771384651280L;
/**
* Le constructeur par defaut.
*/
public Tag() {
super();
}
/**
* Constructeur d'un Tag (prend simplement le nom correspondant au Tag).
* @param name Nom correspondant au Tag
* @param p Le createur du tag.
*/
public Tag(final String name, final IParticipant p) {
super(name, p);
}
/**
* Constructeur de recopie d'un Tag.
* @param tag Tag a recopier
*/
public Tag(final ITag tag) {
super(tag);
}
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Override
public String getIdentifiantServeur() {
return this.identifiantServeur;
}
@ManyToOne
@Override
public Participant getCreateur() {
return (Participant) this.createur;
}
@Basic
@Override
public Date getDateDeDerniereModification() {
return this.dateDeDerniereModification;
}
@Basic
@Override
public String getNom() {
return this.nom;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_qb8akM37EdqwVrslYOdUDA">
<packagedElement xmi:type="uml:Package" xmi:id="_w8IxIM37EdqwVrslYOdUDA" name="serveur">
<packagedElement xmi:type="uml:Interface" xmi:id="_3CUwENjSEd6cN6x_fk6prg" name="ServeurRMI">
<ownedOperation xmi:id="_4jp_8NjSEd6cN6x_fk6prg" name="creerCompte">
<ownedParameter xmi:id="_ROMnENjTEd6cN6x_fk6prg" name="idee" type="_iO_1oNjTEd6cN6x_fk6prg"/>
</ownedOperation>
<ownedOperation xmi:id="_6X16YNjSEd6cN6x_fk6prg" name="creerContexte"/>
<ownedOperation xmi:id="_-Q8S4NjSEd6cN6x_fk6prg" name="creerIdee"/>
<ownedOperation xmi:id="__qITYNjSEd6cN6x_fk6prg" name="creerProjet"/>
<ownedOperation xmi:id="_AoEiUNjTEd6cN6x_fk6prg" name="creerTache"/>
<ownedOperation xmi:id="_BqEK0NjTEd6cN6x_fk6prg" name="creerTag"/>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_iO_1oNjTEd6cN6x_fk6prg" name="IIdee">
<generalization xmi:id="_ktPSU9jWEd6cN6x_fk6prg" general="_kcEKINjTEd6cN6x_fk6prg"/>
<ownedOperation xmi:id="_Au2DQNjUEd6cN6x_fk6prg" name="getCreateur"/>
<ownedOperation xmi:id="_BsQtwNjUEd6cN6x_fk6prg" name="getDescription"/>
<ownedOperation xmi:id="_DBQx0NjUEd6cN6x_fk6prg" name="getNom"/>
<ownedOperation xmi:id="_DyJcMNjUEd6cN6x_fk6prg" name="isDansLaPoubelel"/>
<ownedOperation xmi:id="_E9JPsNjUEd6cN6x_fk6prg" name="setCreateur"/>
<ownedOperation xmi:id="_GdqAMNjUEd6cN6x_fk6prg" name="setDansLaPoubelle"/>
<ownedOperation xmi:id="_IAwxsNjUEd6cN6x_fk6prg" name="setDescription"/>
<ownedOperation xmi:id="_I-nhENjUEd6cN6x_fk6prg" name="setNom"/>
<ownedOperation xmi:id="_1lxyMNjVEd6cN6x_fk6prg" name="mettreALaPoubelle"/>
<ownedOperation xmi:id="_6RTGINjVEd6cN6x_fk6prg" name="restaurer"/>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_jZO0INjTEd6cN6x_fk6prg" name="IContexte">
<generalization xmi:id="_jd2uE9jWEd6cN6x_fk6prg" general="_kcEKINjTEd6cN6x_fk6prg"/>
<ownedOperation xmi:id="_OLf1oNjUEd6cN6x_fk6prg" name="getCreateur"/>
<ownedOperation xmi:id="_O-nUoNjUEd6cN6x_fk6prg" name="getNom"/>
<ownedOperation xmi:id="_PrZiINjUEd6cN6x_fk6prg" name="setCreateur">
<ownedParameter xmi:id="_ZZ1DYNjhEd6cN6x_fk6prg" name="c" type="_l9GfENjTEd6cN6x_fk6prg"/>
</ownedOperation>
<ownedOperation xmi:id="_QiaCoNjUEd6cN6x_fk6prg" name="setNom">
<ownedParameter xmi:id="_kb97INjhEd6cN6x_fk6prg" name="n" type="_f_nzANjeEd6cN6x_fk6prg"/>
</ownedOperation>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_kcEKINjTEd6cN6x_fk6prg" name="IObjetServeur">
<ownedOperation xmi:id="_vdTC8NjTEd6cN6x_fk6prg" name="getDateDeDerniereModification">
<ownedParameter xmi:id="_sF_H4NjeEd6cN6x_fk6prg" name="return" direction="return"/>
</ownedOperation>
<ownedOperation xmi:id="_0iroYNjTEd6cN6x_fk6prg" name="getIdentifiant"/>
<ownedOperation xmi:id="_1qdv0NjTEd6cN6x_fk6prg" name="getIdentifiantServeur"/>
<ownedOperation xmi:id="_3C0C0NjTEd6cN6x_fk6prg" name="setDateDeDerniereModification">
<ownedParameter xmi:id="_KPK3ENjhEd6cN6x_fk6prg" name="date" type="_x5KAYNjeEd6cN6x_fk6prg"/>
</ownedOperation>
<ownedOperation xmi:id="_69-Q0NjTEd6cN6x_fk6prg" name="setIdentifiant">
<ownedParameter xmi:id="_OTOiYNjhEd6cN6x_fk6prg" name="id" type="_f_nzANjeEd6cN6x_fk6prg"/>
</ownedOperation>
<ownedOperation xmi:id="_8dHIUNjTEd6cN6x_fk6prg" name="setIdentifiantServeur">
<ownedParameter xmi:id="_Qn23cNjhEd6cN6x_fk6prg" name="idServeur" type="_f_nzANjeEd6cN6x_fk6prg"/>
</ownedOperation>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_l9GfENjTEd6cN6x_fk6prg" name="IParticipant">
<generalization xmi:id="_j6Wc0tjWEd6cN6x_fk6prg" general="_kcEKINjTEd6cN6x_fk6prg"/>
<ownedOperation xmi:id="_rsue4NjUEd6cN6x_fk6prg" name="getPseudonyme"/>
<ownedOperation xmi:id="_tAB50NjUEd6cN6x_fk6prg" name="setPseudonyme">
<ownedParameter xmi:id="_SUCagNjjEd6cN6x_fk6prg" name="pseudo" type="_f_nzANjeEd6cN6x_fk6prg"/>
</ownedOperation>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_m4iMkNjTEd6cN6x_fk6prg" name="IProjet">
<generalization xmi:id="_mDrg0NjWEd6cN6x_fk6prg" general="_kcEKINjTEd6cN6x_fk6prg"/>
<ownedOperation xmi:id="_x5yMINjWEd6cN6x_fk6prg" name="ajoutTache"/>
<ownedOperation xmi:id="_zKzIENjWEd6cN6x_fk6prg" name="archiver"/>
<ownedOperation xmi:id="_0H_JENjWEd6cN6x_fk6prg" name="getAvancement"/>
<ownedOperation xmi:id="_1QnlENjWEd6cN6x_fk6prg" name="getContexteParDefaut"/>
<ownedOperation xmi:id="_3N5KENjWEd6cN6x_fk6prg" name="getCreateur"/>
<ownedOperation xmi:id="_4LT0kNjWEd6cN6x_fk6prg" name="getListeDesParticipants"/>
<ownedOperation xmi:id="_5o_TgNjWEd6cN6x_fk6prg" name="getListeDesTaches"/>
<ownedOperation xmi:id="_68KLkNjWEd6cN6x_fk6prg" name="getNom"/>
<ownedOperation xmi:id="_7qTrANjWEd6cN6x_fk6prg" name="isDansLaPoubelle"/>
<ownedOperation xmi:id="_82OEgNjWEd6cN6x_fk6prg" name="mettreALaPoubelle"/>
<ownedOperation xmi:id="_-Px4cNjWEd6cN6x_fk6prg" name="restaurer"/>
<ownedOperation xmi:id="__KYfgNjWEd6cN6x_fk6prg" name="setAvancement"/>
<ownedOperation xmi:id="_AedWgNjXEd6cN6x_fk6prg" name="setContexteParDefaut"/>
<ownedOperation xmi:id="_C6xn8NjXEd6cN6x_fk6prg" name="setCreateur"/>
<ownedOperation xmi:id="_D7PmcNjXEd6cN6x_fk6prg" name="setDansLaPoubelle"/>
<ownedOperation xmi:id="_FnuWYNjXEd6cN6x_fk6prg" name="setListeDesParticipants"/>
<ownedOperation xmi:id="_IED18NjXEd6cN6x_fk6prg" name="setListeDesTaches"/>
<ownedOperation xmi:id="_Jl3m8NjXEd6cN6x_fk6prg" name="setNom"/>
<ownedOperation xmi:id="_KqXw4NjXEd6cN6x_fk6prg" name="supprimerToutesTaches"/>
<ownedOperation xmi:id="_L3Ro4NjXEd6cN6x_fk6prg" name="supprimerTache"/>
</packagedElement>
<packagedElement xmi:type="uml:Interface" xmi:id="_nphkoNjTEd6cN6x_fk6prg" name="ITache">
<generalization xmi:id="_lMhPUtjWEd6cN6x_fk6prg" general="_kcEKINjTEd6cN6x_fk6prg"/>
<ownedOperation xmi:id="_5F3qQNjUEd6cN6x_fk6prg" name="archiver"/>
<ownedOperation xmi:id="_6BYQQNjUEd6cN6x_fk6prg" name="getAvancement"/>
<ownedOperation xmi:id="_7UYwQNjUEd6cN6x_fk6prg" name="getContexte"/>
<ownedOperation xmi:id="_8045sNjUEd6cN6x_fk6prg" name="getCreateur"/>
<ownedOperation xmi:id="_99I7MNjUEd6cN6x_fk6prg" name="getDateDebut"/>
<ownedOperation xmi:id="__mk-MNjUEd6cN6x_fk6prg" name="getDateFin"/>
<ownedOperation xmi:id="_AjTsMNjVEd6cN6x_fk6prg" name="getFrequence"/>
<ownedOperation xmi:id="_Bt2MsNjVEd6cN6x_fk6prg" name="getListeDesTags"/>
<ownedOperation xmi:id="_DCJtMNjVEd6cN6x_fk6prg" name="getListeDesURLs"/>