From 5b0ec4e6c0fe806baf559a60065683d02db21b2e Mon Sep 17 00:00:00 2001 From: Teo Sarca Date: Sat, 25 Feb 2017 21:13:28 +0200 Subject: [PATCH] #184 fix UserDashboard.getTargetIndicatorItemById --- .../de/metas/ui/web/dashboard/UserDashboard.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/dashboard/UserDashboard.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/dashboard/UserDashboard.java index e8a7ba9a2..a667b5b41 100644 --- a/metasfresh-webui-api/src/main/java/de/metas/ui/web/dashboard/UserDashboard.java +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/dashboard/UserDashboard.java @@ -10,7 +10,6 @@ import org.adempiere.util.Check; import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; @@ -47,14 +46,14 @@ public static final Builder builder() public static final UserDashboard EMPTY = new UserDashboard(); private final int id; - private final List targetIndicatorItems; + private final Map targetIndicatorItemsById; private final Map kpiItemsById; private UserDashboard(final Builder builder) { super(); id = builder.id; - targetIndicatorItems = ImmutableList.copyOf(builder.targetIndicatorItems); + targetIndicatorItemsById = Maps.uniqueIndex(builder.targetIndicatorItems, UserDashboardItem::getId); kpiItemsById = Maps.uniqueIndex(builder.kpiItems, UserDashboardItem::getId); } @@ -62,7 +61,7 @@ private UserDashboard() { super(); id = -1; - targetIndicatorItems = ImmutableList.of(); + targetIndicatorItemsById = ImmutableMap.of(); kpiItemsById = ImmutableMap.of(); } @@ -72,7 +71,7 @@ public String toString() return MoreObjects.toStringHelper(this) .omitNullValues() .add("id", id) - .add("targetIndicatorItems", targetIndicatorItems.isEmpty() ? null : targetIndicatorItems) + .add("targetIndicatorItems", targetIndicatorItemsById.isEmpty() ? null : targetIndicatorItemsById) .add("kpiItemsById", kpiItemsById.isEmpty() ? null : kpiItemsById) .toString(); } @@ -82,14 +81,14 @@ public int getId() return id; } - public List getTargetIndicatorItems() + public Collection getTargetIndicatorItems() { - return targetIndicatorItems; + return targetIndicatorItemsById.values(); } public UserDashboardItem getTargetIndicatorItemById(final int itemId) { - final UserDashboardItem item = targetIndicatorItems.get(itemId); + final UserDashboardItem item = targetIndicatorItemsById.get(itemId); if(item == null) { throw new IllegalArgumentException("No target indicator item found for "+itemId);