Jean-Francois Leveque

Refactoring de UserAction en ActionType (pas compris comment j'ai un rename et u…

…n delete/add entre classe et son repository).
......@@ -9,10 +9,10 @@ import javax.persistence.Id;
* Classe des actions possibles.
*/
@Entity
public class UserAction {
public class ActionType {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int userActionId;
private int actionTypeId;
private String userActionName;
private String actionTypeName;
}
\ No newline at end of file
......
......@@ -2,6 +2,6 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserActionRepository extends JpaRepository<UserAction, Integer> {
UserAction findByUserActionName(String userActionName);
public interface ActionTypeRepository extends JpaRepository<ActionType, Integer> {
ActionType findByActionTypeName(String actionTypeName);
}
......
......@@ -13,7 +13,7 @@ public class PublisherAction {
private int publisherActionId;
@ManyToOne
private UserAction userAction;
private ActionType actionType;
@ManyToOne
private Person publisherActionAuthor;
@ManyToOne
......@@ -33,8 +33,8 @@ public class PublisherAction {
this.publisherActionDatetime = publisherActionDatetime;
}
public void setUserAction(UserAction userAction) {
this.userAction = userAction;
public void setActionType(ActionType actionType) {
this.actionType = actionType;
}
public void setPublisherVersion(PublisherVersion publisherVersion) {
......@@ -45,8 +45,8 @@ public class PublisherAction {
this.publisher = publisher;
}
public UserAction getUserAction() {
return userAction;
public ActionType getActionType() {
return actionType;
}
public Person getPublisherActionAuthor() {
......@@ -67,7 +67,7 @@ public class PublisherAction {
@Override
public String toString() {
return "publisherActionId = " + publisherActionId + ", userAction = " + userAction +
return "publisherActionId = " + publisherActionId + ", actionType = " + actionType +
", publisherActionAuthor = " + publisherActionAuthor + ", publisherVersion = " + publisherVersion +
", publisherActionDatetime = " + publisherActionDatetime + ", publisher = " + publisher;
}
......
......@@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> {
@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)")
@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)")
PublisherAction publisherLastValidate(Publisher publisher);
}
......
......@@ -25,19 +25,19 @@ public class PublisherServiceSpring implements PublisherService {
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
PublisherActionRepository publisherActionRepository;
UserActionRepository userActionRepository;
ActionTypeRepository actionTypeRepository;
SharedService sharedService;
@Inject
public PublisherServiceSpring(PublisherRepository publisherRepository,
PublisherVersionRepository publisherVersionRepository,
PublisherActionRepository publisherActionRepository,
UserActionRepository userActionRepository,
ActionTypeRepository actionTypeRepository,
SharedService sharedService) {
this.publisherRepository = publisherRepository;
this.publisherVersionRepository = publisherVersionRepository;
this.publisherActionRepository = publisherActionRepository;
this.userActionRepository = userActionRepository;
this.actionTypeRepository = actionTypeRepository;
this.sharedService = sharedService;
}
......@@ -78,7 +78,7 @@ public class PublisherServiceSpring implements PublisherService {
PublisherAction publisherAction = new PublisherAction();
publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser());
publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime()));
publisherAction.setUserAction(userActionRepository.findByUserActionName("Validate"));
publisherAction.setActionType(actionTypeRepository.findByActionTypeName("Validate"));
publisherAction.setPublisherVersion(publisherVersion);
publisherAction.setPublisher(publisher);
this.savePublisher(publisher);
......
-- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21)
INSERT INTO UserAction (userActionId, userActionName) VALUES (1, 'Validate');
INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
INSERT INTO Country (countryId, countryName) VALUES
(1, 'France'),
(2, 'Suisse'),
......@@ -38,7 +38,7 @@ UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId =
UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2;
UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3;
INSERT INTO PublisherAction (publisherActionId, userAction_userActionId, publisherActionAuthor_userId,
INSERT INTO PublisherAction (publisherActionId, actionType_actionTypeId, publisherActionAuthor_userId,
publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES
(1, 1, 2, 1, {ts '2000-05-08 12:00:28'}, 1),
(2, 1, 1, 2, {ts '2010-06-20 14:27:35'}, 2),
......
......@@ -33,10 +33,10 @@ public class PublisherServiceSpringTest {
public void setUp(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository,
@Mock PublisherActionRepository publisherActionRepository,
@Mock UserActionRepository userActionRepository,
@Mock ActionTypeRepository actionTypeRepository,
@Mock SharedService sharedService) throws Exception {
publisherServiceSpring = new PublisherServiceSpring(publisherRepository,
publisherVersionRepository, publisherActionRepository, userActionRepository, sharedService);
publisherVersionRepository, publisherActionRepository, actionTypeRepository, sharedService);
publisherVersion = new PublisherVersion();
publisherVersion1 = new PublisherVersion();
this.publisherRepository = publisherRepository;
......