Jean-Francois Leveque

Formulaire création éditeur OK (à 2 TODO près) en amont enregistrement dans la base

package org.legrog.entities;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Set;
@Entity
......@@ -19,6 +20,8 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
@OneToOne
private User activeValidator;
private Timestamp validationDateTime;
@OneToMany(mappedBy = "publisher")
private Set<PublisherRevision> revisions;
......@@ -53,4 +56,17 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
public void setActiveValidator(User activeValidator) {
this.activeValidator = activeValidator;
}
public Timestamp getValidationDateTime() {
return validationDateTime;
}
public void setValidationDateTime(Timestamp validationDateTime) {
this.validationDateTime = validationDateTime;
}
@Override
public String toString() {
return "PUBLISHER_ID = " + publisherId + ", Active Revision = " + activeRevision + ", Validator = " + activeValidator + ", Validation DateTime = " + validationDateTime;
}
}
......
......@@ -147,4 +147,14 @@ public class PublisherRevision {
public void setPublisherRevisionAuthor(User publisherRevisionAuthor) {
this.publisherRevisionAuthor = publisherRevisionAuthor;
}
@Override
public String toString() {
return "PUBLISHER_REVISION_ID = " + publisherRevisionId + ", 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;
}
}
\ No newline at end of file
......
package org.legrog.presentation;
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.sql.Timestamp;
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;
private String publisherName;
private String publisherStreetAddress;
......@@ -35,6 +46,37 @@ public class AddPublisherBean {
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);
// TODO Remplacer Timestamp de date horloge interne par celui de date locale
publisherRevision.setPublisherRevisionDatetime(new Timestamp(System.currentTimeMillis()));
// 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());
return "success";
}
......