@Override public void addAuditEvent( MetadataRepository repository, AuditEvent event ) throws MetadataRepositoryException { // ignore those with no repository - they will still be logged to the textual audit log if ( event.getRepositoryId() != null ) { repository.addMetadataFacet( event.getRepositoryId(), event ); } }
@Override public void addAuditEvent( MetadataRepository repository, AuditEvent event ) throws MetadataRepositoryException { // ignore those with no repository - they will still be logged to the textual audit log if ( event.getRepositoryId() != null ) { repository.addMetadataFacet( event.getRepositoryId(), event ); } }
@Override public void addStatisticsAfterScan( MetadataRepository metadataRepository, String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) throws MetadataRepositoryException { DefaultRepositoryStatistics repositoryStatistics = new DefaultRepositoryStatistics(); repositoryStatistics.setRepositoryId( repositoryId ); repositoryStatistics.setScanStartTime( startTime ); repositoryStatistics.setScanEndTime( endTime ); repositoryStatistics.setTotalFileCount( totalFiles ); repositoryStatistics.setNewFileCount( newFiles ); // TODO // In the future, instead of being tied to a scan we might want to record information in the fly based on // events that are occurring. Even without these totals we could query much of the information on demand based // on information from the metadata content repository. In the mean time, we lock information in at scan time. // Note that if new types are later discoverable due to a code change or new plugin, historical stats will not // be updated and the repository will need to be rescanned. long startGather = System.currentTimeMillis(); if ( metadataRepository instanceof RepositoryStatisticsProvider) { ((RepositoryStatisticsProvider)metadataRepository).populateStatistics( metadataRepository, repositoryId, repositoryStatistics); } else { walkingProvider.populateStatistics( metadataRepository, repositoryId, repositoryStatistics ); } log.info( "Gathering statistics executed in {} ms", ( System.currentTimeMillis() - startGather ) ); metadataRepository.addMetadataFacet( repositoryId, repositoryStatistics ); }
@Test public void testGetMetadataFacets() throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); assertEquals( Collections.singletonList( TEST_NAME ), repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) ); }
@Test public void hasMetadataFacet() throws Exception { assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); Calendar cal = Calendar.getInstance(); repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime() ) ); assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); cal.add( Calendar.MINUTE, 2 ); repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime() ) ); cal.add( Calendar.MINUTE, 2 ); repository.addMetadataFacet( TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime() ) ); List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); assertThat( facets ).isNotNull().isNotEmpty().hasSize( 3 ); assertTrue( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); repository.removeMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); assertFalse( repository.hasMetadataFacet( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ) ); facets = repository.getMetadataFacets( TEST_REPO_ID, KindOfRepositoryStatistics.class.getName() ); assertThat( facets ).isNotNull().isEmpty(); }
@Test public void testGetMetadataFacetWhenUnknownName() throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) ); }
@Test public void testRemoveFacets() throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertFalse( facets.isEmpty() ); repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); }
@Test public void testGetMetadataFacet() throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); TestMetadataFacet test = (TestMetadataFacet) repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ); assertEquals( new TestMetadataFacet( TEST_VALUE ), test ); }
@Test public void testGetMetadataFacetWhenDefaultValue() throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) ); MetadataFacet metadataFacet = repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ); assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), metadataFacet ); }
@Override public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId, String projectVersion, RepositoryStorageMetadataException exception ) { RepositoryProblemFacet problem = new RepositoryProblemFacet(); problem.setMessage( exception.getMessage() ); problem.setProject( projectId ); problem.setNamespace( namespace ); problem.setRepositoryId( repoId ); problem.setVersion( projectVersion ); problem.setProblem( exception.getId() ); try { session.getRepository().addMetadataFacet( repoId, problem ); session.markDirty(); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to add repository problem facets for the version being removed: {}", e.getMessage(), e ); } }
metadataRepository.addMetadataFacet( repoId, problem );
@Test public void testRemoveFacet() throws Exception { TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE ); repository.addMetadataFacet( TEST_REPO_ID, metadataFacet ); assertEquals( metadataFacet, repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertFalse( facets.isEmpty() ); repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ); assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); }