@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { final ResourcePath relativePath = new ResourcePath(matcher.group(1)); return siteProvider.get().getSite().createLink(relativePath); } }
@Test public void must_do_nothing_when_site_is_available() throws Exception { when(siteProvider.isSiteAvailable()).thenReturn(true); final Status result = underTest.process(request); assertThat(result, is(Status.CONTINUE)); // verifyZeroInteractions(responseHolder); FIXME }
@Override public void notify (final @Nonnull ResourceFileSystemChangedEvent event) { // FIXME: the originator of the event could be a child filesystem in case of composite filesystems. // Either the event is listened by the parent and reposted, or we must be able to find whether a // given filesystem is the parent of another // // e.g. if (siteProvider.get().getSite().getFileSystemProvider().contains(event.getFileSystemProvider())) // // log.info("event fileSystemProvider {}", event.getFileSystemProvider()); // log.info("site fileSystemProvider {}", siteProvider.get().getSite().getFileSystemProvider()); // if (event.getFileSystemProvider() == siteProvider.get().getSite().getFileSystemProvider()) // { log.info("Detected file change, resetting site..."); siteProvider.get().reload(); // } } };
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public List<Locale> getLocales() { final Locale requestLocale = localeHolder.get(); final List<Locale> locales = new ArrayList<>(siteProvider.get().getSite().getConfiguredLocales()); if (requestLocale != null) { locales.remove(requestLocale); locales.add(0, requestLocale); } log.debug(">>>> locales: {}", locales); return locales; }
throws HttpStatusException if (siteProvider.get().isSiteAvailable()) // FIXME no "/" SiteNode available at this point
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { final ResourcePath relativePath = new ResourcePath(matcher.group(1)).prependedWith("media"); return siteProvider.get().getSite().createLink(relativePath); } }
@Test public void must_return_status_503_when_site_is_not_available() throws Exception { when(siteProvider.isSiteAvailable()).thenReturn(false); final Status result = underTest.process(request); final File actualFile = new File("target/test-artifacts/response.txt"); final File expectedFile = new File("src/test/resources/expected-results/response.txt"); actualFile.getParentFile().mkdirs(); Files.write(responseHolder.get(), actualFile); assertThat(result, is(Status.BREAK)); FileComparisonUtils.assertSameContents(expectedFile, actualFile); } }
result.add(beanFactory.getBean(SiteProvider.class).getSite());
throws NotFoundException, IOException, HttpStatusException if (siteProvider.get().isSiteAvailable())
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Status process (final @Nonnull Request request) { final Site site = siteProvider.get().getSite(); for (final Locale locale : request.getPreferredLocales()) { if (site.getConfiguredLocales().contains(locale)) { requestLocaleManager.setRequestLocale(locale); break; } } return CONTINUE; } }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) throws NotFoundException { final String relativePath = matcher.group(1); final Site site = siteProvider.get().getSite(); final SiteNode siteNode = site.find(SiteNode.class).withRelativePath(relativePath).result(); return site.createLink(siteNode.getRelativeUri()); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private String getMetadataString (final @Nonnull Id id, final @Nonnull String format) throws NotFoundException { // FIXME: should use current SiteNode properties final ResourceProperties properties = siteProvider.get().getSite().find(SiteNode.class) .withRelativePath("/") .result() .getProperties(); return mediaMetadataProvider.getMetadataString(id, format, properties); }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { try { // FIXME: should be pushed into @PostConstruct, but can't - see NW-224 final Site site = siteProvider.get().getSite(); final SiteNode rootSiteNode = site.find(SiteNode).withRelativeUri("/").result(); // See NW-223 // END FIXME final String propertyName = matcher.group(1); return rootSiteNode.getProperties().getProperty(new Key<String>(propertyName), ""); } catch (NotFoundException | IOException e) { return "ERR"; } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ // FIXME: this should be shared between instances private void initialize() throws IOException, NotFoundException { log.info("Retrieving XSLT templates"); final String template = IOUtils.toString(getClass().getResourceAsStream("/it/tidalwave/northernwind/core/impl/filter/XsltTemplate.xslt")); final StringBuilder xsltBuffer = new StringBuilder(); for (final Resource resource : siteProvider.get().getSite().find(Resource.class).withRelativePath(XSLT_TEMPLATES_PATH).results()) { final ResourceFile file = resource.getFile(); log.info(">>>> {}", file.getPath().asString()); xsltBuffer.append(file.asText("UTF-8")); } final ST t = new ST(template, '%', '%').add("content", xsltBuffer.toString()); xslt = t.render(); }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) throws NotFoundException, IOException { final String relativePath = matcher.group(1); final String contentRelativePath = matcher.group(2); final String language = matcher.group(4); final Site site = siteProvider.get().getSite(); final SiteNode siteNode = site.find(SiteNode.class).withRelativePath(relativePath).result(); final Content content = site.find(Content.class).withRelativePath(contentRelativePath).result(); final ResourcePath path = siteNode.getRelativeUri().appendedWith(content.getExposedUri()); final String link = site.createLink(path); return ((language == null) || (postProcessor == null)) ? link : postProcessor.postProcess(link, language); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setupFixture() throws Exception { context = new ClassPathXmlApplicationContext("ViewBuilderTestBeans.xml"); siteProvider = context.getBean(SiteProvider.class); service1 = context.getBean(MockService1.class); service2 = context.getBean(MockService2.class); siteNode = mock(SiteNode.class); when(siteProvider.getSite()).thenReturn(site); id = new Id("theId"); underTest = new ViewBuilder(MockView.class, MockController.class); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @SuppressWarnings("unchecked") public FolderBasedFinderSupport (final @Nonnull Type parentResource) { try { final Site site = siteProvider.get().getSite(); this.typeClass = getInterface(parentResource); this.resourceRootPath = site.find(typeClass).withRelativePath("/").result().getFile().getPath(); this.parentFile = parentResource.getFile(); } catch (NotFoundException e) { throw new RuntimeException(e); // never occurs } }
throws IOException, NotFoundException site = siteProvider.get().getSite(); final SiteNode rootSiteNode = site.find(SiteNode).withRelativeUri("/").result(); final ResourceProperties rootSiteNodeProperties = rootSiteNode.getProperties();
@BeforeClass // FIXME: should be BeforeMethod? public void setUp() { context = new ClassPathXmlApplicationContext(contextName); siteProvider = context.getBean(SiteProvider.class); site = context.getBean(Site.class); when(siteProvider.getSite()).thenReturn(site); when(site.find(eq(Content.class))).thenReturn(new MockContentSiteFinder()); when(site.find(eq(SiteNode.class))).thenReturn(new MockSiteNodeSiteFinder()); when(site.createLink(any(ResourcePath.class))).thenAnswer(new Answer<String>() { @Override @Nonnull public String answer (final @Nonnull InvocationOnMock invocation) { return "/LINK" + ((ResourcePath)invocation.getArguments()[0]).asString(); // return ((ResourcePath)invocation.getArguments()[0]).prepend("LINK").asString(); } }); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Status process (final @Nonnull Request request) throws NotFoundException, IOException, HttpStatusException { try { final String relativeUri = request.getRelativeUri(); final Site site = siteProvider.get().getSite(); final SiteNode node = site.find(SiteNode).withRelativeUri(relativeUri).result(); requestContext.setNode(node); siteView.renderSiteNode(node); // // Check *after* finding the SiteNode, since a "not found" must have been already handled here. // enforceTrailingSlash(relativeUri, site); return BREAK; } finally { requestContext.clearNode(); } }