mirror of
https://github.com/apache/archiva.git
synced 2025-02-22 18:31:43 +00:00
[MRM-1282] switch all timestamps to UTC
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@900698 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
70fc5323d6
commit
9c28117ca3
@ -25,6 +25,7 @@
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.archiva.metadata.model.MetadataFacet;
|
||||
|
||||
@ -114,6 +115,8 @@ public class AuditEvent
|
||||
|
||||
public static final String FACET_ID = "org.apache.archiva.audit";
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
public AuditEvent()
|
||||
{
|
||||
/* do nothing */
|
||||
@ -123,7 +126,7 @@ public AuditEvent( String name, String repositoryId )
|
||||
{
|
||||
try
|
||||
{
|
||||
timestamp = new SimpleDateFormat( TIMESTAMP_FORMAT ).parse( name );
|
||||
timestamp = createNameFormat().parse( name );
|
||||
}
|
||||
catch ( ParseException e )
|
||||
{
|
||||
@ -208,7 +211,14 @@ public String getFacetId()
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return new SimpleDateFormat( TIMESTAMP_FORMAT ).format( timestamp );
|
||||
return createNameFormat().format( timestamp );
|
||||
}
|
||||
|
||||
private static SimpleDateFormat createNameFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( UTC_TIME_ZONE );
|
||||
return fmt;
|
||||
}
|
||||
|
||||
public Map<String, String> toProperties()
|
||||
|
@ -27,6 +27,7 @@
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
import org.apache.maven.archiva.repository.audit.AuditEvent;
|
||||
@ -48,6 +49,8 @@ public class DefaultAuditManager
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger( DefaultAuditManager.class );
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
public List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds )
|
||||
{
|
||||
// TODO: consider a more efficient implementation that directly gets the last ten from the content repository
|
||||
@ -98,7 +101,7 @@ public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds,
|
||||
{
|
||||
try
|
||||
{
|
||||
Date date = new SimpleDateFormat( AuditEvent.TIMESTAMP_FORMAT ).parse( name );
|
||||
Date date = createNameFormat().parse( name );
|
||||
if ( ( startTime == null || !date.before( startTime ) ) &&
|
||||
( endTime == null || !date.after( endTime ) ) )
|
||||
{
|
||||
@ -124,6 +127,13 @@ public int compare( AuditEvent o1, AuditEvent o2 )
|
||||
return results;
|
||||
}
|
||||
|
||||
private static SimpleDateFormat createNameFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( AuditEvent.TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( UTC_TIME_ZONE );
|
||||
return fmt;
|
||||
}
|
||||
|
||||
public void setMetadataRepository( MetadataRepository metadataRepository )
|
||||
{
|
||||
this.metadataRepository = metadataRepository;
|
||||
|
@ -29,6 +29,7 @@
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
@ -60,10 +61,17 @@ public class AuditManagerTest
|
||||
|
||||
private static final String TEST_IP_ADDRESS = "127.0.0.1";
|
||||
|
||||
private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat( AuditEvent.TIMESTAMP_FORMAT );
|
||||
private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
|
||||
|
||||
private static final DecimalFormat MILLIS_FORMAT = new DecimalFormat( "000" );
|
||||
|
||||
private static SimpleDateFormat createTimestampFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( AuditEvent.TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ));
|
||||
return fmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
|
@ -26,6 +26,7 @@
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
@ -54,6 +55,8 @@ public class DefaultRepositoryStatisticsManager
|
||||
*/
|
||||
private RepositoryContentFactory repositoryContentFactory;
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
public RepositoryStatistics getLastStatistics( String repositoryId )
|
||||
{
|
||||
// TODO: consider a more efficient implementation that directly gets the last one from the content repository
|
||||
@ -165,7 +168,7 @@ public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Dat
|
||||
{
|
||||
try
|
||||
{
|
||||
Date date = new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT ).parse( name );
|
||||
Date date = createNameFormat().parse( name );
|
||||
if ( ( startTime == null || !date.before( startTime ) ) &&
|
||||
( endTime == null || !date.after( endTime ) ) )
|
||||
{
|
||||
@ -185,6 +188,13 @@ public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Dat
|
||||
return results;
|
||||
}
|
||||
|
||||
private static SimpleDateFormat createNameFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( UTC_TIME_ZONE );
|
||||
return fmt;
|
||||
}
|
||||
|
||||
public void setMetadataRepository( MetadataRepository metadataRepository )
|
||||
{
|
||||
this.metadataRepository = metadataRepository;
|
||||
|
@ -23,6 +23,7 @@
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.archiva.metadata.model.MetadataFacet;
|
||||
|
||||
@ -51,6 +52,8 @@ public class RepositoryStatistics
|
||||
|
||||
private Map<String, Long> totalCountForType = new HashMap<String, Long>();
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
public Date getScanEndTime()
|
||||
{
|
||||
return scanEndTime;
|
||||
@ -143,7 +146,14 @@ public String getFacetId()
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT ).format( scanStartTime );
|
||||
return createNameFormat().format( scanStartTime );
|
||||
}
|
||||
|
||||
private static SimpleDateFormat createNameFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( UTC_TIME_ZONE );
|
||||
return fmt;
|
||||
}
|
||||
|
||||
public Map<String, String> toProperties()
|
||||
|
@ -28,6 +28,7 @@
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||
@ -55,6 +56,15 @@ public class RepositoryStatisticsManagerTest
|
||||
|
||||
private Map<String, RepositoryStatistics> statsCreated = new LinkedHashMap<String, RepositoryStatistics>();
|
||||
|
||||
private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
|
||||
|
||||
private static SimpleDateFormat createTimestampFormat()
|
||||
{
|
||||
SimpleDateFormat fmt = new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT );
|
||||
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||
return fmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
@ -83,7 +93,7 @@ protected void setUp()
|
||||
public void testGetLatestStats()
|
||||
throws ParseException
|
||||
{
|
||||
Date startTime = parseTimestamp( SECOND_TEST_SCAN );
|
||||
Date startTime = TIMESTAMP_FORMAT.parse( SECOND_TEST_SCAN );
|
||||
Date endTime = new Date( startTime.getTime() + 60000 );
|
||||
|
||||
RepositoryStatistics stats = new RepositoryStatistics();
|
||||
@ -112,24 +122,13 @@ public void testGetLatestStats()
|
||||
assertEquals( 2031, stats.getTotalProjectCount() );
|
||||
assertEquals( 529, stats.getTotalGroupCount() );
|
||||
assertEquals( 56229, stats.getTotalFileCount() );
|
||||
assertEquals( SECOND_TEST_SCAN, formatTimestamp( stats.getScanStartTime() ) );
|
||||
assertEquals( SECOND_TEST_SCAN, TIMESTAMP_FORMAT.format( stats.getScanStartTime() ) );
|
||||
assertEquals( SECOND_TEST_SCAN, stats.getName() );
|
||||
assertEquals( endTime, stats.getScanEndTime() );
|
||||
|
||||
metadataRepositoryControl.verify();
|
||||
}
|
||||
|
||||
private static String formatTimestamp( Date value )
|
||||
{
|
||||
return new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT ).format( value );
|
||||
}
|
||||
|
||||
private static Date parseTimestamp( String value )
|
||||
throws ParseException
|
||||
{
|
||||
return new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT ).parse( value );
|
||||
}
|
||||
|
||||
public void testGetLatestStatsWhenEmpty()
|
||||
{
|
||||
metadataRepositoryControl.expectAndReturn(
|
||||
|
Loading…
x
Reference in New Issue
Block a user