Refactoring de UserAction en ActionType (pas compris comment j'ai un rename et u…
…n delete/add entre classe et son repository).
Showing
7 changed files
with
20 additions
and
20 deletions
... | @@ -9,10 +9,10 @@ import javax.persistence.Id; | ... | @@ -9,10 +9,10 @@ import javax.persistence.Id; |
9 | * Classe des actions possibles. | 9 | * Classe des actions possibles. |
10 | */ | 10 | */ |
11 | @Entity | 11 | @Entity |
12 | -public class UserAction { | 12 | +public class ActionType { |
13 | @Id | 13 | @Id |
14 | @GeneratedValue(strategy = GenerationType.AUTO) | 14 | @GeneratedValue(strategy = GenerationType.AUTO) |
15 | - private int userActionId; | 15 | + private int actionTypeId; |
16 | 16 | ||
17 | - private String userActionName; | 17 | + private String actionTypeName; |
18 | } | 18 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,6 +2,6 @@ package org.legrog.entities; | ... | @@ -2,6 +2,6 @@ package org.legrog.entities; |
2 | 2 | ||
3 | import org.springframework.data.jpa.repository.JpaRepository; | 3 | import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 | ||
5 | -public interface UserActionRepository extends JpaRepository<UserAction, Integer> { | 5 | +public interface ActionTypeRepository extends JpaRepository<ActionType, Integer> { |
6 | - UserAction findByUserActionName(String userActionName); | 6 | + ActionType findByActionTypeName(String actionTypeName); |
7 | } | 7 | } | ... | ... |
... | @@ -13,7 +13,7 @@ public class PublisherAction { | ... | @@ -13,7 +13,7 @@ public class PublisherAction { |
13 | private int publisherActionId; | 13 | private int publisherActionId; |
14 | 14 | ||
15 | @ManyToOne | 15 | @ManyToOne |
16 | - private UserAction userAction; | 16 | + private ActionType actionType; |
17 | @ManyToOne | 17 | @ManyToOne |
18 | private Person publisherActionAuthor; | 18 | private Person publisherActionAuthor; |
19 | @ManyToOne | 19 | @ManyToOne |
... | @@ -33,8 +33,8 @@ public class PublisherAction { | ... | @@ -33,8 +33,8 @@ public class PublisherAction { |
33 | this.publisherActionDatetime = publisherActionDatetime; | 33 | this.publisherActionDatetime = publisherActionDatetime; |
34 | } | 34 | } |
35 | 35 | ||
36 | - public void setUserAction(UserAction userAction) { | 36 | + public void setActionType(ActionType actionType) { |
37 | - this.userAction = userAction; | 37 | + this.actionType = actionType; |
38 | } | 38 | } |
39 | 39 | ||
40 | public void setPublisherVersion(PublisherVersion publisherVersion) { | 40 | public void setPublisherVersion(PublisherVersion publisherVersion) { |
... | @@ -45,8 +45,8 @@ public class PublisherAction { | ... | @@ -45,8 +45,8 @@ public class PublisherAction { |
45 | this.publisher = publisher; | 45 | this.publisher = publisher; |
46 | } | 46 | } |
47 | 47 | ||
48 | - public UserAction getUserAction() { | 48 | + public ActionType getActionType() { |
49 | - return userAction; | 49 | + return actionType; |
50 | } | 50 | } |
51 | 51 | ||
52 | public Person getPublisherActionAuthor() { | 52 | public Person getPublisherActionAuthor() { |
... | @@ -67,7 +67,7 @@ public class PublisherAction { | ... | @@ -67,7 +67,7 @@ public class PublisherAction { |
67 | 67 | ||
68 | @Override | 68 | @Override |
69 | public String toString() { | 69 | public String toString() { |
70 | - return "publisherActionId = " + publisherActionId + ", userAction = " + userAction + | 70 | + return "publisherActionId = " + publisherActionId + ", actionType = " + actionType + |
71 | ", publisherActionAuthor = " + publisherActionAuthor + ", publisherVersion = " + publisherVersion + | 71 | ", publisherActionAuthor = " + publisherActionAuthor + ", publisherVersion = " + publisherVersion + |
72 | ", publisherActionDatetime = " + publisherActionDatetime + ", publisher = " + publisher; | 72 | ", publisherActionDatetime = " + publisherActionDatetime + ", publisher = " + publisher; |
73 | } | 73 | } | ... | ... |
... | @@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; | ... | @@ -4,6 +4,6 @@ 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 | public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> { | 6 | public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> { |
7 | - @Query("select pa from PublisherAction pa where pa.userAction = (select ua from UserAction ua where ua.userActionName = 'Validate') and pa.publisherActionDatetime = ( select max(pa2.publisherActionDatetime) from PublisherAction pa2 where pa2.publisher =?1)") | 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)") |
8 | PublisherAction publisherLastValidate(Publisher publisher); | 8 | PublisherAction publisherLastValidate(Publisher publisher); |
9 | } | 9 | } | ... | ... |
... | @@ -25,19 +25,19 @@ public class PublisherServiceSpring implements PublisherService { | ... | @@ -25,19 +25,19 @@ public class PublisherServiceSpring implements PublisherService { |
25 | PublisherRepository publisherRepository; | 25 | PublisherRepository publisherRepository; |
26 | PublisherVersionRepository publisherVersionRepository; | 26 | PublisherVersionRepository publisherVersionRepository; |
27 | PublisherActionRepository publisherActionRepository; | 27 | PublisherActionRepository publisherActionRepository; |
28 | - UserActionRepository userActionRepository; | 28 | + ActionTypeRepository actionTypeRepository; |
29 | SharedService sharedService; | 29 | SharedService sharedService; |
30 | 30 | ||
31 | @Inject | 31 | @Inject |
32 | public PublisherServiceSpring(PublisherRepository publisherRepository, | 32 | public PublisherServiceSpring(PublisherRepository publisherRepository, |
33 | PublisherVersionRepository publisherVersionRepository, | 33 | PublisherVersionRepository publisherVersionRepository, |
34 | PublisherActionRepository publisherActionRepository, | 34 | PublisherActionRepository publisherActionRepository, |
35 | - UserActionRepository userActionRepository, | 35 | + ActionTypeRepository actionTypeRepository, |
36 | SharedService sharedService) { | 36 | SharedService sharedService) { |
37 | this.publisherRepository = publisherRepository; | 37 | this.publisherRepository = publisherRepository; |
38 | this.publisherVersionRepository = publisherVersionRepository; | 38 | this.publisherVersionRepository = publisherVersionRepository; |
39 | this.publisherActionRepository = publisherActionRepository; | 39 | this.publisherActionRepository = publisherActionRepository; |
40 | - this.userActionRepository = userActionRepository; | 40 | + this.actionTypeRepository = actionTypeRepository; |
41 | this.sharedService = sharedService; | 41 | this.sharedService = sharedService; |
42 | } | 42 | } |
43 | 43 | ||
... | @@ -78,7 +78,7 @@ public class PublisherServiceSpring implements PublisherService { | ... | @@ -78,7 +78,7 @@ public class PublisherServiceSpring implements PublisherService { |
78 | PublisherAction publisherAction = new PublisherAction(); | 78 | PublisherAction publisherAction = new PublisherAction(); |
79 | publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser()); | 79 | publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser()); |
80 | publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime())); | 80 | publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime())); |
81 | - publisherAction.setUserAction(userActionRepository.findByUserActionName("Validate")); | 81 | + publisherAction.setActionType(actionTypeRepository.findByActionTypeName("Validate")); |
82 | publisherAction.setPublisherVersion(publisherVersion); | 82 | publisherAction.setPublisherVersion(publisherVersion); |
83 | publisherAction.setPublisher(publisher); | 83 | publisherAction.setPublisher(publisher); |
84 | this.savePublisher(publisher); | 84 | this.savePublisher(publisher); | ... | ... |
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 UserAction (userActionId, userActionName) 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,7 +38,7 @@ UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId = | ... | @@ -38,7 +38,7 @@ 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, userAction_userActionId, publisherActionAuthor_userId, | 41 | +INSERT INTO PublisherAction (publisherActionId, actionType_actionTypeId, 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, 1, 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, 1, 1, 2, {ts '2010-06-20 14:27:35'}, 2), | ... | ... |
... | @@ -33,10 +33,10 @@ public class PublisherServiceSpringTest { | ... | @@ -33,10 +33,10 @@ public class PublisherServiceSpringTest { |
33 | public void setUp(@Mock PublisherRepository publisherRepository, | 33 | public void setUp(@Mock PublisherRepository publisherRepository, |
34 | @Mock PublisherVersionRepository publisherVersionRepository, | 34 | @Mock PublisherVersionRepository publisherVersionRepository, |
35 | @Mock PublisherActionRepository publisherActionRepository, | 35 | @Mock PublisherActionRepository publisherActionRepository, |
36 | - @Mock UserActionRepository userActionRepository, | 36 | + @Mock ActionTypeRepository actionTypeRepository, |
37 | @Mock SharedService sharedService) throws Exception { | 37 | @Mock SharedService sharedService) throws Exception { |
38 | publisherServiceSpring = new PublisherServiceSpring(publisherRepository, | 38 | publisherServiceSpring = new PublisherServiceSpring(publisherRepository, |
39 | - publisherVersionRepository, publisherActionRepository, userActionRepository, sharedService); | 39 | + publisherVersionRepository, publisherActionRepository, actionTypeRepository, sharedService); |
40 | publisherVersion = new PublisherVersion(); | 40 | publisherVersion = new PublisherVersion(); |
41 | publisherVersion1 = new PublisherVersion(); | 41 | publisherVersion1 = new PublisherVersion(); |
42 | this.publisherRepository = publisherRepository; | 42 | this.publisherRepository = publisherRepository; | ... | ... |
-
Please register or login to post a comment