Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1490,11 +1490,16 @@ public UploadSessionQuotaLimit getUploadSessionQuotaLimit(DvObjectContainer pare
// Note that we are checking the recorded storage use not on the
// immediate parent necessarily, but on the specific ancestor
// DvObjectContainer on which the storage quota is defined:
Long currentSize = storageUseService.findStorageSizeByDvContainerId(testDvContainer.getId());
Long currentSize = currentStorageSizeInBytes(testDvContainer);

return new UploadSessionQuotaLimit(quota.getAllocation(), currentSize);
}

public Long currentStorageSizeInBytes(DvObjectContainer dvObjectContainer) {
return storageUseService.findStorageSizeByDvContainerId(dvObjectContainer.getId() != null ?
dvObjectContainer.getId() : dvObjectContainer.getOwner().getId());
}

public boolean isInReleasedVersion(Long id) {
Query query = em.createNativeQuery("SELECT fm.id FROM filemetadata fm WHERE fm.datasetversion_id=(SELECT dv.id FROM datasetversion dv, dvobject dvo WHERE dv.dataset_id=dvo.owner_id AND dv.versionState='RELEASED' and dvo.id=" + id + " ORDER BY dv.versionNumber DESC, dv.minorVersionNumber DESC LIMIT 1) AND fm.datafile_id=" + id);

Expand Down
22 changes: 14 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@
import edu.harvard.iq.dataverse.license.LicenseServiceBean;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.Setting;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.storageuse.UploadSessionQuotaLimit;
import edu.harvard.iq.dataverse.util.FileUtil;
import edu.harvard.iq.dataverse.util.JsfHelper;
import edu.harvard.iq.dataverse.util.SystemConfig;
import edu.harvard.iq.dataverse.util.WebloaderUtil;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.EjbUtil;
import edu.harvard.iq.dataverse.util.FileMetadataUtil;
import edu.harvard.iq.dataverse.util.*;

import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
import java.io.File;
Expand Down Expand Up @@ -188,6 +181,8 @@ public enum Referrer {

private String versionString = "";

private String storageSizeStr;

private boolean saveEnabled = false;

// Used to store results of permissions checks
Expand Down Expand Up @@ -567,6 +562,17 @@ public boolean isFileUploadCountExceeded() {
return !ignoreLimit && !isFileReplaceOperation() && fileUploadsAvailable != null && fileUploadsAvailable == 0;
}

/**
*
* @return cached formatted storage size. '1,234 bytes'; '1.23 GB'; '1.00 TB'
*/
public String getCurrentContainerStorageUse() {
if (storageSizeStr == null) {
storageSizeStr = StringUtil.formatBytes(datafileService.currentStorageSizeInBytes(dataset.getOwner()));
}
return storageSizeStr;
}

public String init() {
// default mode should be EDIT
if (mode == null) {
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.BadPaddingException;
Expand Down Expand Up @@ -237,4 +232,26 @@ static public String normalize(String sentence) {

return sentence;
}

public static final long BYTES_PER_KB = 1024L;
public static final long BYTES_PER_MB = BYTES_PER_KB * 1024L;
public static final long BYTES_PER_GB = BYTES_PER_MB * 1024L;
public static final long BYTES_PER_TB = BYTES_PER_GB * 1024L;
static public String formatBytes(long bytes) {
if (bytes < BYTES_PER_KB) {
return NumberFormat.getNumberInstance().format(bytes) + " bytes";
} else {
double dBytes = bytes;
NumberFormat formatter = new DecimalFormat("#,##0.00");
if (bytes < BYTES_PER_MB) {
return formatter.format(dBytes / BYTES_PER_KB) + " KB";
} else if (bytes < BYTES_PER_GB) {
return formatter.format(dBytes / BYTES_PER_MB) + " MB";
} else if (bytes < BYTES_PER_TB) {
return formatter.format(dBytes / BYTES_PER_GB) + " GB";
} else {
return formatter.format(dBytes / BYTES_PER_TB) + " TB";
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,7 @@ file.selectToAdd.tipMaxNumFilesUploadsAvailable=Maximum of {0} {0, choice, 0#fil
file.selectToAdd.tipTabularLimit=<a href="{0}/{1}/user/dataset-management.html#tabular-data-files" title="Tabular Data Files - Dataverse User Guide" target="_blank" rel="noopener">Tabular file ingest</a> is limited to {2}.
file.selectToAdd.tipPerFileTabularLimit=Ingest is limited to the following file sizes based on their format: {0}.
file.selectToAdd.tipMoreInformation=Select files or drag and drop into the upload widget.
file.selectToAdd.tipTotalSizeUsed=Total size of Collection: {0}.
file.selectToAdd.dragdropMsg=Drag and drop files here.
file.createUploadDisabled=Upload files using rsync via SSH. This method is recommended for large file transfers. The upload script will be available on the Upload Files page once you save this dataset.
file.fromHTTP=Upload with HTTP via your browser
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/editFilesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<f:param value="#{systemConfig.guidesBaseUrl}"/>
<f:param value="#{systemConfig.guidesVersion}"/>
</h:outputFormat>
<h:outputFormat value=" #{bundle['file.selectToAdd.tipTotalSizeUsed']}" escape="false">
<f:param value="#{EditDatafilesPage.currentContainerStorageUse}"/>
</h:outputFormat>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're adding this to JSF? What about the SPA?

Copy link
Contributor Author

@stevenwinship stevenwinship Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPA can call the API to get the storage size for display if they don't now

curl -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/storage/use"

<h:outputFormat value=" #{bundle['file.selectToAdd.tipMaxNumFiles']}" escape="false"
rendered="#{EditDatafilesPage.maxNumberOfFiles > 0}">
<f:param value="#{EditDatafilesPage.maxNumberOfFiles}"/>
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/util/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,16 @@ public void testNormalize() {

// TODO: organization examples...
}

@Test
public void testFormatBytes() {
assertEquals("1,023 bytes", StringUtil.formatBytes(StringUtil.BYTES_PER_KB - 1));
assertEquals("1,024.00 KB", StringUtil.formatBytes(StringUtil.BYTES_PER_MB - 1));
assertEquals("1,024.00 MB", StringUtil.formatBytes(StringUtil.BYTES_PER_GB - 1));
assertEquals("1.00 GB", StringUtil.formatBytes(StringUtil.BYTES_PER_GB));
assertEquals("341.33 GB", StringUtil.formatBytes(StringUtil.BYTES_PER_TB / 3));
assertEquals("1.29 GB", StringUtil.formatBytes(StringUtil.BYTES_PER_GB + 312345678)); // 1386087502 / 1073741824 = 1.290894581
assertEquals("1.49 TB", StringUtil.formatBytes(StringUtil.BYTES_PER_TB + (StringUtil.BYTES_PER_GB * 500))); // 1636382539776 / 1099511627776 = 1.48828125
}
}
}