Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into gh19-w…
Browse files Browse the repository at this point in the history
…ebui
  • Loading branch information
teosarca committed Mar 1, 2017
2 parents 4c282a1 + 16bf9e2 commit f403a87
Show file tree
Hide file tree
Showing 29 changed files with 376 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public class AddressRestController

private JSONOptions newJsonOpts()
{
return JSONOptions.builder()
.setUserSession(userSession)
.build();
return JSONOptions.of(userSession);
}

@RequestMapping(value = { "", "/" }, method = RequestMethod.POST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ public class DashboardRestController
@Autowired
private UserDashboardRepository userDashboardRepo;

private JSONOptions.Builder newJSONOpts()
private JSONOptions newJSONOpts()
{
return JSONOptions.builder()
.setUserSession(userSession);
return JSONOptions.of(userSession);
}

@GetMapping("/kpis")
Expand All @@ -61,7 +60,7 @@ public JSONDashboard getKPIsDashboard()
userSession.assertLoggedIn();

final UserDashboard userDashboard = userDashboardRepo.getUserDashboard();
return JSONDashboard.of(userDashboard.getKPIItems(), newJSONOpts().build());
return JSONDashboard.of(userDashboard.getKPIItems(), newJSONOpts());
}

@PatchMapping("/kpis")
Expand Down Expand Up @@ -92,7 +91,7 @@ public JSONDashboard getTargetIndicatorsDashboard()
userSession.assertLoggedIn();

final UserDashboard userDashboard = userDashboardRepo.getUserDashboard();
return JSONDashboard.of(userDashboard.getTargetIndicatorItems(), newJSONOpts().build());
return JSONDashboard.of(userDashboard.getTargetIndicatorItems(), newJSONOpts());
}

@GetMapping("/targetIndicators/{itemId}/data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -52,7 +52,7 @@ public static enum MenuNodeType
, Window, NewRecord //
, Process, Report //
}

