PublisherServiceSpring.java
3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.legrog.web.publisher;
import org.legrog.entities.*;
import org.legrog.web.xyz.SharedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
/*
Implémentation de l'interface PublisherService
*/
@Stateless
public class PublisherServiceSpring implements PublisherService {
Logger logger = LoggerFactory.getLogger(getClass());
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
PublisherActionRepository publisherActionRepository;
SharedService sharedService;
@Inject
public PublisherServiceSpring(PublisherRepository publisherRepository,
PublisherVersionRepository publisherVersionRepository,
PublisherActionRepository publisherActionRepository,
SharedService sharedService) {
this.publisherRepository = publisherRepository;
this.publisherVersionRepository = publisherVersionRepository;
this.publisherActionRepository = publisherActionRepository;
this.sharedService = sharedService;
}
//no args constructor to make it proxyable
PublisherServiceSpring() {
}
public PublisherVersion addNewPublisher(PublisherVersion publisherVersion) {
Publisher publisher = new Publisher();
Set<PublisherVersion> publisherVersions = new HashSet<>();
publisherVersions.add(publisherVersion);
publisher.setVersions(publisherVersions);
publisherVersion.setPublisher(publisher);
publisherVersion.setPublisherVersionAuthor(sharedService.getCurrentUser());
publisherVersion.setPublisherVersionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherVersion(publisherVersion);
this.savePublisher(publisher);
return publisherVersion;
}
public void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) {
logger.trace("debut addVersionToPublisher, publisherVersion = {}", publisherVersion);
Set<PublisherVersion> publisherVersionSet = publisher.getVersions();
publisherVersionSet.add(publisherVersion);
publisher.setVersions(publisherVersionSet);
publisherVersion.setPublisher(publisher);
publisherVersion.setPublisherVersionAuthor(sharedService.getCurrentUser());
publisherVersion.setPublisherVersionDatetime(new Timestamp(new Date().getTime()));
this.savePublisherVersion(publisherVersion);
this.savePublisher(publisher);
logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
}
public void validatePublisherVersion(PublisherVersion publisherVersion) {
Publisher publisher = publisherVersion.getPublisher();
publisher.setValidatedVersion(publisherVersion);
PublisherAction publisherAction = new PublisherAction();
publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser());
publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime()));
this.savePublisher(publisher);
publisherActionRepository.save(publisherAction);
}
protected void savePublisherVersion(PublisherVersion publisherVersion) {
publisherVersionRepository.save(publisherVersion);
}
protected void savePublisher(Publisher publisher) {
publisherRepository.save(publisher);
}
// get
public List<PublisherVersion> getAllPublisherVersions() {
return publisherVersionRepository.findAll();
}
public PublisherVersion getPublisherVersion(Integer publisherVersionId) {
return publisherVersionRepository.findOne(publisherVersionId);
}
}