FilesystemStore implements PersistentStore { @Override public void setPublished(int metadataId, final boolean published) throws IOException { final Path metadataDir = Lib.resource.getMetadataDir(getBaseCacheDir().resolve(PRIVATE), String.valueOf(metadataId)); if (Files.exists(metadataDir)) { Files.walkFileTree(metadataDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.getFileName().toString().equals(FULL_MD_NAME)) { return FileVisitResult.SKIP_SUBTREE; } return super.preVisitDirectory(dir, attrs); } @Override public FileVisitResult visitFile(Path privatePath, BasicFileAttributes attrs) throws IOException { final Path publicPath = toPublicPath(privatePath); if (published) { if (!Files.exists(publicPath)) { if (!Files.exists(publicPath.getParent())) { Files.createDirectories(publicPath.getParent()); } Files.createLink(publicPath, privatePath); } } else { Files.deleteIfExists(publicPath); } return super.visitFile(privatePath, attrs); } }); } }  @Override synchronized StoreInfoAndData get(@Nonnull Key key); @Override synchronized StoreInfo getInfo(@Nonnull Key key); @Override synchronized void put(@Nonnull Key key, @Nonnull StoreInfoAndData data); @Nullable @Override byte[] getPublished(@Nonnull Key key); @Override synchronized void remove(@Nonnull Key key); @Override void setPublished(int metadataId, final boolean published); @Override void clear(); void setGeonetworkDataDir(GeonetworkDataDirectory geonetworkDataDir); Path getPrivatePath(Key key); Path getPublicPath(Key key); void setMaxSizeKb(long maxSize); void setMaxSizeMb(int maxSize); void setMaxSizeGb(int maxSize); void setTesting(boolean testing); static final String WITHHELD_MD_DIRNAME; static final String FULL_MD_NAME; static final String QUERY_SETCURRENT_SIZE; static final String QUERY_GETCURRENT_SIZE; }
@Test public void testSetPublished() throws Exception { StoreInfoAndData data = new StoreInfoAndData("result", 10000, true); Key key1 = new Key(1, "eng", FormatType.html, "full_view", true, FormatterWidth._100); Key key2 = new Key(1, "fre", FormatType.html, "full_view", true, FormatterWidth._100); Key key3 = new Key(1, "fre", FormatType.xml, "full_view", true, FormatterWidth._100); Key key4 = new Key(1, "fre", FormatType.html, "xml_view", true, FormatterWidth._100); Key key5 = new Key(1, "fre", FormatType.html, "xml_view", true, FormatterWidth._100); store.put(key1, data); store.put(key2, data); store.put(key3, data); store.put(key4, data); store.put(key5, data); assertPublished(key1, key2, key3, key4, key5); store.setPublished(1, true); assertPublished(key1, key2, key3, key4, key5); store.setPublished(1, false); assertUnpublished(key1, key2, key3, key4, key5); store.setPublished(1, false); assertUnpublished(key1, key2, key3, key4, key5); store.setPublished(1, true); assertPublished(key1, key2, key3, key4, key5); }