@Override public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace, String project, String version, String id ) { String name = RepositoryProblemFacet.createName( namespace, project, version, id ); try { metadataRepository.removeMetadataFacet( repositoryId, RepositoryProblemFacet.FACET_ID, name ); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to remove metadata facet as part of delete event: {}", e.getMessage(), e ); } }
@Override public void removeProject( String repositoryId, String namespace, String projectId ) throws MetadataRepositoryException { try { File directory = new File( getDirectory( repositoryId ), namespace + "/" + projectId ); FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
private List<RepositoryStatistics> getMultipleRepositoriesReport( List<String> repositoriesId, int rowCount ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { MetadataRepository metadataRepository = repositorySession.getRepository(); List<RepositoryStatistics> stats = new ArrayList<>(); for ( String repo : repositoriesId ) { try { stats.add( repositoryStatisticsManager.getLastStatistics( metadataRepository, repo ) ); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e ); } } return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() ); } finally { repositorySession.close(); } }
@Override public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataRepositoryException { try { File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
/** * Close the session. Required to be called for all open sessions to ensure resources are properly released. * If the session has been marked as dirty, it will be saved. This may save partial changes in the case of a typical * <code>try { ... } finally { ... }</code> approach - if this is a problem, ensure you revert changes when an * exception occurs. * <b>can throw RuntimeException</b> */ @Override public void close() { try { if ( dirty ) { save(); } } finally { try { repository.close(); } catch ( MetadataRepositoryException e ) { throw new RuntimeException( e.getMessage(), e ); } } }
@Override public void removeMetadataFacets( String repositoryId, String facetId ) throws MetadataRepositoryException { try { File dir = getMetadataDirectory( repositoryId, facetId ); FileUtils.deleteDirectory( dir ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
private List<RepositoryStatistics> getMultipleRepositoriesReport( List<String> repositoriesId, int rowCount ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { MetadataRepository metadataRepository = repositorySession.getRepository(); List<RepositoryStatistics> stats = new ArrayList<>(); for ( String repo : repositoriesId ) { try { stats.add( repositoryStatisticsManager.getLastStatistics( metadataRepository, repo ) ); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e ); } } return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() ); } finally { repositorySession.close(); } }
@Override public void removeMetadataFacet( String repoId, String facetId, String name ) throws MetadataRepositoryException { try { File dir = new File( getMetadataDirectory( repoId, facetId ), name ); FileUtils.deleteDirectory( dir ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
private List<RepositoryStatistics> getUniqueRepositoryReport( String repositoryId, int rowCount, Date startDate, Date endDate ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { MetadataRepository metadataRepository = repositorySession.getRepository(); List<RepositoryStatistics> stats = null; try { stats = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repositoryId, startDate, endDate ); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e ); } if ( stats == null || stats.isEmpty() ) { return Collections.<RepositoryStatistics>emptyList(); } return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() ); } finally { repositorySession.close(); } }
@Override public void removeRepository( String repoId ) throws MetadataRepositoryException { try { File dir = getDirectory( repoId ); FileUtils.deleteDirectory( dir ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
private List<RepositoryStatistics> getUniqueRepositoryReport( String repositoryId, int rowCount, Date startDate, Date endDate ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { MetadataRepository metadataRepository = repositorySession.getRepository(); List<RepositoryStatistics> stats = null; try { stats = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repositoryId, startDate, endDate ); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e ); } if ( stats == null || stats.isEmpty() ) { return Collections.<RepositoryStatistics>emptyList(); } return stats.subList( 0, stats.size() > rowCount ? rowCount : stats.size() ); } finally { repositorySession.close(); } }
@Override public void removeNamespace( String repositoryId, String project ) throws MetadataRepositoryException { try { File namespaceDirectory = new File( getDirectory( repositoryId ), project ); FileUtils.deleteDirectory( namespaceDirectory ); //Properties properties = new Properties(); //properties.setProperty( "namespace", namespace ); //writeProperties( properties, namespaceDirectory, NAMESPACE_METADATA_KEY ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
throw new RepositoryMergerException( e.getMessage(), e );
@Override public boolean hasMetadataFacet( String repositoryId, String facetId ) throws MetadataRepositoryException { try { Path directory = getMetadataDirectory(repositoryId, facetId); if (!(Files.exists(directory) && Files.isDirectory(directory))) { return false; } final String searchFile = METADATA_KEY + ".properties"; try (Stream<Path> fs = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return fs.filter(Files::isDirectory).anyMatch(path -> Files.exists(path.resolve(searchFile))); } } catch (IOException e) { log.error("Could not retrieve facet metatadata {}, {}: {}", repositoryId, facetId, e.getMessage(), e); throw new MetadataRepositoryException(e.getMessage(), e); } }
@Override public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId, ProjectVersionMetadata metadata ) { // Remove problems associated with this version on successful addition // TODO: this removes all problems - do we need something that just remove the problems we know are corrected? String name = RepositoryProblemFacet.createName( namespace, projectId, metadata.getId(), null ); try { MetadataRepository metadataRepository = session.getRepository(); metadataRepository.removeMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, name ); session.markDirty(); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: {}", e.getMessage(), e ); } }
@Override public List<String> getMetadataFacets( String repoId, String facetId ) throws MetadataRepositoryException { try { Path directory = getMetadataDirectory( repoId, facetId ); if (!(Files.exists(directory) && Files.isDirectory(directory))) { return Collections.emptyList(); } List<String> facets; final String searchFile = METADATA_KEY + ".properties"; try(Stream<Path> fs = Files.walk(directory, FileVisitOption.FOLLOW_LINKS) ) { facets = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))) .map(path -> directory.relativize(path).toString()).collect(Collectors.toList()); } return facets; } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
@Override public void auditEvent( AuditEvent event ) { // for now we only log upload events, some of the others are quite noisy if ( event.getAction().equals( AuditEvent.CREATE_FILE ) || event.getAction().equals( AuditEvent.UPLOAD_FILE ) || event.getAction().equals( AuditEvent.MERGING_REPOSITORIES ) ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { auditManager.addAuditEvent( repositorySession.getRepository(), event ); repositorySession.save(); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to write audit event to repository: {}", e.getMessage(), e ); } finally { repositorySession.close(); } } } }
@Override public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataRepositoryException { try { Path directory = getDirectory( repoId ).resolve( namespace + "/" + projectId + "/" + projectVersion ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }
@Override public void auditEvent( AuditEvent event ) { // for now we only log upload events, some of the others are quite noisy if ( event.getAction().equals( AuditEvent.CREATE_FILE ) || event.getAction().equals( AuditEvent.UPLOAD_FILE ) || event.getAction().equals( AuditEvent.MERGING_REPOSITORIES ) ) { RepositorySession repositorySession = repositorySessionFactory.createSession(); try { auditManager.addAuditEvent( repositorySession.getRepository(), event ); repositorySession.save(); } catch ( MetadataRepositoryException e ) { log.warn( "Unable to write audit event to repository: {}", e.getMessage(), e ); } finally { repositorySession.close(); } } } }
@Override public void removeProject( String repositoryId, String namespace, String projectId ) throws MetadataRepositoryException { try { Path directory = getDirectory( repositoryId ).resolve( namespace + "/" + projectId ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MetadataRepositoryException( e.getMessage(), e ); } }