Skip to content

Commit

Permalink
remove IView reference from ViewResult
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Apr 28, 2017
1 parent ddeadeb commit 2c9b7db
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 57 deletions.
54 changes: 42 additions & 12 deletions src/main/java/de/metas/ui/web/view/ViewResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,21 @@ public static ViewResult ofView(final IView view)
return new ViewResult(view);
}

private final IView view;
private final int firstRow;
private final int pageLength;
//
// View info
private final ViewId viewId;
private final ViewId parentViewId;
private final long size;
private final int queryLimit;
private final boolean queryLimitHit;

private final List<DocumentFilter> filters;
private final List<DocumentQueryOrderBy> orderBys;

//
// Page info
private final int firstRow;
private final int pageLength;
private final List<IViewRow> page;

/** View and loaded page constructor */
Expand All @@ -77,7 +87,12 @@ private ViewResult(
)
{
super();
this.view = view;
this.viewId = view.getViewId();
this.parentViewId = view.getParentViewId();
this.size = view.size();
this.queryLimit = view.getQueryLimit();
this.queryLimitHit = view.isQueryLimitHit();

filters = ImmutableList.copyOf(view.getFilters());
this.orderBys = ImmutableList.copyOf(orderBys);

Expand All @@ -92,7 +107,12 @@ private ViewResult(
private ViewResult(final IView view)
{
super();
this.view = view;
this.viewId = view.getViewId();
this.parentViewId = view.getParentViewId();
this.size = view.size();
this.queryLimit = view.getQueryLimit();
this.queryLimitHit = view.isQueryLimitHit();

filters = ImmutableList.copyOf(view.getFilters());
orderBys = view.getDefaultOrderBys();

Expand All @@ -110,7 +130,7 @@ public String toString()
.omitNullValues()
//
// View info
.add("view", view)
.add("viewId", viewId)
.add("filters", filters)
.add("orderBys", orderBys)
//
Expand All @@ -122,9 +142,19 @@ public String toString()
.toString();
}

public IView getView()
public ViewId getViewId()
{
return viewId;
}

public ViewId getParentViewId()
{
return parentViewId;
}

public long getSize()
{
return view;
return size;
}

public int getFirstRow()
Expand Down Expand Up @@ -164,14 +194,14 @@ public List<IViewRow> getPage()
}
return page;
}

public int getQueryLimit()
{
return view.getQueryLimit();
return queryLimit;
}

public boolean isQueryLimitHit()
{
return view.isQueryLimitHit();
return queryLimitHit;
}
}
49 changes: 4 additions & 45 deletions src/main/java/de/metas/ui/web/view/json/JSONViewResult.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package de.metas.ui.web.view.json;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.window.WindowConstants;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.datatypes.json.filters.JSONDocumentFilter;

Expand Down Expand Up @@ -110,27 +103,22 @@ public static final JSONViewResult of(final ViewResult result)
@JsonInclude(JsonInclude.Include.NON_NULL)
private final Integer queryLimit;

//
// Debug properties
private final Map<String, Object> debugPropeties;

public JSONViewResult(final ViewResult viewResult)
{
super();

//
// View informations
final IView view = viewResult.getView();
final ViewId viewId = view.getViewId();
final ViewId viewId = viewResult.getViewId();
this.viewId = viewId.getViewId();
this.windowId = viewId.getWindowId();
type = windowId;

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

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

filters = JSONDocumentFilter.ofList(viewResult.getFilters());
Expand All @@ -155,17 +143,6 @@ public JSONViewResult(final ViewResult viewResult)
// Query limit informations
queryLimit = viewResult.getQueryLimit() > 0 ? viewResult.getQueryLimit() : null;
queryLimitHit = viewResult.isQueryLimitHit() ? Boolean.TRUE : null;

//
// Debugging informations
if (WindowConstants.isProtocolDebugging())
{
debugPropeties = ImmutableMap.<String, Object> of("debug-view-info", view.toString());
}
else
{
debugPropeties = ImmutableMap.of();
}
}

@JsonCreator
Expand Down Expand Up @@ -213,12 +190,6 @@ private JSONViewResult( //
// Query limit hit
this.queryLimit = queryLimit;
this.queryLimitHit = queryLimitHit;

//
// Debug informations
// NOTE: initialize as mutable.
// The actual debug properties will be loaded by calling #putDebugProperty(...)
debugPropeties = new HashMap<>();
}

@Override
Expand All @@ -239,16 +210,4 @@ public String toString()
//
.toString();
}

@JsonAnyGetter
public Map<String, Object> getDebugPropeties()
{
return debugPropeties;
}

@JsonAnySetter
private void putDebugProperty(final String name, final Object value)
{
debugPropeties.put(name, value);
}
}

0 comments on commit 2c9b7db

Please sign in to comment.