Migration of Action History to vaadin grid (#420)

* Migration of Action History to vaadin Grid
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Marcel Mager
2017-03-24 14:03:39 +01:00
committed by Kai Zimmermann
parent 081c3cccbf
commit c8db41ff85
65 changed files with 4713 additions and 1585 deletions

View File

@@ -62,7 +62,7 @@ public interface DeploymentManagement {
* @throws IncompleteDistributionSetException
* if mandatory {@link SoftwareModuleType} are not assigned as
* define by the {@link DistributionSetType}.
*
*
* @throws EntityNotFoundException
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
@@ -84,7 +84,7 @@ public interface DeploymentManagement {
* @throws IncompleteDistributionSetException
* if mandatory {@link SoftwareModuleType} are not assigned as
* define by the {@link DistributionSetType}.
*
*
* @throws EntityNotFoundException
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
@@ -108,7 +108,7 @@ public interface DeploymentManagement {
* @throws IncompleteDistributionSetException
* if mandatory {@link SoftwareModuleType} are not assigned as
* define by the {@link DistributionSetType}.
*
*
* @throws EntityNotFoundException
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
@@ -145,7 +145,7 @@ public interface DeploymentManagement {
* @param controllerId
* the target associated to the actions to count
* @return the count value of found actions associated to the target
*
*
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
@@ -290,6 +290,19 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<ActionStatus> findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Long actionId);
/**
* Retrieves all messages for an {@link ActionStatus}.
*
*
* @param pageable
* the page request parameter for paging and sorting the result
* @param actionStatusId
* the id of {@link ActionStatus} to retrieve the messages from
* @return a page of messages by a specific {@link ActionStatus} id
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<String> findMessagesByActionStatusId(@NotNull Pageable pageable, @NotNull Long actionStatusId);
/**
* Retrieves all {@link Action}s of a specific target ordered by action ID.
*
@@ -297,7 +310,7 @@ public interface DeploymentManagement {
* the target associated with the actions
* @return a list of actions associated with the given target ordered by
* action ID
*
*
* @throws EntityNotFoundException
* if target with given ID does not exist
*/
@@ -392,7 +405,7 @@ public interface DeploymentManagement {
/**
* All {@link ActionStatus} entries in the repository.
*
*
* @param pageable
* the pagination parameter
* @return {@link Page} of {@link ActionStatus} entries

View File

@@ -78,6 +78,17 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
*/
Slice<Action> findByTargetControllerId(Pageable pageable, String controllerId);
/**
* Retrieves all {@link Action}s which are referring the given targetId
*
* @param pageable
* page parameters
* @param targetId
* the target to find assigned actions for
* @return the found {@link Action}s
*/
Page<Action> findByTargetId(Pageable pageable, Long targetId);
/**
* Retrieves all {@link Action}s which are active and referring to the given
* {@link Target} order by ID ascending.
@@ -93,14 +104,14 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
/**
* Retrieves the oldest {@link Action} that is active and referring to the
* given {@link Target}.
*
*
* @param sort
* order
* @param controllerId
* the target to find assigned actions
* @param active
* the action active flag
*
*
* @return the found {@link Action}
*/
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
@@ -209,6 +220,15 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
*/
Long countByTargetControllerId(String controllerId);
/**
* Counts all {@link Action}s referring to the given targetId.
*
* @param targetId
* the target to count the {@link Action}s
* @return the count of actions referring to the given target
*/
Long countByTargetId(Long targetId);
/**
* Counts all {@link Action}s referring to the given DistributionSet.
*

View File

@@ -40,8 +40,8 @@ public interface ActionStatusRepository
/**
* Retrieves all {@link ActionStatus} entries from repository of given
* {@link Action}.
*
* ActionId.
*
* @param pageReq
* parameters
* @param actionId
@@ -64,5 +64,4 @@ public interface ActionStatusRepository
*/
@EntityGraph(value = "ActionStatus.withMessages", type = EntityGraphType.LOAD)
Page<ActionStatus> getByActionId(Pageable pageReq, Long actionId);
}

View File

@@ -43,6 +43,7 @@ import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionWithStatusCount;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
@@ -656,6 +657,29 @@ public class JpaDeploymentManagement implements DeploymentManagement {
return actionStatusRepository.getByActionId(pageReq, actionId);
}
@Override
public Page<String> findMessagesByActionStatusId(final Pageable pageable, final Long actionStatusId) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Long> countMsgQuery = cb.createQuery(Long.class);
final Root<JpaActionStatus> countMsgQueryFrom = countMsgQuery.distinct(true).from(JpaActionStatus.class);
final ListJoin<JpaActionStatus, String> cJoin = countMsgQueryFrom.joinList("messages", JoinType.LEFT);
countMsgQuery.select(cb.count(cJoin))
.where(cb.equal(countMsgQueryFrom.get(JpaActionStatus_.id), actionStatusId));
final Long totalCount = entityManager.createQuery(countMsgQuery).getSingleResult();
final CriteriaQuery<String> msgQuery = cb.createQuery(String.class);
final Root<JpaActionStatus>as = msgQuery.from(JpaActionStatus.class);
final ListJoin<JpaActionStatus, String> join = as.joinList("messages", JoinType.LEFT);
final CriteriaQuery<String> selMsgQuery = msgQuery.select(join);
selMsgQuery.where(cb.equal(as.get(JpaActionStatus_.id), actionStatusId));
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult(pageable.getOffset())
.setMaxResults(pageable.getPageSize()).getResultList().stream().collect(Collectors.toList());
return new PageImpl<>(result, pageable, totalCount);
}
@Override
public Page<ActionStatus> findActionStatusAll(final Pageable pageable) {
return convertAcSPage(actionStatusRepository.findAll(pageable), pageable);

View File

@@ -30,13 +30,12 @@ import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedExcepti
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -53,6 +52,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Iterables;
@@ -148,24 +148,65 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Test verifies that the custom query to find all actions include the count of action status is working correctly")
public void findActionsWithStatusCountByTarget() {
@Description("Test verifies that actions of a target are found by using id-based search.")
public void findActionByTargetId() {
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
new ArrayList<DistributionSetTag>());
final List<Target> testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Action action = deploymentManagement
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0)).get();
// save 2 action status
actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
final List<ActionWithStatusCount> findActionsWithStatusCountByTarget = deploymentManagement
.findActionsWithStatusCountByTargetOrderByIdDesc(testTarget.get(0).getControllerId());
// act
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
pageReq);
final Long count = deploymentManagement.countActionsByTarget(testTarget.get(0).getControllerId());
assertThat(findActionsWithStatusCountByTarget).as("wrong action size").hasSize(1);
assertThat(findActionsWithStatusCountByTarget.get(0).getActionStatusCount()).as("wrong action status size")
.isEqualTo(3);
assertThat(count).as("One Action for target").isEqualTo(1L).isEqualTo(actions.getContent().size());
assertThat(actions.getContent().get(0).getId()).as("Action of target").isEqualTo(actionId);
}
@Test
@Description("Test verifies that action-states of an action are found by using id-based search.")
public void findActionStatusByActionId() {
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
new ArrayList<DistributionSetTag>());
final List<Target> testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
final Slice<Action> actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(),
pageReq);
final ActionStatus expectedActionStatus = actions.getContent().get(0).getActionStatus().get(0);
// act
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId);
assertThat(actionStates.getContent()).hasSize(1);
assertThat(actionStates.getContent().get(0)).as("Action-status of action").isEqualTo(expectedActionStatus);
}
@Test
@Description("Test verifies that messages of an action-status are found by using id-based search.")
public void findMessagesByActionStatusId() {
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
new ArrayList<DistributionSetTag>());
final List<Target> testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
// create action-status entry with one message
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.FINISHED).messages(Lists.newArrayList("finished message")));
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId);
// find newly created action-status entry with message
final ActionStatus actionStatusWithMessage = actionStates.getContent().stream()
.filter(entry -> entry.getMessages() != null && entry.getMessages().size() > 0).findFirst().get();
final String expectedMsg = actionStatusWithMessage.getMessages().get(0);
// act
final Page<String> messages = deploymentManagement.findMessagesByActionStatusId(pageReq,
actionStatusWithMessage.getId());
assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L);
assertThat(messages.getContent().get(0)).as("Message of action-status").isEqualTo(expectedMsg);
}
@Test
@@ -176,7 +217,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId());
}
// not exists
assignDS.add(Long.valueOf(100));
assignDS.add(100L);
final DistributionSetTag tag = tagManagement
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));