Skip to content

Commit

Permalink
Merge pull request #6349 from IQSS/6099-refactor-index-files
Browse files Browse the repository at this point in the history
6099 refactor index files
  • Loading branch information
kcondon authored Nov 8, 2019
2 parents 5dca95d + 27c6e2e commit 41acae1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ public void setFileProvFree2(String fileProvFree2) {
}

public String getFileRest1() {
if(fileRest1 == null) return fileRest1;
String localeFileRest1 = BundleUtil.getStringFromBundle(fileRest1.toLowerCase().replace(" ", "_"));
return localeFileRest1;
}
Expand All @@ -1628,6 +1629,7 @@ public void setFileRest1(String fileRest1) {
}

public String getFileRest2() {
if(fileRest2 == null) return fileRest2;
String localeFileRest2 = BundleUtil.getStringFromBundle(fileRest2.toLowerCase().replace(" ", "_"));
return localeFileRest2;
}
Expand Down
56 changes: 10 additions & 46 deletions src/main/java/edu/harvard/iq/dataverse/FileMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,56 +511,20 @@ public boolean equals(Object object) {

return !((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)));
}


public boolean contentEquals(FileMetadata other) {
/*
* An experimental method for comparing 2 file metadatas *by content*; i.e.,
* this would be for checking 2 metadatas from 2 different versions, to
* determine if any of the actual metadata fields have changed between
* versions.
This method now invokes the logic contained in the FileVersionDifference compareMetadata method
so that the logic is in a single place
*/
public boolean contentEquals(FileMetadata other) {
if (other == null) {
return false;
}

if (this.getLabel() != null) {
if (!this.getLabel().equals(other.getLabel())) {
return false;
}
} else if (other.getLabel() != null) {
return false;
}

if (this.getDirectoryLabel() != null) {
if (!this.getDirectoryLabel().equals(other.getDirectoryLabel())) {
return false;
}
} else if (other.getDirectoryLabel() != null) {
return false;
}

if (this.getDescription() != null) {
if (!this.getDescription().equals(other.getDescription())) {
return false;
}
} else if (other.getDescription() != null) {
return false;
}
List<String> categoryNames =this.getCategoriesByName();
List<String> otherCategoryNames =other.getCategoriesByName();
if(!categoryNames.isEmpty()) {
categoryNames.sort(null);
otherCategoryNames.sort(null);
if (!categoryNames.equals(otherCategoryNames)) {
return false;
}
} else if(!otherCategoryNames.isEmpty()) {
return false;
}

return true;
return compareContent(other);
}


public boolean compareContent(FileMetadata other){
FileVersionDifference diffObj = new FileVersionDifference(this, other, false);
return diffObj.compareMetadata(this, other);
}

@Override
public String toString() {
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/FileVersionDifference.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author skraffmi
*/
public class FileVersionDifference {
public final class FileVersionDifference {

private FileMetadata newFileMetadata;
private FileMetadata originalFileMetadata;
Expand All @@ -43,28 +43,40 @@ public FileVersionDifference(FileMetadata newFileMetadata, FileMetadata original
}


private void compareMetadata(FileMetadata newFileMetadata, FileMetadata originalFileMetadata ){
public boolean compareMetadata(FileMetadata newFileMetadata, FileMetadata originalFileMetadata) {

/*
This method both determines if there has been a change in file metadata between the two versions supplied
and it updates the FileVersionDifference object which is used to display the differences on the dataset versions tab.
The return value is used by the index service bean tomark whether a file needs to be re-indexed in the context of a dataset update.
When there are changes (after v4.19)to the file metadata data model this method must be updated.
retVal of True means metadatas are equal.
*/

boolean retVal = true;
if (newFileMetadata.getDataFile() == null && originalFileMetadata == null){
//File in neither version
//Don't add any groups
return true;
}

if (newFileMetadata.getDataFile() == null && originalFileMetadata != null){
//File Deleted
updateDifferenceSummary("", BundleUtil.getStringFromBundle("file.versionDifferences.fileGroupTitle"), 0, 0, 1, 0);
return;
return false;
}

if (this.originalFileMetadata == null && this.newFileMetadata.getDataFile() != null ){
//File Added
retVal = false;
updateDifferenceSummary( "", BundleUtil.getStringFromBundle("file.versionDifferences.fileGroupTitle"), 1, 0, 0, 0);
}

//Check to see if File replaced
if (originalFileMetadata != null &&
newFileMetadata.getDataFile() != null && originalFileMetadata.getDataFile() != null &&!this.originalFileMetadata.getDataFile().equals(this.newFileMetadata.getDataFile())){
updateDifferenceSummary( "", BundleUtil.getStringFromBundle("file.versionDifferences.fileGroupTitle"), 0, 0, 0, 1);
retVal = false;
}

if ( originalFileMetadata != null) {
Expand All @@ -74,6 +86,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.fileNameDetailTitle"), 0, 1, 0, 0);
retVal = false;
}
}

Expand All @@ -87,6 +100,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.descriptionDetailTitle"), 0, 1, 0, 0);
retVal = false;
}
if (newFileMetadata.getDescription() != null
&& originalFileMetadata.getDescription() == null
Expand All @@ -96,6 +110,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.descriptionDetailTitle"), 1, 0, 0, 0);
retVal = false;
}
if (newFileMetadata.getDescription() == null
&& originalFileMetadata.getDescription() != null
Expand All @@ -105,8 +120,9 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.descriptionDetailTitle"), 0, 0, 1, 0);
retVal = false;
}
}
}
//Provenance Description differences
if ( originalFileMetadata != null) {
if ((newFileMetadata.getProvFreeForm() != null && !newFileMetadata.getProvFreeForm().isEmpty())
Expand All @@ -117,6 +133,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.provenanceDetailTitle"), 0, 1, 0, 0);
retVal = false;
}
if ((newFileMetadata.getProvFreeForm() != null && !newFileMetadata.getProvFreeForm().isEmpty())
&& (originalFileMetadata.getProvFreeForm() == null || originalFileMetadata.getProvFreeForm().isEmpty())
Expand All @@ -126,6 +143,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.provenanceDetailTitle"), 1, 0, 0, 0);
retVal = false;
}
if ((newFileMetadata.getProvFreeForm() == null || newFileMetadata.getProvFreeForm().isEmpty())
&& (originalFileMetadata.getProvFreeForm() != null && !originalFileMetadata.getProvFreeForm().isEmpty())
Expand All @@ -135,6 +153,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
}
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileMetadataGroupTitle"),
BundleUtil.getStringFromBundle("file.versionDifferences.provenanceDetailTitle"), 0, 0, 1, 0);
retVal = false;
}
}
if (originalFileMetadata != null) {
Expand Down Expand Up @@ -184,7 +203,7 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
if (deleted > 0){
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileTagsGroupTitle"), "", 0, 0, deleted, 0, true);
}

retVal = false;
}

/*
Expand All @@ -193,11 +212,11 @@ private void compareMetadata(FileMetadata newFileMetadata, FileMetadata original
value1 = originalFileMetadata.isRestricted() ? BundleUtil.getStringFromBundle("file.versionDifferences.fileRestricted") : BundleUtil.getStringFromBundle("file.versionDifferences.fileUnrestricted");
value2 = newFileMetadata.isRestricted() ? BundleUtil.getStringFromBundle("file.versionDifferences.fileRestricted") : BundleUtil.getStringFromBundle("file.versionDifferences.fileUnrestricted");
if (!value1.equals(value2)) {
if (!value1.equals(value2)) {
updateDifferenceSummary(BundleUtil.getStringFromBundle("file.versionDifferences.fileAccessTitle"), value2, 0, 0, 0, 0);
}
retVal = false;
}
}
return retVal;
}

private void updateDifferenceSummary(String groupLabel, String itemLabel, int added, int changed, int deleted, int replaced) {
Expand Down

0 comments on commit 41acae1

Please sign in to comment.