Mercurial > hg > LGDataverses
comparison src/main/java/edu/harvard/iq/dataverse/DatasetVersionDifference.java @ 10:a50cf11e5178
Rewrite LGDataverse completely upgrading to dataverse4.0
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 08 Sep 2015 17:00:21 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:5926d6419569 | 10:a50cf11e5178 |
|---|---|
| 1 package edu.harvard.iq.dataverse; | |
| 2 | |
| 3 import java.util.ArrayList; | |
| 4 import java.util.Collections; | |
| 5 import java.util.Comparator; | |
| 6 import java.util.List; | |
| 7 import org.apache.commons.lang.StringUtils; | |
| 8 | |
| 9 /** | |
| 10 * | |
| 11 * @author skraffmiller | |
| 12 */ | |
| 13 public class DatasetVersionDifference { | |
| 14 | |
| 15 private DatasetVersion newVersion; | |
| 16 private DatasetVersion originalVersion; | |
| 17 private List<List> detailDataByBlock = new ArrayList<>(); | |
| 18 private List<datasetFileDifferenceItem> datasetFilesDiffList; | |
| 19 private List<FileMetadata> addedFiles = new ArrayList(); | |
| 20 private List<FileMetadata> removedFiles = new ArrayList(); | |
| 21 private List<FileMetadata> changedFileMetadata = new ArrayList(); | |
| 22 private List<Object[]> summaryDataForNote = new ArrayList(); | |
| 23 private List<Object[]> blockDataForNote = new ArrayList(); | |
| 24 String noFileDifferencesFoundLabel = ""; | |
| 25 | |
| 26 public DatasetVersionDifference(DatasetVersion newVersion, DatasetVersion originalVersion) { | |
| 27 setOriginalVersion(originalVersion); | |
| 28 setNewVersion(newVersion); | |
| 29 //Compare Data | |
| 30 for (DatasetField dsfo : originalVersion.getDatasetFields()) { | |
| 31 boolean deleted = true; | |
| 32 for (DatasetField dsfn : newVersion.getDatasetFields()) { | |
| 33 if (dsfo.getDatasetFieldType().equals(dsfn.getDatasetFieldType())) { | |
| 34 deleted = false; | |
| 35 if (dsfo.getDatasetFieldType().isPrimitive()) { | |
| 36 if (!dsfo.getDatasetFieldType().getFieldType().equals("email")) { | |
| 37 compareValues(dsfo, dsfn, false); | |
| 38 } | |
| 39 } else { | |
| 40 compareValues(dsfo, dsfn, true); | |
| 41 } | |
| 42 break; //if found go to next dataset field | |
| 43 } | |
| 44 } | |
| 45 if (deleted && !dsfo.isEmpty()) { | |
| 46 updateBlockSummary(dsfo, 0, dsfo.getDatasetFieldValues().size(), 0); | |
| 47 addToSummary(dsfo, null); | |
| 48 } | |
| 49 } | |
| 50 for (DatasetField dsfn : newVersion.getDatasetFields()) { | |
| 51 boolean added = true; | |
| 52 if (dsfn.getDatasetFieldType().isPrimitive()) { | |
| 53 for (DatasetField dsfo : originalVersion.getDatasetFields()) { | |
| 54 if (dsfo.getDatasetFieldType().equals(dsfn.getDatasetFieldType())) { | |
| 55 added = false; | |
| 56 break; | |
| 57 } | |
| 58 } | |
| 59 if (added && !dsfn.isEmpty()) { | |
| 60 updateBlockSummary(dsfn, dsfn.getDatasetFieldValues().size(), 0, 0); | |
| 61 addToSummary(null, dsfn); | |
| 62 } | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 for (FileMetadata fmdo : originalVersion.getFileMetadatas()) { | |
| 67 boolean deleted = true; | |
| 68 for (FileMetadata fmdn : newVersion.getFileMetadatas()) { | |
| 69 if (fmdo.getDataFile().equals(fmdn.getDataFile())) { | |
| 70 deleted = false; | |
| 71 if (!compareFileMetadatas(fmdo, fmdn)) { | |
| 72 changedFileMetadata.add(fmdo); | |
| 73 changedFileMetadata.add(fmdn); | |
| 74 } | |
| 75 break; | |
| 76 } | |
| 77 } | |
| 78 if (deleted) { | |
| 79 removedFiles.add(fmdo); | |
| 80 } | |
| 81 } | |
| 82 for (FileMetadata fmdn : newVersion.getFileMetadatas()) { | |
| 83 boolean added = true; | |
| 84 for (FileMetadata fmdo : originalVersion.getFileMetadatas()) { | |
| 85 if (fmdo.getDataFile().equals(fmdn.getDataFile())) { | |
| 86 added = false; | |
| 87 break; | |
| 88 } | |
| 89 } | |
| 90 if (added) { | |
| 91 addedFiles.add(fmdn); | |
| 92 } | |
| 93 } | |
| 94 initDatasetFilesDifferencesList(); | |
| 95 | |
| 96 //Sort within blocks by datasetfieldtype dispaly order then.... | |
| 97 //sort via metadatablock order - citation first... | |
| 98 for (List blockList : detailDataByBlock) { | |
| 99 Collections.sort(blockList, new Comparator<DatasetField[]>() { | |
| 100 public int compare(DatasetField[] l1, DatasetField[] l2) { | |
| 101 DatasetField dsfa = l1[0]; //(DatasetField[]) l1.get(0); | |
| 102 DatasetField dsfb = l2[0]; | |
| 103 int a = dsfa.getDatasetFieldType().getDisplayOrder(); | |
| 104 int b = dsfb.getDatasetFieldType().getDisplayOrder(); | |
| 105 return Integer.valueOf(a).compareTo(Integer.valueOf(b)); | |
| 106 } | |
| 107 }); | |
| 108 } | |
| 109 Collections.sort(detailDataByBlock, new Comparator<List>() { | |
| 110 public int compare(List l1, List l2) { | |
| 111 DatasetField dsfa[] = (DatasetField[]) l1.get(0); | |
| 112 DatasetField dsfb[] = (DatasetField[]) l2.get(0); | |
| 113 int a = dsfa[0].getDatasetFieldType().getMetadataBlock().getId().intValue(); | |
| 114 int b = dsfb[0].getDatasetFieldType().getMetadataBlock().getId().intValue(); | |
| 115 return Integer.valueOf(a).compareTo(Integer.valueOf(b)); | |
| 116 } | |
| 117 }); | |
| 118 } | |
| 119 | |
| 120 private void addToList(List listIn, DatasetField dsfo, DatasetField dsfn) { | |
| 121 DatasetField[] dsfArray; | |
| 122 dsfArray = new DatasetField[2]; | |
| 123 dsfArray[0] = dsfo; | |
| 124 dsfArray[1] = dsfn; | |
| 125 listIn.add(dsfArray); | |
| 126 } | |
| 127 | |
| 128 private void addToSummary(DatasetField dsfo, DatasetField dsfn) { | |
| 129 if (dsfo == null) { | |
| 130 dsfo = new DatasetField(); | |
| 131 dsfo.setDatasetFieldType(dsfn.getDatasetFieldType()); | |
| 132 } | |
| 133 if (dsfn == null) { | |
| 134 dsfn = new DatasetField(); | |
| 135 dsfn.setDatasetFieldType(dsfo.getDatasetFieldType()); | |
| 136 } | |
| 137 boolean addedToAll = false; | |
| 138 for (List blockList : detailDataByBlock) { | |
| 139 DatasetField dsft[] = (DatasetField[]) blockList.get(0); | |
| 140 if (dsft[0].getDatasetFieldType().getMetadataBlock().equals(dsfo.getDatasetFieldType().getMetadataBlock())) { | |
| 141 addToList(blockList, dsfo, dsfn); | |
| 142 addedToAll = true; | |
| 143 } | |
| 144 } | |
| 145 if (!addedToAll) { | |
| 146 List<DatasetField[]> newList = new ArrayList<>(); | |
| 147 addToList(newList, dsfo, dsfn); | |
| 148 detailDataByBlock.add(newList); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 private void updateBlockSummary(DatasetField dsf, int added, int deleted, int changed) { | |
| 153 | |
| 154 boolean addedToAll = false; | |
| 155 for (Object[] blockList : blockDataForNote) { | |
| 156 DatasetField dsft = (DatasetField) blockList[0]; | |
| 157 if (dsft.getDatasetFieldType().getMetadataBlock().equals(dsf.getDatasetFieldType().getMetadataBlock())) { | |
| 158 blockList[1] = (Integer) blockList[1] + added; | |
| 159 blockList[2] = (Integer) blockList[2] + deleted; | |
| 160 blockList[3] = (Integer) blockList[3] + changed; | |
| 161 addedToAll = true; | |
| 162 } | |
| 163 } | |
| 164 if (!addedToAll) { | |
| 165 Object[] newArray = new Object[4]; | |
| 166 newArray[0] = dsf; | |
| 167 newArray[1] = added; | |
| 168 newArray[2] = deleted; | |
| 169 newArray[3] = changed; | |
| 170 blockDataForNote.add(newArray); | |
| 171 } | |
| 172 | |
| 173 } | |
| 174 | |
| 175 private void addToNoteSummary(DatasetField dsfo, int added, int deleted, int changed) { | |
| 176 Object[] noteArray = new Object[4]; | |
| 177 noteArray[0] = dsfo; | |
| 178 noteArray[1] = added; | |
| 179 noteArray[2] = deleted; | |
| 180 noteArray[3] = changed; | |
| 181 summaryDataForNote.add(noteArray); | |
| 182 } | |
| 183 | |
| 184 private boolean compareFileMetadatas(FileMetadata fmdo, FileMetadata fmdn) { | |
| 185 | |
| 186 if (!StringUtils.equals(fmdo.getDescription(), fmdn.getDescription())) { | |
| 187 return false; | |
| 188 } | |
| 189 //if (!StringUtils.equals(fmdo.getCategory(), fmdn.getCategory())) { | |
| 190 // return false; | |
| 191 //} | |
| 192 if (!StringUtils.equals(fmdo.getLabel(), fmdn.getLabel())) { | |
| 193 return false; | |
| 194 } | |
| 195 | |
| 196 return true; | |
| 197 } | |
| 198 | |
| 199 private void compareValues(DatasetField originalField, DatasetField newField, boolean compound) { | |
| 200 String originalValue = ""; | |
| 201 String newValue = ""; | |
| 202 int countOriginal = 0; | |
| 203 int countNew = 0; | |
| 204 int totalAdded = 0; | |
| 205 int totalDeleted = 0; | |
| 206 int totalChanged = 0; | |
| 207 int loopIndex = 0; | |
| 208 | |
| 209 if (compound) { | |
| 210 for (DatasetFieldCompoundValue datasetFieldCompoundValueOriginal : originalField.getDatasetFieldCompoundValues()) { | |
| 211 if (newField.getDatasetFieldCompoundValues().size() >= loopIndex + 1) { | |
| 212 for (DatasetField dsfo : datasetFieldCompoundValueOriginal.getChildDatasetFields()) { | |
| 213 if (!dsfo.getDisplayValue().isEmpty()) { | |
| 214 originalValue += dsfo.getDisplayValue() + ", "; | |
| 215 } | |
| 216 } | |
| 217 for (DatasetField dsfn : newField.getDatasetFieldCompoundValues().get(loopIndex).getChildDatasetFields()) { | |
| 218 if (!dsfn.getDisplayValue().isEmpty()) { | |
| 219 newValue += dsfn.getDisplayValue() + ", "; | |
| 220 } | |
| 221 } | |
| 222 if (originalValue.isEmpty() && !newValue.isEmpty()) { | |
| 223 totalAdded++; | |
| 224 } else if (!newValue.isEmpty() && !originalValue.trim().equals(newValue.trim())) { | |
| 225 totalChanged++; | |
| 226 } | |
| 227 } | |
| 228 loopIndex++; | |
| 229 } | |
| 230 countNew = newField.getDatasetFieldCompoundValues().size(); | |
| 231 countOriginal = originalField.getDatasetFieldCompoundValues().size(); | |
| 232 } else { | |
| 233 int index = 0; | |
| 234 for (String valString : originalField.getValues()) { | |
| 235 if (valString != null && !valString.isEmpty()) { | |
| 236 countOriginal++; | |
| 237 } | |
| 238 } | |
| 239 for (String valString : newField.getValues()) { | |
| 240 if (valString != null && !valString.isEmpty()) { | |
| 241 countNew++; | |
| 242 } | |
| 243 } | |
| 244 String nString = ""; | |
| 245 originalValue = originalField.getDisplayValue(); | |
| 246 newValue = newField.getDisplayValue(); | |
| 247 for (String oString : originalField.getValues()) { | |
| 248 if (newField.getValues().size() >= (index + 1)) { | |
| 249 nString = newField.getValues().get(index); | |
| 250 } | |
| 251 if (nString != null && oString != null && !oString.trim().equals(nString.trim())) { | |
| 252 totalChanged++; | |
| 253 } | |
| 254 } | |
| 255 if (originalValue.equalsIgnoreCase(newValue)) { | |
| 256 totalChanged = 0; | |
| 257 } | |
| 258 } | |
| 259 | |
| 260 if (countNew > countOriginal) { | |
| 261 totalAdded = countNew - countOriginal; | |
| 262 } | |
| 263 | |
| 264 if (countOriginal > countNew) { | |
| 265 totalDeleted = countOriginal - countNew; | |
| 266 } | |
| 267 if ((totalAdded + totalDeleted + totalChanged) > 0) { | |
| 268 if (originalField.getDatasetFieldType().isDisplayOnCreate()) { | |
| 269 addToNoteSummary(originalField, totalAdded, totalDeleted, totalChanged); | |
| 270 addToSummary(originalField, newField); | |
| 271 } else { | |
| 272 updateBlockSummary(originalField, totalAdded, totalDeleted, totalChanged); | |
| 273 addToSummary(originalField, newField); | |
| 274 } | |
| 275 } | |
| 276 } | |
| 277 | |
| 278 public String getFileNote() { | |
| 279 String retString = ""; | |
| 280 | |
| 281 if (addedFiles.size() > 0) { | |
| 282 retString = "Files (Added: " + addedFiles.size(); | |
| 283 } | |
| 284 | |
| 285 if (removedFiles.size() > 0) { | |
| 286 if (retString.isEmpty()) { | |
| 287 retString = "Files (Removed: " + removedFiles.size(); | |
| 288 } else { | |
| 289 retString += "; Removed: " + removedFiles.size(); | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 if (changedFileMetadata.size() > 0) { | |
| 294 if (retString.isEmpty()) { | |
| 295 retString = "Files (Changed File Metadata: " + changedFileMetadata.size() / 2; | |
| 296 } else { | |
| 297 retString += "; Changed File Metadata: " + changedFileMetadata.size() / 2; | |
| 298 } | |
| 299 } | |
| 300 | |
| 301 if (!retString.isEmpty()) { | |
| 302 retString += ")"; | |
| 303 } | |
| 304 | |
| 305 return retString; | |
| 306 } | |
| 307 | |
| 308 public List<List> getDetailDataByBlock() { | |
| 309 return detailDataByBlock; | |
| 310 } | |
| 311 | |
| 312 public void setDetailDataByBlock(List<List> detailDataByBlock) { | |
| 313 this.detailDataByBlock = detailDataByBlock; | |
| 314 } | |
| 315 | |
| 316 public List<FileMetadata> getAddedFiles() { | |
| 317 return addedFiles; | |
| 318 } | |
| 319 | |
| 320 public void setAddedFiles(List<FileMetadata> addedFiles) { | |
| 321 this.addedFiles = addedFiles; | |
| 322 } | |
| 323 | |
| 324 public List<FileMetadata> getRemovedFiles() { | |
| 325 return removedFiles; | |
| 326 } | |
| 327 | |
| 328 public void setRemovedFiles(List<FileMetadata> removedFiles) { | |
| 329 this.removedFiles = removedFiles; | |
| 330 } | |
| 331 | |
| 332 public DatasetVersion getNewVersion() { | |
| 333 return newVersion; | |
| 334 } | |
| 335 | |
| 336 public void setNewVersion(DatasetVersion newVersion) { | |
| 337 this.newVersion = newVersion; | |
| 338 } | |
| 339 | |
| 340 public DatasetVersion getOriginalVersion() { | |
| 341 return originalVersion; | |
| 342 } | |
| 343 | |
| 344 public void setOriginalVersion(DatasetVersion originalVersion) { | |
| 345 this.originalVersion = originalVersion; | |
| 346 } | |
| 347 | |
| 348 public List<FileMetadata> getChangedFileMetadata() { | |
| 349 return changedFileMetadata; | |
| 350 } | |
| 351 | |
| 352 public void setChangedFileMetadata(List<FileMetadata> changedFileMetadata) { | |
| 353 this.changedFileMetadata = changedFileMetadata; | |
| 354 } | |
| 355 | |
| 356 public List<Object[]> getSummaryDataForNote() { | |
| 357 return summaryDataForNote; | |
| 358 } | |
| 359 | |
| 360 public List<Object[]> getBlockDataForNote() { | |
| 361 return blockDataForNote; | |
| 362 } | |
| 363 | |
| 364 public void setSummaryDataForNote(List<Object[]> summaryDataForNote) { | |
| 365 this.summaryDataForNote = summaryDataForNote; | |
| 366 } | |
| 367 | |
| 368 public void setBlockDataForNote(List<Object[]> blockDataForNote) { | |
| 369 this.blockDataForNote = blockDataForNote; | |
| 370 } | |
| 371 | |
| 372 private void initDatasetFilesDifferencesList() { | |
| 373 datasetFilesDiffList = new ArrayList<datasetFileDifferenceItem>(); | |
| 374 | |
| 375 // Study Files themselves are version-less; | |
| 376 // In other words, 2 different versions can have different sets of | |
| 377 // study files, but the files themselves don't have versions. | |
| 378 // So in order to find the differences between the 2 sets of study | |
| 379 // files in 2 versions we can just go through the lists of the | |
| 380 // files and compare the ids. If both versions have the file with | |
| 381 // the same file id, it is the same file. | |
| 382 // UPDATE: in addition to the above, even when the 2 versions share the | |
| 383 // same study file, the file metadatas ARE version-specific, so some of | |
| 384 // the fields there (filename, etc.) may be different. If this is the | |
| 385 // case, we want to display these differences as well. | |
| 386 if (originalVersion.getFileMetadatas().size() == 0 && newVersion.getFileMetadatas().size() == 0) { | |
| 387 noFileDifferencesFoundLabel = "No data files in either version of the study"; | |
| 388 return; | |
| 389 } | |
| 390 | |
| 391 int i = 0; | |
| 392 int j = 0; | |
| 393 | |
| 394 FileMetadata fm1; | |
| 395 FileMetadata fm2; | |
| 396 | |
| 397 Collections.sort(originalVersion.getFileMetadatas(), new Comparator<FileMetadata>() { | |
| 398 public int compare(FileMetadata l1, FileMetadata l2) { | |
| 399 FileMetadata fm1 = l1; //(DatasetField[]) l1.get(0); | |
| 400 FileMetadata fm2 = l2; | |
| 401 int a = fm1.getDataFile().getId().intValue(); | |
| 402 int b = fm2.getDataFile().getId().intValue(); | |
| 403 return Integer.valueOf(a).compareTo(Integer.valueOf(b)); | |
| 404 } | |
| 405 }); | |
| 406 | |
| 407 // Here's a potential problem: this new version may have been created | |
| 408 // specifically because new files are being added to the dataset. | |
| 409 // In which case there may be files associated with this new version | |
| 410 // with no database ids - since they haven't been saved yet. | |
| 411 // So if we try to sort the files in the version the way we did above, | |
| 412 // by ID, it may fail with a null pointer. | |
| 413 // To solve this, we should simply check if the file has the id; and if not, | |
| 414 // sort it higher than any file with an id - because it is a most recently | |
| 415 // added file. Since we are only doing this for the purposes of generating | |
| 416 // version differences, this should be OK. | |
| 417 // -- L.A. Aug. 2014 | |
| 418 | |
| 419 Collections.sort(newVersion.getFileMetadatas(), new Comparator<FileMetadata>() { | |
| 420 public int compare(FileMetadata l1, FileMetadata l2) { | |
| 421 FileMetadata fm1 = l1; //(DatasetField[]) l1.get(0); | |
| 422 FileMetadata fm2 = l2; | |
| 423 Long a = fm1.getDataFile().getId(); | |
| 424 Long b = fm2.getDataFile().getId(); | |
| 425 | |
| 426 if (a == null && b == null) { | |
| 427 return 0; | |
| 428 } else if (a == null) { | |
| 429 return 1; | |
| 430 } else if (b == null) { | |
| 431 return -1; | |
| 432 } | |
| 433 return a.compareTo(b); | |
| 434 } | |
| 435 }); | |
| 436 | |
| 437 while (i < originalVersion.getFileMetadatas().size() | |
| 438 && j < newVersion.getFileMetadatas().size()) { | |
| 439 fm1 = originalVersion.getFileMetadatas().get(i); | |
| 440 fm2 = newVersion.getFileMetadatas().get(j); | |
| 441 | |
| 442 if (fm2.getDataFile().getId() != null && fm1.getDataFile().getId().compareTo(fm2.getDataFile().getId()) == 0) { | |
| 443 // The 2 versions share the same study file; | |
| 444 // Check if the metadata information is identical in the 2 versions | |
| 445 // of the metadata: | |
| 446 if (fileMetadataIsDifferent(fm1, fm2)) { | |
| 447 datasetFileDifferenceItem fdi = selectFileMetadataDiffs(fm1, fm2); | |
| 448 fdi.setFileId(fm1.getDataFile().getId().toString()); | |
| 449 datasetFilesDiffList.add(fdi); | |
| 450 } | |
| 451 i++; | |
| 452 j++; | |
| 453 } else if (fm2.getDataFile().getId() != null && fm1.getDataFile().getId().compareTo(fm2.getDataFile().getId()) > 0) { | |
| 454 datasetFileDifferenceItem fdi = selectFileMetadataDiffs(null, fm2); | |
| 455 fdi.setFileId(fm2.getDataFile().getId().toString()); | |
| 456 datasetFilesDiffList.add(fdi); | |
| 457 | |
| 458 j++; | |
| 459 } else if (fm2.getDataFile().getId() == null || fm1.getDataFile().getId().compareTo(fm2.getDataFile().getId()) < 0) { | |
| 460 datasetFileDifferenceItem fdi = selectFileMetadataDiffs(fm1, null); | |
| 461 fdi.setFileId(fm1.getDataFile().getId().toString()); | |
| 462 datasetFilesDiffList.add(fdi); | |
| 463 | |
| 464 i++; | |
| 465 } | |
| 466 } | |
| 467 | |
| 468 // We've reached the end of at least one file list. | |
| 469 // Whatever files are left on either of the 2 lists are automatically "different" | |
| 470 // between the 2 versions. | |
| 471 while (i < originalVersion.getFileMetadatas().size()) { | |
| 472 fm1 = originalVersion.getFileMetadatas().get(i); | |
| 473 datasetFileDifferenceItem fdi = selectFileMetadataDiffs(fm1, null); | |
| 474 fdi.setFileId(fm1.getDataFile().getId().toString()); | |
| 475 datasetFilesDiffList.add(fdi); | |
| 476 | |
| 477 i++; | |
| 478 } | |
| 479 | |
| 480 while (j < newVersion.getFileMetadatas().size()) { | |
| 481 fm2 = newVersion.getFileMetadatas().get(j); | |
| 482 datasetFileDifferenceItem fdi = selectFileMetadataDiffs(null, fm2); | |
| 483 if (fm2.getDataFile().getId() != null) { | |
| 484 fdi.setFileId(fm2.getDataFile().getId().toString()); | |
| 485 } else { | |
| 486 fdi.setFileId("[UNASSIGNED]"); | |
| 487 } | |
| 488 datasetFilesDiffList.add(fdi); | |
| 489 | |
| 490 j++; | |
| 491 } | |
| 492 | |
| 493 if (datasetFilesDiffList.size() == 0) { | |
| 494 noFileDifferencesFoundLabel = "These study versions have identical sets of data files"; | |
| 495 } | |
| 496 } | |
| 497 | |
| 498 private boolean fileMetadataIsDifferent(FileMetadata fm1, FileMetadata fm2) { | |
| 499 if (fm1 == null && fm2 == null) { | |
| 500 return false; | |
| 501 } | |
| 502 | |
| 503 if (fm1 == null && fm2 != null) { | |
| 504 return true; | |
| 505 } | |
| 506 | |
| 507 if (fm2 == null && fm1 != null) { | |
| 508 return true; | |
| 509 } | |
| 510 | |
| 511 // Both are non-null metadata objects. | |
| 512 // We simply go through the 5 metadata fields, if any one of them | |
| 513 // is different between the 2 versions, we declare the objects | |
| 514 // different. | |
| 515 String value1; | |
| 516 String value2; | |
| 517 | |
| 518 // filename: | |
| 519 value1 = fm1.getLabel(); | |
| 520 value2 = fm2.getLabel(); | |
| 521 | |
| 522 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 523 value1 = ""; | |
| 524 } | |
| 525 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 526 value2 = ""; | |
| 527 } | |
| 528 | |
| 529 if (!value1.equals(value2)) { | |
| 530 return true; | |
| 531 } | |
| 532 | |
| 533 // file type: | |
| 534 value1 = fm1.getDataFile().getFriendlyType(); | |
| 535 value2 = fm2.getDataFile().getFriendlyType(); | |
| 536 | |
| 537 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 538 value1 = ""; | |
| 539 } | |
| 540 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 541 value2 = ""; | |
| 542 } | |
| 543 | |
| 544 if (!value1.equals(value2)) { | |
| 545 return true; | |
| 546 } | |
| 547 | |
| 548 // file size: | |
| 549 /* | |
| 550 value1 = FileUtil.byteCountToDisplaySize(new File(fm1.getStudyFile().getFileSystemLocation()).length()); | |
| 551 value2 = FileUtil.byteCountToDisplaySize(new File(fm2.getStudyFile().getFileSystemLocation()).length()); | |
| 552 | |
| 553 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 554 value1 = ""; | |
| 555 } | |
| 556 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 557 value2 = ""; | |
| 558 } | |
| 559 | |
| 560 if(!value1.equals(value2)) { | |
| 561 return true; | |
| 562 } | |
| 563 */ | |
| 564 // file category: | |
| 565 /*deprecated: value1 = fm1.getCategory(); | |
| 566 value2 = fm2.getCategory(); | |
| 567 | |
| 568 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 569 value1 = ""; | |
| 570 } | |
| 571 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 572 value2 = ""; | |
| 573 } | |
| 574 | |
| 575 if (!value1.equals(value2)) { | |
| 576 return true; | |
| 577 }*/ | |
| 578 | |
| 579 // file description: | |
| 580 value1 = fm1.getDescription(); | |
| 581 value2 = fm2.getDescription(); | |
| 582 | |
| 583 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 584 value1 = ""; | |
| 585 } | |
| 586 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 587 value2 = ""; | |
| 588 } | |
| 589 | |
| 590 if (!value1.equals(value2)) { | |
| 591 return true; | |
| 592 } | |
| 593 | |
| 594 // if we got this far, the 2 metadatas are identical: | |
| 595 return false; | |
| 596 } | |
| 597 | |
| 598 private datasetFileDifferenceItem selectFileMetadataDiffs(FileMetadata fm1, FileMetadata fm2) { | |
| 599 datasetFileDifferenceItem fdi = new datasetFileDifferenceItem(); | |
| 600 | |
| 601 if (fm1 == null && fm2 == null) { | |
| 602 // this should never happen; but if it does, | |
| 603 // we return an empty diff object. | |
| 604 | |
| 605 return fdi; | |
| 606 | |
| 607 } | |
| 608 if (fm2 == null) { | |
| 609 fdi.setFileName1(fm1.getLabel()); | |
| 610 fdi.setFileType1(fm1.getDataFile().getFriendlyType()); | |
| 611 //fdi.setFileSize1(FileUtil. (new File(fm1.getDataFile().getFileSystemLocation()).length())); | |
| 612 | |
| 613 // deprecated: fdi.setFileCat1(fm1.getCategory()); | |
| 614 fdi.setFileDesc1(fm1.getDescription()); | |
| 615 | |
| 616 fdi.setFile2Empty(true); | |
| 617 | |
| 618 } else if (fm1 == null) { | |
| 619 fdi.setFile1Empty(true); | |
| 620 | |
| 621 fdi.setFileName2(fm2.getLabel()); | |
| 622 fdi.setFileType2(fm2.getDataFile().getFriendlyType()); | |
| 623 //fdi.setFileSize2(FileUtil.byteCountToDisplaySize(new File(fm2.getStudyFile().getFileSystemLocation()).length())); | |
| 624 // deprecated: fdi.setFileCat2(fm2.getCategory()); | |
| 625 fdi.setFileDesc2(fm2.getDescription()); | |
| 626 | |
| 627 } else { | |
| 628 // Both are non-null metadata objects. | |
| 629 // We simply go through the 5 metadata fields, if any are | |
| 630 // different between the 2 versions, we add them to the | |
| 631 // difference object: | |
| 632 | |
| 633 String value1; | |
| 634 String value2; | |
| 635 | |
| 636 // filename: | |
| 637 value1 = fm1.getLabel(); | |
| 638 value2 = fm2.getLabel(); | |
| 639 | |
| 640 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 641 value1 = ""; | |
| 642 } | |
| 643 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 644 value2 = ""; | |
| 645 } | |
| 646 | |
| 647 if (!value1.equals(value2)) { | |
| 648 | |
| 649 fdi.setFileName1(value1); | |
| 650 fdi.setFileName2(value2); | |
| 651 } | |
| 652 | |
| 653 // NOTE: | |
| 654 // fileType and fileSize will always be the same | |
| 655 // for the same studyFile! -- so no need to check for differences in | |
| 656 // these 2 items. | |
| 657 // file category: | |
| 658 /* deprecated: value1 = fm1.getCategory(); | |
| 659 value2 = fm2.getCategory(); | |
| 660 | |
| 661 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 662 value1 = ""; | |
| 663 } | |
| 664 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 665 value2 = ""; | |
| 666 } | |
| 667 | |
| 668 if (!value1.equals(value2)) { | |
| 669 | |
| 670 fdi.setFileCat1(value1); | |
| 671 fdi.setFileCat2(value2); | |
| 672 } */ | |
| 673 | |
| 674 // file description: | |
| 675 value1 = fm1.getDescription(); | |
| 676 value2 = fm2.getDescription(); | |
| 677 | |
| 678 if (value1 == null || value1.equals("") || value1.equals(" ")) { | |
| 679 value1 = ""; | |
| 680 } | |
| 681 if (value2 == null || value2.equals("") || value2.equals(" ")) { | |
| 682 value2 = ""; | |
| 683 } | |
| 684 | |
| 685 if (!value1.equals(value2)) { | |
| 686 | |
| 687 fdi.setFileDesc1(value1); | |
| 688 fdi.setFileDesc2(value2); | |
| 689 } | |
| 690 } | |
| 691 return fdi; | |
| 692 } | |
| 693 | |
| 694 public class datasetFileDifferenceItem { | |
| 695 | |
| 696 public datasetFileDifferenceItem() { | |
| 697 } | |
| 698 | |
| 699 private String fileId; | |
| 700 | |
| 701 private String fileName1; | |
| 702 private String fileType1; | |
| 703 private String fileSize1; | |
| 704 private String fileCat1; | |
| 705 private String fileDesc1; | |
| 706 | |
| 707 private String fileName2; | |
| 708 private String fileType2; | |
| 709 private String fileSize2; | |
| 710 private String fileCat2; | |
| 711 private String fileDesc2; | |
| 712 | |
| 713 private boolean file1Empty = false; | |
| 714 private boolean file2Empty = false; | |
| 715 | |
| 716 public String getFileId() { | |
| 717 return fileId; | |
| 718 } | |
| 719 | |
| 720 public void setFileId(String fid) { | |
| 721 this.fileId = fid; | |
| 722 } | |
| 723 | |
| 724 public String getFileName1() { | |
| 725 return fileName1; | |
| 726 } | |
| 727 | |
| 728 public void setFileName1(String fn) { | |
| 729 this.fileName1 = fn; | |
| 730 } | |
| 731 | |
| 732 public String getFileType1() { | |
| 733 return fileType1; | |
| 734 } | |
| 735 | |
| 736 public void setFileType1(String ft) { | |
| 737 this.fileType1 = ft; | |
| 738 } | |
| 739 | |
| 740 public String getFileSize1() { | |
| 741 return fileSize1; | |
| 742 } | |
| 743 | |
| 744 public void setFileSize1(String fs) { | |
| 745 this.fileSize1 = fs; | |
| 746 } | |
| 747 | |
| 748 public String getFileCat1() { | |
| 749 return fileCat1; | |
| 750 } | |
| 751 | |
| 752 public void setFileCat1(String fc) { | |
| 753 this.fileCat1 = fc; | |
| 754 } | |
| 755 | |
| 756 public String getFileDesc1() { | |
| 757 return fileDesc1; | |
| 758 } | |
| 759 | |
| 760 public void setFileDesc1(String fd) { | |
| 761 this.fileDesc1 = fd; | |
| 762 } | |
| 763 | |
| 764 public String getFileName2() { | |
| 765 return fileName2; | |
| 766 } | |
| 767 | |
| 768 public void setFileName2(String fn) { | |
| 769 this.fileName2 = fn; | |
| 770 } | |
| 771 | |
| 772 public String getFileType2() { | |
| 773 return fileType2; | |
| 774 } | |
| 775 | |
| 776 public void setFileType2(String ft) { | |
| 777 this.fileType2 = ft; | |
| 778 } | |
| 779 | |
| 780 public String getFileSize2() { | |
| 781 return fileSize2; | |
| 782 } | |
| 783 | |
| 784 public void setFileSize2(String fs) { | |
| 785 this.fileSize2 = fs; | |
| 786 } | |
| 787 | |
| 788 public String getFileCat2() { | |
| 789 return fileCat2; | |
| 790 } | |
| 791 | |
| 792 public void setFileCat2(String fc) { | |
| 793 this.fileCat2 = fc; | |
| 794 } | |
| 795 | |
| 796 public String getFileDesc2() { | |
| 797 return fileDesc2; | |
| 798 } | |
| 799 | |
| 800 public void setFileDesc2(String fd) { | |
| 801 this.fileDesc2 = fd; | |
| 802 } | |
| 803 | |
| 804 public boolean isFile1Empty() { | |
| 805 return file1Empty; | |
| 806 } | |
| 807 | |
| 808 public boolean isFile2Empty() { | |
| 809 return file2Empty; | |
| 810 } | |
| 811 | |
| 812 public void setFile1Empty(boolean state) { | |
| 813 file1Empty = state; | |
| 814 } | |
| 815 | |
| 816 public void setFile2Empty(boolean state) { | |
| 817 file2Empty = state; | |
| 818 } | |
| 819 | |
| 820 } | |
| 821 | |
| 822 public List<datasetFileDifferenceItem> getDatasetFilesDiffList() { | |
| 823 return datasetFilesDiffList; | |
| 824 } | |
| 825 | |
| 826 public void setDatasetFilesDiffList(List<datasetFileDifferenceItem> datasetFilesDiffList) { | |
| 827 this.datasetFilesDiffList = datasetFilesDiffList; | |
| 828 } | |
| 829 | |
| 830 public String getNoFileDifferencesFoundLabel() { | |
| 831 return noFileDifferencesFoundLabel; | |
| 832 } | |
| 833 | |
| 834 public void setNoFileDifferencesFoundLabel(String noFileDifferencesFoundLabel) { | |
| 835 this.noFileDifferencesFoundLabel = noFileDifferencesFoundLabel; | |
| 836 } | |
| 837 } |
