ViewHelper { public static View viewFromJson(final BundleService bundleService, final JSONObject viewJSON) throws JSONException, IllegalArgumentException { final View view = new View(); view.setName(viewJSON.getString("name")); view.setType(viewJSON.getString("type")); view.setCreator(viewJSON.optLong("creator", -1L)); view.setIsDefault(viewJSON.optBoolean("default")); view.setIsPublic(viewJSON.optBoolean("public", false)); view.setOnlyForUuId(viewJSON.optBoolean("onlyUuid", true)); view.setMetadata(viewJSON.optJSONObject("metadata")); if (viewJSON.has("oskari")) { final JSONObject oskari = viewJSON.getJSONObject("oskari"); view.setApplication(oskari.getString("application")); view.setPage(oskari.getString("page")); } else { view.setApplication(viewJSON.getString("application")); view.setPage(viewJSON.getString("page")); } addBundles(bundleService, view, viewJSON.getJSONArray("bundles")); return view; } private  ViewHelper(); static JSONArray getStartupSequence(final View view); static boolean isRefererDomain(final String referer, final String pubdomain); static JSONObject getConfiguration(final View view); static JSONObject viewToJson(final BundleService bundleService,
            final View view); static View viewFromJson(final BundleService bundleService,
            final JSONObject viewJSON); static List<View> getSystemViews(ViewService viewService); static Set<String> getSystemCRSs(ViewService viewService);  }
@Test public void testThatParsingWorks() throws IOException, IllegalArgumentException, JSONException { byte[] b = null; try (InputStream in = this.getClass() .getResourceAsStream("view-to-import.json")) { b = IOHelper.readBytes(in); } if (b == null || b.length == 0) { fail("Failed to read view-to-import.json"); return; } String jsonStr = new String(b, StandardCharsets.UTF_8); JSONObject viewJSON = new JSONObject(jsonStr); Bundle foobar = new Bundle(); foobar.setName("foobar"); bundleService.addBundleTemplate(foobar); View view = ViewHelper.viewFromJson(bundleService, viewJSON); assertEquals("Default view", view.getName()); assertEquals("DEFAULT", view.getType()); assertEquals(true, view.isDefault()); assertEquals(true, view.isPublic()); assertEquals(false, view.isOnlyForUuId()); assertEquals("servlet", view.getApplication()); assertEquals("index", view.getPage()); List<Bundle> bundles = view.getBundles(); assertNotNull(bundles); assertEquals(1, bundles.size()); assertEquals(foobar.getName(), bundles.get(0).getName()); }