summaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/repository-statistics/src
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-12-15 23:07:36 +0000
committerBrett Porter <brett@apache.org>2009-12-15 23:07:36 +0000
commit4331620db667226493479efa67b44ae27e890582 (patch)
tree76eb805c6a301589e441abce751f233ff24fe89c /archiva-modules/plugins/repository-statistics/src
parent7da14962fa313809e961ffd1d248260b146b1045 (diff)
downloadarchiva-4331620db667226493479efa67b44ae27e890582.tar.gz
archiva-4331620db667226493479efa67b44ae27e890582.zip
[MRM-1301] migrate reports to metadata repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@891064 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/repository-statistics/src')
-rw-r--r--archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java10
-rw-r--r--archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java9
-rw-r--r--archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java38
3 files changed, 27 insertions, 30 deletions
diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
index b47e1166f..561cf3c8c 100644
--- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
+++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
@@ -19,9 +19,7 @@ package org.apache.archiva.metadata.repository.stats;
* under the License.
*/
-import java.text.DateFormat;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -44,8 +42,6 @@ public class DefaultRepositoryStatisticsManager
*/
private MetadataRepository metadataRepository;
- static final DateFormat SCAN_TIMESTAMP = new SimpleDateFormat( "yyyyMMdd.HHmmss.SSS" );
-
public RepositoryStatistics getLastStatistics( String repositoryId )
{
// TODO: consider a more efficient implementation that directly gets the last one from the content repository
@@ -81,9 +77,7 @@ public class DefaultRepositoryStatisticsManager
// populate total project count from content repository
// repositoryStatistics.setTotalProjectCount( );
- metadataRepository.addMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID,
- SCAN_TIMESTAMP.format( repositoryStatistics.getScanStartTime() ),
- repositoryStatistics );
+ metadataRepository.addMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID, repositoryStatistics );
}
public void deleteStatistics( String repositoryId )
@@ -100,7 +94,7 @@ public class DefaultRepositoryStatisticsManager
{
try
{
- Date date = SCAN_TIMESTAMP.parse( name );
+ Date date = RepositoryStatistics.SCAN_TIMESTAMP.parse( name );
if ( ( startTime == null || !date.before( startTime ) ) &&
( endTime == null || !date.after( endTime ) ) )
{
diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
index efc26bf85..272d524dd 100644
--- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
+++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
@@ -19,6 +19,8 @@ package org.apache.archiva.metadata.repository.stats;
* under the License.
*/
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -46,6 +48,8 @@ public class RepositoryStatistics
public static String FACET_ID = "org.apache.archiva.metadata.repository.stats";
+ static final DateFormat SCAN_TIMESTAMP = new SimpleDateFormat( "yyyyMMdd.HHmmss.SSS" );
+
public Date getScanEndTime()
{
return scanEndTime;
@@ -136,6 +140,11 @@ public class RepositoryStatistics
return FACET_ID;
}
+ public String getName()
+ {
+ return SCAN_TIMESTAMP.format( scanStartTime );
+ }
+
public Map<String, String> toProperties()
{
Map<String, String> properties = new HashMap<String, String>();
diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
index d561b77f3..d75e68330 100644
--- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
+++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
@@ -65,11 +65,10 @@ public class RepositoryStatisticsManagerTest
public void testGetLatestStats()
throws ParseException
{
- Date endTime =
- new Date( DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ).getTime() + 60000 );
+ Date endTime = new Date( RepositoryStatistics.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ).getTime() + 60000 );
RepositoryStatistics stats = new RepositoryStatistics();
- stats.setScanStartTime( DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ) );
+ stats.setScanStartTime( RepositoryStatistics.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ) );
stats.setScanEndTime( endTime );
stats.setTotalArtifactFileSize( 1314527915L );
stats.setNewFileCount( 123 );
@@ -94,8 +93,8 @@ public class RepositoryStatisticsManagerTest
assertEquals( 2031, stats.getTotalProjectCount() );
assertEquals( 529, stats.getTotalGroupCount() );
assertEquals( 56229, stats.getTotalFileCount() );
- assertEquals( SECOND_TEST_SCAN,
- DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( stats.getScanStartTime() ) );
+ assertEquals( SECOND_TEST_SCAN, RepositoryStatistics.SCAN_TIMESTAMP.format( stats.getScanStartTime() ) );
+ assertEquals( SECOND_TEST_SCAN, stats.getName() );
assertEquals( endTime, stats.getScanEndTime() );
metadataRepositoryControl.verify();
@@ -119,17 +118,15 @@ public class RepositoryStatisticsManagerTest
Date current = new Date();
Date startTime = new Date( current.getTime() - 12345 );
- RepositoryStatistics stats1 = createTestStats( startTime, current );
+ RepositoryStatistics stats = createTestStats( startTime, current );
- String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime );
- metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats1 );
+ metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats );
metadataRepositoryControl.expectAndReturn(
metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
- Arrays.asList( startTimeAsString ) );
+ Arrays.asList( stats.getName() ) );
metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString ),
- stats1 );
- RepositoryStatistics stats = stats1;
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats.getName() ),
+ stats );
metadataRepositoryControl.replay();
@@ -155,19 +152,17 @@ public class RepositoryStatisticsManagerTest
Date startTime1 = new Date( current.getTime() - 12345 );
RepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) );
- String startTimeAsString1 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime1 );
- metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString1, stats1 );
+ metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats1 );
Date startTime2 = new Date( current.getTime() - 3000 );
RepositoryStatistics stats2 = createTestStats( startTime2, current );
- String startTimeAsString2 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime2 );
- metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2, stats2 );
+ metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2 );
metadataRepositoryControl.expectAndReturn(
metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
- Arrays.asList( startTimeAsString1, startTimeAsString2 ) );
+ Arrays.asList( stats1.getName(), stats2.getName() ) );
metadataRepositoryControl.expectAndReturn(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2 ),
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2.getName() ),
stats2 );
metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID );
@@ -230,7 +225,7 @@ public class RepositoryStatisticsManagerTest
for ( RepositoryStatistics stats : statsCreated.values() )
{
- repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+ repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
}
List<RepositoryStatistics> list =
@@ -396,9 +391,8 @@ public class RepositoryStatisticsManagerTest
private void addStats( Date startTime, Date endTime )
{
RepositoryStatistics stats = createTestStats( startTime, endTime );
- String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime );
- metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats );
- statsCreated.put( startTimeAsString, stats );
+ metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats );
+ statsCreated.put( stats.getName(), stats );
}
private RepositoryStatistics createTestStats( Date startTime, Date endTime )