@FunctionalInterface
public static interface MenuNodeFilter
{
Expand All @@ -69,9 +69,12 @@ public static enum MenuNodeFilterResolution
private final String captionBreadcrumb;
private final MenuNodeType type;
private final int elementId;
private final String mainTableName;

private final List<MenuNode> children;
private MenuNode parent;

private MenuNode parent;

//
// Characteristics
private final boolean matchedByFilter;
Expand All @@ -89,17 +92,18 @@ private MenuNode(final Builder builder)
captionBreadcrumb = builder.captionBreadcrumb;
type = builder.type;
elementId = builder.elementId;
mainTableName = builder.mainTableName;

children = ImmutableList.copyOf(Iterables.concat(builder.childrenFirst, builder.childrenRest));
for (final MenuNode child : children)
{
child.parent = this;
}

matchedByFilter = false;

// Validate
if(type != MenuNodeType.Group && !children.isEmpty())
if (type != MenuNodeType.Group && !children.isEmpty())
{
throw new IllegalArgumentException("Only grouping nodes can have children");
}
Expand All @@ -114,13 +118,14 @@ private MenuNode(final MenuNode node, final List<MenuNode> children, final boole
captionBreadcrumb = node.captionBreadcrumb;
type = node.type;
elementId = node.elementId;
mainTableName = node.mainTableName;

this.children = ImmutableList.copyOf(children);
for (final MenuNode child : this.children)
{
child.parent = this;
}

this.matchedByFilter = matchedByFilter;
}

Expand All @@ -133,6 +138,7 @@ public String toString()
.add("caption", caption)
.add("type", type)
.add("elementId", elementId)
.add("mainTableName", mainTableName)
.add("children-count", children.size())
.add("matchedByFilter", matchedByFilter ? Boolean.TRUE : null)
.toString();
Expand Down Expand Up @@ -177,7 +183,7 @@ public String getCaption()
{
return caption;
}

public String getCaptionBreadcrumb()
{
return captionBreadcrumb;
Expand All @@ -187,7 +193,7 @@ public MenuNode getParent()
{
return parent;
}

public String getParentId()
{
return parent == null ? null : parent.getId();
Expand All @@ -207,6 +213,12 @@ public int getElementId()
{
return elementId;
}

/** @return window's main table name or null */
public String getMainTableName()
{
return mainTableName;
}

public void iterate(final Consumer<MenuNode> consumer)
{
Expand Down Expand Up @@ -240,21 +252,21 @@ private IPair<MenuNode, MenuNodeFilterResolution> deepCopy0(final MenuNodeFilter
for (final MenuNode child : children)
{
final IPair<MenuNode, MenuNodeFilterResolution> childCopyAndResolution = child.deepCopy0(filter);
if(childCopyAndResolution == null)
if (childCopyAndResolution == null)
{
continue;
}

final MenuNode childCopy = childCopyAndResolution.getLeft();
if (childCopy == null)
{
continue;
}

childrenCopy.add(childCopy);

final MenuNodeFilterResolution childResolution = childCopyAndResolution.getRight();
switch(childResolution)
switch (childResolution)
{
case Accept:
case AcceptIfHasChildren:
Expand All @@ -272,7 +284,7 @@ private IPair<MenuNode, MenuNodeFilterResolution> deepCopy0(final MenuNodeFilter
{
return null;
}

final boolean matchedByFilter = resolution == MenuNodeFilterResolution.Accept;
final MenuNode thisCopy = new MenuNode(this, childrenCopy, matchedByFilter);
return ImmutablePair.of(thisCopy, resolution);
Expand All @@ -287,19 +299,19 @@ public boolean isGroupingNode()
{
return type == MenuNodeType.Group;
}

/**
* Returns true if this node is effectively a leaf node.
*
*
* An effectively leaf node it's a node which it's not a grouping node, or even if it's grouping node, it does no have any children.
*
*
* @return
*/
public boolean isEffectiveLeafNode()
{
return children.isEmpty();
}

public boolean isMatchedByFilter()
{
return matchedByFilter;
Expand All @@ -313,6 +325,7 @@ public static final class Builder
private String captionBreadcrumb;
private MenuNodeType type;
private int elementId;
private String mainTableName;
private final List<MenuNode> childrenFirst = new ArrayList<>();
private final List<MenuNode> childrenRest = new ArrayList<>();

Expand Down Expand Up @@ -343,8 +356,8 @@ public Builder setCaption(final String caption)
this.caption = caption;
return this;
}
public Builder setCaptionBreadcrumb(String captionBreadcrumb)

public Builder setCaptionBreadcrumb(final String captionBreadcrumb)
{
this.captionBreadcrumb = captionBreadcrumb;
return this;
Expand Down Expand Up @@ -378,7 +391,13 @@ public Builder addChildren(final Collection<MenuNode> children)
return this;
}

this.childrenRest.addAll(children);
childrenRest.addAll(children);
return this;
}

public Builder setMainTableName(final String mainTableName)
{
this.mainTableName = mainTableName;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public static final MenuTree of(final MenuNode rootNode)

private final MenuNode rootNode;
private final Map<String, MenuNode> nodesById;

private final ListMultimap<ArrayKey, MenuNode> nodesByTypeAndElementId;
private final ListMultimap<String, MenuNode> nodesByMainTableName;

private MenuTree(final MenuNode rootNode)
{
Expand All @@ -65,12 +67,20 @@ private MenuTree(final MenuNode rootNode)

final ImmutableMap.Builder<String, MenuNode> nodesByIdBuilder = ImmutableMap.builder();
final ImmutableListMultimap.Builder<ArrayKey, MenuNode> nodesByTypeAndElementIdBuilder = ImmutableListMultimap.builder();
final ImmutableListMultimap.Builder<String, MenuNode> nodesByMainTableNameBuilder = ImmutableListMultimap.builder();
rootNode.iterate(node -> {
nodesByIdBuilder.put(node.getId(), node);
nodesByTypeAndElementIdBuilder.put(mkTypeAndElementIdKey(node.getType(), node.getElementId()), node);

final String mainTableName = node.getMainTableName();
if (mainTableName != null)
{
nodesByMainTableNameBuilder.put(mainTableName, node);
}
});
nodesById = nodesByIdBuilder.build();
nodesByTypeAndElementId = nodesByTypeAndElementIdBuilder.build();
nodesByMainTableName = nodesByMainTableNameBuilder.build();
}

private static final ArrayKey mkTypeAndElementIdKey(final MenuNodeType type, final int elementId)
Expand Down Expand Up @@ -109,10 +119,10 @@ public MenuNode getFirstNodeByElementId(final MenuNodeType type, final int eleme
{
throw new NoMenuNodesFoundException("No menu node found for type=" + type + " and elementId=" + elementId);
}

return nodes.get(0);
}

public Optional<MenuNode> getNewRecordNodeForWindowId(final int adWindowId)
{
final ArrayKey key = mkTypeAndElementIdKey(MenuNodeType.NewRecord, adWindowId);
Expand All @@ -121,11 +131,19 @@ public Optional<MenuNode> getNewRecordNodeForWindowId(final int adWindowId)
{
return Optional.empty();
}

final MenuNode newRecordNode = nodes.get(0);
return Optional.of(newRecordNode);
}

public Optional<MenuNode> getNewRecordNodeForTableName(final String tableName)
{
return nodesByMainTableName.get(tableName)
.stream()
.filter(node -> node.getType() == MenuNodeType.NewRecord)
.findFirst();
}

public List<MenuNode> getPath(final String nodeId)
{
final MenuNode node = getNodeById(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ private MenuNode.Builder createMenuNodeBuilder(final MTreeNode nodeModel, final
final MenuNode.Builder builder = MenuNode.builder()
.setId(nodeModel.getNode_ID())
.setCaption(caption)
.setCaptionBreadcrumb(captionBreadcrumb);
.setCaptionBreadcrumb(captionBreadcrumb)
.setMainTableName(nodeModel.getMainTableName());

final String action = nodeModel.getImageIndiactor();
if (nodeModel.isSummary())
Expand Down Expand Up @@ -219,6 +220,7 @@ private MenuNode createNewRecordNode(final MenuNode node, final String caption,
.setCaption(captionEffective)
.setCaptionBreadcrumb(captionBreadcrumbEffective)
.setType(MenuNodeType.NewRecord, node.getElementId())
.setMainTableName(node.getMainTableName())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public class ASIRestController

private JSONOptions newJsonOpts()
{
return JSONOptions.builder()
.setUserSession(userSession)
.build();
return JSONOptions.of(userSession);
}

@PostMapping({ "", "/" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public class ProcessRestController

private JSONOptions newJsonOpts()
{
return JSONOptions.builder()
.setUserSession(userSession)
.build();
return JSONOptions.of(userSession);
}

@RequestMapping(value = "/{processId}/layout", method = RequestMethod.GET)
Expand Down
Loading

0 comments on commit f403a87

Please sign in to comment.