Search in sources :

Example 1 with ArchivaRepositoryStatistics

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;
}
Also used : Locale(java.util.Locale) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) SimpleDateFormat(java.text.SimpleDateFormat) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)

Example 2 with ArchivaRepositoryStatistics

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);
}
Also used : ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Aggregations

ArchivaRepositoryStatistics (org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)1 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)1 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)1 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)1 Test (org.junit.Test)1