Jean-Francois Leveque
package org.legrog.application;
import org.legrog.entities.PublisherRevision;
import java.util.List;
public interface PublisherRevisionService {
void addPublisherRevission(PublisherRevision publisherRevision);
List<PublisherRevision> getAllPublisherRevisions();
}
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 addPublisherRevission(PublisherRevision publisherRevision) {
publisherRevisionRepository.save(publisherRevision);
}
public List<PublisherRevision> getAllPublisherRevisions() {
return publisherRevisionRepository.findAll();
}
}
......@@ -5,7 +5,8 @@ import javax.persistence.*;
@Entity
public class Country /* extends org.roliste.data.DbEntity */ {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
// @GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="COUNTRY_ID")
private int countryId;
private String countryName;
......
package org.legrog.entities;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Timestamp;
@Entity
......
package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PublisherRevisionRepository extends JpaRepository<PublisherRevision, Integer> {
}
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;
......@@ -13,7 +15,9 @@ 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;
......@@ -27,6 +31,10 @@ public class AddPublisherBean {
private SharedService sharedService;
@Inject
private UserService userService;
@Inject
private PublisherService publisherService;
@Inject
private PublisherRevisionService publisherRevisionService;
private String publisherName;
private String publisherStreetAddress;
......@@ -65,8 +73,7 @@ public class AddPublisherBean {
publisherRevision.setPublisherTelephone(publisherTelephone);
publisherRevision.setPublisherURL(publisherURL);
// TODO Savoir si on utilise les temps UTC dans la base ou pas (ici, c'est le cas, mais il faut convertir à chaque affichage)
publisherRevision.setPublisherRevisionDatetime(new Timestamp(System.currentTimeMillis()));
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();
......@@ -75,6 +82,8 @@ public class AddPublisherBean {
// End TODO
publisherRevision.setPublisherRevisionAuthor(user);
logger.info(publisherRevision.toString());
publisherRevisionService.addPublisherRevission(publisherRevision);
publisherService.addPublisher(publisher);
return "success";
}
......
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();
}
}
INSERT INTO Country VALUES (1, 'France');
INSERT INTO Country VALUES (2, 'Suisse');
INSERT INTO Country VALUES (4, 'Belgique');
INSERT INTO Country VALUES (5, 'Canada');
INSERT INTO Country VALUES (6, 'États-Unis d''Amérique');
INSERT INTO Country VALUES (7, 'Australie');
INSERT INTO Country VALUES (8, 'Espagne');
INSERT INTO Country VALUES (9, 'Portugal');
INSERT INTO Country VALUES (10, 'Royaume-Uni');
INSERT INTO Country VALUES (11, 'Allemagne');
INSERT INTO Country VALUES (12, 'Pologne');
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);
......
......@@ -44,7 +44,13 @@
<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>
......@@ -95,4 +101,12 @@
<to-view-id>/updateUser.xhtml</to-view-id>
</navigation-case>
</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>
</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">
<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 id="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>
<?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">
<body>
<h:outputText value="#{param['publisherRevisionId']}" />
</body>
</html>