public Context addPage(Page page) { Page existingPageWithSameKey = pagesByPath.putIfAbsent(page.getKey(), page); if (existingPageWithSameKey != null) { throw new IllegalArgumentException(format("Page '%s' cannot be loaded. Another page with key '%s' already exists.", page.getName(), page.getKey())); } return this; }
private Page[] createPages() { Page page = Page.builder("my_plugin/page").setName("My Plugin Page").build(); Page anotherPage = Page.builder("another_plugin/page").setName("My Another Page").build(); Page adminPage = Page.builder("my_plugin/admin_page").setName("Admin Page").setAdmin(true).build(); return new Page[] {page, anotherPage, adminPage}; } }
@Test public void full_test() { Page result = underTest .setComponentQualifiers(PROJECT, MODULE) .setScope(COMPONENT) .setAdmin(true) .build(); assertThat(result.getKey()).isEqualTo("governance/project_dump"); assertThat(result.getPluginKey()).isEqualTo("governance"); assertThat(result.getName()).isEqualTo("Project Dump"); assertThat(result.getComponentQualifiers()).containsOnly(PROJECT, MODULE); assertThat(result.getScope()).isEqualTo(COMPONENT); assertThat(result.isAdmin()).isTrue(); }
private void checkPluginExists(Page page) { String pluginKey = page.getPluginKey(); checkState(pluginRepository.hasPlugin(pluginKey), "Page '%s' references plugin '%s' that does not exist", page.getName(), pluginKey); }
private List<Page> getPages(Scope scope, boolean isAdmin, @Nullable Qualifier qualifier) { return getAllPages().stream() .filter(p -> p.getScope().equals(scope)) .filter(p -> p.isAdmin() == isAdmin) .filter(p -> !COMPONENT.equals(p.getScope()) || p.getComponentQualifiers().contains(qualifier)) .collect(toList()); }
Page myPage = ... // the Page object Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("_yyyy-MM-dd_HH-mm"); String newName = myPage.getName() + df.format(date); pageManager.copy(myPage, newName, null, true, false);
Page p = (Page)getIntent().getExtras().getSerializable("Page"); Toast.makeText(this, "Name: " + p.getName() + ", Description:" + p.getDescription(), Toast.LENGTH_LONG).show();
private void writeExtensions(JsonWriter json, ComponentDto component, List<Page> pages) { json.name("extensions").beginArray(); Predicate<Page> isAuthorized = page -> { String requiredPermission = page.isAdmin() ? UserRole.ADMIN : UserRole.USER; return userSession.hasComponentPermission(requiredPermission, component); }; pages.stream() .filter(isAuthorized) .forEach(page -> writePage(json, page)); json.endArray(); }
@Test public void all_qualifiers_when_component_page() { Page result = underTest.setScope(COMPONENT).build(); assertThat(result.getComponentQualifiers()).containsOnly(Qualifier.values()); }
public Page build() { if (key == null || key.isEmpty()) { throw new IllegalArgumentException("Key must not be empty"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Name must be defined and not empty"); } if (qualifiers.length > 0 && !COMPONENT.equals(scope)) { throw new IllegalArgumentException(format("The scope must be '%s' when component qualifiers are provided", COMPONENT)); } if (qualifiers.length == 0 && COMPONENT.equals(scope)) { qualifiers = Qualifier.values(); } return new Page(this); } }
private void checkCoreExtensionExists(Page page) { String coreExtensionName = page.getPluginKey(); checkState(coreExtensionRepository.isInstalled(coreExtensionName), "Page '%s' references Core Extension '%s' which is not installed", page.getName(), coreExtensionName); }
@Test public void default_values() { Page result = underTest.build(); assertThat(result.getComponentQualifiers()).isEmpty(); assertThat(result.getScope()).isEqualTo(GLOBAL); assertThat(result.isAdmin()).isFalse(); }
@Override public Object instantiateItem(ViewGroup container, int position) { Page page = pages.get(position); Magazine magazine = dispatcher.getMagazine(); WebView webView = new WebView( activity ); ActionBar.LayoutParams params = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); webView.setLayoutParams(params); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl( magazine.getFileLocation() + "/" + page.getName()); container.addView( webView ); return webView; }
Page p = (Page)getIntent().getExtras().getSerializable("Page"); Toast.makeText(this, "Name: " + p.getName() + ", Description:" + p.getDescription(), Toast.LENGTH_LONG).show();
private void writeExtensions(JsonWriter json, ComponentDto component, List<Page> pages) { json.name("extensions").beginArray(); Predicate<Page> isAuthorized = page -> { String requiredPermission = page.isAdmin() ? UserRole.ADMIN : UserRole.USER; return userSession.hasComponentPermission(requiredPermission, component); }; pages.stream() .filter(isAuthorized) .forEach(page -> writePage(json, page)); json.endArray(); }
public Page build() { if (key == null || key.isEmpty()) { throw new IllegalArgumentException("Key must not be empty"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Name must be defined and not empty"); } if (qualifiers.length > 0 && !COMPONENT.equals(scope)) { throw new IllegalArgumentException(format("The scope must be '%s' when component qualifiers are provided", COMPONENT)); } if (qualifiers.length == 0 && COMPONENT.equals(scope)) { qualifiers = Qualifier.values(); } return new Page(this); } }
@Test public void fail_if_a_page_has_a_null_name() { expectedException.expect(IllegalArgumentException.class); Page.builder("governance/project_dump").build(); }
private void checkPluginExists(Page page) { String pluginKey = page.getPluginKey(); checkState(pluginRepository.hasPlugin(pluginKey), "Page '%s' references plugin '%s' that does not exist", page.getName(), pluginKey); }
private List<Page> getPages(Scope scope, boolean isAdmin, @Nullable Qualifier qualifier) { return getAllPages().stream() .filter(p -> p.getScope().equals(scope)) .filter(p -> p.isAdmin() == isAdmin) .filter(p -> !COMPONENT.equals(p.getScope()) || p.getComponentQualifiers().contains(qualifier)) .collect(toList()); }