PageRepository extends AbstractRepository<Page> implements RefreshingRepository, WidgetContainerRepository<Page> { @Override public void refresh(String id) { try { Page page = this.get(id); Path metadataPath = persister.updateMetadata(this.path.resolve(page.getId()), page); persister.saveInIndex(metadataPath, page); } catch (RepositoryException e) { logger.error(format("Cannot read page %s. Maybe a migration is required.", id), e); } catch (IOException e) { logger.error("Cannot update index file.", e); } } @Inject  PageRepository(
            @Named("pagesPath") Path path,
            @Named("pageFileBasedPersister") JsonFileBasedPersister<Page> persister,
            @Named("pageFileBasedLoader") JsonFileBasedLoader<Page> loader,
            BeanValidator validator,
            Watcher watcher); @Override String getComponentName(); List<Page> getArtifactsUsingWidget(String widgetId); Map<String, List<Page>> getArtifactsUsingWidgets(List<String> widgetIds); @Override void refresh(String id); void refreshIndexing(List<Page> pages); static final String METADATA; }
@Test public void should_refresh_repository() throws Exception { Page page = addToRepository(aPage()); pagesPath.resolve(".metadata").resolve(page.getId() + ".json").toFile().delete(); pagesPath.resolve(".metadata").resolve(".index.json").toFile().delete(); repository.refresh(page.getId()); Page fetchedPage = repository.get(page.getId()); assertThat(fetchedPage.isFavorite()).isFalse(); assertThat(pagesPath.resolve(".metadata").resolve(".index.json").toFile()).exists(); }