Skip to content

Commit

Permalink
Merge pull request #7312 from IQSS/7081-file-metadata-include
Browse files Browse the repository at this point in the history
Checksum truncation, click to copy + file metadata fragment code consolidation
  • Loading branch information
kcondon authored Feb 3, 2021
2 parents 1b18bfb + e9e99b4 commit 78a1044
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public DataFile findCheapAndEasy(Long id) {
// If content type indicates it's tabular data, spend 2 extra queries
// looking up the data table and tabular tags objects:

if (MIME_TYPE_TSV.equalsIgnoreCase(contentType)) {
if (MIME_TYPE_TSV.equalsIgnoreCase(contentType) || MIME_TYPE_TSV_ALT.equalsIgnoreCase(contentType)) {
Object[] dtResult;
try {
dtResult = (Object[]) em.createNativeQuery("SELECT ID, UNF, CASEQUANTITY, VARQUANTITY, ORIGINALFILEFORMAT, ORIGINALFILESIZE FROM dataTable WHERE DATAFILE_ID = " + id).getSingleResult();
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -1310,15 +1310,6 @@ public boolean isSuperUser(){
}
return false;
}
/*
TODO/OPTIMIZATION: This is still costing us N SELECT FROM GuestbookResponse queries,
where N is the number of files. This could of course be replaced by a query that'll
look up all N at once... Not sure if it's worth it; especially now that N
will always be 10, for the initial page load. -- L.A. 4.2.1
*/
public Long getGuestbookResponseCount(FileMetadata fileMetadata) {
return guestbookResponseService.getCountGuestbookResponsesByDataFileId(fileMetadata.getDataFile().getId());
}
/**
* Check Dataset related permissions
*
Expand Down Expand Up @@ -5107,15 +5098,7 @@ public String getPrivateUrlLink(PrivateUrl privateUrl) {
}


public FileDownloadHelper getFileDownloadHelper() {
return fileDownloadHelper;
}

public void setFileDownloadHelper(FileDownloadHelper fileDownloadHelper) {
this.fileDownloadHelper = fileDownloadHelper;
}


// todo: we should be able to remove - this is passed in the html pages to other fragments, but they could just access this service bean directly.
public FileDownloadServiceBean getFileDownloadService() {
return fileDownloadService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public final class DatasetVersionDifference {
private List<String[]> changedTermsAccess = new ArrayList<>();
private List<Object[]> summaryDataForNote = new ArrayList<>();
private List<Object[]> blockDataForNote = new ArrayList<>();
String noFileDifferencesFoundLabel = "";

private VariableMetadataUtil variableMetadataUtil;

Expand Down Expand Up @@ -104,7 +103,6 @@ public DatasetVersionDifference(DatasetVersion newVersion, DatasetVersion origin
addToSummary(null, dsfn);
}
}


// TODO: ?
// It looks like we are going through the filemetadatas in both versions,
Expand Down Expand Up @@ -493,7 +491,6 @@ private void addToSummary(DatasetField dsfo, DatasetField dsfn) {
}

private void updateBlockSummary(DatasetField dsf, int added, int deleted, int changed) {

boolean addedToAll = false;
for (Object[] blockList : blockDataForNote) {
DatasetField dsft = (DatasetField) blockList[0];
Expand All @@ -512,7 +509,6 @@ private void updateBlockSummary(DatasetField dsf, int added, int deleted, int ch
newArray[3] = changed;
blockDataForNote.add(newArray);
}

}

private void addToNoteSummary(DatasetField dsfo, int added, int deleted, int changed) {
Expand Down Expand Up @@ -552,8 +548,6 @@ private boolean compareVarGroup(FileMetadata fmdo, FileMetadata fmdn) {
}
}



private boolean compareFileMetadatas(FileMetadata fmdo, FileMetadata fmdn) {

if (!StringUtils.equals(fmdo.getDescription(), fmdn.getDescription())) {
Expand Down Expand Up @@ -786,7 +780,6 @@ private void initDatasetFilesDifferencesList() {
datasetFilesDiffList = new ArrayList<>();
datasetFilesReplacementList = new ArrayList <>();


// Study Files themselves are version-less;
// In other words, 2 different versions can have different sets of
// study files, but the files themselves don't have versions.
Expand All @@ -798,13 +791,6 @@ private void initDatasetFilesDifferencesList() {
// same study file, the file metadatas ARE version-specific, so some of
// the fields there (filename, etc.) may be different. If this is the
// case, we want to display these differences as well.

if (originalVersion.getFileMetadatas().isEmpty() && newVersion.getFileMetadatas().isEmpty()) {
noFileDifferencesFoundLabel = "No data files in either version of the study";
return;
}



int i = 0;
int j = 0;
Expand All @@ -825,7 +811,6 @@ private void initDatasetFilesDifferencesList() {

if (!replacedFiles.isEmpty()) {


replacedFiles.stream().map((replacedPair) -> {
FileMetadata replacedFile = replacedPair[0];
FileMetadata newFile = replacedPair[1];
Expand All @@ -851,7 +836,6 @@ private void initDatasetFilesDifferencesList() {

}


Collections.sort(fileMetadatasOriginal, (FileMetadata l1, FileMetadata l2) -> {
FileMetadata fm3 = l1; //(DatasetField[]) l1.get(0);
FileMetadata fm4 = l2;
Expand All @@ -871,7 +855,6 @@ private void initDatasetFilesDifferencesList() {
// added file. Since we are only doing this for the purposes of generating
// version differences, this should be OK.
// -- L.A. Aug. 2014


Collections.sort(fileMetadatasNew, (FileMetadata l1, FileMetadata l2) -> {
FileMetadata fm3 = l1; //(DatasetField[]) l1.get(0);
Expand Down Expand Up @@ -964,14 +947,6 @@ private void initDatasetFilesDifferencesList() {

j++;
}





if (datasetFilesDiffList.isEmpty()) {
noFileDifferencesFoundLabel = "These study versions have identical sets of data files";
}
}

private boolean fileMetadataIsDifferent(FileMetadata fm1, FileMetadata fm2) {
Expand Down Expand Up @@ -1080,12 +1055,8 @@ private boolean fileMetadataIsDifferent(FileMetadata fm1, FileMetadata fm2) {
return true;
}

//File restrictions

value1 = fm1.isRestricted() ? "Restricted" : "Not Restricted";
value2 = fm2.isRestricted() ? "Restricted" : "Not Restricted";

return !value1.equals(value2);
// File restrictions
return fm1.isRestricted() != fm2.isRestricted();
}

private datasetFileDifferenceItem selectFileMetadataDiffs(FileMetadata fm1, FileMetadata fm2) {
Expand All @@ -1109,7 +1080,7 @@ private datasetFileDifferenceItem selectFileMetadataDiffs(FileMetadata fm1, File
}

fdi.setFileProvFree1(fm1.getProvFreeForm());
fdi.setFileRest1(fm1.isRestricted() ? "Restricted" : "Not Restricted");
fdi.setFileRest1(fm1.isRestricted() ? BundleUtil.getStringFromBundle("restricted") : BundleUtil.getStringFromBundle("public"));
fdi.setFile2Empty(true);

} else if (fm1 == null) {
Expand All @@ -1125,7 +1096,7 @@ private datasetFileDifferenceItem selectFileMetadataDiffs(FileMetadata fm1, File
fdi.setFileCat2(fm2.getCategoriesByName().toString());
}
fdi.setFileProvFree2(fm2.getProvFreeForm());
fdi.setFileRest2(fm2.isRestricted() ? "Restricted" : "Not Restricted");
fdi.setFileRest2(fm2.isRestricted() ? BundleUtil.getStringFromBundle("restricted") : BundleUtil.getStringFromBundle("public"));
} else {
// Both are non-null metadata objects.
// We simply go through the 5 metadata fields, if any are
Expand Down Expand Up @@ -1206,11 +1177,9 @@ private datasetFileDifferenceItem selectFileMetadataDiffs(FileMetadata fm1, File
}

// file restricted:
value1 = fm1.isRestricted() ? "Restricted" : "Not Restricted";
value2 = fm2.isRestricted() ? "Restricted" : "Not Restricted";
if (!value1.equals(value2)) {
fdi.setFileRest1(value1);
fdi.setFileRest2(value2);
if (fm1.isRestricted() != fm2.isRestricted() ) {
fdi.setFileRest1(fm1.isRestricted() ? BundleUtil.getStringFromBundle("restricted") : BundleUtil.getStringFromBundle("public"));
fdi.setFileRest2(fm2.isRestricted() ? BundleUtil.getStringFromBundle("restricted") : BundleUtil.getStringFromBundle("public"));
}
}
return fdi;
Expand Down Expand Up @@ -1314,7 +1283,7 @@ public String getEditSummaryForLog() {
}

if (item.fileRest1 != null || item.fileRest2 != null) {
itemDiff += System.lineSeparator() + " " + BundleUtil.getStringFromBundle("file.viewDiffDialog.restricted") + ": ";
itemDiff += System.lineSeparator() + " " + BundleUtil.getStringFromBundle("file.viewDiffDialog.fileAccess") + ": ";
itemDiff += item.fileRest1 != null ? item.fileRest1 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable");
itemDiff += " : ";
itemDiff += item.fileRest2 != null ? item.fileRest2 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable") + " ";
Expand Down Expand Up @@ -1356,7 +1325,7 @@ public String getEditSummaryForLog() {
itemDiff += item.fdi.fileProvFree1 != null ? item.fdi.fileProvFree1 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable");
itemDiff += " : ";
itemDiff += item.fdi.fileProvFree2 != null ? item.fdi.fileProvFree2 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable") + " ";
itemDiff += System.lineSeparator() + " " + BundleUtil.getStringFromBundle("file.viewDiffDialog.restricted") + ": ";
itemDiff += System.lineSeparator() + " " + BundleUtil.getStringFromBundle("file.viewDiffDialog.fileAccess") + ": ";
itemDiff += item.fdi.fileRest1 != null ? item.fdi.fileRest1 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable");
itemDiff += " : ";
itemDiff += item.fdi.fileRest2 != null ? item.fdi.fileRest2 : BundleUtil.getStringFromBundle("file.viewDiffDialog.notAvailable") + " ";
Expand All @@ -1377,12 +1346,11 @@ public String getEditSummaryForLog() {
retVal +=termsOfUseDiff;
}


return retVal;
}


public class DifferenceSummaryGroup{
public class DifferenceSummaryGroup {

private String displayName;
private String type;
Expand Down Expand Up @@ -1411,8 +1379,6 @@ public List<DifferenceSummaryItem> getDifferenceSummaryItems() {
public void setDifferenceSummaryItems(List<DifferenceSummaryItem> differenceSummaryItems) {
this.differenceSummaryItems = differenceSummaryItems;
}


}

public class DifferenceSummaryItem {
Expand Down Expand Up @@ -1470,9 +1436,6 @@ public boolean isMultiple() {
public void setMultiple(boolean multiple) {
this.multiple = multiple;
}



}

public class datasetReplaceFileItem {
Expand Down Expand Up @@ -1733,7 +1696,6 @@ public String getFileChecksumValue() {
public void setFileChecksumValue(String fileChecksumValue) {
this.fileChecksumValue = fileChecksumValue;
}

}

public List<datasetFileDifferenceItem> getDatasetFilesDiffList() {
Expand All @@ -1744,11 +1706,4 @@ public void setDatasetFilesDiffList(List<datasetFileDifferenceItem> datasetFiles
this.datasetFilesDiffList = datasetFilesDiffList;
}

public String getNoFileDifferencesFoundLabel() {
return noFileDifferencesFoundLabel;
}

public void setNoFileDifferencesFoundLabel(String noFileDifferencesFoundLabel) {
this.noFileDifferencesFoundLabel = noFileDifferencesFoundLabel;
}
}
14 changes: 0 additions & 14 deletions src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2453,20 +2453,6 @@ public boolean isLocked() {
return false;
}

public boolean isThumbnailAvailable(FileMetadata fileMetadata) {
// new and optimized logic:
// - check download permission here (should be cached - so it's free!)
// - only then ask the file service if the thumbnail is available/exists.
// the service itself no longer checks download permissions.
if (!fileDownloadHelper.canDownloadFile(fileMetadata)) {
return false;
}

return datafileService.isThumbnailAvailable(fileMetadata.getDataFile());
}



private Boolean lockedFromEditsVar;

public boolean isLockedFromEdits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,53 +1201,52 @@ public SearchException getSearchException() {
}

public String tabularDataDisplayInfo(DataFile datafile) {
String ret = "";
String tabInfo = "";

if (datafile == null) {
return null;
return "";
}

if (datafile.isTabularData() && datafile.getDataTable() != null) {
DataTable datatable = datafile.getDataTable();
String unf = datatable.getUnf();
Long varNumber = datatable.getVarQuantity();
Long obsNumber = datatable.getCaseQuantity();
if (varNumber != null && varNumber.intValue() != 0) {
ret = ret.concat(varNumber + " Variables");
tabInfo = tabInfo.concat(varNumber + " " + BundleUtil.getStringFromBundle("file.metaData.dataFile.dataTab.variables"));
if (obsNumber != null && obsNumber.intValue() != 0) {
ret = ret.concat(", " + obsNumber + " Observations");
tabInfo = tabInfo.concat(", " + obsNumber + " " + BundleUtil.getStringFromBundle("file.metaData.dataFile.dataTab.observations"));
}
ret = ret.concat(" - ");
}
if (unf != null && !unf.equals("")) {
ret = ret.concat("UNF: " + unf);
}
}

return ret;
return tabInfo;
}

public String tabularDataUnfDisplay(DataFile datafile) {
String tabUnf = "";

public String dataFileSizeDisplay(DataFile datafile) {
if (datafile == null) {
return "";
}

return datafile.getFriendlySize();
if (datafile.isTabularData() && datafile.getDataTable() != null) {
DataTable datatable = datafile.getDataTable();
String unf = datatable.getUnf();
if (unf != null && !unf.equals("")) {
tabUnf = tabUnf.concat(unf);
}
}

return tabUnf;
}

public String dataFileChecksumDisplay(DataFile datafile) {
public String dataFileSizeDisplay(DataFile datafile) {
if (datafile == null) {
return "";
}

if (datafile.getChecksumValue() != null && !StringUtils.isEmpty(datafile.getChecksumValue())) {
if (datafile.getChecksumType() != null) {
return " " + datafile.getChecksumType() + ": " + datafile.getChecksumValue() + " ";
}
}
return datafile.getFriendlySize();

return "";
}

public void setDisplayCardValues() {
Expand Down
Loading

0 comments on commit 78a1044

Please sign in to comment.