1 package org.apache.archiva.metadata.repository.stats;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.HashMap;
26 import java.util.TimeZone;
28 import org.apache.archiva.metadata.model.MetadataFacet;
30 public class RepositoryStatistics
31 implements MetadataFacet
33 private Date scanEndTime;
35 private Date scanStartTime;
37 private long totalArtifactCount;
39 private long totalArtifactFileSize;
41 private long totalFileCount;
43 private long totalGroupCount;
45 private long totalProjectCount;
47 private long newFileCount;
49 public static String FACET_ID = "org.apache.archiva.metadata.repository.stats";
51 static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
53 private Map<String, Long> totalCountForType = new HashMap<String, Long>();
55 private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
57 public Date getScanEndTime()
62 public void setScanEndTime( Date scanEndTime )
64 this.scanEndTime = scanEndTime;
67 public Date getScanStartTime()
72 public void setScanStartTime( Date scanStartTime )
74 this.scanStartTime = scanStartTime;
77 public long getTotalArtifactCount()
79 return totalArtifactCount;
82 public void setTotalArtifactCount( long totalArtifactCount )
84 this.totalArtifactCount = totalArtifactCount;
87 public long getTotalArtifactFileSize()
89 return totalArtifactFileSize;
92 public void setTotalArtifactFileSize( long totalArtifactFileSize )
94 this.totalArtifactFileSize = totalArtifactFileSize;
97 public long getTotalFileCount()
99 return totalFileCount;
102 public void setTotalFileCount( long totalFileCount )
104 this.totalFileCount = totalFileCount;
107 public long getTotalGroupCount()
109 return totalGroupCount;
112 public void setTotalGroupCount( long totalGroupCount )
114 this.totalGroupCount = totalGroupCount;
117 public long getTotalProjectCount()
119 return totalProjectCount;
122 public void setTotalProjectCount( long totalProjectCount )
124 this.totalProjectCount = totalProjectCount;
127 public void setNewFileCount( long newFileCount )
129 this.newFileCount = newFileCount;
132 public long getNewFileCount()
137 public long getDuration()
139 return scanEndTime.getTime() - scanStartTime.getTime();
142 public String getFacetId()
147 public String getName()
149 return createNameFormat().format( scanStartTime );
152 private static SimpleDateFormat createNameFormat()
154 SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
155 fmt.setTimeZone( UTC_TIME_ZONE );
159 public Map<String, String> toProperties()
161 Map<String, String> properties = new HashMap<String, String>();
162 properties.put( "scanEndTime", String.valueOf( scanEndTime.getTime() ) );
163 properties.put( "scanStartTime", String.valueOf( scanStartTime.getTime() ) );
164 properties.put( "totalArtifactCount", String.valueOf( totalArtifactCount ) );
165 properties.put( "totalArtifactFileSize", String.valueOf( totalArtifactFileSize ) );
166 properties.put( "totalFileCount", String.valueOf( totalFileCount ) );
167 properties.put( "totalGroupCount", String.valueOf( totalGroupCount ) );
168 properties.put( "totalProjectCount", String.valueOf( totalProjectCount ) );
169 properties.put( "newFileCount", String.valueOf( newFileCount ) );
170 for ( Map.Entry<String, Long> entry : totalCountForType.entrySet() )
172 properties.put( "count-" + entry.getKey(), String.valueOf( entry.getValue() ) );
177 public void fromProperties( Map<String, String> properties )
179 scanEndTime = new Date( Long.valueOf( properties.get( "scanEndTime" ) ) );
180 scanStartTime = new Date( Long.valueOf( properties.get( "scanStartTime" ) ) );
181 totalArtifactCount = Long.valueOf( properties.get( "totalArtifactCount" ) );
182 totalArtifactFileSize = Long.valueOf( properties.get( "totalArtifactFileSize" ) );
183 totalFileCount = Long.valueOf( properties.get( "totalFileCount" ) );
184 totalGroupCount = Long.valueOf( properties.get( "totalGroupCount" ) );
185 totalProjectCount = Long.valueOf( properties.get( "totalProjectCount" ) );
186 newFileCount = Long.valueOf( properties.get( "newFileCount" ) );
187 totalCountForType.clear();
188 for ( Map.Entry<String, String> entry : properties.entrySet() )
190 if ( entry.getKey().startsWith( "count-" ) )
192 totalCountForType.put( entry.getKey().substring( 6 ), Long.valueOf( entry.getValue() ) );
198 public boolean equals( Object o )
204 if ( o == null || getClass() != o.getClass() )
209 RepositoryStatistics that = (RepositoryStatistics) o;
211 if ( newFileCount != that.newFileCount )
215 if ( totalArtifactCount != that.totalArtifactCount )
219 if ( totalArtifactFileSize != that.totalArtifactFileSize )
223 if ( totalFileCount != that.totalFileCount )
227 if ( totalGroupCount != that.totalGroupCount )
231 if ( totalProjectCount != that.totalProjectCount )
235 if ( !scanEndTime.equals( that.scanEndTime ) )
239 if ( !scanStartTime.equals( that.scanStartTime ) )
243 if ( !totalCountForType.equals( that.totalCountForType ) )
252 public int hashCode()
254 int result = scanEndTime.hashCode();
255 result = 31 * result + scanStartTime.hashCode();
256 result = 31 * result + (int) ( totalArtifactCount ^ ( totalArtifactCount >>> 32 ) );
257 result = 31 * result + (int) ( totalArtifactFileSize ^ ( totalArtifactFileSize >>> 32 ) );
258 result = 31 * result + (int) ( totalFileCount ^ ( totalFileCount >>> 32 ) );
259 result = 31 * result + (int) ( totalGroupCount ^ ( totalGroupCount >>> 32 ) );
260 result = 31 * result + (int) ( totalProjectCount ^ ( totalProjectCount >>> 32 ) );
261 result = 31 * result + (int) ( newFileCount ^ ( newFileCount >>> 32 ) );
262 result = 31 * result + totalCountForType.hashCode();
267 public String toString()
269 return "RepositoryStatistics{" + "scanEndTime=" + scanEndTime + ", scanStartTime=" + scanStartTime +
270 ", totalArtifactCount=" + totalArtifactCount + ", totalArtifactFileSize=" + totalArtifactFileSize +
271 ", totalFileCount=" + totalFileCount + ", totalGroupCount=" + totalGroupCount + ", totalProjectCount=" +
272 totalProjectCount + ", newFileCount=" + newFileCount + ", totalCountForType=" + totalCountForType + '}';
275 public Map<String, Long> getTotalCountForType()
277 return totalCountForType;
280 public long getTotalCountForType( String type )
282 Long value = totalCountForType.get( type );
283 return value != null ? value : 0;
286 public void setTotalCountForType( String type, long count )
288 totalCountForType.put( type, count );