Jean-Francois Leveque

Merge de master dans migrateUser pour prendre la suite.

Showing 74 changed files with 1869 additions and 1178 deletions
#!groovy
node {
stage 'Environment'
if (scm.branches == 'master') {
println 'Nous sommes dans master'
}
// println scm.branches
stage 'Config'
def sonarqubeScannerHome = tool name: 'sonar', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
stage 'Checkout'
checkout([$class: 'GitSCM', branches: [[name: "origin/$scm.branches"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'grogdevSSH', url: 'git@grogv3.legrog.org:grogv3/web-application.git']]])
stage 'clean install'
withMaven(mavenLocalRepo: '', mavenOpts: '', mavenSettingsFilePath: '') {
sh "mvn clean install"
}
stage 'Scan'
sh "${sonarqubeScannerHome}/bin/sonar-scanner -Dsonar.host.url=http://grogv3.legrog.org:9000"
}
\ No newline at end of file
This diff is collapsed. Click to expand it.
package org.legrog.application;
import org.legrog.entities.PublisherRevision;
import java.util.List;
public interface PublisherRevisionService {
void addPublisherRevision(PublisherRevision publisherRevision);
List<PublisherRevision> getAllPublisherRevisions();
PublisherRevision getPublisherRevision(Integer publisherRevisionId);
}
package org.legrog.application;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.PublisherRevisionRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
@Stateless
public class PublisherRevisionServiceSpring implements PublisherRevisionService {
@Inject
PublisherRevisionRepository publisherRevisionRepository;
public void addPublisherRevision(PublisherRevision publisherRevision) {
publisherRevisionRepository.save(publisherRevision);
}
public List<PublisherRevision> getAllPublisherRevisions() {
return publisherRevisionRepository.findAll();
}
public PublisherRevision getPublisherRevision(Integer publisherRevisionId) {
return publisherRevisionRepository.findOne(publisherRevisionId);
}
}
\ No newline at end of file
package org.legrog.application;
import org.legrog.entities.Publisher;
import java.util.List;
public interface PublisherService {
void addPublisher(Publisher publisher);
List<Publisher> getAllPublishers();
}
package org.legrog.application;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
@Stateless
public class PublisherServiceSpring implements PublisherService {
@Inject
PublisherRepository publisherRepository;
public void addPublisher(Publisher publisher) {
publisherRepository.save(publisher);
}
public List<Publisher> getAllPublishers() {
return publisherRepository.findAll();
}
}
package org.legrog.application;
import org.legrog.entities.User;
import java.util.List;
public interface UserService {
void addUser(User user);
List<User> getAllUsers();
User findUserById(int id);
void updateUser(User user);
}
package org.legrog.application;
import org.legrog.entities.User;
import org.legrog.entities.UserRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
@Stateless
public class UserServiceSpring implements UserService {
@Inject
UserRepository userRepository;
public void addUser(User user) {
userRepository.save(user);
}
public List<User> getAllUsers() {
return userRepository.findAll();
}
public User findUserById(int id) {
return userRepository.findOne(new Integer(id));
}
public void updateUser(User user) {
userRepository.save(user);
}
}
\ No newline at end of file
package org.legrog.configuration;
import org.omnifaces.filter.CharacterEncodingFilter;
import javax.servlet.annotation.WebFilter;
/**
* ensure every request parameters (and so the content of forms in POST request) are done in utf-8
*/
@WebFilter("/*")
public class Utf8CharacterEncodingFilter extends CharacterEncodingFilter {
}
package org.legrog.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* Classe des actions possibles.
*/
@Entity
public class ActionType {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int actionTypeId;
private String actionTypeName;
public String getActionTypeName() {
return actionTypeName;
}
}
\ No newline at end of file
package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActionTypeRepository extends JpaRepository<ActionType, Integer> {
ActionType findByActionTypeName(String actionTypeName);
}
......@@ -6,7 +6,7 @@ import javax.persistence.*;
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int bookId;
private String bookTitle;
......
......@@ -2,12 +2,14 @@ package org.legrog.entities;
import javax.persistence.*;
/*
Entité persistante repésentant un pays.
Simplement composée d'un identitiant et d'un libellé.
*/
@Entity
public class Country /* extends org.roliste.data.DbEntity */ {
@Id
// @GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="COUNTRY_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int countryId;
private String countryName;
......@@ -27,21 +29,9 @@ public class Country /* extends org.roliste.data.DbEntity */ {
this.countryName = countryName;
}
/**
* Returns a string representation of this country definition.
* @return a string representing this country definition.
* @hidden
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ID_PAYS=");
sb.append(countryId);
sb.append(" LIB_PAYS=");
sb.append(countryName);
return sb.toString();
return "ID_PAYS=" + countryId + " LIB_PAYS=" + countryName;
}
}
\ No newline at end of file
......
......@@ -6,6 +6,9 @@ package org.legrog.entities;
* capabilities, that may be "masked", thus shown in some specific way depending on chosen
* NameMask.
*/
/*
v3 {@link org.legrog.entities.DisplayNameConfigurable}
*/
public enum DisplayNameMask
{
PRENOMNOM("Prénom Nom")
......@@ -89,7 +92,7 @@ public enum DisplayNameMask
public String getDisplayName(DisplayNameConfigurable person)
{
StringBuffer myResult = new StringBuffer();
StringBuilder myResult = new StringBuilder();
if (person.getFirstName() != null)
{
......@@ -113,8 +116,7 @@ public enum DisplayNameMask
private final String symbol;
private DisplayNameMask(String symbol)
{
DisplayNameMask(String symbol) {
this.symbol = symbol;
}
......
......@@ -2,19 +2,19 @@ package org.legrog.entities;
import javax.persistence.*;
import java.util.*;
// TODO Evaluer l'interet de ces imports
//import org.roliste.data.DbMaskableEntity;
// TODO Evaluer l'interet de cet import
//import org.roliste.data.DbValidationEntity;
// TODO Vérifier les extends
// TODO NameMask et DbMaskableEntity à traiter ensemble
/*
Entité persistante représentant un utilisateur.
Migréee depuis la v2.
*/
@Entity
@Table(name="UserTable")
public class User /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
public class Person /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
@Column(name="USER_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int userId;
// TODO traiter Traceable
......@@ -36,7 +36,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
return _traceRoot;
}
*/
// TODO NameMask et DbMaskableEntity à traiter ensemble
/**
* The mask used for user name.
*/
......@@ -68,7 +68,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
* column="MASQUE_NOM_UTILISATEUR"
* access="property"
* length="50"
* @hibernate.type
* hibernate.type
* name="org.roliste.data.util.NameMaskUserType"
*/
public DisplayNameMask getDisplayNameMask() {
......@@ -81,7 +81,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
* see #getNameMask()
*/
public void setDisplayNameMask(DisplayNameMask mask) {
mask = mask;
this.displayNameMask = mask;
}
......@@ -120,7 +120,6 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
* The {link org.roliste.data.db.UserRole}s for this user.
*/
@ManyToMany(fetch = FetchType.EAGER)
@Column(name = "USER_ROLE_ID")
private List<UserRole> roles;
/**
......@@ -181,7 +180,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
{
if ((role != null) && !(getRoles().contains(role)) )
{
role.getUsers().add(this);
role.getPersons().add(this);
getRoles().add(role);
}
}
......@@ -189,7 +188,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove the user from a given {@link UserRole}s.
* @param role the {@link UserRole} this {@link User} will lose. Ignored if <code>null</code>.
* @param role the {@link UserRole} this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getRoles()
* @see #setRoles(List)
* @see #addToRole(UserRole)
......@@ -200,7 +199,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
{
if ((role != null) && (getRoles().contains(role)) )
{
role.getUsers().remove(this);
role.getPersons().remove(this);
getRoles().remove(role);
}
}
......@@ -301,7 +300,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove a book from user's collection.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link User} will lose. Ignored if <code>null</code>.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getCollection()
* @see #setCollection(List)
* @see #addToCollection(BookDetails)
......@@ -390,7 +389,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove delegation on a given {@link Traceable} from this user.
* @param object the delegation this {@link User} will lose. Ignored if <code>null</code>.
* @param object the delegation this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getDelegations()
* @see #setDelegations(List)
* @see #giveDelegation(Traceable)
......@@ -426,7 +425,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
/**
* The list of attributes / properties for this user.
*/
@OneToMany(mappedBy = "user")
@OneToMany(mappedBy = "person")
private List<UserAttribute> userAttributes;
/**
......@@ -773,33 +772,10 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
this.creationDate = date;
}
/**
* Returns a string representation of this user definition.
* @return a string representing this user definition.
* hidden
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ID_UTILISATEUR=");
sb.append(userId);
sb.append(" LOGIN_UTILISATEUR=");
sb.append(username);
sb.append(" EMAIL_UTILISATEUR=");
sb.append(email);
sb.append(" PRENOM_UTILISATEUR=");
sb.append(firstName);
sb.append(" NOM_UTILISATEUR=");
sb.append(lastName);
sb.append(" PSEUDO_UTILISATEUR=");
sb.append(nickname);
return sb.toString();
return "ID_UTILISATEUR=" + userId + " LOGIN_UTILISATEUR=" + username + " EMAIL_UTILISATEUR=" + email +
" PRENOM_UTILISATEUR=" + firstName + " NOM_UTILISATEUR=" + lastName + " PSEUDO_UTILISATEUR=" + nickname;
}
}
\ No newline at end of file
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Integer> {
public interface PersonRepository extends JpaRepository<Person, Integer> {
}
......
......@@ -4,26 +4,27 @@ import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Set;
/*
Entité persistante correspondant à un éditeur.
Pointe vers la version valide si elle existe, ainsi que son validateur et la date de validation.
Pointe vers l'ensemble de ses versions.
*/
@Entity
//@Table(name = "editeur")
public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
// TODO L'éventuel usage de Linkable reste à confirmer https://tree.taiga.io/project/jr-utily-grog-v3/us/48
// TODO Attention, en v2 Linkable implique Traceable (journalisable) qui devrait aussi être évalué
@Id
@Column(name = "PUBLISHER_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int publisherId;
@OneToOne
private PublisherRevision activeRevision;
private PublisherVersion validatedVersion;
@OneToOne
private User activeValidator;
private Timestamp validationDateTime;
@OneToMany(mappedBy = "publisher", fetch = FetchType.EAGER)
private Set<PublisherVersion> versions;
@OneToMany(mappedBy = "publisher")
private Set<PublisherRevision> revisions;
@OneToMany(mappedBy = "publisher", fetch = FetchType.EAGER)
private Set<PublisherAction> actions;
public int getPublisherId() {
return publisherId;
......@@ -33,40 +34,32 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
this.publisherId = publisherId;
}
public PublisherRevision getActiveRevision() {
return activeRevision;
}
public void setActiveRevision(PublisherRevision activeRevision) {
this.activeRevision = activeRevision;
}
public Set<PublisherRevision> getRevisions() {
return revisions;
public PublisherVersion getValidatedVersion() {
return validatedVersion;
}
public void setRevisions(Set<PublisherRevision> revisions) {
this.revisions = revisions;
public void setValidatedVersion(PublisherVersion activeVersion) {
this.validatedVersion = activeVersion;
}
public User getActiveValidator() {
return activeValidator;
public Set<PublisherVersion> getVersions() {
return versions;
}
public void setActiveValidator(User activeValidator) {
this.activeValidator = activeValidator;
public void setVersions(Set<PublisherVersion> versions) {
this.versions = versions;
}
public Timestamp getValidationDateTime() {
return validationDateTime;
public Set<PublisherAction> getActions() {
return actions;
}
public void setValidationDateTime(Timestamp validationDateTime) {
this.validationDateTime = validationDateTime;
public void setActions(Set<PublisherAction> actions) {
this.actions = actions;
}
@Override
public String toString() {
return "PUBLISHER_ID = " + publisherId + ", Active Revision = " + activeRevision + ", Validator = " + activeValidator + ", Validation DateTime = " + validationDateTime;
return "PUBLISHER_ID = " + publisherId + ", Validated Version = " + validatedVersion;
}
}
......
package org.legrog.entities;
import javax.persistence.*;
import java.sql.Timestamp;
/**
* Classe des actions sur des (versions d') éditeurs.
*/
@Entity
public class PublisherAction {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int publisherActionId;
@ManyToOne
private ActionType actionType;
@ManyToOne
private Person publisherActionAuthor;
@ManyToOne
private PublisherVersion publisherVersion;
private Timestamp publisherActionDatetime;
// Accessible par publisherVersion, demande spécifique de la MOE
@ManyToOne
private Publisher publisher;
public void setPublisherActionAuthor(Person publisherActionAuthor) {
this.publisherActionAuthor = publisherActionAuthor;
}
public void setPublisherActionDatetime(Timestamp publisherActionDatetime) {
this.publisherActionDatetime = publisherActionDatetime;
}
public void setActionType(ActionType actionType) {
this.actionType = actionType;
}
public void setPublisherVersion(PublisherVersion publisherVersion) {
this.publisherVersion = publisherVersion;
}
public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
public ActionType getActionType() {
return actionType;
}
public Person getPublisherActionAuthor() {
return publisherActionAuthor;
}
public PublisherVersion getPublisherVersion() {
return publisherVersion;
}
public Timestamp getPublisherActionDatetime() {
return publisherActionDatetime;
}
public Publisher getPublisher() {
return publisher;
}
@Override
public String toString() {
return "publisherActionId = " + publisherActionId + ", actionType = " + actionType +
", publisherActionAuthor = " + publisherActionAuthor + ", publisherVersion = " + publisherVersion +
", publisherActionDatetime = " + publisherActionDatetime + ", publisher = " + publisher;
}
}
\ No newline at end of file
package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> {
@Query("select pa from PublisherAction pa where pa.actionType = (select ua from ActionType ua where ua.actionTypeName = 'Validate') and pa.publisherActionDatetime = ( select max(pa2.publisherActionDatetime) from PublisherAction pa2 where pa2.publisher =?1)")
PublisherAction publisherLastValidate(Publisher publisher);
}
package org.legrog.entities;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Timestamp;
/*
Entité persistente représentant une version d'un éditeur.
Contient les données représentant un éditeur.
Adresse découpée en suivant http://schema.org/PostalAddress.
Pointe vers l'éditeur auquel elle correspond.
Pointe vers l'auteur de la version et contient la date et heure de celle-ci.
*/
@Entity
public class PublisherRevision {
public class PublisherVersion {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PUBLISHER_REVISION_ID")
private int publisherRevisionId;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int publisherVersionId;
@ManyToOne
private Publisher publisher;
private String publisherName;
......@@ -26,15 +31,15 @@ public class PublisherRevision {
private boolean publisherActive;
private String publisherHistory;
@ManyToOne
private User publisherRevisionAuthor;
private Timestamp publisherRevisionDatetime;
private Person publisherVersionAuthor;
private Timestamp publisherVersionDatetime;
public Timestamp getPublisherRevisionDatetime() {
return publisherRevisionDatetime;
public Timestamp getPublisherVersionDatetime() {
return publisherVersionDatetime;
}
public void setPublisherRevisionDatetime(Timestamp publisherRevisionDatetime) {
this.publisherRevisionDatetime = publisherRevisionDatetime;
public void setPublisherVersionDatetime(Timestamp publisherVersionDatetime) {
this.publisherVersionDatetime = publisherVersionDatetime;
}
public boolean isPublisherActive() {
......@@ -117,12 +122,12 @@ public class PublisherRevision {
this.publisherURL = publisherURL;
}
public int getPublisherRevisionId() {
return publisherRevisionId;
public int getPublisherVersionId() {
return publisherVersionId;
}
public void setPublisherRevisionId(int publisherRevisionId) {
this.publisherRevisionId = publisherRevisionId;
public void setPublisherVersionId(int publisherVersionId) {
this.publisherVersionId = publisherVersionId;
}
public String getPublisherName() {
......@@ -141,21 +146,29 @@ public class PublisherRevision {
this.publisherAddressCountry = publisherAddressCountry;
}
public User getPublisherRevisionAuthor() {
return publisherRevisionAuthor;
public Person getPublisherVersionAuthor() {
return publisherVersionAuthor;
}
public void setPublisherRevisionAuthor(User publisherRevisionAuthor) {
this.publisherRevisionAuthor = publisherRevisionAuthor;
public void setPublisherVersionAuthor(Person publisherVersionAuthor) {
this.publisherVersionAuthor = publisherVersionAuthor;
}
@Override
public String toString() {
return "PUBLISHER_REVISION_ID = " + publisherRevisionId + ", Name = " + publisherName + ", St Address = " +
return "PUBLISHER_VERSION_ID = " + publisherVersionId + ", Name = " + publisherName + ", St Address = " +
publisherStreetAddress + ", CP = " + publisherPostalCode + ", BP = " + publisherPostOfficeBoxNumber +
", Region = " + publisherAddressRegion + ", Ville = " + publisherAddressLocality + ", Pays = " +
publisherAddressCountry + ", Telephone = " + publisherTelephone + ", email = " + publisherEmail +
", URL = " + publisherURL + ", actif = " + publisherActive + ", History = " + publisherHistory +
", Revision Author = " + publisherRevisionAuthor + ", Revision DateTime = " + publisherRevisionDatetime;
", Version Author = " + publisherVersionAuthor + ", Version DateTime = " + publisherVersionDatetime;
}
public Publisher getPublisher() {
return publisher;
}
public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
}
\ No newline at end of file
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PublisherRevisionRepository extends JpaRepository<PublisherRevision, Integer> {
public interface PublisherVersionRepository extends JpaRepository<PublisherVersion, Integer> {
}
......
......@@ -2,10 +2,14 @@ package org.legrog.entities;
import javax.persistence.*;
/*
Entité persistante représentant les propriétés qui sont paramétrées pour un utilisateur.
Migréee depuis la v2.
*/
@Entity
public class UserAttribute {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int userAttributeId;
public int getUserAttributeId() {
......@@ -13,49 +17,47 @@ public class UserAttribute {
}
/**
* The linked user.
* The linked person.
*/
@ManyToOne
@JoinColumn(name = "USER_ID")
private User user;
private Person person;
/**
* Retrieve the user this attribute is attached to.
* @hibernate.many-to-one
* Retrieve the person this attribute is attached to.
* hibernate.many-to-one
* column="ID_UTILISATEUR"
* class="org.roliste.data.db.User"
* class="org.roliste.data.db.Person"
* not-null="true"
* access="property"
* lazy="proxy"
* properties-name="PropertyPerUser"
* foreign-key="FK_ATTRIBUTUTILISATEUR_UTILISATEUR"
* @return the {link org.roliste.data.db.User} this attribute is attached to.
* @return the {link org.roliste.data.db.Person} this attribute is attached to.
* Shall not be <code>null</code>.
* see #setUser(org.roliste.data.db.User)
* see #setPerson(org.roliste.data.db.Person)
*/
public User getUser() {
return user;
public Person getPerson() {
return person;
}
/**
* Set the user this attribute is attached to.
* @param user the new {link org.roliste.data.db.User} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getUser()
* Set the person this attribute is attached to.
* @param person the new {link org.roliste.data.db.Person} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getPerson()
*/
public void setUser(User user) {
this.user = user;
public void setPerson(Person person) {
this.person = person;
}
/**
* The linked property.
*/
@ManyToOne
@JoinColumn(name = "USER_PROPERTY_ID")
private UserProperty userProperty;
/**
* Retrieve the property this attribute is attached to.
* @hibernate.many-to-one
* hibernate.many-to-one
* column="ID_PROP"
* class="org.roliste.data.db.UserProperty"
* not-null="true"
......@@ -91,7 +93,7 @@ public class UserAttribute {
* convert it yourself. May be <code>null</code>, in cases where the sole existence of the attribute
* is the value, or for unset attributes.
* @see #setValue(String)
* @hibernate.property
* hibernate.property
* column="ATTR_VALUE"
* access="property"
* length="200"
......@@ -110,24 +112,14 @@ public class UserAttribute {
}
/**
* Returns a string representation of this user attribute definition.
* @return a string representing this user attribute definition.
* @hidden
* Returns a string representation of this person attribute definition.
* @return a string representing this person attribute definition.
* hidden
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ID_ATTR=");
sb.append(getUserAttributeId());
sb.append(" ATTR_PROP=");
sb.append(userProperty);
sb.append(" ATTR_VALUE=");
sb.append(value);
return sb.toString();
return "ID_ATTR=" + getUserAttributeId() + " ATTR_PROP=" + userProperty + " ATTR_VALUE=" + value;
}
}
......
......@@ -2,11 +2,14 @@ package org.legrog.entities;
import javax.persistence.*;
/*
Entité persistente représentant la codification des propriétés qui peuvent être paramétrées pour un utilisateur.
Importée depuis la v2.
*/
@Entity
public class UserProperty {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
@Column(name="USER_PROPERTY_ID")
private int userPropertyId;
/**
......@@ -110,23 +113,11 @@ public class UserProperty {
* @return a string representing this property definition.
* hidden
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ID_PROP=");
sb.append(getUserPropertyId());
sb.append(" PROP_NAME=");
sb.append(name);
sb.append(" PROP_TAG=");
sb.append(tag);
sb.append(" IND_VISIBLE=");
sb.append(visible);
return sb.toString();
return "ID_PROP=" + getUserPropertyId() + "PROP_NAME=" + name + " PROP_TAG=" + tag + " IND_VISIBLE=" + visible;
}
}
\ No newline at end of file
......
......@@ -7,20 +7,22 @@ import javax.persistence.*;
/**
* The database representation of a user role or group.
* A given {@link User} may be part of one or more {@link UserRole}.
* A given {@link Person} may be part of one or more {@link UserRole}.
* <br/>
* Warning: due to laziness of mapped objects, private attributes of all DB entities shall never be used directly.
* You shall always use the getter/setter methods.
* alias UserRole
*
*/
/*
Importé depuis la v2.
*/
@Entity
// TODO évaluer extend v2
public class UserRole /* extends org.roliste.data.DbEntity */
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
@Column(name="USER_ROLE_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int userRoleId;
/**
......@@ -29,11 +31,10 @@ public class UserRole /* extends org.roliste.data.DbEntity */
private String rolename;
/**
* The {@link User}s for this user role.
* The {@link Person}s for this user role.
*/
@ManyToMany(mappedBy = "roles")
@Column(name = "USER_ID")
private Set<User> users;
private Set<Person> persons;
/**
* Builds a new and empty user role definition.
......@@ -46,7 +47,7 @@ public class UserRole /* extends org.roliste.data.DbEntity */
rolename = null;
visible = true;
// no need to synchronize this
users = new HashSet<User>();
persons = new HashSet<Person>();
}
public int getUserRoleId() {
......@@ -89,7 +90,7 @@ public class UserRole /* extends org.roliste.data.DbEntity */
/**
* Indicates if the role is visible.
* If not, users should not be able to access the privileges
* If not, persons should not be able to access the privileges
* they inherit from being part of this role.
* @return the visible flag.
* @see #setVisible(boolean)
......@@ -111,15 +112,15 @@ public class UserRole /* extends org.roliste.data.DbEntity */
}
/**
* Retrieves the list of {@link User}s for this user role.
* Retrieves the list of {@link Person}s for this user role.
* SHALL be used as a read-only attribute. In particular, avoid
* using {@link Set#add(Object)} or {@link Set#remove(Object)} on
* the returned value without caution.
* @return a {@link Set} of {@link User}. May be <code>null</code>.
* @see #setUsers(Set)
* @return a {@link Set} of {@link Person}. May be <code>null</code>.
* @see #setPersons(Set)
* hibernate.many-to-many
* column="UTILISATEUR_FK"
* class="org.roliste.data.db.User"
* class="org.roliste.data.db.Person"
* foreign-key="FK_UTILISATEURROLE_UTILISATEUR"
* hibernate.key
* column="ROLE_FK"
......@@ -131,18 +132,18 @@ public class UserRole /* extends org.roliste.data.DbEntity */
* lazy="true"
* inverse="true"
*/
public Set<User> getUsers() {
return users;
public Set<Person> getPersons() {
return persons;
}
/**
* Sets the list of {@link User}s for this user role.
* @param users the new {@link Set} of {@link User}s. May be
* Sets the list of {@link Person}s for this user role.
* @param persons the new {@link Set} of {@link Person}s. May be
* <code>null</code> (we don't handle the relation from this side).
* @see #getUsers()
* @see #getPersons()
*/
protected void setUsers(Set<User> users) {
this.users = users;
protected void setPersons(Set<Person> persons) {
this.persons = persons;
}
/**
......@@ -150,19 +151,8 @@ public class UserRole /* extends org.roliste.data.DbEntity */
* @return a string representing this user role definition.
* hidden
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ID_ROLE=");
sb.append(getUserRoleId());
sb.append(" NOM_ROLE=");
sb.append(rolename);
sb.append(" IND_VISIBLE=");
sb.append(visible);
return sb.toString();
@Override
public String toString() {
return "ID_ROLE=" + getUserRoleId() + " NOM_ROLE=" + rolename + " IND_VISIBLE=" + visible;
}
}
\ No newline at end of file
......
package org.legrog.presentation;
import org.legrog.application.PublisherRevisionService;
import org.legrog.application.PublisherService;
import org.legrog.application.SharedService;
import org.legrog.application.UserService;
import org.legrog.entities.Country;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.Date;
import java.sql.Timestamp;
import java.time.ZoneId;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
@Named
@RequestScoped
public class AddPublisherBean {
Logger logger = LoggerFactory.getLogger(getClass());
@Inject
private SharedService sharedService;
@Inject
private UserService userService;
@Inject
private PublisherService publisherService;
@Inject
private PublisherRevisionService publisherRevisionService;
private String publisherName;
private String publisherStreetAddress;
private String publisherPostalCode;
private String publisherPostOfficeBoxNumber;
private String publisherAddressRegion;
private String publisherAddressLocality;
private Country publisherAddressCountry;
private String publisherTelephone;
private String publisherEmail;
private String publisherURL;
private boolean publisherActive;
private String publisherHistory;
private List<Country> availableCountries;
public String add() {
logger.info("add");
Publisher publisher = new Publisher();
PublisherRevision publisherRevision = new PublisherRevision();
HashSet<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>();
publisherRevisions.add(publisherRevision);
publisher.setRevisions(publisherRevisions);
logger.info(publisher.toString());
publisherRevision.setPublisherActive(publisherActive);
publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
publisherRevision.setPublisherEmail(publisherEmail);
publisherRevision.setPublisherHistory(publisherHistory);
publisherRevision.setPublisherName(publisherName);
publisherRevision.setPublisherPostalCode(publisherPostalCode);
publisherRevision.setPublisherPostOfficeBoxNumber(publisherPostOfficeBoxNumber);
publisherRevision.setPublisherStreetAddress(publisherStreetAddress);
publisherRevision.setPublisherTelephone(publisherTelephone);
publisherRevision.setPublisherURL(publisherURL);
publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime()));
// TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
List<User> users = userService.getAllUsers();
Random random = new Random();
User user = users.get(random.nextInt(users.size()));
// End TODO
publisherRevision.setPublisherRevisionAuthor(user);
logger.info(publisherRevision.toString());
publisherRevisionService.addPublisherRevision(publisherRevision);
publisherService.addPublisher(publisher);
// Test de récupération de l'Id
logger.info(publisherRevision.toString());
return "success";
}
@PostConstruct
public void init() {
availableCountries = sharedService.getAllCountries();
}
public String getPublisherName() {
return publisherName;
}
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}
public String getPublisherStreetAddress() {
return publisherStreetAddress;
}
public void setPublisherStreetAddress(String publisherStreetAddress) {
this.publisherStreetAddress = publisherStreetAddress;
}
public String getPublisherPostalCode() {
return publisherPostalCode;
}
public void setPublisherPostalCode(String publisherPostalCode) {
this.publisherPostalCode = publisherPostalCode;
}
public String getPublisherPostOfficeBoxNumber() {
return publisherPostOfficeBoxNumber;
}
public void setPublisherPostOfficeBoxNumber(String publisherPostOfficeBoxNumber) {
this.publisherPostOfficeBoxNumber = publisherPostOfficeBoxNumber;
}
public String getPublisherAddressRegion() {
return publisherAddressRegion;
}
public void setPublisherAddressRegion(String publisherAddressRegion) {
this.publisherAddressRegion = publisherAddressRegion;
}
public String getPublisherAddressLocality() {
return publisherAddressLocality;
}
public void setPublisherAddressLocality(String publisherAddressLocality) {
this.publisherAddressLocality = publisherAddressLocality;
}
public Country getPublisherAddressCountry() {
return publisherAddressCountry;
}
public void setPublisherAddressCountry(Country publisherAddressCountry) {
this.publisherAddressCountry = publisherAddressCountry;
}
public String getPublisherTelephone() {
return publisherTelephone;
}
public void setPublisherTelephone(String publisherTelephone) {
this.publisherTelephone = publisherTelephone;
}
public String getPublisherEmail() {
return publisherEmail;
}
public void setPublisherEmail(String publisherEmail) {
this.publisherEmail = publisherEmail;
}
public String getPublisherURL() {
return publisherURL;
}
public void setPublisherURL(String publisherURL) {
this.publisherURL = publisherURL;
}
public boolean isPublisherActive() {
return publisherActive;
}
public void setPublisherActive(boolean publisherActive) {
this.publisherActive = publisherActive;
}
public String getPublisherHistory() {
return publisherHistory;
}
public void setPublisherHistory(String publisherHistory) {
this.publisherHistory = publisherHistory;
}
public List<Country> getAvailableCountries() {
return availableCountries;
}
public void setAvailableCountries(List<Country> availableCountries) {
this.availableCountries = availableCountries;
}
}
\ No newline at end of file
package org.legrog.presentation;
import org.legrog.application.PublisherRevisionService;
import org.legrog.application.PublisherService;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
@Named
@RequestScoped
public class ListPublisherRevisionsBean {
@Inject
PublisherRevisionService publisherRevisionService;
private List<PublisherRevision> publisherRevisions;
public List<PublisherRevision> getPublisherRevisions() {
return publisherRevisions;
}
@PostConstruct
public void init() {
publisherRevisions = publisherRevisionService.getAllPublisherRevisions();
}
}
package org.legrog.presentation;
import org.legrog.application.PublisherRevisionService;
import org.legrog.entities.Country;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.sql.Timestamp;
@Named
@ViewScoped
public class PublisherRevisionView implements Serializable {
Logger logger = LoggerFactory.getLogger(getClass());
@Inject
PublisherRevisionService publisherRevisionService;
private int publisherRevisionId;
private String publisherName;
private String publisherStreetAddress;
private String publisherPostalCode;
private String publisherPostOfficeBoxNumber;
private String publisherAddressRegion;
private String publisherAddressLocality;
private Country publisherAddressCountry;
private String publisherTelephone;
private String publisherEmail;
private String publisherURL;
private boolean publisherActive;
private String publisherHistory;
private User publisherRevisionAuthor;
private Timestamp publisherRevisionDatetime;
public void loadData() {
logger.debug("publisherRevisionId = {}", this.publisherRevisionId);
PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId);
logger.debug("Found a publisher revision : {}", publisherRevision.toString());
// Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
//
// PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(new Integer(params.get("publisherRevisionId")));
// setPublisherRevisionId(publisherRevision.getPublisherRevisionId());
// logger.info("publisherRevisionId = " + getPublisherRevisionId());
}
public int getPublisherRevisionId() {
return publisherRevisionId;
}
public void setPublisherRevisionId(int publisherRevisionId) {
this.publisherRevisionId = publisherRevisionId;
}
public String getPublisherName() {
return publisherName;
}
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}
public String getPublisherStreetAddress() {
return publisherStreetAddress;
}
public void setPublisherStreetAddress(String publisherStreetAddress) {
this.publisherStreetAddress = publisherStreetAddress;
}
public String getPublisherPostalCode() {
return publisherPostalCode;
}
public void setPublisherPostalCode(String publisherPostalCode) {
this.publisherPostalCode = publisherPostalCode;
}
public String getPublisherPostOfficeBoxNumber() {
return publisherPostOfficeBoxNumber;
}
public void setPublisherPostOfficeBoxNumber(String publisherPostOfficeBoxNumber) {
this.publisherPostOfficeBoxNumber = publisherPostOfficeBoxNumber;
}
public String getPublisherAddressRegion() {
return publisherAddressRegion;
}
public void setPublisherAddressRegion(String publisherAddressRegion) {
this.publisherAddressRegion = publisherAddressRegion;
}
public String getPublisherAddressLocality() {
return publisherAddressLocality;
}
public void setPublisherAddressLocality(String publisherAddressLocality) {
this.publisherAddressLocality = publisherAddressLocality;
}
public Country getPublisherAddressCountry() {
return publisherAddressCountry;
}
public void setPublisherAddressCountry(Country publisherAddressCountry) {
this.publisherAddressCountry = publisherAddressCountry;
}
public String getPublisherTelephone() {
return publisherTelephone;
}
public void setPublisherTelephone(String publisherTelephone) {
this.publisherTelephone = publisherTelephone;
}
public String getPublisherEmail() {
return publisherEmail;
}
public void setPublisherEmail(String publisherEmail) {
this.publisherEmail = publisherEmail;
}
public String getPublisherURL() {
return publisherURL;
}
public void setPublisherURL(String publisherURL) {
this.publisherURL = publisherURL;
}
public boolean isPublisherActive() {
return publisherActive;
}
public void setPublisherActive(boolean publisherActive) {
this.publisherActive = publisherActive;
}
public String getPublisherHistory() {
return publisherHistory;
}
public void setPublisherHistory(String publisherHistory) {
this.publisherHistory = publisherHistory;
}
public User getPublisherRevisionAuthor() {
return publisherRevisionAuthor;
}
public void setPublisherRevisionAuthor(User publisherRevisionAuthor) {
this.publisherRevisionAuthor = publisherRevisionAuthor;
}
public Timestamp getPublisherRevisionDatetime() {
return publisherRevisionDatetime;
}
public void setPublisherRevisionDatetime(Timestamp publisherRevisionDatetime) {
this.publisherRevisionDatetime = publisherRevisionDatetime;
}
}
package org.legrog.presentation;
package org.legrog.web.book;
import org.legrog.application.BookService;
import org.legrog.entities.Book;
import javax.enterprise.context.RequestScoped;
......
package org.legrog.application;
package org.legrog.web.book;
import org.legrog.entities.Book;
......
package org.legrog.application;
package org.legrog.web.book;
import org.legrog.entities.Book;
import org.slf4j.Logger;
......@@ -8,7 +8,6 @@ import javax.ejb.Stateless;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import java.util.List;
......
package org.legrog.application;
package org.legrog.web.book;
import org.legrog.entities.Book;
import org.legrog.entities.BookRepository;
import org.legrog.web.book.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import java.util.List;
......
package org.legrog.web.publisher;
import org.legrog.entities.PublisherAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/*
Vue de listPublisherVersions.xhtml
Permet de voir l'ensemble des actions des éditeurs.
Permet de voir l'ensemble des actions d'un éditeur.
*/
@Named
@ViewScoped
public class ListPublisherActionsView implements Serializable {
Logger logger = LoggerFactory.getLogger(getClass());
protected PublisherService publisherService;
private Integer publisherId;
private boolean viewAll;
private List<PublisherAction> publisherActions;
@Inject
public ListPublisherActionsView(PublisherService publisherService) {
this.publisherService = publisherService;
}
//no args constructor to make it proxyable
ListPublisherActionsView() {
}
public void setView() {
logger.trace("setView : publisherId = {}", publisherId);
publisherActions = publisherService.getAllPublisherActions();
viewAll = (publisherId == null);
if (!viewAll) {
logger.trace("setView : !viewAll");
filterOnID();
}
}
public void filterOnID() {
publisherActions = publisherActions.stream()
.filter(action -> action.getPublisher().getPublisherId() == publisherId)
.collect(Collectors.toList());
}
public void setPublisherId(Integer publisherId) {
this.publisherId = publisherId;
}
public List<PublisherAction> getPublisherActions() {
return publisherActions;
}
public boolean isViewAll() {
return viewAll;
}
public Integer getPublisherId() {
return publisherId;
}
public void setViewAll(boolean viewAll) {
this.viewAll = viewAll;
}
public void setPublisherActions(List<PublisherAction> publisherActions) {
this.publisherActions = publisherActions;
}
}
package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.entities.PublisherVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/*
Vue de listPublisherVersions.xhtml
Permet de voir l'ensemble des versions des éditeurs.
Permet de voir l'ensemble des versions d'un éditeur et de valider l'une d'elles.
*/
@Named
@ViewScoped
public class ListPublisherVersionsView implements Serializable {
Logger logger = LoggerFactory.getLogger(getClass());
protected PublisherService publisherService;
private Integer publisherId;
private boolean viewAll;
private List<PublisherVersion> publisherVersions;
@Inject
public ListPublisherVersionsView(PublisherService publisherService) {
this.publisherService = publisherService;
}
//no args constructor to make it proxyable
ListPublisherVersionsView() {
}
public PublisherAction getLastValidate(Publisher publisher) {
return publisherService.getLastValidate(publisher);
}
// View Action being executed at view loading
public void setView() {
logger.trace("setView : publisherId = {}", publisherId);
publisherVersions = publisherService.getAllPublisherVersions();
viewAll = (publisherId == null);
if (!viewAll) {
logger.trace("setView : !viewAll");
filterOnID();
}
}
protected void filterOnID() {
publisherVersions = publisherVersions.stream()
.filter(version -> version.getPublisher().getPublisherId() == publisherId)
.collect(Collectors.toList());
}
public void validate(PublisherVersion publisherVersion) {
logger.trace("validate");
publisherService.validatePublisherVersion(publisherVersion);
publisherVersions = publisherService.getAllPublisherVersions();
filterOnID();
}
//
public PublisherService getPublisherService() {
return publisherService;
}
public void setPublisherService(PublisherService publisherService) {
this.publisherService = publisherService;
}
public Integer getPublisherId() {
return publisherId;
}
public void setPublisherId(Integer publisherId) {
this.publisherId = publisherId;
}
public boolean isViewAll() {
return viewAll;
}
public void setViewAll(boolean viewAll) {
this.viewAll = viewAll;
}
public List<PublisherVersion> getPublisherVersions() {
return publisherVersions;
}
public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
this.publisherVersions = publisherVersions;
}
@Override
public String toString() {
return "publisherId = " + publisherId + ", viewAll = " + viewAll + ", publisherVersions = " + publisherVersions;
}
}
\ No newline at end of file
package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.entities.PublisherVersion;
import java.util.List;
/*
Interface correspondant à la gestion des éditeurs et de leurs versions.
Contient des signatures méthodes d'ajout, de modification et de validation de version ainsi que de restitution.
*/
public interface PublisherService {
PublisherVersion addNewPublisher(PublisherVersion publisherVersion);
PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
PublisherAction validatePublisherVersion(PublisherVersion publisherVersion);
List<PublisherVersion> getAllPublisherVersions();
PublisherVersion getPublisherVersion(Integer publisherVersionId);
PublisherAction getLastValidate(Publisher publisher);
List<PublisherAction> getAllPublisherActions();
}
package org.legrog.web.publisher;
import org.legrog.entities.*;
import org.legrog.web.xyz.SharedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*
Implémentation de l'interface PublisherService
*/
@Stateless
public class PublisherServiceSpring implements PublisherService {
Logger logger = LoggerFactory.getLogger(getClass());
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
PublisherActionRepository publisherActionRepository;
ActionTypeRepository actionTypeRepository;
SharedService sharedService;
@Inject
public PublisherServiceSpring(PublisherRepository publisherRepository,
PublisherVersionRepository publisherVersionRepository,
PublisherActionRepository publisherActionRepository,
ActionTypeRepository actionTypeRepository,
SharedService sharedService) {
this.publisherRepository = publisherRepository;
this.publisherVersionRepository = publisherVersionRepository;
this.publisherActionRepository = publisherActionRepository;
this.actionTypeRepository = actionTypeRepository;
this.sharedService = sharedService;
}
//no args constructor to make it proxyable
PublisherServiceSpring() {
}
public PublisherVersion addNewPublisher(PublisherVersion publisherVersion) {
Publisher publisher = new Publisher();
Set<PublisherVersion> publisherVersions = new HashSet<>();
publisherVersions.add(publisherVersion);
publisher.setVersions(publisherVersions);
publisherVersion.setPublisher(publisher);
publisherVersion.setPublisherVersionAuthor(sharedService.getCurrentUser());
publisherVersion.setPublisherVersionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherVersion(publisherVersion);
this.savePublisher(publisher);
return publisherVersion;
}
public PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) {
logger.trace("debut addVersionToPublisher, publisherVersion = {}", publisherVersion);
Set<PublisherVersion> publisherVersionSet = publisher.getVersions();
publisherVersionSet.add(publisherVersion);
publisher.setVersions(publisherVersionSet);
publisherVersion.setPublisher(publisher);
publisherVersion.setPublisherVersionAuthor(sharedService.getCurrentUser());
publisherVersion.setPublisherVersionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherVersion(publisherVersion);
this.savePublisher(publisher);
logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
return publisherVersion;
}
public PublisherAction validatePublisherVersion(PublisherVersion publisherVersion) {
Publisher publisher = publisherVersion.getPublisher();
publisher.setValidatedVersion(publisherVersion);
PublisherAction publisherAction = new PublisherAction();
publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser());
publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime()));
publisherAction.setActionType(actionTypeRepository.findByActionTypeName("Validate"));
publisherAction.setPublisherVersion(publisherVersion);
publisherAction.setPublisher(publisher);
this.savePublisher(publisher);
publisherActionRepository.save(publisherAction);
return publisherAction;
}
protected void savePublisherVersion(PublisherVersion publisherVersion) {
publisherVersionRepository.save(publisherVersion);
}
protected void savePublisher(Publisher publisher) {
publisherRepository.save(publisher);
}
// get
public List<PublisherVersion> getAllPublisherVersions() {
return publisherVersionRepository.findAll();
}
public PublisherVersion getPublisherVersion(Integer publisherVersionId) {
return publisherVersionRepository.findOne(publisherVersionId);
}
public PublisherAction getLastValidate(Publisher publisher) {
return publisherActionRepository.publisherLastValidate(publisher);
}
public List<PublisherAction> getAllPublisherActions() {
return publisherActionRepository.findAll();
}
}
This diff is collapsed. Click to expand it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam name="publisherId" value="#{listPublisherActionsView.publisherId}"/>
<f:viewAction action="#{listPublisherActionsView.setView}"/>
</f:metadata>
<head>
<link rel="stylesheet" type="text/css" href="/minimal.css"/>
</head>
<body>
<ul>
<li>
<a jsf:outcome="/index">Menu principal</a>
</li>
<li>
<a jsf:outcome="listPublisherVersions">Liste des versions des éditeurs</a>
</li>
<li>
<a jsf:outcome="publisherVersion">Ajouter un éditeur</a>
</li>
</ul>
<a jsf:outcome="listPublisherActions" jsf:rendered="#{not listPublisherActionsView.viewAll}">Voir toutes les actions</a>
<h:dataTable value="#{listPublisherActionsView.publisherActions}" var="action">
<h:column>
<f:facet name="header">Action</f:facet>
${action.actionType.actionTypeName}
</h:column>
<h:column>
<f:facet name="header">Author</f:facet>
${action.publisherActionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Action Datetime</f:facet>
${action.publisherActionDatetime}
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
${action.publisherVersion.publisherName}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
${action.publisherVersion.publisherPostOfficeBoxNumber}<br />
${action.publisherVersion.publisherStreetAddress}<br />
${action.publisherVersion.publisherPostalCode} ${action.publisherVersion.publisherAddressLocality}<br />
${action.publisherVersion.publisherAddressRegion}<br />
${action.publisherVersion.publisherAddressCountry.countryName}
</h:column>
<h:column>
<f:facet name="header">Telephone</f:facet>
${action.publisherVersion.publisherTelephone}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
${action.publisherVersion.publisherEmail}
</h:column>
<h:column>
<f:facet name="header">URL</f:facet>
${action.publisherVersion.publisherURL}
</h:column>
<h:column>
<f:facet name="header">Active ?</f:facet>
${action.publisherVersion.publisherActive}
</h:column>
<h:column>
<f:facet name="header">History</f:facet>
${action.publisherVersion.publisherHistory}
</h:column>
<h:column>
<f:facet name="header">Version Author</f:facet>
${action.publisherVersion.publisherVersionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Version Datetime</f:facet>
${action.publisherVersion.publisherVersionDatetime}
</h:column>
</h:dataTable>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam name="publisherId" value="#{listPublisherVersionsView.publisherId}"/>
<f:viewAction action="#{listPublisherVersionsView.setView}"/>
</f:metadata>
<head>
<link rel="stylesheet" type="text/css" href="/minimal.css"/>
</head>
<body>
<ul>
<li>
<a jsf:outcome="/index">Menu principal</a>
</li>
<li>
<a jsf:outcome="listPublisherActions">Liste des actions des éditeurs</a>
</li>
<li>
<a jsf:outcome="publisherVersion">Ajouter un éditeur</a>
</li>
</ul>
<a jsf:outcome="listPublisherVersions" jsf:rendered="#{not listPublisherVersionsView.viewAll}">Voir toutes les versions d'éditeurs</a>
<p jsf:rendered="#{listPublisherVersionsView.publisherVersions.isEmpty()}">Liste des révisions est vide</p>
<h:dataTable value="#{listPublisherVersionsView.publisherVersions}" var="version">
<h:column>
<f:facet name="header">Visualiser ou Modifier</f:facet>
<a jsf:outcome="publisherVersion">Visualiser ou Modifier Version
<f:param name="publisherVersionId" value="#{version.publisherVersionId}"/>
</a>
</h:column>
<h:column rendered="#{listPublisherVersionsView.viewAll}">
<f:facet name="header">Editeur</f:facet>
<a jsf:outcome="listPublisherVersions">Visualiser ou valider version éditeur
<f:param name="publisherId" value="#{version.publisher.publisherId}"/>
</a>
</h:column>
<h:column>
<f:facet name="header">Actions</f:facet>
<p jsf:rendered="#{version.publisher.actions.size() == 0}">Aucune action à lister</p>
<a jsf:outcome="listPublisherActions" jsf:rendered="#{version.publisher.actions.size() > 0}">Voir les actions
<f:param name="publisherId" value="#{version.publisher.publisherId}"/>
</a>
</h:column>
<h:column>
<f:facet name="header">Valide</f:facet>
<p jsf:rendered="#{version.publisherVersionId == version.publisher.validatedVersion.publisherVersionId}">Validé</p>
<p jsf:rendered="#{listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">Non validé</p>
<!-- https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ f:param, problème avec Method expression -->
<form action="" jsf:rendered="#{not listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">
<button jsf:action="#{listPublisherVersionsView.validate(version)}">Valider
</button>
</form>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
${version.publisherName}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
${version.publisherPostOfficeBoxNumber}<br />
${version.publisherStreetAddress}<br />
${version.publisherPostalCode} ${version.publisherAddressLocality}<br />
${version.publisherAddressRegion}<br />
${version.publisherAddressCountry.countryName}
</h:column>
<h:column>
<f:facet name="header">Telephone</f:facet>
${version.publisherTelephone}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
${version.publisherEmail}
</h:column>
<h:column>
<f:facet name="header">URL</f:facet>
${version.publisherURL}
</h:column>
<h:column>
<f:facet name="header">Active ?</f:facet>
${version.publisherActive}
</h:column>
<h:column>
<f:facet name="header">History</f:facet>
${version.publisherHistory}
</h:column>
<h:column>
<f:facet name="header">Version Author</f:facet>
${version.publisherVersionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Version Datetime</f:facet>
${version.publisherVersionDatetime}
</h:column>
<h:column>
<f:facet name="header">Validation author</f:facet>
<div jsf:rendered="#{version.publisherVersionId == version.publisher.validatedVersion.publisherVersionId}">
${listPublisherVersionsView.getLastValidate(version.publisher).publisherActionAuthor.displayName}
</div>
</h:column>
<h:column>
<f:facet name="header">Validation Datetime</f:facet>
<div jsf:rendered="#{version.publisherVersionId == version.publisher.validatedVersion.publisherVersionId}">
${listPublisherVersionsView.getLastValidate(version.publisher).publisherActionDatetime}
</div>
</h:column>
</h:dataTable>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<f:metadata>
<f:viewParam name="publisherVersionId" value="#{publisherVersionView.publisherVersionId}" />
<f:viewAction action="#{publisherVersionView.loadData}" />
</f:metadata>
</head>
<body>
<form jsf:id="publisherVersion" action="">
<ul>
<li>
<a jsf:outcome="/index">Menu principal</a>
</li>
<li>
<a jsf:outcome="listPublisherVersions">Liste des versions des éditeurs</a>
</li>
<li>
<a jsf:outcome="listPublisherActions">Liste des actions des éditeurs</a>
</li>
</ul>
<h:panelGrid columns="2">
<label for="publisherName">publisherName</label>
<input type="text" id="publisherName" jsf:value='#{publisherVersionView.publisherName}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherStreetAddress">publisherStreetAddress</label>
<input type="text" id="publisherStreetAddress" jsf:value='#{publisherVersionView.publisherStreetAddress}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherPostalCode">publisherPostalCode</label>
<input type="text" id="publisherPostalCode" jsf:value='#{publisherVersionView.publisherPostalCode}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherPostOfficeBoxNumber">publisherPostOfficeBoxNumber</label>
<input type="text" id="publisherPostOfficeBoxNumber" jsf:value='#{publisherVersionView.publisherPostOfficeBoxNumber}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherAddressRegion">publisherAddressRegion</label>
<input type="text" id="publisherAddressRegion" jsf:value='#{publisherVersionView.publisherAddressRegion}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherAddressLocality">publisherAddressLocality</label>
<input type="text" id="publisherAddressLocality" jsf:value='#{publisherVersionView.publisherAddressLocality}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherAddressCountry">publisherAddressCountry</label>
<h:selectOneMenu id="publisherAddressCountry" value="#{publisherVersionView.publisherAddressCountry}" converter="omnifaces.SelectItemsConverter" disabled="#{not publisherVersionView.editMode}">
<f:selectItems value="#{publisherVersionView.availableCountries}" var="country" itemLabel="#{country.countryName}"/>
</h:selectOneMenu>
<label for="publisherTelephone">publisherTelephone</label>
<input type="text" id="publisherTelephone" jsf:value='#{publisherVersionView.publisherTelephone}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherEmail">publisherEmail</label>
<input type="text" id="publisherEmail" jsf:value='#{publisherVersionView.publisherEmail}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherURL">publisherURL</label>
<input type="text" id="publisherURL" jsf:value='#{publisherVersionView.publisherURL}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherActive">publisherActive</label>
<input type="checkbox" id="publisherActive" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherActive}"/>
<label for="publisherHistory">publisherHistory</label>
<textarea id="publisherHistory" rows="" cols="" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherHistory}"/>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">publisherVersionAuthor</div>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">#{publisherVersionView.publisherVersionAuthor.displayName}</div>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">publisherVersionDatetime</div>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">#{publisherVersionView.publisherVersionDatetime}</div>
<button jsf:rendered="#{not publisherVersionView.editMode}" jsf:action="#{publisherVersionView.edit}">Edit</button>
<button jsf:rendered="#{publisherVersionView.editMode}" jsf:action="#{publisherVersionView.save}">Save</button>
<button jsf:rendered="#{publisherVersionView.editMode}" jsf:action="#{publisherVersionView.cancel}">Cancel</button>
</h:panelGrid>
</form>
</body>
</html>
\ No newline at end of file
package org.legrog.presentation;
package org.legrog.web.user;
import org.legrog.application.UserService;
import org.legrog.entities.User;
import org.legrog.entities.Person;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
......@@ -15,19 +14,19 @@ public class ListUsersBean {
@Inject
private UserService userService;
private List<User> users;
private List<Person> persons;
public List<User> getUsers() {
return users;
public List<Person> getPersons() {
return persons;
}
public void setUsers(List<User> users) {
this.users = users;
public void setPersons(List<Person> persons) {
this.persons = persons;
}
@PostConstruct
public void init() {
users = userService.getAllUsers();
persons = userService.getAllUsers();
}
}
......
package org.legrog.presentation;
package org.legrog.web.user;
import org.legrog.application.SharedService;
import org.legrog.application.UserService;
import org.legrog.web.xyz.SharedService;
import org.legrog.entities.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -23,110 +18,111 @@ import java.util.List;
@Named
@RequestScoped
public class UpdateUserBean {
@Inject
Logger logger = LoggerFactory.getLogger(getClass());
private UserService userService;
@Inject
private SharedService sharedService;
private List<DisplayNameMask> allDisplayNameMasks;
private List<UserRole> availableUserRoles;
private List<UserProperty> availableUserProperties;
@ManagedProperty("#{param.userId}")
private int userId;
private String username;
private String firstName;
private String lastName;
private String nickName;
private DisplayNameMask displayNameMask;
private List<DisplayNameMask> allDisplayNameMasks;
private List<UserRole> availableUserRoles;
private List<UserProperty> availableUserProperties;
private String email;
private boolean anonymous;
private String password;
private List<UserRole> roles;
private String presentation;
private List<UserAttribute> userAttributes;
private boolean criticProvider;
private boolean visible;
private boolean activated;
@Inject
public UpdateUserBean(UserService userService, SharedService sharedService) {
this.userService = userService;
this.sharedService = sharedService;
}
//no args constructor to make it proxyable
UpdateUserBean() {
}
public String add()
{
User user = new User();
user.setActivated(activated);
user.setAnonymous(anonymous);
@PostConstruct
public void init() {
logger.info("init");
allDisplayNameMasks = sharedService.getAllDisplayNameMasks();
availableUserRoles = sharedService.getAvailableUserRoles();
availableUserProperties = sharedService.getAvailableUserProperties();
}
public String add() {
Person person = new Person();
person.setActivated(activated);
person.setAnonymous(anonymous);
if (userAttributes != null) {
user.setAttributes(userAttributes);
person.setAttributes(userAttributes);
}
user.setCriticProvider(criticProvider);
person.setCriticProvider(criticProvider);
if (displayNameMask != null) {
user.setDisplayNameMask(displayNameMask);
person.setDisplayNameMask(displayNameMask);
} else {
user.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
person.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
}
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
if (nickName != null && !nickName.isEmpty()) {
user.setNickName(nickName);
person.setNickName(nickName);
}
user.setPassword(password);
person.setPassword(password);
if (presentation != null) {
user.setPresentation(presentation);
person.setPresentation(presentation);
}
if (roles != null) {
user.setRoles(roles);
person.setRoles(roles);
}
user.setUsername(username);
user.setVisible(visible);
user.setCreationDate(new Date());
userService.addUser(user);
person.setUsername(username);
person.setVisible(visible);
person.setCreationDate(new Date());
userService.addUser(person);
return "success";
}
public String prepareUpdate(int userId) {
Logger logger = LoggerFactory.getLogger(UpdateUserBean.class);
logger.info("prepareUpdate");
logger.info("userId ="+userId);
logger.info("userId =" + userId);
this.userId = userId;
if (userId != 0) {
User user = userService.findUserById(userId);
if (user != null) {
activated = user.isActivated();
anonymous = user.isAnonymous();
userAttributes = user.getAttributes();
criticProvider = user.isCriticProvider();
displayNameMask = user.getDisplayNameMask();
email = user.getEmail();
firstName = user.getFirstName();
lastName = user.getLastName();
nickName = user.getNickName();
password = user.getPassword();
presentation = user.getPresentation();
roles = user.getRoles();
Person person = userService.findUserById(userId);
if (person != null) {
activated = person.isActivated();
anonymous = person.isAnonymous();
userAttributes = person.getAttributes();
criticProvider = person.isCriticProvider();
displayNameMask = person.getDisplayNameMask();
email = person.getEmail();
firstName = person.getFirstName();
lastName = person.getLastName();
nickName = person.getNickName();
password = person.getPassword();
presentation = person.getPresentation();
roles = person.getRoles();
if (roles == null) {
roles = new ArrayList<UserRole>();
}
username = user.getUsername();
visible = user.isVisible();
username = person.getUsername();
visible = person.isVisible();
return "updateUser.xhtml";
}
}
......@@ -134,39 +130,29 @@ public class UpdateUserBean {
}
public String update() {
Logger logger = LoggerFactory.getLogger(UpdateUserBean.class);
logger.info("update");
logger.info("userId ="+userId);
User user = userService.findUserById(userId);
user.setActivated(activated);
user.setAnonymous(anonymous);
user.setAttributes(userAttributes);
user.setCriticProvider(criticProvider);
user.setDisplayNameMask(displayNameMask);
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setNickName(nickName);
user.setPassword(password);
user.setPresentation(presentation);
user.setRoles(roles);
user.setUsername(username);
user.setVisible(visible);
userService.updateUser(user);
logger.info("userId =" + userId);
Person person = userService.findUserById(userId);
person.setActivated(activated);
person.setAnonymous(anonymous);
person.setAttributes(userAttributes);
person.setCriticProvider(criticProvider);
person.setDisplayNameMask(displayNameMask);
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
person.setNickName(nickName);
person.setPassword(password);
person.setPresentation(presentation);
person.setRoles(roles);
person.setUsername(username);
person.setVisible(visible);
userService.updateUser(person);
return "success";
}
@PostConstruct
public void init() {
Logger logger = LoggerFactory.getLogger(UpdateUserBean.class);
logger.info("init");
allDisplayNameMasks = sharedService.getAllDisplayNameMasks();
availableUserRoles = sharedService.getAvailableUserRoles();
availableUserProperties = sharedService.getAvailableUserProperties();
}
public List<UserRole> getAvailableUserRoles() {
return availableUserRoles;
}
......
package org.legrog.web.user;
import org.legrog.entities.Person;
import java.util.List;
public interface UserService {
void addUser(Person person);
List<Person> getAllUsers();
Person findUserById(int id);
void updateUser(Person person);
}
package org.legrog.web.user;
import org.legrog.entities.Person;
import org.legrog.entities.PersonRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
@Stateless
public class UserServiceSpring implements UserService {
@Inject
PersonRepository personRepository;
public void addUser(Person person) {
personRepository.save(person);
}
public List<Person> getAllUsers() {
return personRepository.findAll();
}
public Person findUserById(int id) {
return personRepository.findOne(new Integer(id));
}
public void updateUser(Person person) {
personRepository.save(person);
}
}
\ No newline at end of file
......@@ -32,17 +32,17 @@
<div id="listElements">
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.users}" >
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.persons}" >
<img src="/images/structure/vide.gif" class="icAddC" alt="" title="Crer un nouvel utilisateur" />
Nouvel Utilisateur
</h:commandLink>
<p:dataTable id="tableElements" rendered="#{not empty listUsersBean.users}"
var="user" value="#{listUsersBean.users}"
<p:dataTable id="tableElements" rendered="#{not empty listUsersBean.persons}"
var="person" value="#{listUsersBean.persons}"
styleClass="results" rowClasses="altRichRow,altRow">
<!-- TODO Grer la pagination -->
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.users.size>0}"
var="user" value="#{listUsersBean.users}" rows="#{userListMgr.pageSize}"
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.persons.size>0}"
var="person" value="#{listUsersBean.persons}" rows="#{userListMgr.pageSize}"
styleClass="results" rowClasses="altRichRow,altRow">-->
<f:facet name="header">
<p:dataScroller for="tableElements"
......@@ -61,35 +61,35 @@
</h:commandLink>-->
</p:column>
<p:column>
<h:commandLink action="#{updateUserBean.prepareUpdate(user.userId)}">
<h:commandLink action="#{updateUserBean.prepareUpdate(person.userId)}">
<img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" />
</h:commandLink>
</p:column>
<p:column styleClass="third" sortBy="#{user.username}">
<p:column styleClass="third" sortBy="#{person.username}">
<f:facet name="header">Identifiant</f:facet>
<!-- TODO Dcider de l'avenir de traceable -->
<ui:remove>
<!-- <h:outputLink value="#{user.traceable.urlRewrite}">-->
<!-- <h:outputLink value="#{person.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{user.username}" />
<h:outputText value="#{person.username}" />
<!-- </h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{user.firstName} #{user.lastName}">
<p:column styleClass="third" sortBy="#{person.firstName} #{person.lastName}">
<f:facet name="header">Nom</f:facet>
<ui:remove>
<!--<h:outputLink value="#{user.traceable.urlRewrite}">-->
<!--<h:outputLink value="#{person.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{user.firstName} #{user.lastName}" />
<h:outputText value="#{person.firstName} #{person.lastName}" />
<!--</h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{user.email}">
<p:column styleClass="third" sortBy="#{person.email}">
<f:facet name="header">Email</f:facet>
<h:outputText value="#{user.email}" />
<h:outputText value="#{person.email}" />
</p:column>
<p:column>
<h:graphicImage value="/images/structure/dVert.gif" rendered="#{user.visible and user.activated}" title="Utilisateur activ" />
<h:graphicImage value="/images/structure/dOrange.gif" rendered="#{(not user.visible) and user.activated}" title="Utilisateur dsactiv" />
<h:graphicImage value="/images/structure/dRouge.gif" rendered="#{not user.activated}" title="Utilisateur non enregistr" />
<h:graphicImage value="/images/structure/dVert.gif" rendered="#{person.visible and person.activated}" title="Utilisateur activ" />
<h:graphicImage value="/images/structure/dOrange.gif" rendered="#{(not person.visible) and person.activated}" title="Utilisateur dsactiv" />
<h:graphicImage value="/images/structure/dRouge.gif" rendered="#{not person.activated}" title="Utilisateur non enregistr" />
</p:column>
<f:facet name="footer">
<h:commandLink action="add" value="Crer un nouvel utilisateur" >
......@@ -99,7 +99,7 @@
</div>
<p>
<h:commandLink action="add" value="Crer un nouvel utilisateur"
rendered="#{empty listUsersBean.users}">
rendered="#{empty listUsersBean.persons}">
</h:commandLink>
</p>
</h:form>
......
......@@ -12,8 +12,8 @@
</h:commandLink>
</h:form>
<ul>
<ui:repeat value="#{listUsersBean.users}" var="user">
<li>#{user.username}</li>
<ui:repeat value="#{listUsersBean.persons}" var="person">
<li>#{person.username}</li>
</ui:repeat>
</ul>
</f:view>
......
package org.legrog.presentation;
package org.legrog.web.xyz;
import org.legrog.application.SharedService;
import org.legrog.entities.Country;
import javax.enterprise.context.RequestScoped;
......
package org.legrog.presentation;
package org.legrog.web.xyz;
import org.legrog.application.SharedService;
import org.legrog.entities.Country;
import javax.annotation.PostConstruct;
......
package org.legrog.application;
package org.legrog.web.xyz;
import org.legrog.entities.Country;
import org.legrog.entities.DisplayNameMask;
import org.legrog.entities.UserProperty;
import org.legrog.entities.UserRole;
import org.legrog.entities.*;
import java.util.List;
......@@ -19,4 +16,5 @@ public interface SharedService {
List<UserProperty> getAvailableUserProperties();
Person getCurrentUser();
}
\ No newline at end of file
......
package org.legrog.application;
package org.legrog.web.xyz;
import org.legrog.entities.*;
import org.legrog.web.user.UserService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
import java.util.Random;
import java.util.Vector;
@Stateless
......@@ -18,6 +20,8 @@ public class SharedServiceSpring implements SharedService {
UserRoleRepository userRoleRepository;
@Inject
UserPropertyRepository userPropertyRepository;
@Inject
UserService userService;
private List<DisplayNameMask> allDisplayNameMasks;
......@@ -47,4 +51,13 @@ public class SharedServiceSpring implements SharedService {
}
public List<UserProperty> getAvailableUserProperties() { return userPropertyRepository.findAll(); }
public Person getCurrentUser() {
// TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
List<Person> persons = userService.getAllUsers();
Random random = new Random();
Person person = persons.get(random.nextInt(persons.size()));
// End TODO
return person;
}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<body jsf:id="root-body" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<p>
I'm looking for something
</p>
<p>
And this is my string : #{testRouteView.foo}
</p>
<p>
And this is another string : #{testRouteView.bar}
</p>
</body>
package org.legrog.web.xyz;
import org.ocpsoft.rewrite.annotation.Join;
import org.ocpsoft.rewrite.annotation.Parameter;
import org.ocpsoft.rewrite.annotation.RequestAction;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.el.El;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.servlet.ServletContext;
import java.io.Serializable;
@Named
@RequestScoped
@Join(path = "/TestRoute/{bar}", to = "/xyz/TestRoute.jsf")
public class TestRouteView implements Serializable {
String foo = "my first String";
@Parameter
String bar;
@RequestAction
public void init() {
if (bar == null) {
foo = "my modified string without bar";
} else {
foo = "my string modified with "+ bar;
}
}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
@RewriteConfiguration
public static class RewriteConfig extends HttpConfigurationProvider {
public Configuration getConfiguration(ServletContext context) {
return ConfigurationBuilder.begin()
.addRule(org.ocpsoft.rewrite.servlet.config.rule.Join.path("/TestRoute2/{bar}").to("/xyz/TestRoute.jsf"))
.where("bar").bindsTo(El.property("testRouteView.bar"))
;
}
public int priority() {
return 0;
}
}
}
......@@ -10,6 +10,10 @@
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.hbm2ddl.import_files" value="import.sql"/>
<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />
<!-- DDL control OFF
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
-->
</properties>
</persistence-unit>
......
-- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21)
INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
INSERT INTO Country (countryId, countryName) VALUES
(1, 'France'),
(2, 'Suisse'),
(3, 'Belgique'),
(4, 'Canada'),
(5, 'États-Unis d''Amérique'),
(6, 'Australie'),
(7, 'Espagne'),
(8, 'Portugal'),
(9, 'Royaume-Uni'),
(10, 'Allemagne'),
(11, 'Pologne'),
(12, 'Italie');
INSERT INTO Person (userId, username, password, firstName, lastName, nickname, email, activated, anonymous, visible,
criticProvider) VALUES
(1, 'one', 'one', 'Derrick', 'Moss', 'one', 'one@raza.org', TRUE, FALSE, TRUE, TRUE),
(2, 'two', 'two', 'Portia', 'Lin', 'two', 'two@raza.org', TRUE, FALSE, TRUE, TRUE),
(3, 'three', 'three', 'Marcus', 'Boone', 'three', 'three@raza.org', TRUE, FALSE, TRUE, TRUE),
(4, 'four', 'four', 'Ryo', 'Tetsuda', 'four', 'four@raza.org', TRUE, FALSE, TRUE, TRUE),
(5, 'five', 'five', 'Emily', 'Kolburn', 'five', 'five@raza.org', TRUE, FALSE, TRUE, TRUE),
(6, 'six', 'six', 'Kal', 'Varrik', 'six', 'six@raza.org', TRUE, FALSE, TRUE, TRUE);
INSERT INTO Publisher (publisherId) VALUES (1), (2), (3), (4);
INSERT INTO PublisherVersion (publisherVersionId, publisher_publisherId, publisherName, publisherStreetAddress,
publisherPostalCode, publisherPostOfficeBoxNumber, publisherAddressRegion,
publisherAddressLocality, publisherAddressCountry_countryId, publisherTelephone,
publisherEmail, publisherURL, publisherActive, publisherHistory,
publisherVersionAuthor_userId, publisherVersionDatetime) VALUES
(1, 1, 'GRôG', '', '', '', '', '', 1, '', 'passerelle@legrog.org', 'www.legrog.org', TRUE, 'Ouvert…', 1, {ts '2000-05-08 00:00:47'}),
(2, 2, 'Rôliste TV', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'www.rolistetv.com', TRUE, 'Ouvert…', 3, {ts '2010-05-20 08:43:16'}),
(3, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', TRUE, 'Ouvert…', 1, {ts '2000-01-01 00:02:33'}),
(4, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', FALSE, '… en 2015', 2, {ts '2015-01-01 00:05:22'}),
(5, 4, 'Archmagus', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'archimage.net', TRUE, 'Ouvert…', 4, {ts '2016-10-14 10:56:03'});
UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId = 1;
UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2;
UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3;
INSERT INTO PublisherAction (publisherActionId, actionType_actionTypeId, publisherActionAuthor_userId,
publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES
(1, 1, 2, 1, {ts '2000-05-08 12:00:28'}, 1),
(2, 1, 1, 2, {ts '2010-06-20 14:27:35'}, 2),
(3, 1, 1, 4, {ts '2015-01-01 16:18:17'}, 3);
INSERT INTO UserRole (userRoleId, rolename, visible) VALUES
(1, 'VISITEUR', TRUE),
(2,'RECRUE', TRUE),
(3, 'CONTRIBUTEUR', TRUE),
(4, 'ADMINISTRATEUR', TRUE),
(5, 'RETRAITE', TRUE),
(6, 'ASSOCE', TRUE);
INSERT INTO UserProperty (userPropertyId, name, tag, visible) VALUES
(1, 'nb_vignettes', 'Nombre de vignettes en home', TRUE),
(2, 'avatar', 'Lien vers une icône ou une photo', TRUE),
(3, 'tagline', 'Ligne de présentation pour les contributeurs', TRUE),
(4, 'taille_listes', 'Nombre d''éléments affichés dans les listes', TRUE),
(5,'skin', 'Thème visuel', TRUE);
INSERT INTO Person_UserRole VALUES (1,2);
INSERT INTO Person_UserRole VALUES (2,2);
INSERT INTO Person_UserRole VALUES (3,2);
INSERT INTO Person_UserRole VALUES (4,2);
INSERT INTO Person_UserRole VALUES (5,2);
INSERT INTO Person_UserRole VALUES (6,2);
INSERT INTO Person_UserRole VALUES (5,4);
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="org.legrog" level="DEBUG"/>
<logger name="org.legrog.web.publisher" level="TRACE"/>
<!-- Liste incomplète pour diagnostiquer si nécessaire -->
<logger name="org.hibernate" level="TRACE"/>
<logger name="org.hibernate.SQL" level="WARN"/>
<logger name="org.hibernate.annotations" level="WARN"/>
<logger name="org.hibernate.boot" level="WARN"/>
<logger name="org.hibernate.boot.archive" level="WARN"/>
<logger name="org.hibernate.boot.cfgxml" level="WARN"/>
<logger name="org.hibernate.boot.internal" level="WARN"/>
<logger name="org.hibernate.boot.jaxb" level="WARN"/>
<logger name="org.hibernate.boot.model" level="WARN"/>
<logger name="org.hibernate.boot.registry" level="WARN"/>
<logger name="org.hibernate.boot.registry.classloading" level="WARN"/>
<logger name="org.hibernate.boot.registry.internal" level="WARN"/>
<logger name="org.hibernate.boot.registry.selector" level="WARN"/>
<logger name="org.hibernate.boot.spi" level="WARN"/>
<logger name="org.hibernate.cache" level="WARN"/>
<logger name="org.hibernate.cfg" level="WARN"/>
<logger name="org.hibernate.cfg.Environment" level="WARN"/>
<logger name="org.hibernate.cfg.AnnotationBinder" level="WARN"/>
<logger name="org.hibernate.cfg.Ejb3Column" level="WARN"/>
<logger name="org.hibernate.cfg.AbstractPropertyHolder" level="WARN"/>
<logger name="org.hibernate.cfg.AnnotationBinder" level="WARN"/>
<logger name="org.hibernate.cfg.CollectionSecondPass" level="WARN"/>
<logger name="org.hibernate.cfg.Settings" level="WARN"/>
<logger name="org.hibernate.cfg.annotations" level="WARN"/>
<logger name="org.hibernate.cfg.beanvalidation" level="WARN"/>
<logger name="org.hibernate.dialect" level="WARN"/>
<logger name="org.hibernate.engine" level="WARN"/>
<logger name="org.hibernate.event.internal" level="WARN"/>
<logger name="org.hibernate.hql.antlr" level="WARN"/>
<logger name="org.hibernate.hql.internal" level="WARN"/>
<logger name="org.hibernate.id" level="WARN"/>
<logger name="org.hibernate.integrator" level="WARN"/>
<logger name="org.hibernate.internal" level="WARN"/>
<logger name="org.hibernate.jpa" level="WARN"/>
<logger name="org.hibernate.loader" level="WARN"/>
<logger name="org.hibernate.mapping" level="WARN"/>
<logger name="org.hibernate.persister" level="WARN"/>
<logger name="org.hibernate.resource" level="WARN"/>
<logger name="org.hibernate.resource.transaction.backend.jta.internal" level="WARN"/>
<logger name="org.hibernate.resource.jdbc.internal" level="WARN"/>
<logger name="org.hibernate.secure" level="WARN"/>
<logger name="org.hibernate.service" level="WARN"/>
<logger name="org.hibernate.stat.internal" level="WARN"/>
<logger name="org.hibernate.stat.spi" level="WARN"/>
<logger name="org.hibernate.tool" level="TRACE"/>
<logger name="org.hibernate.type" level="WARN"/>
<logger name="org.hibernate.validator" level="WARN"/>
<root level="warn">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
INSERT INTO Country (countryName) VALUES ('France');
INSERT INTO Country (countryName) VALUES ('Suisse');
INSERT INTO Country (countryName) VALUES ('Belgique');
INSERT INTO Country (countryName) VALUES ('Canada');
INSERT INTO Country (countryName) VALUES ('États-Unis d''Amérique');
INSERT INTO Country (countryName) VALUES ('Australie');
INSERT INTO Country (countryName) VALUES ('Espagne');
INSERT INTO Country (countryName) VALUES ('Portugal');
INSERT INTO Country (countryName) VALUES ('Royaume-Uni');
INSERT INTO Country (countryName) VALUES ('Allemagne');
INSERT INTO Country (countryName) VALUES ('Pologne');
INSERT INTO Country (countryName) VALUES ('Italie');
INSERT INTO UserRole VALUES (1, 'VISITEUR', TRUE);
INSERT INTO UserRole VALUES (2, 'RECRUE', TRUE);
INSERT INTO UserRole VALUES (3, 'CONTRIBUTEUR', TRUE);
INSERT INTO UserRole VALUES (4, 'ADMINISTRATEUR', TRUE);
INSERT INTO UserRole VALUES (5, 'RETRAITE', TRUE);
INSERT INTO UserRole VALUES (6, 'ASSOCE', TRUE);
INSERT INTO UserProperty VALUES (1, 'nb_vignettes', 'Nombre de vignettes en home', TRUE);
INSERT INTO UserProperty VALUES (2, 'avatar', 'Lien vers une icône ou une photo', TRUE);
INSERT INTO UserProperty VALUES (3, 'tagline', 'Ligne de présentation pour les contributeurs', TRUE);
INSERT INTO UserProperty VALUES (4, 'taille_listes', 'Nombre d''éléments affichés dans les listes', TRUE);
INSERT INTO UserProperty VALUES (5, 'skin', 'Thème visuel', TRUE);
INSERT INTO UserTable (USER_ID, username, password, firstName, lastName, nickname, email, activated, anonymous, visible, criticProvider) VALUES
(1, 'one', 'one', 'Derrick', 'Moss', 'one', 'one@raza.org', TRUE, FALSE, TRUE, TRUE),
(2, 'two', 'two', 'Portia', 'Lin', 'two', 'two@raza.org', TRUE, FALSE, TRUE, TRUE),
(3, 'three', 'three', 'Marcus', 'Boone', 'three', 'three@raza.org', TRUE, FALSE, TRUE, TRUE),
(4, 'four', 'four', 'Ryo', 'Tetsuda', 'four', 'four@raza.org', TRUE, FALSE, TRUE, TRUE),
(5, 'five', 'five', 'Emily', 'Kolburn', 'five', 'five@raza.org', TRUE, FALSE, TRUE, TRUE),
(6, 'six', 'six', 'Kal', 'Varrik', 'six', 'six@raza.org', TRUE, FALSE, TRUE, TRUE);
INSERT INTO UserTable_UserRole VALUES (1,2);
INSERT INTO UserTable_UserRole VALUES (2,2);
INSERT INTO UserTable_UserRole VALUES (3,2);
INSERT INTO UserTable_UserRole VALUES (4,2);
INSERT INTO UserTable_UserRole VALUES (5,2);
INSERT INTO UserTable_UserRole VALUES (6,2);
INSERT INTO UserTable_UserRole VALUES (5,4);
......@@ -4,109 +4,91 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<!--
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>addBook</from-outcome>
<to-view-id>/book/book.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listBooks</from-outcome>
<to-view-id>/book/result.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addCountry</from-outcome>
<to-view-id>/xyz/addCountry.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listCountries</from-outcome>
<to-view-id>/xyz/listCountries.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addUser</from-outcome>
<to-view-id>/user/updateUser.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listUsers</from-outcome>
<to-view-id>/user/listUsers.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/xyz/addCountry.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/xyz/listCountries.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>addBook</from-outcome>
<to-view-id>/book.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listBooks</from-outcome>
<to-view-id>/result.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addCountry</from-outcome>
<to-view-id>/addCountry.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listCountries</from-outcome>
<to-view-id>/listCountries.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addUser</from-outcome>
<to-view-id>/updateUser.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>listUsers</from-outcome>
<to-view-id>/listUsers.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addPublisher</from-outcome>
<to-view-id>/addPublisher.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/addPublisher.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/listPublisherRevisions.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/addCountry.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/listCountries.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/user/addUser_short.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/user/listUsers_short.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/addUser_short.xhtml</from-view-id>
<navigation-rule>
<from-view-id>/book/book.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/listUsers_short.xhtml</to-view-id>
<from-outcome>success</from-outcome>
<to-view-id>/book/result.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/book.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/result.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</navigation-rule>
<navigation-rule>
<from-view-id>/result.xhtml</from-view-id>
<navigation-case>
<from-outcome>back</from-outcome>
<to-view-id>/book.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/updateUser.xhtml</from-view-id>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/listUsers.xhtml</to-view-id>
</navigation-case>
<navigation-rule>
<from-view-id>/book/result.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/listUsers.xhtml</to-view-id>
<from-outcome>back</from-outcome>
<to-view-id>/book/book.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/listUsers.xhtml</from-view-id>
<navigation-case>
<from-outcome>add</from-outcome>
<to-view-id>/updateUser.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</navigation-rule>
<navigation-rule>
<from-view-id>/listPublisherRevisions.xhtml</from-view-id>
<navigation-case>
<from-outcome>view</from-outcome>
<to-view-id>/publisherRevision.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/user/updateUser.xhtml</from-view-id>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/user/listUsers.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/user/listUsers.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/user/listUsers.xhtml</from-view-id>
<navigation-case>
<from-outcome>add</from-outcome>
<to-view-id>/user/updateUser.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
-->
</faces-config>
\ No newline at end of file
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:form>
<h:commandLink action="home">
<h:outputText value="Menu principal"/>
</h:commandLink>
<h:panelGrid columns="2">
<h:outputText value='publisherName'/>
<h:inputText value='#{addPublisherBean.publisherName}'/>
<h:outputText value='publisherStreetAddress'/>
<h:inputText value='#{addPublisherBean.publisherStreetAddress}'/>
<h:outputText value='publisherPostalCode'/>
<h:inputText value='#{addPublisherBean.publisherPostalCode}'/>
<h:outputText value='publisherPostOfficeBoxNumber'/>
<h:inputText value='#{addPublisherBean.publisherPostOfficeBoxNumber}'/>
<h:outputText value='publisherAddressRegion'/>
<h:inputText value='#{addPublisherBean.publisherAddressRegion}'/>
<h:outputText value='publisherAddressLocality'/>
<h:inputText value='#{addPublisherBean.publisherAddressLocality}'/>
<h:outputText value='publisherAddressCountry'/>
<h:selectOneMenu value="#{addPublisherBean.publisherAddressCountry}" converter="omnifaces.SelectItemsConverter">
<f:selectItems value="#{addPublisherBean.availableCountries}" var="country" itemLabel="#{country.countryName}"/>
</h:selectOneMenu>
<h:outputText value='publisherTelephone'/>
<h:inputText value='#{addPublisherBean.publisherTelephone}'/>
<h:outputText value='publisherEmail'/>
<h:inputText value='#{addPublisherBean.publisherEmail}'/>
<h:outputText value='publisherURL'/>
<h:inputText value='#{addPublisherBean.publisherURL}'/>
<h:outputText value='publisherActive'/>
<h:selectBooleanCheckbox value="#{addPublisherBean.publisherActive}"/>
<h:outputText value='publisherHistory'/>
<h:inputTextarea value='#{addPublisherBean.publisherHistory}'/>
<h:outputText value='Add'/>
<h:commandButton action="#{addPublisherBean.add}" value="Add"/>
</h:panelGrid>
</h:form>
</f:view>
</html>
......@@ -2,48 +2,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
xmlns:jsf="http://xmlns.jcp.org/jsf">
<body>
<h:form>
<ul>
<li>
<h:commandLink action="addBook">
<h:outputText value="Add book"/>
</h:commandLink>
<a jsf:outcome="publisher/listPublisherVersions">Liste des versions des éditeurs</a>
</li>
<li>
<h:commandLink action="listBooks">
<h:outputText value="List books"/>
</h:commandLink>
<a jsf:outcome="publisher/listPublisherActions">Liste des actions des éditeurs</a>
</li>
<li>
<h:commandLink action="addCountry">
<h:outputText value="Add country"/>
</h:commandLink>
</li>
<li>
<h:commandLink action="listCountries">
<h:outputText value="List countries"/>
</h:commandLink>
</li>
<li>
<h:commandLink action="addUser">
<h:outputText value="Add user"/>
</h:commandLink>
</li>
<li>
<h:commandLink action="listUsers">
<h:outputText value="List users"/>
</h:commandLink>
</li>
<li>
<h:commandLink action="addPublisher">
<h:outputText value="Add Publisher"/>
</h:commandLink>
<a jsf:outcome="publisher/publisherVersion">Ajouter un éditeur</a>
</li>
</ul>
</h:form>
</body>
</html>
</html>
\ No newline at end of file
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body>
<h:outputText rendered="#{listPublisherRevisionsBean.publisherRevisions.isEmpty()}">Liste des révisions est vide</h:outputText>
<h:dataTable value="#{listPublisherRevisionsBean.publisherRevisions}" var="revision">
<h:column>
<f:facet name="header">Visualiser<!--ou Modifier--></f:facet>
<h:link outcome="view">Visualiser<!--ou Modifier-->
<f:param name="publisherRevisionId" value="#{revision.publisherRevisionId}"/>
</h:link>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
#{revision.publisherName}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
#{revision.publisherPostOfficeBoxNumber}<br />
#{revision.publisherStreetAddress}<br />
#{revision.publisherPostalCode} #{revision.publisherAddressLocality}<br />
#{revision.publisherAddressRegion}<br />
#{revision.publisherAddressCountry.countryName}
</h:column>
<h:column>
<f:facet name="header">Telephone</f:facet>
#{revision.publisherTelephone}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
#{revision.publisherEmail}
</h:column>
<h:column>
<f:facet name="header">URL</f:facet>
#{revision.publisherURL}
</h:column>
<h:column>
<f:facet name="header">Active ?</f:facet>
#{revision.publisherActive}
</h:column>
<h:column>
<f:facet name="header">History</f:facet>
#{revision.publisherHistory}
</h:column>
<h:column>
<f:facet name="header">Revision Author</f:facet>
#{revision.publisherRevisionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Revision Datetime</f:facet>
#{revision.publisherRevisionDatetime}
</h:column>
</h:dataTable>
</h:body>
</html>
table {
border-collapse: collapse;
}
table, th, td {
border-style: solid;
border-width: 1px;
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf"
>
<head>
<f:metadata>
<f:viewParam name="publisherRevisionId" value="#{publisherRevisionView.publisherRevisionId}" />
<f:viewAction action="#{publisherRevisionView.loadData}" />
</f:metadata>
</head>
<body>
<p>Depuis le paramètre : #{param['publisherRevisionId']} </p>
<p>En passant par la vue : #{publisherRevisionView.publisherRevisionId} </p>
<form action="" jsf:id="reload-form">
<button jsf:id="reload" jsf:action="#{publisherRevisionView.loadData}">Reload !</button>
</form>
</body>
</html>
\ No newline at end of file
package org.legrog.test;
/*
TAKEN FROM JUnit 5 Sample
https://github.com/junit-team/junit5-samples/blob/master/junit5-mockito-extension/src/main/java/com/example/mockito/MockitoExtension.java
*/
/*
* Copyright 2015-2016 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
*/
import static org.mockito.Mockito.mock;
import java.lang.reflect.Parameter;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* {@code MockitoExtension} showcases the {@link TestInstancePostProcessor}
* and {@link ParameterResolver} extension APIs of JUnit 5 by providing
* dependency injection support at the field level and at the method parameter
* level via Mockito 2.x's {@link Mock @Mock} annotation.
*/
public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver {
@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
MockitoAnnotations.initMocks(testInstance);
}
@Override
public boolean supports(ParameterContext parameterContext, ExtensionContext extensionContext) {
return parameterContext.getParameter().isAnnotationPresent(Mock.class);
}
@Override
public Object resolve(ParameterContext parameterContext, ExtensionContext extensionContext) {
return getMock(parameterContext.getParameter(), extensionContext);
}
private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
} else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
}
private String getMockName(Parameter parameter) {
String explicitMockName = parameter.getAnnotation(Mock.class).name().trim();
if (!explicitMockName.isEmpty()) {
return explicitMockName;
} else if (parameter.isNamePresent()) {
return parameter.getName();
}
return null;
}
}
package org.legrog.application;
package org.legrog.web.book;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.Book;
import org.legrog.test.MockitoExtension;
import org.legrog.web.book.BookServiceOld;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
......@@ -17,21 +22,22 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(MockitoJUnitRunner.class)
public class BookServiceOldTest {
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
public class BookServiceOldTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityManager entityManager;
private BookServiceOld bookServiceOld;
@Before
public void setUp() throws Exception {
@BeforeEach
public void setUp() {
bookServiceOld = new BookServiceOld(entityManager);
}
@Test
public void testAddBook() throws Exception {
public void testAddBook() {
Book book = new Book();
bookServiceOld.addBook(book);
Mockito.verify(entityManager).persist(book);
......@@ -39,7 +45,7 @@ public class BookServiceOldTest {
@Test
public void testAllBooks() throws Exception {
public void testAllBooks() {
Book book = new Book();
book.setBookId(0);
......
package org.legrog.web.publisher;
import org.junit.Before;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.test.MockitoExtension;
import org.mockito.Mock;
import org.mockito.Mockito;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Classe testant ListPublisherActionsView.
*/
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Visualisation d'actions sur éditeur")
public class ListPublisherActionsViewTest {
ListPublisherActionsView listPublisherActionsView;
@Nested
@DisplayName("setView method")
public class testSetView {
boolean filtered;
@BeforeEach
public void setUp(@Mock PublisherService publisherServiceMock){
filtered = false;
listPublisherActionsView = new ListPublisherActionsView(publisherServiceMock) {
@Override
public void filterOnID() {
filtered = true;
}
};
}
@Test
@DisplayName("should show all")
public void showAll(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(null);
listPublisherActionsView.setViewAll(false);
listPublisherActionsView.setView();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isTrue();
assertThat(filtered).isFalse();
}
@Test
@DisplayName("should show filtered")
public void showFiltered(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(1);
listPublisherActionsView.setViewAll(true);
listPublisherActionsView.setView();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isFalse();
assertThat(filtered).isTrue();
}
}
@Test
@DisplayName("filterId should filter")
public void testFilter(@Mock PublisherService publisherServiceMock) {
List<PublisherAction> publisherActions = new ArrayList<PublisherAction>();
Publisher publisher = new Publisher();
Publisher publisher1 = new Publisher();
PublisherAction publisherAction = new PublisherAction();
PublisherAction publisherAction1 = new PublisherAction();
publisher.setPublisherId(0);
publisher1.setPublisherId(1);
publisherAction.setPublisher(publisher);
publisherAction1.setPublisher(publisher1);
publisherActions.add(publisherAction);
publisherActions.add(publisherAction1);
listPublisherActionsView = new ListPublisherActionsView();
listPublisherActionsView.setPublisherActions(publisherActions);
listPublisherActionsView.setPublisherId(1);
listPublisherActionsView.filterOnID();
assertThat(listPublisherActionsView.getPublisherActions()).containsExactly(publisherAction1);
}
}
package org.legrog.web.publisher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.DisplayName;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.entities.PublisherVersion;
import org.legrog.test.MockitoExtension;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
/**
* Classe testant ListPublisherVersionsView.
*/
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Listes de versions d'éditeurs")
public class ListPublisherVersionsViewTest {
Logger logger = LoggerFactory.getLogger(getClass());
private ListPublisherVersionsView listPublisherVersionsView;
private List<PublisherVersion> publisherVersions;
private PublisherVersion publisherVersion;
private PublisherVersion publisherVersion1;
private PublisherVersion publisherVersion2;
private Publisher publisher;
private Publisher publisher1;
PublisherAction publisherAction;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PublisherService publisherService;
@BeforeEach
public void setUp() {
// Données
publisherVersion = new PublisherVersion();
publisherVersion1 = new PublisherVersion();
publisherVersion2 = new PublisherVersion();
publisherVersion.setPublisherVersionId(0);
publisherVersion1.setPublisherVersionId(1);
publisherVersion2.setPublisherVersionId(2);
publisher = new Publisher();
publisher1 = new Publisher();
publisher.setPublisherId(0);
publisher1.setPublisherId(1);
publisherVersion.setPublisher(publisher);
publisherVersion1.setPublisher(publisher1);
publisherVersion2.setPublisher(publisher);
publisher.setValidatedVersion(publisherVersion);
publisherVersions = new ArrayList<PublisherVersion>();
publisherVersions.add(publisherVersion);
publisherVersions.add(publisherVersion1);
publisherAction = new PublisherAction();
// Mock
when(publisherService.getAllPublisherVersions()).thenReturn(publisherVersions);
listPublisherVersionsView = new ListPublisherVersionsView(publisherService);
when(publisherService.getLastValidate(publisher)).thenReturn(publisherAction);
when(publisherService.getLastValidate(publisher1)).thenReturn(null);
}
@Test
@DisplayName("Liste complète")
public void testSetViewAll() {
listPublisherVersionsView.setPublisherId(null);
listPublisherVersionsView.setView();
Mockito.verify(publisherService).getAllPublisherVersions();
assertThat(listPublisherVersionsView.isViewAll()).isTrue();
assertThat(listPublisherVersionsView.getPublisherVersions()).isEqualTo(publisherVersions);
}
@Test
@DisplayName("Liste pour un éditeur")
public void testSetViewNotAllAlsoTestingFilterOnId() {
listPublisherVersionsView.setPublisherId(1);
listPublisherVersionsView.setView();
Mockito.verify(publisherService).getAllPublisherVersions();
assertThat(listPublisherVersionsView.isViewAll()).isFalse();
assertThat(listPublisherVersionsView.getPublisherVersions()).containsExactly(publisherVersion1);
}
@Test
@DisplayName("Test de l'appel de validation")
public void testValidate() {
listPublisherVersionsView.setPublisherId(0);
listPublisherVersionsView.validate(publisherVersion2);
Mockito.verify(publisherService).validatePublisherVersion(publisherVersion2);
}
@Test
@DisplayName("Récupération effective dernière validation d'un éditeur")
public void testGetLastValidate() {
assertThat(listPublisherVersionsView.getLastValidate(publisher)).isEqualTo(publisherAction);
}
@Test
@DisplayName("Échec de récupération de dernière validation d'un éditeur")
public void testGetLastValidateNull() {
assertThat(listPublisherVersionsView.getLastValidate(publisher1)).isNull();
}
}
\ No newline at end of file
package org.legrog.web.publisher;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.*;
import org.legrog.test.MockitoExtension;
import org.legrog.web.xyz.SharedService;
import org.mockito.Mock;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
/**
* Classe testant PublisherServiceSpring.
*/
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Couche service de gestion d'éditeur")
public class PublisherServiceSpringTest {
PublisherServiceSpring publisherServiceSpring;
PublisherVersion publisherVersion;
PublisherVersion publisherVersion1;
Publisher publisher;
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
@Inject
ActionTypeRepository actionTypeRepository;
@Mock
PublisherVersion publisherVersionMock;
@BeforeEach
public void setUp(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository,
@Mock PublisherActionRepository publisherActionRepository,
@Mock ActionTypeRepository actionTypeRepository,
@Mock SharedService sharedService) throws Exception {
publisherServiceSpring = new PublisherServiceSpring(publisherRepository,
publisherVersionRepository, publisherActionRepository, actionTypeRepository, sharedService);
publisherVersion = new PublisherVersion();
publisherVersion1 = new PublisherVersion();
this.publisherRepository = publisherRepository;
}
@DisplayName("Test ajout nouvel éditeur")
@Test
public void testAddNewPublisher(@Mock PublisherVersionRepository publisherVersionRepository) {
publisherServiceSpring.addNewPublisher(publisherVersion);
publisher = publisherVersion.getPublisher();
assertThat(publisher.getVersions()).containsExactly(publisherVersion);
assertThat(publisherVersion.getPublisher()).isEqualTo(publisher);
verify(publisherRepository).save(publisher);
verify(publisherVersionRepository).save(publisherVersion);
}
@DisplayName("Test ajout nouvelle version éditeur")
@Test
public void testAddVersionToPublisher(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository) {
publisherServiceSpring.addNewPublisher(publisherVersion);
publisher = publisherVersion.getPublisher();
publisherServiceSpring.addVersionToPublisher(publisher, publisherVersion1);
assertThat(publisherVersion1.getPublisher()).isEqualTo(publisher);
assertThat(publisher.getVersions()).contains(publisherVersion, publisherVersion1);
verify(publisherRepository, times(2)).save(publisher);
verify(publisherVersionRepository).save(publisherVersion1);
}
@DisplayName("Test validation version éditeur")
@Test
public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository) {
Set<PublisherVersion> publisherVersions;
publisher = new Publisher();
publisherVersion = new PublisherVersion();
publisherVersions = new HashSet<PublisherVersion>();
publisherVersions.add(publisherVersion);
publisherVersions.add(publisherVersionMock);
when(publisherVersionMock.getPublisher()).thenReturn(publisher);
PublisherAction publisherAction;
publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
verify(publisherActionRepository).save(publisherAction);
assertThat(publisherAction.getPublisherVersion()).isEqualTo(publisherVersionMock);
assertThat(publisherAction.getPublisher()).isEqualTo(publisher);
assertThat(publisherAction.getPublisher().getValidatedVersion()).isEqualTo(publisherVersionMock);
// TODO Régler ce problème de NPE
// assertThat(publisherAction.getActionType()).isEqualTo(actionTypeRepository.findByActionTypeName("Validate"));
}
}
package org.legrog.web.user;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.DisplayNameMask;
import org.legrog.test.MockitoExtension;
import org.legrog.web.xyz.SharedService;
import org.mockito.Mock;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
/**
* Created by jai on 15/11/16.
*/
@DisplayName("Update Person Bean")
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
public class UpdatePersonBeanTest {
UpdateUserBean updateUserBean;
@BeforeEach
public void setUp(@Mock UserService userService, @Mock SharedService sharedService) throws Exception {
updateUserBean = new UpdateUserBean(userService, sharedService) ;
}
@Test
@DisplayName("depends on Shared Service and Person Service")
public void testDependencies() {
assertThat(updateUserBean).isNotNull();
}
@Nested
@DisplayName("post construct method")
class init {
private List<DisplayNameMask> displayNameMasks;
private List<org.legrog.entities.UserProperty> userProperties;
private List<org.legrog.entities.UserRole> userRoles;
@BeforeEach
public void setUp(@Mock SharedService sharedService) {
when(sharedService.getAllDisplayNameMasks()).thenReturn(displayNameMasks);
when(sharedService.getAvailableUserProperties()).thenReturn(userProperties);
when(sharedService.getAvailableUserRoles()).thenReturn(userRoles);
}
@Test
@DisplayName("should set lists of available masks, user roles, and user properties from shared service")
public void testList(@Mock SharedService sharedService) {
updateUserBean.init();
assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
assertThat(updateUserBean.getAvailableUserProperties()).isEqualTo(userProperties);
assertThat(updateUserBean.getAvailableUserRoles()).isEqualTo(userRoles);
}
}
}
\ No newline at end of file