Skip to content

Commit

Permalink
JSONViewResult: provide filters and sticky filters together
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 14, 2017
1 parent 9ac9dcb commit 4679bb1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,35 @@ public static final List<JSONDocumentFilter> ofList(final List<DocumentFilter> f
public static final JSONDocumentFilter of(final DocumentFilter filter, final String adLanguage)
{
final String filterId = filter.getFilterId();
final boolean stickyFilter = false;
final List<JSONDocumentFilterParam> jsonParameters = filter.getParameters()
.stream()
.map(filterParam -> JSONDocumentFilterParam.of(filterParam))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(GuavaCollectors.toImmutableList());

return new JSONDocumentFilter(filterId, filter.getCaption(adLanguage), jsonParameters);
return new JSONDocumentFilter(filterId, filter.getCaption(adLanguage), stickyFilter, jsonParameters);
}

public static final List<JSONDocumentFilter> ofStickyFiltersList(final List<DocumentFilter> filters, final String adLanguage)
{
if (filters == null || filters.isEmpty())
{
return ImmutableList.of();
}

return filters.stream()
.map(filter -> ofStickyFilter(filter, adLanguage))
.collect(GuavaCollectors.toImmutableList());
}

public static final JSONDocumentFilter ofStickyFilter(final DocumentFilter filter, final String adLanguage)
{
final String filterId = filter.getFilterId();
final boolean stickyFilter = true;
final List<JSONDocumentFilterParam> jsonParameters = ImmutableList.of(); // don't export the parameters
return new JSONDocumentFilter(filterId, filter.getCaption(adLanguage), stickyFilter, jsonParameters);
}

@JsonProperty("filterId")
Expand All @@ -178,19 +199,24 @@ public static final JSONDocumentFilter of(final DocumentFilter filter, final Str
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String caption;

@JsonProperty("static")
private boolean stickyFilter;

@JsonProperty("parameters")
private final List<JSONDocumentFilterParam> parameters;

@JsonCreator
private JSONDocumentFilter(
@JsonProperty("filterId") final String filterId,
@JsonProperty("caption") final String caption,
@JsonProperty("static") final boolean stickyFilter,
@JsonProperty("parameters") final List<JSONDocumentFilterParam> parameters)
{
Check.assumeNotEmpty(filterId, "filterId is not empty");

this.filterId = filterId;
this.caption = caption;
this.stickyFilter = stickyFilter;
this.parameters = parameters == null ? ImmutableList.of() : ImmutableList.copyOf(parameters);
}
}
22 changes: 10 additions & 12 deletions src/main/java/de/metas/ui/web/view/json/JSONViewResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public static final JSONViewResult of(final ViewResult result, final String adLa
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final List<JSONDocumentFilter> filters;

@JsonProperty(value = "stickyFilters")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final List<JSONDocumentFilter> stickyFilters;

//
// Page informations (optional)
// NOTE: important to distinguish between "empty" and "null", i.e.
Expand Down Expand Up @@ -120,21 +116,25 @@ public JSONViewResult(final ViewResult viewResult, final String adLanguage)
// View informations
final ViewId viewId = viewResult.getViewId();
this.viewId = viewId.getViewId();
this.windowId = viewId.getWindowId();
windowId = viewId.getWindowId();
type = windowId;

final ViewId parentViewId = viewResult.getParentViewId();
this.parentWindowId = parentViewId == null ? null : parentViewId.getWindowId();
parentWindowId = parentViewId == null ? null : parentViewId.getWindowId();
this.parentViewId = parentViewId == null ? null : parentViewId.getViewId();

this.description = viewResult.getViewDescription(adLanguage);
description = viewResult.getViewDescription(adLanguage);

final long size = viewResult.getSize();
this.size = size >= 0 ? size : null;

// NOTE: stickyFilters are not used by frontend but we are adding them to ease the troubleshooting
stickyFilters = JSONDocumentFilter.ofList(viewResult.getStickyFilters(), adLanguage);
filters = JSONDocumentFilter.ofList(viewResult.getFilters(), adLanguage);
final List<JSONDocumentFilter> filters = JSONDocumentFilter.ofList(viewResult.getFilters(), adLanguage);
final List<JSONDocumentFilter> stickyFilters = JSONDocumentFilter.ofList(viewResult.getStickyFilters(), adLanguage);
this.filters = ImmutableList.<JSONDocumentFilter> builder()
.addAll(filters)
.addAll(stickyFilters)
.build();

orderBy = JSONViewOrderBy.ofList(viewResult.getOrderBys());

//
Expand Down Expand Up @@ -170,7 +170,6 @@ private JSONViewResult( //
//
, @JsonProperty("size") final Long size //
, @JsonProperty("filters") final List<JSONDocumentFilter> filters //
, @JsonProperty(value = "stickyFilters") final List<JSONDocumentFilter> stickyFilters //
, @JsonProperty("orderBy") final List<JSONViewOrderBy> orderBy //
//
, @JsonProperty("result") final List<JSONViewRow> result //
Expand All @@ -196,7 +195,6 @@ private JSONViewResult( //
//
this.size = size;
this.filters = filters == null ? ImmutableList.of() : filters;
this.stickyFilters = stickyFilters == null ? ImmutableList.of() : stickyFilters;
this.orderBy = orderBy == null ? ImmutableList.of() : orderBy;

//
Expand Down

0 comments on commit 4679bb1

Please sign in to comment.