Search in sources :

Example 1 with ViewRowsOrderBy

use of de.metas.ui.web.view.ViewRowsOrderBy in project metasfresh-webui-api by metasfresh.

the class BoardRestController method getNewCardsView.

@GetMapping("/{boardId}/newCardsView/{viewId}")
public JSONViewResult getNewCardsView(@PathVariable("boardId") final int boardId, @PathVariable("viewId") final String viewIdStr, @RequestParam("firstRow") final int firstRow, @RequestParam("pageLength") final int pageLength, @RequestParam(name = "orderBy", required = false) final String orderBysListStr) {
    userSession.assertLoggedIn();
    final JSONOptions jsonOpts = newJSONOptions();
    final ViewRowsOrderBy orderBys = ViewRowsOrderBy.parseString(orderBysListStr, jsonOpts);
    final ViewResult viewResult = viewsRepo.getView(viewIdStr).getPageWithRowIdsOnly(firstRow, pageLength, orderBys);
    final List<Integer> boardCardIds = boardsRepo.retrieveCardIds(boardId);
    return toJSONCardsViewResult(boardId, viewResult, jsonOpts, // filter out cards which already exist in our board
    cardId -> !boardCardIds.contains(cardId));
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) ViewResult(de.metas.ui.web.view.ViewResult) JSONViewResult(de.metas.ui.web.view.json.JSONViewResult) ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with ViewRowsOrderBy

use of de.metas.ui.web.view.ViewRowsOrderBy in project metasfresh-webui-api by metasfresh.

the class AbstractCustomView method getPage.

/**
 * Simple in-memory implementation with paging and ordering.
 */
@Override
public final ViewResult getPage(final int firstRow, final int pageLength, @NonNull final ViewRowsOrderBy orderBys) {
    final ViewRowsOrderBy orderBysEffective = !orderBys.isEmpty() ? orderBys : orderBys.withOrderBys(getDefaultOrderBys());
    final List<IViewRow> pageRows = getRows().stream().sorted(orderBysEffective.toComparator()).skip(firstRow >= 0 ? firstRow : 0).limit(pageLength > 0 ? pageLength : 30).collect(ImmutableList.toImmutableList());
    return ViewResult.ofViewAndPage(this, firstRow, pageLength, orderBysEffective.toDocumentQueryOrderByList(), pageRows);
}
Also used : IViewRow(de.metas.ui.web.view.IViewRow) ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy)

Example 3 with ViewRowsOrderBy

use of de.metas.ui.web.view.ViewRowsOrderBy in project metasfresh-webui-api by metasfresh.

the class HUEditorViewBuffer_FullyCached method streamPage.

@Override
public Stream<HUEditorRow> streamPage(final int firstRow, final int pageLength, @NonNull final HUEditorRowFilter filter, @NonNull final ViewRowsOrderBy orderBys) {
    final ViewRowsOrderBy orderBysEffective = !orderBys.isEmpty() ? orderBys : orderBys.withOrderBys(defaultOrderBys);
    Stream<HUEditorRow> stream = getRows().stream().skip(firstRow).limit(pageLength).filter(HUEditorRowFilters.toPredicate(filter));
    final Comparator<HUEditorRow> comparator = orderBysEffective.toComparatorOrNull();
    if (comparator != null) {
        stream = stream.sorted(comparator);
    }
    return stream;
}
Also used : ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy)

Example 4 with ViewRowsOrderBy

use of de.metas.ui.web.view.ViewRowsOrderBy in project metasfresh-webui-api by metasfresh.

the class HUEditorViewBuffer_HighVolume method streamAllRecursive.

@Override
public Stream<HUEditorRow> streamAllRecursive(@NonNull final HUEditorRowFilter filter) throws UnsupportedOperationException {
    final ViewRowIdsOrderedSelection defaultSelection = getDefaultSelection();
    if (defaultSelection.getSize() > STREAM_ALL_MAX_SIZE_ALLOWED) {
        throw new UnsupportedOperationException("Streaming all rows when selection is bigger than " + STREAM_ALL_MAX_SIZE_ALLOWED + " is not allowed");
    }
    final JSONOptions jsonOpts = JSONOptions.newInstance();
    final ViewRowsOrderBy orderBys = ViewRowsOrderBy.of(defaultSelection.getOrderBys(), jsonOpts);
    return streamPage(0, STREAM_ALL_MAX_SIZE_ALLOWED, filter, orderBys).flatMap(HUEditorRow::streamRecursive).map(HUEditorRow::cast).filter(HUEditorRowFilters.toPredicate(filter));
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) ViewRowIdsOrderedSelection(de.metas.ui.web.view.ViewRowIdsOrderedSelection) ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy)

Example 5 with ViewRowsOrderBy

use of de.metas.ui.web.view.ViewRowsOrderBy in project metasfresh-webui-api by metasfresh.

the class ViewGeoLocationsRestController method getAll.

@GetMapping
public JsonViewGeoLocationsResult getAll(@PathVariable(PARAM_WindowId) final String windowIdStr, @PathVariable(PARAM_ViewId) final String viewIdStr, @RequestParam(value = "limit", required = false, defaultValue = "0") final int limit) {
    userSession.assertLoggedIn();
    final ViewId viewId = ViewId.of(windowIdStr, viewIdStr);
    final int limitEffective = limit > 0 ? limit : DEFAULT_LIMIT;
    final IView view = viewsRepo.getView(viewId);
    final ImmutableSet<String> viewFieldNames = getViewFieldNames(view);
    final GeoLocationDocumentDescriptor geoLocationDescriptor = geoLocationDocumentService.getGeoLocationDocumentDescriptor(viewFieldNames);
    final ViewRowsOrderBy orderBy = ViewRowsOrderBy.of(view.getDefaultOrderBys(), newJsonOpts());
    final ViewResult rows = view.getPage(0, limitEffective, orderBy);
    final List<JsonViewRowGeoLocation> geoLocations = retrieveGeoLocations(rows, geoLocationDescriptor);
    return JsonViewGeoLocationsResult.builder().viewId(viewId.toJson()).locations(geoLocations).build();
}
Also used : IView(de.metas.ui.web.view.IView) ViewId(de.metas.ui.web.view.ViewId) JsonViewRowGeoLocation(de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation) ViewResult(de.metas.ui.web.view.ViewResult) ViewRowsOrderBy(de.metas.ui.web.view.ViewRowsOrderBy) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ViewRowsOrderBy (de.metas.ui.web.view.ViewRowsOrderBy)5 ViewResult (de.metas.ui.web.view.ViewResult)2 JSONOptions (de.metas.ui.web.window.datatypes.json.JSONOptions)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JsonViewRowGeoLocation (de.metas.ui.web.document.geo_location.json.JsonViewRowGeoLocation)1 IView (de.metas.ui.web.view.IView)1 IViewRow (de.metas.ui.web.view.IViewRow)1 ViewId (de.metas.ui.web.view.ViewId)1 ViewRowIdsOrderedSelection (de.metas.ui.web.view.ViewRowIdsOrderedSelection)1 JSONViewResult (de.metas.ui.web.view.json.JSONViewResult)1