Jean-Francois Leveque
......@@ -2,9 +2,6 @@ package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.User;
import org.legrog.web.user.UserService;
import org.legrog.web.xyz.SharedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -13,8 +10,9 @@ import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.sql.Timestamp;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Named
@RequestScoped
......@@ -23,10 +21,6 @@ public class ListPublisherRevisionsBean {
@Inject
PublisherService publisherService;
@Inject
SharedService sharedService;
@Inject
UserService userService;
private Integer publisherId;
......@@ -42,15 +36,10 @@ public class ListPublisherRevisionsBean {
logger.debug("validate");
Publisher publisher = publisherService.getPublisher(publisherId);
logger.debug("publisher (pre-validate) = {}", publisher);
FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String,String> params =
facesContext.getExternalContext().getRequestParameterMap();
Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Integer publisherRevisionId = new Integer(params.get("publisherRevisionId"));
publisher.setValidatedRevision(publisherService.getPublisherRevision(publisherRevisionId));
User user = sharedService.getCurrentUser();
publisher.setValidator(user);
publisher.setValidationDateTime(new Timestamp(new Date().getTime()));
publisherService.updatePublisher(publisher);
publisherService.validatePublisherRevision(publisher, publisherRevisionId);
// TODO : comprendre pourquoi ceci est nécessaire
publisherRevisions = publisherService.getAllPublisherRevisions();
publisherRevisions = filter();
......@@ -59,12 +48,11 @@ public class ListPublisherRevisionsBean {
@PostConstruct
public void init() {
publisherRevisions = publisherRevisionService.getAllPublisherRevisions();
logger.info("init");
publisherRevisions = publisherService.getAllPublisherRevisions();
logger.debug("init");
}
List<PublisherRevision> filter() {
protected List<PublisherRevision> filter() {
ArrayList<PublisherRevision> filteredPublisherRevisions= new ArrayList<PublisherRevision>();
for(PublisherRevision publisherRevision : publisherRevisions) {
......@@ -85,6 +73,7 @@ public class ListPublisherRevisionsBean {
}
}
// get, set et is
public Integer getPublisherId() {
return publisherId;
}
......
package org.legrog.web.publisher;
import org.legrog.web.xyz.SharedService;
import org.legrog.web.user.UserService;
import org.legrog.entities.Country;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRevision;
......@@ -16,9 +15,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.Set;
@Named
@ViewScoped
......@@ -28,8 +25,6 @@ public class PublisherRevisionView implements Serializable {
@Inject
PublisherService publisherService;
@Inject
UserService userService;
@Inject
SharedService sharedService;
private boolean editMode;
......@@ -74,9 +69,12 @@ public class PublisherRevisionView implements Serializable {
}
public void save() {
logger.debug("save()");
if (newPublisher) {
logger.debug("->add");
add();
} else {
logger.debug("->update");
update();
}
}
......@@ -94,31 +92,17 @@ public class PublisherRevisionView implements Serializable {
publisherRevision.setPublisherStreetAddress(publisherStreetAddress);
publisherRevision.setPublisherTelephone(publisherTelephone);
publisherRevision.setPublisherURL(publisherURL);
publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime()));
User user = sharedService.getCurrentUser();
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);
publisherService.addPublisherWithRevision(publisher, publisherRevision);
newPublisher = false;
publisherRevisionId = publisherRevision.getPublisherRevisionId();
// int publisherId = publisher.getPublisherId();
this.publisher = publisher;
publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
......@@ -127,11 +111,9 @@ public class PublisherRevisionView implements Serializable {
public void update() {
PublisherRevision publisherRevision = new PublisherRevision();
setValues(publisherRevision);
publisherService.addRevisionToPublisher(publisher, publisherRevision);
publisherService.addPublisherRevision(publisherRevision);
editMode = false;
}
......@@ -170,6 +152,7 @@ public class PublisherRevisionView implements Serializable {
}
// get, set et is
public int getPublisherRevisionId() {
return publisherRevisionId;
}
......
......@@ -7,18 +7,16 @@ import java.util.List;
public interface PublisherService {
void addPublisher(Publisher publisher);
void addPublisherWithRevision(Publisher publisher, PublisherRevision publisherRevision);
void updatePublisher(Publisher publisher);
void validatePublisherRevision(Publisher publisher, Integer publisherRevisionId);
void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision);
List<Publisher> getAllPublishers();
// List<Publisher> getAllPublishers();
Publisher getPublisher(Integer publisherId);
void addPublisherRevision(PublisherRevision publisherRevision);
List<PublisherRevision> getAllPublisherRevisions();
PublisherRevision getPublisherRevision(Integer publisherRevisionId);
......
package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherRepository;
import org.legrog.entities.PublisherRevision;
import org.legrog.entities.PublisherRevisionRepository;
import org.legrog.entities.*;
import org.legrog.web.xyz.SharedService;
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;
......@@ -19,39 +20,61 @@ public class PublisherServiceSpring implements PublisherService {
@Inject
PublisherRevisionRepository publisherRevisionRepository;
public void addPublisherRevision(PublisherRevision publisherRevision) {
publisherRevisionRepository.save(publisherRevision);
@Inject
SharedService sharedService;
public void addPublisherWithRevision(Publisher publisher, PublisherRevision publisherRevision) {
Set<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>();
publisherRevisions.add(publisherRevision);
publisher.setRevisions(publisherRevisions);
publisherRevision.setPublisher(publisher);
publisherRevision.setPublisherRevisionAuthor(sharedService.getCurrentUser());
publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherRevision(publisherRevision);
this.savePublisher(publisher);
}
public List<PublisherRevision> getAllPublisherRevisions() {
return publisherRevisionRepository.findAll();
public void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision) {
Set<PublisherRevision> publisherRevisionSet = publisher.getRevisions();
publisherRevisionSet.add(publisherRevision);
publisher.setRevisions(publisherRevisionSet);
publisherRevision.setPublisher(publisher);
publisherRevision.setPublisherRevisionAuthor(sharedService.getCurrentUser());
publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherRevision(publisherRevision);
this.savePublisher(publisher);
}
public PublisherRevision getPublisherRevision(Integer publisherRevisionId) {
return publisherRevisionRepository.findOne(publisherRevisionId);
public void validatePublisherRevision(Publisher publisher, Integer publisherRevisionId) {
publisher.setValidatedRevision(this.getPublisherRevision(publisherRevisionId));
publisher.setValidator(sharedService.getCurrentUser());
publisher.setValidationDateTime(new Timestamp(new Date().getTime()));
this.savePublisher(publisher);
}
public void addPublisher(Publisher publisher) {
publisherRepository.save(publisher);
protected void savePublisherRevision(PublisherRevision publisherRevision) {
publisherRevisionRepository.save(publisherRevision);
}
public void updatePublisher(Publisher publisher) {
protected void savePublisher(Publisher publisher) {
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);
// get
public List<PublisherRevision> getAllPublisherRevisions() {
return publisherRevisionRepository.findAll();
}
public PublisherRevision getPublisherRevision(Integer publisherRevisionId) {
return publisherRevisionRepository.findOne(publisherRevisionId);
}
public Publisher getPublisher(Integer publisherId) {
return publisherRepository.findOne(publisherId);
}
/*
public List<Publisher> getAllPublishers() {
return publisherRepository.findAll();
}
*/
}
......
......@@ -47,56 +47,56 @@
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
#{revision.publisherName}
${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}
${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}
${revision.publisherTelephone}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
#{revision.publisherEmail}
${revision.publisherEmail}
</h:column>
<h:column>
<f:facet name="header">URL</f:facet>
#{revision.publisherURL}
${revision.publisherURL}
</h:column>
<h:column>
<f:facet name="header">Active ?</f:facet>
#{revision.publisherActive}
${revision.publisherActive}
</h:column>
<h:column>
<f:facet name="header">History</f:facet>
#{revision.publisherHistory}
${revision.publisherHistory}
</h:column>
<h:column>
<f:facet name="header">Revision Author</f:facet>
#{revision.publisherRevisionAuthor.displayName}
${revision.publisherRevisionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Revision Datetime</f:facet>
#{revision.publisherRevisionDatetime}
${revision.publisherRevisionDatetime}
</h:column>
<h:column>
<f:facet name="header">Validation author</f:facet>
<h:outputText rendered="#{revision.publisherRevisionId == revision.publisher.validatedRevision.publisherRevisionId}">
#{revision.publisher.validator.displayName}
</h:outputText>
<div jsf:rendered="#{revision.publisherRevisionId == revision.publisher.validatedRevision.publisherRevisionId}">
${revision.publisher.validator.displayName}
</div>
</h:column>
<h:column>
<f:facet name="header">Validation Datetime</f:facet>
<h:outputText rendered="#{revision.publisherRevisionId == revision.publisher.validatedRevision.publisherRevisionId}">
#{revision.publisher.validationDateTime}
</h:outputText>
<div jsf:rendered="#{revision.publisherRevisionId == revision.publisher.validatedRevision.publisherRevisionId}">
${revision.publisher.validationDateTime}
</div>
</h:column>
</h:dataTable>
</body>
</html>
</html>
\ No newline at end of file
......
......@@ -25,39 +25,39 @@
</ul>
<h:panelGrid columns="2">
publisherName
<input type="text" value='#{publisherRevisionView.publisherName}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherStreetAddress
<input type="text" value='#{publisherRevisionView.publisherStreetAddress}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherPostalCode
<input type="text" value='#{publisherRevisionView.publisherPostalCode}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherPostOfficeBoxNumber
<input type="text" value='#{publisherRevisionView.publisherPostOfficeBoxNumber}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherAddressRegion
<input type="text" value='#{publisherRevisionView.publisherAddressRegion}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherAddressLocality
<input type="text" value='#{publisherRevisionView.publisherAddressLocality}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherName">publisherName</label>
<input type="text" id="publisherName" jsf:value='#{publisherRevisionView.publisherName}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherStreetAddress">publisherStreetAddress</label>
<input type="text" id="publisherStreetAddress" jsf:value='#{publisherRevisionView.publisherStreetAddress}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherPostalCode">publisherPostalCode</label>
<input type="text" id="publisherPostalCode" jsf:value='#{publisherRevisionView.publisherPostalCode}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherPostOfficeBoxNumber">publisherPostOfficeBoxNumber</label>
<input type="text" id="publisherPostOfficeBoxNumber" jsf:value='#{publisherRevisionView.publisherPostOfficeBoxNumber}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherAddressRegion">publisherAddressRegion</label>
<input type="text" id="publisherAddressRegion" jsf:value='#{publisherRevisionView.publisherAddressRegion}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherAddressLocality">publisherAddressLocality</label>
<input type="text" id="publisherAddressLocality" jsf:value='#{publisherRevisionView.publisherAddressLocality}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherAddressCountry
<h:selectOneMenu value="#{publisherRevisionView.publisherAddressCountry}" converter="omnifaces.SelectItemsConverter" disabled="#{not publisherRevisionView.editMode}">
<f:selectItems value="#{publisherRevisionView.availableCountries}" var="country" itemLabel="#{country.countryName}"/>
</h:selectOneMenu>
<label for="publisherAddressCountry">publisherAddressCountry</label>
<h:selectOneMenu id="publisherAddressCountry" value="#{publisherRevisionView.publisherAddressCountry}" converter="omnifaces.SelectItemsConverter" disabled="#{not publisherRevisionView.editMode}">
<f:selectItems value="#{publisherRevisionView.availableCountries}" var="country" itemLabel="#{country.countryName}"/>
</h:selectOneMenu>
publisherTelephone
<input type="text" value='#{publisherRevisionView.publisherTelephone}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherEmail
<input type="text" value='#{publisherRevisionView.publisherEmail}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherURL
<input type="text" value='#{publisherRevisionView.publisherURL}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherTelephone">publisherTelephone</label>
<input type="text" id="publisherTelephone" jsf:value='#{publisherRevisionView.publisherTelephone}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherEmail">publisherEmail</label>
<input type="text" id="publisherEmail" jsf:value='#{publisherRevisionView.publisherEmail}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
<label for="publisherURL">publisherURL</label>
<input type="text" id="publisherURL" jsf:value='#{publisherRevisionView.publisherURL}' jsf:disabled="#{not publisherRevisionView.editMode}"/>
publisherActive
<input type="checkbox" jsf:disabled="#{not publisherRevisionView.editMode}" value="#{publisherRevisionView.publisherActive}"/>
<label for="publisherActive">publisherActive</label>
<input type="checkbox" id="publisherActive" jsf:disabled="#{not publisherRevisionView.editMode}" jsf:value="#{publisherRevisionView.publisherActive}"/>
<ui:remove>
<h:selectBooleanCheckbox value="#{publisherRevisionView.publisherActive}" disabled="#{not publisherRevisionView.editMode}"/>
</ui:remove>
publisherHistory
<textarea rows="" cols="" jsf:disabled="#{not publisherRevisionView.editMode}" jsf:value="#{publisherRevisionView.publisherHistory}"/>
<label for="publisherHistory">publisherHistory</label>
<textarea id="publisherHistory" rows="" cols="" jsf:disabled="#{not publisherRevisionView.editMode}" jsf:value="#{publisherRevisionView.publisherHistory}"/>
<div jsf:rendered="#{not publisherRevisionView.newPublisher}">publisherRevisionAuthor</div>
<div jsf:rendered="#{not publisherRevisionView.newPublisher}">#{publisherRevisionView.publisherRevisionAuthor.displayName}</div>
......