Jean-Francois Leveque

Changement d'implémentation, d'ActionType.

package org.legrog.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* Classe des actions possibles.
* Énumération des actions possibles.
*/
@Entity
public class ActionType {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int actionTypeId;
private String actionTypeName;
public String getActionTypeName() {
return actionTypeName;
}
public enum ActionType {
VALIDATE;
}
\ No newline at end of file
......
package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActionTypeRepository extends JpaRepository<ActionType, Integer> {
ActionType findByActionTypeName(String actionTypeName);
}
......@@ -12,7 +12,7 @@ public class PublisherAction {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int publisherActionId;
@ManyToOne
@Enumerated
private ActionType actionType;
@ManyToOne
private Person publisherActionAuthor;
......
......@@ -3,7 +3,11 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface PublisherActionRepository extends JpaRepository<PublisherAction, Integer> {
@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);
PublisherAction findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType actionType, Publisher publisher);
List<PublisherAction> findByPublisherVersion(PublisherVersion publisherVersion);
}
......
......@@ -25,19 +25,16 @@ public class PublisherServiceSpring implements PublisherService {
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
PublisherActionRepository publisherActionRepository;
ActionTypeRepository actionTypeRepository;
SharedService sharedService;
@Inject
public PublisherServiceSpring(PublisherRepository publisherRepository,
PublisherVersionRepository publisherVersionRepository,
PublisherActionRepository publisherActionRepository,
ActionTypeRepository actionTypeRepository,
SharedService sharedService) {
this.publisherRepository = publisherRepository;
this.publisherVersionRepository = publisherVersionRepository;
this.publisherActionRepository = publisherActionRepository;
this.actionTypeRepository = actionTypeRepository;
this.sharedService = sharedService;
}
......@@ -78,7 +75,7 @@ public class PublisherServiceSpring implements PublisherService {
PublisherAction publisherAction = new PublisherAction();
publisherAction.setPublisherActionAuthor(sharedService.getCurrentUser());
publisherAction.setPublisherActionDatetime(new Timestamp(new Date().getTime()));
publisherAction.setActionType(actionTypeRepository.findByActionTypeName("Validate"));
publisherAction.setActionType(ActionType.VALIDATE);
publisherAction.setPublisherVersion(publisherVersion);
publisherAction.setPublisher(publisher);
this.savePublisher(publisher);
......@@ -104,11 +101,15 @@ public class PublisherServiceSpring implements PublisherService {
}
public PublisherAction getLastValidate(Publisher publisher) {
return publisherActionRepository.publisherLastValidate(publisher);
return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType.VALIDATE, publisher);
}
public List<PublisherAction> getAllPublisherActions() {
return publisherActionRepository.findAll();
}
public List<PublisherAction> getAllPublisherVersionActions(PublisherVersion publisherVersion) {
return publisherActionRepository.findByPublisherVersion(publisherVersion);
}
}
......
......@@ -29,15 +29,15 @@
<h:dataTable value="#{listPublisherActionsView.publisherActions}" var="action">
<h:column>
<f:facet name="header">Action</f:facet>
${action.actionType.actionTypeName}
<f:facet name="header"/>
${action.actionType.name()}
</h:column>
<h:column>
<f:facet name="header">Author</f:facet>
<f:facet name="header"/>
${action.publisherActionAuthor.displayName}
</h:column>
<h:column>
<f:facet name="header">Action Datetime</f:facet>
<f:facet name="header"/>
${action.publisherActionDatetime}
</h:column>
<h:column>
......
-- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21)
INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
//INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
INSERT INTO Country (countryId, countryName) VALUES
(1, 'France'),
(2, 'Suisse'),
......@@ -38,11 +38,11 @@ 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, actionType_actionTypeId, publisherActionAuthor_userId,
INSERT INTO PublisherAction (publisherActionId, actionType, 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),
(3, 1, 1, 4, {ts '2015-01-01 16:18:17'}, 3);
(1, 0, 2, 1, {ts '2000-05-08 12:00:28'}, 1),
(2, 0, 1, 2, {ts '2010-06-20 14:27:35'}, 2),
(3, 0, 1, 4, {ts '2015-01-01 16:18:17'}, 3);
INSERT INTO UserRole (userRoleId, rolename, visible) VALUES
(1, 'VISITEUR', TRUE),
......
......@@ -35,9 +35,6 @@ public class PublisherServiceSpringTest {
PublisherRepository publisherRepository;
PublisherVersionRepository publisherVersionRepository;
@Inject
ActionTypeRepository actionTypeRepository;
@Mock
PublisherVersion publisherVersionMock;
......@@ -45,10 +42,9 @@ public class PublisherServiceSpringTest {
public void setUp(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository,
@Mock PublisherActionRepository publisherActionRepository,
@Mock ActionTypeRepository actionTypeRepository,
@Mock SharedService sharedService) throws Exception {
publisherServiceSpring = new PublisherServiceSpring(publisherRepository,
publisherVersionRepository, publisherActionRepository, actionTypeRepository, sharedService);
publisherVersionRepository, publisherActionRepository, sharedService);
publisherVersion = new PublisherVersion();
publisherVersion1 = new PublisherVersion();
this.publisherRepository = publisherRepository;
......@@ -80,10 +76,9 @@ public class PublisherServiceSpringTest {
@DisplayName("Test validation version éditeur")
@Test
public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository,
@Mock ActionTypeRepository actionTypeRepository) {
public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository) {
Set<PublisherVersion> publisherVersions;
ActionType actionType = new ActionType();
ActionType actionType = ActionType.VALIDATE;
publisher = new Publisher();
publisherVersion = new PublisherVersion();
......@@ -94,7 +89,6 @@ public class PublisherServiceSpringTest {
publisherVersions.add(publisherVersionMock);
when(publisherVersionMock.getPublisher()).thenReturn(publisher);
when(actionTypeRepository.findByActionTypeName("Validate")).thenReturn(actionType);
PublisherAction publisherAction;
publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
verify(publisherActionRepository).save(publisherAction);
......