Jean-Francois Leveque

https://tree.taiga.io/project/jr-utily-grog-v3/us/44 Implementer l'historisation pour les éditeurs

package org.legrog.application;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
import java.util.List;
public interface PublisherService {
void addPublisher(Publisher publisher);
void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision);
List<Publisher> getAllPublishers();
}
......
......@@ -3,10 +3,12 @@ package org.legrog.application;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRepository;
import org.legrog.entities.PublisherRevision;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
import java.util.Set;
@Stateless
public class PublisherServiceSpring implements PublisherService {
......@@ -17,6 +19,14 @@ public class PublisherServiceSpring implements PublisherService {
publisherRepository.save(publisher);
}
public void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision) {
Set<PublisherRevision> publisherRevisionSet = publisher.getRevisions();
publisherRevisionSet.add(publisherRevision);
publisher.setRevisions(publisherRevisionSet);
publisherRevision.setPublisher(publisher);
publisherRepository.save(publisher);
}
public List<Publisher> getAllPublishers() {
return publisherRepository.findAll();
}
......
......@@ -22,7 +22,7 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
private Timestamp validationDateTime;
@OneToMany(mappedBy = "publisher")
@OneToMany(mappedBy = "publisher", fetch = FetchType.EAGER)
private Set<PublisherRevision> revisions;
public int getPublisherId() {
......
......@@ -158,4 +158,12 @@ public class PublisherRevision {
", URL = " + publisherURL + ", actif = " + publisherActive + ", History = " + publisherHistory +
", Revision Author = " + publisherRevisionAuthor + ", Revision DateTime = " + publisherRevisionDatetime;
}
public Publisher getPublisher() {
return publisher;
}
public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
}
\ No newline at end of file
......
......@@ -59,11 +59,11 @@ public class AddPublisherBean {
publisherRevisions.add(publisherRevision);
publisher.setRevisions(publisherRevisions);
logger.info(publisher.toString());
publisherRevision.setPublisher(publisher);
publisherRevision.setPublisherActive(publisherActive);
publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
publisherRevision.setPublisherEmail(publisherEmail);
publisherRevision.setPublisherHistory(publisherHistory);
publisherRevision.setPublisherName(publisherName);
......@@ -82,8 +82,8 @@ public class AddPublisherBean {
// End TODO
publisherRevision.setPublisherRevisionAuthor(user);
logger.info(publisherRevision.toString());
publisherRevisionService.addPublisherRevision(publisherRevision);
publisherService.addPublisher(publisher);
publisherRevisionService.addPublisherRevision(publisherRevision);
// Test de récupération de l'Id
logger.info(publisherRevision.toString());
return "success";
......
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;
......@@ -14,7 +17,10 @@ import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.Set;
@Named
@ViewScoped
......@@ -22,8 +28,12 @@ public class PublisherRevisionView implements Serializable {
Logger logger = LoggerFactory.getLogger(getClass());
@Inject
private PublisherService publisherService;
@Inject
PublisherRevisionService publisherRevisionService;
@Inject
UserService userService;
@Inject
private SharedService sharedService;
private boolean editMode;
......@@ -44,6 +54,7 @@ public class PublisherRevisionView implements Serializable {
private String publisherHistory;
private User publisherRevisionAuthor;
private Timestamp publisherRevisionDatetime;
private Publisher publisher;
// Table de codification
private List<Country> availableCountries;
......@@ -65,6 +76,36 @@ public class PublisherRevisionView implements Serializable {
return editMode;
}
public void update() {
PublisherRevision publisherRevision = new PublisherRevision();
publisherRevision.setPublisherActive(publisherActive);
publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
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);
publisherService.addRevisionToPublisher(publisher, publisherRevision);
publisherRevisionService.addPublisherRevision(publisherRevision);
editMode = false;
}
public void loadData() {
logger.debug("publisherRevisionId = {}", this.publisherRevisionId);
......@@ -86,7 +127,9 @@ public class PublisherRevisionView implements Serializable {
publisherHistory = publisherRevision.getPublisherHistory();
publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
publisher = publisherRevision.getPublisher();
logger.debug("Found a publisher : {}", publisher.toString());
// Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
//
......
......@@ -43,6 +43,11 @@
<h:outputText value="Add Publisher"/>
</h:commandLink>
</li>
<li>
<h:commandLink action="listPublisherRevisions">
<h:outputText value="List Publisher Revisions"/>
</h:commandLink>
</li>
</ul>
</h:form>
</body>
......
......@@ -6,15 +6,25 @@
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body>
<h:form>
<h:commandLink action="home">
<h:outputText value="Menu principal"/>
</h:commandLink>
</h:form>
<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:facet name="header">Visualiser ou Modifier</f:facet>
<h:link outcome="view">Visualiser ou Modifier Version
<f:param name="publisherRevisionId" value="#{revision.publisherRevisionId}"/>
</h:link>
</h:column>
<h:column>
<f:facet name="header">Editeur</f:facet>
#{revision.publisher.publisherId}
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
#{revision.publisherName}
</h:column>
......
......@@ -62,6 +62,7 @@
<h:outputText value="publisherRevisionDatetime"/>
<h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}"/>
<h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/>
<h:commandButton value="Save" action="#{publisherRevisionView.update}" rendered="#{publisherRevisionView.editMode}"/>
<h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/>
<ui:remove>
<h:outputText value='Add'/>
......