1 18 19 package sync4j.syncclient.spap; 20 21 import java.sql.Timestamp ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.text.SimpleDateFormat ; 25 26 27 46 public class Asset { 47 48 50 public static final String STATE_NEW = "N"; 52 public static final String STATE_UPDATE = "U"; 53 public static final String STATE_DELETE = "D"; 54 public static final String STATE_ASSET_INSTALLED = "AI"; 55 public static final String STATE_FILE_DOWNLOAD = "FD"; 56 public static final String STATE_FILE_EXTRACTED = "FE"; 57 public static final String STATE_PREVIOUS_VERSION_UNINSTALLED = "PVU"; 58 public static final String STATE_NEW_VERSION_NOT_WANTED = "NVNW"; 59 public static final String STATE_NOT_VALID = "NV"; 60 61 62 public static final String PROPERTY_ID = "id"; 65 public static final String PROPERTY_NAME = "name"; 66 public static final String PROPERTY_MANUFACTURER = "manufacturer"; 67 public static final String PROPERTY_DESCRIPTION = "description"; 68 public static final String PROPERTY_STATE = "state"; 69 public static final String PROPERTY_LAST_UPDATE = "last_update"; 70 71 72 74 77 private String id; 78 79 85 public void setId(String id) { 86 this.id = id; 87 } 88 89 92 public String getId() { 93 return id; 94 } 95 96 99 private String manufacturer; 100 101 107 public void setManufacturer(String manufacturer) { 108 this.manufacturer = manufacturer; 109 } 110 111 114 public String getManufacturer() { 115 return manufacturer; 116 } 117 118 119 122 private String name; 123 124 130 public void setName(String name) { 131 this.name = name; 132 } 133 134 137 public String getName() { 138 return name; 139 } 140 141 142 145 private String description; 146 147 153 public void setDescription(String description) { 154 this.description = description; 155 } 156 157 160 public String getDescription() { 161 return description; 162 } 163 164 167 private String state; 168 169 175 public void setState(String state) { 176 this.state = state; 177 } 178 179 182 public String getState() { 183 return state; 184 } 185 186 189 private Timestamp lastUpdate; 190 191 197 public void setLastUpdate(Timestamp lastUpdate) { 198 this.lastUpdate = lastUpdate; 199 } 200 201 204 public Timestamp getLastUpdate() { 205 return lastUpdate; 206 } 207 208 209 212 private AssetVersion currentVersion; 213 214 220 public void setCurrentVersion(AssetVersion currentVersion) { 221 this.currentVersion = currentVersion; 222 } 223 224 227 public AssetVersion getCurrentVersion() { 228 return currentVersion; 229 } 230 231 232 235 private AssetVersion newVersion; 236 237 243 public void setNewVersion(AssetVersion newVersion) { 244 this.newVersion = newVersion; 245 } 246 247 250 public AssetVersion getNewVersion() { 251 return newVersion; 252 } 253 254 255 257 260 public Asset(Map values) { 261 this.id = (String )values.get(PROPERTY_ID); 262 this.manufacturer = (String )values.get(PROPERTY_MANUFACTURER); 263 this.name = (String )values.get(PROPERTY_NAME); 264 this.description = (String )values.get(PROPERTY_DESCRIPTION); 265 this.state = (String )values.get(PROPERTY_STATE); 266 267 String lastUpdate = (String )values.get(PROPERTY_LAST_UPDATE); 272 if (lastUpdate != null) { 273 try { 274 SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.S"); 275 this.lastUpdate = new Timestamp (format.parse(lastUpdate).getTime()); 276 } catch (Exception e1) { 277 try { 278 this.lastUpdate = new Timestamp (Long.parseLong(lastUpdate)); 279 } catch (Exception e2) { 280 throw new IllegalArgumentException ( 281 "'" + 282 lastUpdate + 283 "' is neither a date (yyyy-MM-dd HH:mm:ss.S) " + 284 "nor a timestamp in milliseconds." 285 ); 286 } 287 288 } 289 } 290 } 291 292 298 public Asset(Map values, boolean buildNewVersion) { 299 this(values); 300 301 if (buildNewVersion) { 302 newVersion = new AssetVersion(values); 303 } 304 } 305 306 308 312 public void setCurrentVersion(Map values) { 313 currentVersion = new AssetVersion(values); 314 } 315 316 320 public void setNewVersion(Map values) { 321 newVersion = new AssetVersion(values); 322 } 323 324 328 public Map toMap() { 329 Map map = new HashMap (); 330 331 map.put(PROPERTY_ID, getId()); 332 map.put(PROPERTY_NAME,getName()); 333 map.put(PROPERTY_DESCRIPTION,getDescription()); 334 map.put(PROPERTY_MANUFACTURER,getManufacturer()); 335 map.put(PROPERTY_STATE, getState()); 336 map.put(PROPERTY_LAST_UPDATE, getLastUpdate()); 337 338 return map; 339 } 340 341 342 346 public String toString() { 347 StringBuffer sb = new StringBuffer ("Asset: \n"); 348 349 sb.append("\tId: "); 350 sb.append(getId()); 351 sb.append("\n\tName: "); 352 sb.append(getName()); 353 sb.append("\n\tManufacturer: "); 354 sb.append(getManufacturer()); 355 sb.append("\n\tDescription: "); 356 sb.append(getDescription()); 357 sb.append("\n\tState: "); 358 sb.append(getState()); 359 sb.append("\n\tLast update: "); 360 sb.append(getLastUpdate()); 361 362 sb.append("\n\t----"); 363 sb.append("\n\tCurrentVersion: \n"); 364 if (currentVersion!=null) { 365 sb.append(currentVersion.toString()); 366 } else { 367 sb.append("\t\tNot found\n"); 368 }; 369 sb.append("\n\t----\n"); 370 sb.append("\tNewVersion: \n"); 371 if (newVersion!=null) { 372 sb.append(newVersion.toString()); 373 } else { 374 sb.append("\t\tNot found"); 375 } 376 377 return sb.toString(); 378 } 379 380 381 } | Popular Tags |