Added comments and changed default sorting for actions.

This commit is contained in:
Kai Zimmermann
2016-03-03 20:46:50 +01:00
parent e7173aa846
commit 794db18673
3 changed files with 31 additions and 22 deletions

View File

@@ -21,38 +21,47 @@ import org.springframework.transaction.annotation.Transactional;
/**
* {@link ActionStatus} repository.
*
*
*
*
*/
@Transactional(readOnly = true)
public interface ActionStatusRepository
extends BaseEntityRepository<ActionStatus, Long>, JpaSpecificationExecutor<ActionStatus> {
/**
* @param target
* Counts {@link ActionStatus} entries of given {@link Action} in
* repository.
*
* @param action
* @return
* to count status entries
* @return number of actions in repository
*/
Long countByAction(Action action);
/**
* Counts {@link ActionStatus} entries of given {@link Action} with given
* {@link Status} in repository.
*
* @param action
* @param retrieved
* @return
* to count status entries
* @param status
* to filter for
* @return number of actions in repository
*/
Long countByActionAndStatus(Action action, Status retrieved);
Long countByActionAndStatus(Action action, Status status);
/**
* Retrieves all {@link ActionStatus} entries from repository of given
* {@link Action}.
*
* @param pageReq
* parameters
* @param action
* @return
* of the status entries
* @return pages list of {@link ActionStatus} entries
*/
Page<ActionStatus> findByAction(Pageable pageReq, Action action);
/**
* Finds all status updates for the defined action and target order by
* {@link ActionStatus#getId()} desc including
* Finds all status updates for the defined action and target including
* {@link ActionStatus#getMessages()}.
*
* @param pageReq

View File

@@ -23,11 +23,6 @@ import org.springframework.data.domain.Sort.Direction;
/**
* Utility class for for paged body generation.
*
*
*
*
*
*
*/
public final class PagingUtility {
/*
@@ -90,8 +85,9 @@ public final class PagingUtility {
if (sortParam != null) {
sorting = new Sort(SortUtility.parse(ActionFields.class, sortParam));
} else {
// default sort
sorting = new Sort(Direction.ASC, ActionFields.ID.getFieldName());
// default sort is DESC in case of action to match behavior
// of management UI (last entry on top)
sorting = new Sort(Direction.DESC, ActionFields.ID.getFieldName());
}
return sorting;
}
@@ -101,7 +97,8 @@ public final class PagingUtility {
if (sortParam != null) {
sorting = new Sort(SortUtility.parse(ActionStatusFields.class, sortParam));
} else {
// default sort
// default sort is DESC in case of action status to match behavior
// of management UI (last entry on top)
sorting = new Sort(Direction.DESC, ActionStatusFields.ID.getFieldName());
}
return sorting;

View File

@@ -833,7 +833,8 @@ public class TargetResourceTest extends AbstractIntegrationTest {
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
mvc.perform(get(
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS))
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS)
.param(RestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("content.[1].id", equalTo(actions.get(1).getId().intValue())))
.andExpect(jsonPath("content.[1].type", equalTo("update")))
@@ -960,7 +961,8 @@ public class TargetResourceTest extends AbstractIntegrationTest {
// page 1: one entry
mvc.perform(get(
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS)
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1)))
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
.param(RestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("content.[0].id", equalTo(actions.get(0).getId().intValue())))
.andExpect(jsonPath("content.[0].type", equalTo("cancel")))
@@ -976,7 +978,8 @@ public class TargetResourceTest extends AbstractIntegrationTest {
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS)
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1))
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1)))
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1))
.param(RestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("content.[0].id", equalTo(actions.get(1).getId().intValue())))
.andExpect(jsonPath("content.[0].type", equalTo("update")))