Jean-Francois Leveque

Changement d'implémentation, d'ActionType.

1 package org.legrog.entities; 1 package org.legrog.entities;
2 2
3 -import javax.persistence.Entity;
4 -import javax.persistence.GeneratedValue;
5 -import javax.persistence.GenerationType;
6 -import javax.persistence.Id;
7 -
8 /** 3 /**
9 - * Classe des actions possibles. 4 + * Énumération des actions possibles.
10 */ 5 */
11 -@Entity 6 +public enum ActionType {
12 -public class ActionType { 7 + VALIDATE;
13 - @Id
14 - @GeneratedValue(strategy = GenerationType.AUTO)
15 - private int actionTypeId;
16 -
17 - private String actionTypeName;
18 -
19 - public String getActionTypeName() {
20 - return actionTypeName;
21 - }
22 } 8 }
...\ No newline at end of file ...\ No newline at end of file
......
1 -package org.legrog.entities;
2 -
3 -import org.springframework.data.jpa.repository.JpaRepository;
4 -
5 -public interface ActionTypeRepository extends JpaRepository<ActionType, Integer> {
6 - ActionType findByActionTypeName(String actionTypeName);
7 -}
...@@ -12,7 +12,7 @@ public class PublisherAction { ...@@ -12,7 +12,7 @@ public class PublisherAction {
12 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @GeneratedValue(strategy = GenerationType.IDENTITY)
13 private int publisherActionId; 13 private int publisherActionId;
14 14
15 - @ManyToOne 15 + @Enumerated
16 private ActionType actionType; 16 private ActionType actionType;
17 @ManyToOne 17 @ManyToOne
18 private Person publisherActionAuthor; 18 private Person publisherActionAuthor;
......
...@@ -3,7 +3,11 @@ package org.legrog.entities; ...@@ -3,7 +3,11 @@ package org.legrog.entities;
3 import org.springframework.data.jpa.repository.JpaRepository; 3 import org.springframework.data.jpa.repository.JpaRepository;
4 import org.springframework.data.jpa.repository.Query; 4 import org.springframework.data.jpa.repository.Query;
5 5
6 +import java.util.List;
7 +
6 public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> { 8 public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> {
7 - @Query("select pa from PublisherAction pa where pa.actionType = (select ua from ActionType ua where ua.actionTypeName = 'Validate') and pa.publisherActionDatetime = ( select max(pa2.publisherActionDatetime) from PublisherAction pa2 where pa2.publisher =?1)") 9 +
8 - PublisherAction publisherLastValidate(Publisher publisher); 10 + PublisherAction findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType actionType, Publisher publisher);
11 +
12 + List<PublisherAction> findByPublisherVersion(PublisherVersion publisherVersion);
9 } 13 }
......
...@@ -25,19 +25,16 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -25,19 +25,16 @@ public class PublisherServiceSpring implements PublisherService {
25 PublisherRepository publisherRepository; 25 PublisherRepository publisherRepository;
26 PublisherVersionRepository publisherVersionRepository; 26 PublisherVersionRepository publisherVersionRepository;
27 PublisherActionRepository publisherActionRepository; 27 PublisherActionRepository publisherActionRepository;
28 - ActionTypeRepository actionTypeRepository;
29 SharedService sharedService; 28 SharedService sharedService;
30 29
31 @Inject 30 @Inject
32 public PublisherServiceSpring(PublisherRepository publisherRepository, 31 public PublisherServiceSpring(PublisherRepository publisherRepository,
33 PublisherVersionRepository publisherVersionRepository, 32 PublisherVersionRepository publisherVersionRepository,
34 PublisherActionRepository publisherActionRepository, 33 PublisherActionRepository publisherActionRepository,
35 - ActionTypeRepository actionTypeRepository,
36 SharedService sharedService) { 34 SharedService sharedService) {
37 this.publisherRepository = publisherRepository; 35 this.publisherRepository = publisherRepository;
38 this.publisherVersionRepository = publisherVersionRepository; 36 this.publisherVersionRepository = publisherVersionRepository;
39 this.publisherActionRepository = publisherActionRepository; 37 this.publisherActionRepository = publisherActionRepository;
40 - this.actionTypeRepository = actionTypeRepository;
41 this.sharedService = sharedService; 38 this.sharedService = sharedService;
42 } 39 }
43 40
...@@ -78,7 +75,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -78,7 +75,7 @@ public class PublisherServiceSpring implements PublisherService {
78 PublisherAction publisherAction = new PublisherAction(); 75 PublisherAction publisherAction = new PublisherAction();
79 publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser()); 76 publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser());
80 publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime())); 77 publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime()));
81 - publisherAction.setActionType(actionTypeRepository.findByActionTypeName("Validate")); 78 + publisherAction.setActionType(ActionType.VALIDATE);
82 publisherAction.setPublisherVersion(publisherVersion); 79 publisherAction.setPublisherVersion(publisherVersion);
83 publisherAction.setPublisher(publisher); 80 publisherAction.setPublisher(publisher);
84 this.savePublisher(publisher); 81 this.savePublisher(publisher);
...@@ -104,11 +101,15 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -104,11 +101,15 @@ public class PublisherServiceSpring implements PublisherService {
104 } 101 }
105 102
106 public PublisherAction getLastValidate(Publisher publisher) { 103 public PublisherAction getLastValidate(Publisher publisher) {
107 - return publisherActionRepository.publisherLastValidate(publisher); 104 + return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType.VALIDATE, publisher);
108 } 105 }
109 106
110 public List<PublisherAction> getAllPublisherActions() { 107 public List<PublisherAction> getAllPublisherActions() {
111 return publisherActionRepository.findAll(); 108 return publisherActionRepository.findAll();
112 } 109 }
113 110
111 + public List<PublisherAction> getAllPublisherVersionActions(PublisherVersion publisherVersion) {
112 + return publisherActionRepository.findByPublisherVersion(publisherVersion);
113 + }
114 +
114 } 115 }
......
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
29 29
30 <h:dataTable value="#{listPublisherActionsView.publisherActions}" var="action"> 30 <h:dataTable value="#{listPublisherActionsView.publisherActions}" var="action">
31 <h:column> 31 <h:column>
32 - <f:facet name="header">Action</f:facet> 32 + <f:facet name="header"/>
33 - ${action.actionType.actionTypeName} 33 + ${action.actionType.name()}
34 </h:column> 34 </h:column>
35 <h:column> 35 <h:column>
36 - <f:facet name="header">Author</f:facet> 36 + <f:facet name="header"/>
37 ${action.publisherActionAuthor.displayName} 37 ${action.publisherActionAuthor.displayName}
38 </h:column> 38 </h:column>
39 <h:column> 39 <h:column>
40 - <f:facet name="header">Action Datetime</f:facet> 40 + <f:facet name="header"/>
41 ${action.publisherActionDatetime} 41 ${action.publisherActionDatetime}
42 </h:column> 42 </h:column>
43 <h:column> 43 <h:column>
......
1 -- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21) 1 -- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21)
2 -INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate'); 2 +//INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
3 INSERT INTO Country (countryId, countryName) VALUES 3 INSERT INTO Country (countryId, countryName) VALUES
4 (1, 'France'), 4 (1, 'France'),
5 (2, 'Suisse'), 5 (2, 'Suisse'),
...@@ -38,11 +38,11 @@ UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId = ...@@ -38,11 +38,11 @@ UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId =
38 UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2; 38 UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2;
39 UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3; 39 UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3;
40 40
41 -INSERT INTO PublisherAction (publisherActionId, actionType_actionTypeId, publisherActionAuthor_userId, 41 +INSERT INTO PublisherAction (publisherActionId, actionType, publisherActionAuthor_userId,
42 publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES 42 publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES
43 - (1, 1, 2, 1, {ts '2000-05-08 12:00:28'}, 1), 43 + (1, 0, 2, 1, {ts '2000-05-08 12:00:28'}, 1),
44 - (2, 1, 1, 2, {ts '2010-06-20 14:27:35'}, 2), 44 + (2, 0, 1, 2, {ts '2010-06-20 14:27:35'}, 2),
45 - (3, 1, 1, 4, {ts '2015-01-01 16:18:17'}, 3); 45 + (3, 0, 1, 4, {ts '2015-01-01 16:18:17'}, 3);
46 46
47 INSERT INTO UserRole (userRoleId, rolename, visible) VALUES 47 INSERT INTO UserRole (userRoleId, rolename, visible) VALUES
48 (1, 'VISITEUR', TRUE), 48 (1, 'VISITEUR', TRUE),
......
...@@ -35,9 +35,6 @@ public class PublisherServiceSpringTest { ...@@ -35,9 +35,6 @@ public class PublisherServiceSpringTest {
35 PublisherRepository publisherRepository; 35 PublisherRepository publisherRepository;
36 PublisherVersionRepository publisherVersionRepository; 36 PublisherVersionRepository publisherVersionRepository;
37 37
38 - @Inject
39 - ActionTypeRepository actionTypeRepository;
40 -
41 @Mock 38 @Mock
42 PublisherVersion publisherVersionMock; 39 PublisherVersion publisherVersionMock;
43 40
...@@ -45,10 +42,9 @@ public class PublisherServiceSpringTest { ...@@ -45,10 +42,9 @@ public class PublisherServiceSpringTest {
45 public void setUp(@Mock PublisherRepository publisherRepository, 42 public void setUp(@Mock PublisherRepository publisherRepository,
46 @Mock PublisherVersionRepository publisherVersionRepository, 43 @Mock PublisherVersionRepository publisherVersionRepository,
47 @Mock PublisherActionRepository publisherActionRepository, 44 @Mock PublisherActionRepository publisherActionRepository,
48 - @Mock ActionTypeRepository actionTypeRepository,
49 @Mock SharedService sharedService) throws Exception { 45 @Mock SharedService sharedService) throws Exception {
50 publisherServiceSpring = new PublisherServiceSpring(publisherRepository, 46 publisherServiceSpring = new PublisherServiceSpring(publisherRepository,
51 - publisherVersionRepository, publisherActionRepository, actionTypeRepository, sharedService); 47 + publisherVersionRepository, publisherActionRepository, sharedService);
52 publisherVersion = new PublisherVersion(); 48 publisherVersion = new PublisherVersion();
53 publisherVersion1 = new PublisherVersion(); 49 publisherVersion1 = new PublisherVersion();
54 this.publisherRepository = publisherRepository; 50 this.publisherRepository = publisherRepository;
...@@ -80,10 +76,9 @@ public class PublisherServiceSpringTest { ...@@ -80,10 +76,9 @@ public class PublisherServiceSpringTest {
80 76
81 @DisplayName("Test validation version éditeur") 77 @DisplayName("Test validation version éditeur")
82 @Test 78 @Test
83 - public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository, 79 + public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository) {
84 - @Mock ActionTypeRepository actionTypeRepository) {
85 Set<PublisherVersion> publisherVersions; 80 Set<PublisherVersion> publisherVersions;
86 - ActionType actionType = new ActionType(); 81 + ActionType actionType = ActionType.VALIDATE;
87 82
88 publisher = new Publisher(); 83 publisher = new Publisher();
89 publisherVersion = new PublisherVersion(); 84 publisherVersion = new PublisherVersion();
...@@ -94,7 +89,6 @@ public class PublisherServiceSpringTest { ...@@ -94,7 +89,6 @@ public class PublisherServiceSpringTest {
94 publisherVersions.add(publisherVersionMock); 89 publisherVersions.add(publisherVersionMock);
95 90
96 when(publisherVersionMock.getPublisher()).thenReturn(publisher); 91 when(publisherVersionMock.getPublisher()).thenReturn(publisher);
97 - when(actionTypeRepository.findByActionTypeName("Validate")).thenReturn(actionType);
98 PublisherAction publisherAction; 92 PublisherAction publisherAction;
99 publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock); 93 publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
100 verify(publisherActionRepository).save(publisherAction); 94 verify(publisherActionRepository).save(publisherAction);
......