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
17 changes: 5 additions & 12 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,17 +618,11 @@ public LocalDate getMinRetentionDate() {
return minRetentionDate;
}

public LocalDate getMaxRetentionDate() {
Long maxMonths = 12000l; // Arbitrary cutoff at 1000 years - needs to keep maxDate < year 999999999 and
// somehwere 1K> x >10K years the datepicker widget stops showing a popup
// calendar
return LocalDate.now().plusMonths(maxMonths);
}

public boolean isValidRetentionDate(Retention r) {

if (r.getDateUnavailable()==null ||
isRetentionAllowed() && r.getDateUnavailable().isAfter(getMinRetentionDate())) {
var date = r.getDateUnavailable();
if (date == null ||
isRetentionAllowed() && date.isAfter(getMinRetentionDate().minusDays(1))) {
return true;
}

Expand Down Expand Up @@ -662,15 +656,14 @@ public void validateRetentionDate(FacesContext context, UIComponent component, O
Retention newR = new Retention(((LocalDate) value), null);
if (!isValidRetentionDate(newR)) {
String minDate = getMinRetentionDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String maxDate = getMaxRetentionDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String msgString = BundleUtil.getStringFromBundle("retention.date.invalid",
Arrays.asList(minDate, maxDate));
Arrays.asList(minDate));
// If we don't throw an exception here, the datePicker will use it's own
// vaidator and display a default message. The value for that can be set by
// adding validatorMessage="#{bundle['retention.date.invalid']}" (a version with
// no params) to the datepicker
// element in file-edit-popup-fragment.html, but it would be better to catch all
// problems here (so we can show a message with the min/max dates).
// problems here (so we can show a message with the min date).
FacesMessage msg = new FacesMessage(msgString);
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ public Response createFileRetention(@Context ContainerRequestContext crc, @PathP

// dateAvailable is within limits
if (minRetentionDateTime != null){
if (dateUnavailable.isBefore(minRetentionDateTime)){
if (dateUnavailable.isBefore(minRetentionDateTime.minusDays(1))){
return error(Status.BAD_REQUEST, "Date unavailable can not be earlier than MinRetentionDurationInMonths: "+minRetentionDurationInMonths + " from now");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ retention.after=Was retained until
retention.isfrom=Is retained until
retention.willbeafter=Draft: will be retained until
retention.enddateinfo=after which it will no longer be accessible
retention.date.invalid=Date is outside the allowed range: ({0} to {1})
retention.date.invalid=Date is before the allowed value: {0}
retention.date.required=A retention period end date is required
cancel=Cancel
ok=OK
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/file-edit-popup-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
value="#{bean.selectionRetention.dateUnavailable}"
locale="#{dataverseSession.localeCode}"
mindate="#{settingsWrapper.minRetentionDate}" pattern="yyyy-MM-dd"
maxdate="#{settingsWrapper.maxRetentionDate}"
disabled="#{bean.removeRetention}"
validator="#{settingsWrapper.validateRetentionDate}" >
<p:ajax process="#{updateRetentionElements}"
Expand Down
Loading