Skip to content

Commit

Permalink
Merge pull request #64 from bsinno/mgmtapi-shows-wrong-status-content
Browse files Browse the repository at this point in the history
👍 ok merging
  • Loading branch information
michahirsch committed Mar 4, 2016
2 parents f15ba53 + 0fc63a4 commit ba4e0fa
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public enum ActionStatusFields implements FieldNameProvider {
/**
* The id field.
*/
ID("id");
ID("id"),

/**
* The reportedAt field.
*/
REPORTEDAT("createdAt");

private final String fieldName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,47 @@
/**
* {@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);

/**
* @param pageReq
* @param action
* @return
*/
Page<ActionStatus> findByActionOrderByIdDesc(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
Expand All @@ -71,6 +73,6 @@ public interface ActionStatusRepository
* @return Page with found targets
*/
@EntityGraph(value = "ActionStatus.withMessages", type = EntityGraphType.LOAD)
Page<ActionStatus> getByActionOrderByIdDesc(Pageable pageReq, Action action);
Page<ActionStatus> getByAction(Pageable pageReq, Action action);

}
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ public Action forceTargetAction(final Long actionId) {

/**
* retrieves all the {@link ActionStatus} entries of the given
* {@link Action} and {@link Target} in the order latest first.
* {@link Action} and {@link Target}.
*
* @param pageReq
* pagination parameter
Expand All @@ -937,12 +937,12 @@ public Action forceTargetAction(final Long actionId) {
* @return the corresponding {@link Page} of {@link ActionStatus}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public Page<ActionStatus> findActionStatusMessagesByActionInDescOrder(final Pageable pageReq, final Action action,
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final Action action,
final boolean withMessages) {
if (withMessages) {
return actionStatusRepository.getByActionOrderByIdDesc(pageReq, action);
return actionStatusRepository.getByAction(pageReq, action);
} else {
return actionStatusRepository.findByActionOrderByIdDesc(pageReq, action);
return actionStatusRepository.findByAction(pageReq, action);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void controllerAddsActionStatus() {
.isEqualTo(TargetUpdateStatus.IN_SYNC);

assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusMessagesByActionInDescOrder(pageReq, savedAction, false)
.getNumberOfElements()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction, false).getNumberOfElements())
.isEqualTo(3);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
/**
* Utility class for for paged body generation.
*
*
*
*
*
*
*/
public final class PagingUtility {
/*
Expand Down Expand Up @@ -90,8 +85,9 @@ static Sort sanitizeActionSortParam(final String sortParam) {
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;
}
Expand All @@ -101,8 +97,9 @@ static Sort sanitizeActionStatusSortParam(final String sortParam) {
if (sortParam != null) {
sorting = new Sort(SortUtility.parse(ActionStatusFields.class, sortParam));
} else {
// default sort
sorting = new Sort(Direction.ASC, ActionStatusFields.ID.getFieldName());
// 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ private static ActionStatusRest toResponse(final Action action, final ActionStat
final ActionStatusRest result = new ActionStatusRest();

result.setMessages(actionStatus.getMessages());
result.setReportedAt(action.getCreatedAt());
result.setStatusId(action.getId());
result.setReportedAt(actionStatus.getCreatedAt());
result.setStatusId(actionStatus.getId());
result.setType(getNameOfActionStatusType(actionStatus.getStatus()));

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public ResponseEntity<ActionStatusPagedList> getActionStatusList(final String ta
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam);

final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusMessagesByActionInDescOrder(
final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusByAction(
new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action, true);

return new ResponseEntity<>(
Expand Down
Loading

0 comments on commit ba4e0fa

Please sign in to comment.