Jean-Francois Leveque

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

Passage à la page unique pour CRU
......@@ -231,17 +231,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.5.1</version>-->
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- <version>2.19.1</version>-->
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<!-- <version>2.6</version>-->
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
......@@ -249,7 +249,7 @@
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<!-- <version>7.0.1</version>-->
<version>7.0.1</version>
<configuration>
<context>ROOT</context>
</configuration>
......
......@@ -11,4 +11,6 @@ public interface PublisherService {
void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision);
List<Publisher> getAllPublishers();
Publisher getPublisher(Integer publisherId);
}
......
......@@ -27,6 +27,10 @@ public class PublisherServiceSpring implements PublisherService {
publisherRepository.save(publisher);
}
public Publisher getPublisher(Integer publisherId) {
return publisherRepository.findOne(publisherId);
}
public List<Publisher> getAllPublishers() {
return publisherRepository.findAll();
}
......
......@@ -17,10 +17,7 @@ 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;
import java.util.*;
@Named
@ViewScoped
......@@ -37,7 +34,9 @@ public class PublisherRevisionView implements Serializable {
private SharedService sharedService;
private boolean editMode;
private boolean newPublisher;
private int publisherId;
// Données temporaires d'un PublisherRevision
private int publisherRevisionId;
private String publisherName;
......@@ -76,9 +75,15 @@ public class PublisherRevisionView implements Serializable {
return editMode;
}
public void update() {
PublisherRevision publisherRevision = new PublisherRevision();
public void save() {
if (newPublisher) {
add();
} else {
update();
}
}
private void setValues(PublisherRevision publisherRevision) {
publisherRevision.setPublisherActive(publisherActive);
publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
......@@ -101,6 +106,35 @@ public class PublisherRevisionView implements Serializable {
// End TODO
publisherRevision.setPublisherRevisionAuthor(user);
}
public void add() {
Publisher publisher = new Publisher();
PublisherRevision publisherRevision = new PublisherRevision();
HashSet<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>();
publisherRevisions.add(publisherRevision);
publisher.setRevisions(publisherRevisions);
publisherRevision.setPublisher(publisher);
setValues(publisherRevision);
publisherService.addPublisher(publisher);
publisherRevisionService.addPublisherRevision(publisherRevision);
newPublisher = false;
publisherRevisionId = publisherRevision.getPublisherRevisionId();
publisherId = publisher.getPublisherId();
this.publisher = publisher;
publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
editMode = false;
}
public void update() {
PublisherRevision publisherRevision = new PublisherRevision();
setValues(publisherRevision);
publisherService.addRevisionToPublisher(publisher, publisherRevision);
publisherRevisionService.addPublisherRevision(publisherRevision);
editMode = false;
......@@ -109,33 +143,35 @@ public class PublisherRevisionView implements Serializable {
public void loadData() {
logger.debug("publisherRevisionId = {}", this.publisherRevisionId);
PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId);
logger.debug("Found a publisher revision : {}", publisherRevision.toString());
publisherName = publisherRevision.getPublisherName();
publisherStreetAddress = publisherRevision.getPublisherStreetAddress();
publisherPostalCode = publisherRevision.getPublisherPostalCode();
publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber();
publisherAddressRegion = publisherRevision.getPublisherAddressRegion();
publisherAddressLocality = publisherRevision.getPublisherAddressLocality();
publisherAddressCountry = publisherRevision.getPublisherAddressCountry();
publisherTelephone = publisherRevision.getPublisherTelephone();
publisherEmail = publisherRevision.getPublisherEmail();
publisherURL = publisherRevision.getPublisherURL();
publisherActive = publisherRevision.isPublisherActive();
publisherHistory = publisherRevision.getPublisherHistory();
publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
publisher = publisherRevision.getPublisher();
logger.debug("Found a publisher : {}", publisher.toString());
if (publisherRevisionId != 0) {
PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId);
logger.debug("Found a publisher revision : {}", publisherRevision.toString());
publisherName = publisherRevision.getPublisherName();
publisherStreetAddress = publisherRevision.getPublisherStreetAddress();
publisherPostalCode = publisherRevision.getPublisherPostalCode();
publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber();
publisherAddressRegion = publisherRevision.getPublisherAddressRegion();
publisherAddressLocality = publisherRevision.getPublisherAddressLocality();
publisherAddressCountry = publisherRevision.getPublisherAddressCountry();
publisherTelephone = publisherRevision.getPublisherTelephone();
publisherEmail = publisherRevision.getPublisherEmail();
publisherURL = publisherRevision.getPublisherURL();
publisherActive = publisherRevision.isPublisherActive();
publisherHistory = publisherRevision.getPublisherHistory();
publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
publisher = publisherRevision.getPublisher();
logger.debug("Found a publisher : {}", publisher.toString());
newPublisher = false;
} else {
logger.debug("No publisher.");
editMode = true;
newPublisher = true;
}
// 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() {
......@@ -265,4 +301,8 @@ public class PublisherRevisionView implements Serializable {
public void setAvailableCountries(List<Country> availableCountries) {
this.availableCountries = availableCountries;
}
public boolean isNewPublisher() {
return newPublisher;
}
}
......
......@@ -39,13 +39,13 @@
</h:commandLink>
</li>
<li>
<h:link outcome="/addPublisher.xhtml">
<h:outputText value="Add a Publisher"/>
<h:link outcome="/publisherRevision">
<h:outputText value="Ajouter un éditeur"/>
</h:link>
</li>
<li>
<h:link outcome="/listPublisherRevisions.xhtml">
<h:outputText value="List Publisher Revisions"/>
<h:link outcome="/listPublisherRevisions">
<h:outputText value="Liste des versions des éditeurs"/>
</h:link>
</li>
</ul>
......
......@@ -11,9 +11,18 @@
</f:metadata>
<h:body>
<h:form>
<h:commandLink action="home">
<h:outputText value="Menu principal"/>
</h:commandLink>
<ul>
<li>
<h:link outcome="/index">
<h:outputText value="Menu principal"/>
</h:link>
</li>
<li>
<h:link outcome="/publisherRevision">
<h:outputText value="Ajouter un éditeur"/>
</h:link>
</li>
</ul>
</h:form>
<h:link rendered="#{not listPublisherRevisionsBean.viewAll}" outcome="/listPublisherRevisions.xhtml">Voir tous les éditeurs</h:link>
......
......@@ -16,9 +16,18 @@
<body>
<h:form>
<h:commandLink action="home">
<h:outputText value="Menu principal"/>
</h:commandLink>
<ul>
<li>
<h:link outcome="/index">
<h:outputText value="Menu principal"/>
</h:link>
</li>
<li>
<h:link outcome="/listPublisherRevisions">
<h:outputText value="Versions des éditeurs"/>
</h:link>
</li>
</ul>
<h:panelGrid columns="2">
<h:outputText value='publisherName'/>
......@@ -56,13 +65,13 @@
<h:selectBooleanCheckbox value="#{publisherRevisionView.publisherActive}" disabled="#{not publisherRevisionView.editMode}"/>
<h:outputText value='publisherHistory'/>
<h:inputText value='#{publisherRevisionView.publisherHistory}' disabled="#{not publisherRevisionView.editMode}"/>
<h:outputText value="publisherRevisionAuthor"/>
<h:outputText value="#{publisherRevisionView.publisherRevisionAuthor.displayName}"/>
<h:outputText value="publisherRevisionDatetime"/>
<h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}"/>
<h:inputTextarea value='#{publisherRevisionView.publisherHistory}' disabled="#{not publisherRevisionView.editMode}"/>
<h:outputText value="publisherRevisionAuthor" rendered="#{not publisherRevisionView.newPublisher}"/>
<h:outputText value="#{publisherRevisionView.publisherRevisionAuthor.displayName}" rendered="#{not publisherRevisionView.newPublisher}"/>
<h:outputText value="publisherRevisionDatetime" rendered="#{not publisherRevisionView.newPublisher}"/>
<h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}" rendered="#{not publisherRevisionView.newPublisher}"/>
<h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/>
<h:commandButton value="Save" action="#{publisherRevisionView.update}" rendered="#{publisherRevisionView.editMode}"/>
<h:commandButton value="Save" action="#{publisherRevisionView.save}" rendered="#{publisherRevisionView.editMode}"/>
<h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/>
<ui:remove>
<h:outputText value='Add'/>
......