001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.harvester.datamodel; 024 025import java.util.Date; 026 027import dk.netarkivet.common.exceptions.ArgumentNotValid; 028 029/** 030 * Summary information about a specific harvest of a domain. This class is immutable. 031 */ 032public class HarvestInfo { 033 034 /** The date the harvest information was created. */ 035 private final Date date; 036 037 /** The identifier of the harvest. */ 038 private final Long harvestID; 039 040 /** The total number of objects retrieved. */ 041 private final long countObjectRetrieved; 042 043 /** The total size in bytes of the downloaded data. */ 044 private final long sizeDataRetrieved; 045 046 /** The reason the harvest stopped. */ 047 private final StopReason stopReason; 048 049 /** The name of the domain harvested. */ 050 private final String domainName; 051 052 /** The configuration that the domain was harvested with. */ 053 private final String domainCfgName; 054 055 /** 056 * The job that was used to create this info, or null if it cannot be determined (for old harvestinfo only). 057 */ 058 private final Long jobID; 059 060 /** ID autogenerated by DB, ignored otherwise. */ 061 private Long id; 062 063 /** 064 * Create new harvest info instance. 065 * 066 * @param harvestID The id of the harvest 067 * @param domainName The name of the Domain 068 * @param domainCfgName The name of the Domain configuration 069 * @param date The date of the harvest 070 * @param sizeDataRetrieved The number of bytes retrieved for this Domain 071 * @param countObjectRetrieved The number of objects retrieved for this Domain 072 * @param stopReason The reason why the current harvest terminated 073 */ 074 public HarvestInfo(Long harvestID, String domainName, String domainCfgName, Date date, long sizeDataRetrieved, 075 long countObjectRetrieved, StopReason stopReason) { 076 this(harvestID, null, domainName, domainCfgName, date, sizeDataRetrieved, countObjectRetrieved, stopReason); 077 } 078 079 /** 080 * Create new harvest info instance. 081 * 082 * @param harvestID The id of the harvest 083 * @param jobID The id of the job, if available 084 * @param domainName The name of the Domain 085 * @param domainCfgName The name of the Domain configuration 086 * @param date The date of the harvest 087 * @param sizeDataRetrieved The number of bytes retrieved for this Domain 088 * @param countObjectRetrieved The number of objects retrieved for this Domain 089 * @param stopReason The reason why the current harvest terminated 090 */ 091 public HarvestInfo(Long harvestID, Long jobID, String domainName, String domainCfgName, Date date, 092 long sizeDataRetrieved, long countObjectRetrieved, StopReason stopReason) { 093 ArgumentNotValid.checkNotNull(harvestID, "harvestID"); 094 ArgumentNotValid.checkNotNull(date, "date"); 095 ArgumentNotValid.checkNotNullOrEmpty(domainName, "domainName"); 096 ArgumentNotValid.checkNotNullOrEmpty(domainCfgName, "domainCfgName"); 097 ArgumentNotValid.checkNotNegative(sizeDataRetrieved, "sizeDataRetrieved"); 098 ArgumentNotValid.checkNotNegative(countObjectRetrieved, "countObjectRetrieved"); 099 ArgumentNotValid.checkNotNull(stopReason, "stopReason"); 100 101 this.harvestID = harvestID; 102 this.jobID = jobID; 103 this.domainCfgName = domainCfgName; 104 this.domainName = domainName; 105 this.date = date; 106 this.sizeDataRetrieved = sizeDataRetrieved; 107 this.countObjectRetrieved = countObjectRetrieved; 108 this.stopReason = stopReason; 109 } 110 111 /** 112 * Get the total amount of data downloaded (bytes). 113 * 114 * @return the total amount of data downloaded (bytes) 115 */ 116 public long getSizeDataRetrieved() { 117 return sizeDataRetrieved; 118 } 119 120 /** 121 * Get the total number of objects downloaded. 122 * 123 * @return the total number of objects downloaded 124 */ 125 public long getCountObjectRetrieved() { 126 return countObjectRetrieved; 127 } 128 129 /** 130 * Get the reason the harvest stopped. 131 * 132 * @return the reason the harvest stopped 133 */ 134 public StopReason getStopReason() { 135 return stopReason; 136 } 137 138 /** 139 * Get the date this harvest information was recorded. 140 * 141 * @return the date the harvest information was recorded 142 */ 143 public Date getDate() { 144 return date; 145 } 146 147 /** 148 * Get the id of the harvest. 149 * 150 * @return the harvest ID 151 */ 152 public Long getHarvestID() { 153 return harvestID; 154 } 155 156 /** 157 * Get the id of the job, if available. 158 * 159 * @return the job ID or null. 160 */ 161 public Long getJobID() { 162 return jobID; 163 } 164 165 /** 166 * Get the domain name of the harvest. 167 * 168 * @return the domain name 169 */ 170 public String getDomainName() { 171 return domainName; 172 } 173 174 /** 175 * Get the domain configuration name of the harvest. 176 * 177 * @return the domain configuration name 178 */ 179 public String getDomainConfigurationName() { 180 return domainCfgName; 181 } 182 183 /** 184 * Get the ID of this harvestinfo. Only for use by DBDAO. 185 * 186 * @return the ID of this harvestinfo 187 */ 188 long getID() { 189 return id; 190 } 191 192 /** 193 * Set the ID of this harvestinfo. Only for use by DBDAO 194 * 195 * @param newid the new ID of this harvestinfo 196 */ 197 void setID(long newid) { 198 this.id = newid; 199 } 200 201 /** 202 * Check if this harvestinfo has an ID set yet (doesn't happen until the DBDAO persists it). 203 * 204 * @return true, if this harvestinfo has an ID set 205 */ 206 boolean hasID() { 207 return id != null; 208 } 209 210 /** 211 * Autogenerated from IDEA. 212 * 213 * @return true if object fields are equal 214 * @see Object#equals(java.lang.Object) 215 */ 216 public boolean equals(Object o) { 217 if (this == o) { 218 return true; 219 } 220 if (!(o instanceof HarvestInfo)) { 221 return false; 222 } 223 224 final HarvestInfo harvestInfo = (HarvestInfo) o; 225 226 if (countObjectRetrieved != harvestInfo.countObjectRetrieved) { 227 return false; 228 } 229 if (sizeDataRetrieved != harvestInfo.sizeDataRetrieved) { 230 return false; 231 } 232 if (!date.equals(harvestInfo.date)) { 233 return false; 234 } 235 if (!domainCfgName.equals(harvestInfo.domainCfgName)) { 236 return false; 237 } 238 if (!domainName.equals(harvestInfo.domainName)) { 239 return false; 240 } 241 if (!harvestID.equals(harvestInfo.harvestID)) { 242 return false; 243 } 244 if (!stopReason.equals(harvestInfo.stopReason)) { 245 return false; 246 } 247 248 return true; 249 } 250 251 /** 252 * Autogenerated from IDEA. 253 * 254 * @return hashcode 255 * @see Object#hashCode() 256 */ 257 public int hashCode() { 258 int result; 259 result = date.hashCode(); 260 result = 29 * result + harvestID.hashCode(); 261 result = 29 * result + (int) (countObjectRetrieved ^ (countObjectRetrieved >>> 32)); 262 result = 29 * result + (int) (sizeDataRetrieved ^ (sizeDataRetrieved >>> 32)); 263 result = 29 * result + stopReason.hashCode(); 264 result = 29 * result + domainName.hashCode(); 265 result = 29 * result + domainCfgName.hashCode(); 266 return result; 267 } 268 269 /** 270 * A human readable representation. 271 * 272 * @return A human readable representation 273 */ 274 public String toString() { 275 return "Harvest info for harvest #" + harvestID + " of " + domainName + "(" + domainCfgName + ")" + " on " 276 + date + "\n" + "Status: " + stopReason + "\n" + countObjectRetrieved + "objects / " 277 + sizeDataRetrieved + "bytes\n"; 278 } 279 280}