From d6ef1d994c8bc25684fb84c52540e5c0183e5680 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 2 Oct 2016 12:45:56 +0300 Subject: [PATCH] Storage servlet update --- .../inr/numass/server/NumassRootHandler.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java index 78d4e8e3..bc095691 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java @@ -17,6 +17,7 @@ import ratpack.handling.Context; import ratpack.handling.Handler; import java.io.StringWriter; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; @@ -67,7 +68,7 @@ public class NumassRootHandler implements Handler { StringBuilder b = new StringBuilder(); renderStorage(ctx, b, server.getRun().getStorage()); data.put("storageContent", b.toString()); - } catch (StorageException ex) { + } catch (Exception ex) { data.put("storageContent", ex.toString()); } } else { @@ -85,18 +86,23 @@ public class NumassRootHandler implements Handler { } } - private void renderStorage(Context ctx, StringBuilder b, Storage storage) throws StorageException { - b.append("
\n"); - for (Storage shelf : storage.shelves().values()) { - b.append(String.format("

+ %s

%n", shelf.getName())); - renderStorage(ctx, b, shelf); + private void renderStorage(Context ctx, StringBuilder b, Storage storage){ + try { + b.append("
\n"); + storage.shelves().values().stream().sorted(Comparator.comparing(it -> it.getName())).forEach(shelf -> { + b.append(String.format("

+ %s

%n", shelf.getName())); + renderStorage(ctx, b, shelf); + }); + + b.append("
\n"); + + storage.loaders().values().stream().sorted(Comparator.comparing(it->it.getName())).forEach(loader -> renderLoader(ctx, b, loader)); + + b.append("
\n"); + b.append("
\n"); + }catch (StorageException ex){ + throw new RuntimeException(ex); } - b.append("
\n"); - for (Loader loader : storage.loaders().values()) { - renderLoader(ctx, b, loader); - } - b.append("
\n"); - b.append("
\n"); } private void renderLoader(Context ctx, StringBuilder b, Loader loader) {