Skip to content

Commit

Permalink
upload limit, change from int to long. #2149
Browse files Browse the repository at this point in the history
  • Loading branch information
raprasad committed May 14, 2015
1 parent 6bc409f commit 51ff578
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public enum DisplayMode {

private DataFile selectedDownloadFile;

private Integer maxFileUploadSizeInBytes = null;
private Long maxFileUploadSizeInBytes = null;


/*
Save the setting locally so db isn't hit repeatedly
This may be "null", signifying unlimited download size
*/
public Integer getMaxFileUploadSizeInBytes(){
public Long getMaxFileUploadSizeInBytes(){
return this.maxFileUploadSizeInBytes;
}

Expand Down Expand Up @@ -507,7 +507,6 @@ public String getDropBoxSelection() {
public String getDropBoxKey() {
// Site-specific DropBox application registration key is configured
// via a JVM option under glassfish.

String configuredDropBoxKey = System.getProperty("dataverse.dropbox.key");
if (configuredDropBoxKey != null) {
return configuredDropBoxKey;
Expand Down Expand Up @@ -960,8 +959,8 @@ private void loadMapLayerMetadataLookup() {
public String init() {
// System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
String nonNullDefaultIfKeyNotFound = "";
this.maxFileUploadSizeInBytes = settingsService.getValueForKeyAsInt(SettingsServiceBean.Key.MaxFileUploadSizeInBytes);

this.maxFileUploadSizeInBytes = systemConfig.getMaxFileUploadSize();
guestbookResponse = new GuestbookResponse();
protocol = settingsService.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
authority = settingsService.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class SwordConfigurationImpl implements SwordConfiguration {

@EJB
SettingsServiceBean settingsService;
@EJB
SystemConfig systemConfig;

private static final Logger logger = Logger.getLogger(SwordConfigurationImpl.class.getCanonicalName());

Expand Down Expand Up @@ -126,12 +128,21 @@ public int getMaxUploadSize() {

int unlimited = -1;

Integer maxUploadInBytes = settingsService.getValueForKeyAsInt(SettingsServiceBean.Key.MaxFileUploadSizeInBytes);
Long maxUploadInBytes = systemConfig.getMaxFileUploadSize();

if (maxUploadInBytes == null){
return unlimited;
}
// (a) No setting, return unlimited
return unlimited;

}else if (maxUploadInBytes > Integer.MAX_VALUE){
// (b) setting returns the limit of int, return max int value (BUG)
return Integer.MAX_VALUE;

}else{
// (c) Return the setting as an int
return maxUploadInBytes.intValue();

return maxUploadInBytes;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ public List<DataFile> createDataFiles(DatasetVersion version, InputStream inputS
DataFile new_datafile = createSingleDataFile(version, finalFileInputStream, finalFile.getName(), finalType);
if (new_datafile != null) {
datafiles.add(new_datafile);
}else{
logger.severe("Could not add part of rezipped shapefile. new_datafile was null: " + finalFile.getName());
}
finalFileInputStream.close();

Expand All @@ -549,6 +551,8 @@ public List<DataFile> createDataFiles(DatasetVersion version, InputStream inputS

if (datafiles.size() > 0) {
return datafiles;
}else{
logger.severe("No files added from directory of rezipped shapefiles");
}
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public String getValueForKey( Key key ) {
* Attempt to convert the value to an integer
* - Applicable for keys such as MaxFileUploadSizeInBytes
*
* On failure (key not found or string not convertible to an int), returns null
* On failure (key not found or string not convertible to a long), returns null
* @param key
* @return
*/
public Integer getValueForKeyAsInt(Key key){
public Long getValueForKeyAsLong(Key key){

String val = this.getValueForKey(key);

Expand All @@ -195,15 +195,16 @@ public Integer getValueForKeyAsInt(Key key){
}

try {
int valAsInt = Integer.parseInt(val);
long valAsInt = Long.parseLong(val);
return valAsInt;
} catch (NumberFormatException ex) {
logger.warning("Incorrect setting. Could not convert \"" + val + "\" from setting " + key.toString() + " to int.");
logger.warning("Incorrect setting. Could not convert \"" + val + "\" from setting " + key.toString() + " to long.");
return null;
}

}


/**
* Return the value stored, or the default value, in case no setting by that
* name exists. The main difference between this method and the other {@code get()}s
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,12 @@ public boolean isDebugEnabled() {
boolean safeDefaultIfKeyNotFound = false;
return settingsService.isTrueForKey(SettingsServiceBean.Key.Debug, safeDefaultIfKeyNotFound);
}


public Long getMaxFileUploadSize(){

return settingsService.getValueForKeyAsLong(SettingsServiceBean.Key.MaxFileUploadSizeInBytes);
}


}

0 comments on commit 51ff578

Please sign in to comment.