use of org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics in project archiva by apache.
the class DefaultManagedRepositoriesService method getManagedRepositoryStatistics.
@Override
public ArchivaRepositoryStatistics getManagedRepositoryStatistics(String repositoryId, String lang) throws ArchivaRestServiceException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", new Locale(lang));
try {
MetadataRepository metadataRepository = repositorySession.getRepository();
RepositoryStatistics stats = null;
try {
stats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repositoryId);
} catch (MetadataRepositoryException e) {
log.warn("Error retrieving repository statistics: {}", e.getMessage(), e);
}
if (stats != null) {
ArchivaRepositoryStatistics archivaRepositoryStatistics = getModelMapper().map(stats, ArchivaRepositoryStatistics.class);
archivaRepositoryStatistics.setDuration(archivaRepositoryStatistics.getScanEndTime().getTime() - archivaRepositoryStatistics.getScanStartTime().getTime());
archivaRepositoryStatistics.setLastScanDate(sdf.format(archivaRepositoryStatistics.getScanEndTime()));
return archivaRepositoryStatistics;
}
} finally {
if (repositorySession != null) {
repositorySession.close();
}
}
return null;
}
use of org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics in project archiva by apache.
the class ManagedRepositoriesServiceTest method getManagedRepositoryStatistics.
@Test
public void getManagedRepositoryStatistics() throws Exception {
String testRepoId = "test-repo";
// force guest user creation if not exists
if (getUserService(authorizationHeader).getGuestUser() == null) {
assertNotNull(getUserService(authorizationHeader).createGuestUser());
}
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
createAndIndexRepo(testRepoId, Paths.get(System.getProperty("basedir"), "src/test/repo-with-osgi").toAbsolutePath().toString());
repositoriesService.scanRepositoryDirectoriesNow(testRepoId);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(testRepoId)) {
Thread.sleep(500);
timeout -= 500;
}
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ArchivaRepositoryStatistics archivaRepositoryStatistics = service.getManagedRepositoryStatistics(testRepoId, "en");
assertNotNull(archivaRepositoryStatistics);
log.info("archivaRepositoryStatistics: {}", archivaRepositoryStatistics.toString());
assertEquals(92, archivaRepositoryStatistics.getNewFileCount());
assertEquals(92, archivaRepositoryStatistics.getTotalFileCount());
deleteTestRepo(testRepoId);
}
Aggregations