Skip to content
Open
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
45 changes: 39 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@

@OneToMany(mappedBy = "datasetVersion", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
@OrderBy("label") // this is not our preferred ordering, which is with the AlphaNumericComparator, but does allow the files to be grouped by category
private List<FileMetadata> fileMetadatas = new ArrayList();

Check warning on line 140 in src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java

View workflow job for this annotation

GitHub Actions / (Stable / JDK 21) Unit Tests

unchecked conversion

@OneToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, orphanRemoval=true)
@JoinColumn(name = "termsOfUseAndAccess_id")
private TermsOfUseAndAccess termsOfUseAndAccess;

@OneToMany(mappedBy = "datasetVersion", orphanRemoval = true, cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
private List<DatasetField> datasetFields = new ArrayList();

Check warning on line 147 in src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java

View workflow job for this annotation

GitHub Actions / (Stable / JDK 21) Unit Tests

unchecked conversion

@Temporal(value = TemporalType.TIMESTAMP)
@Column( nullable=false )
Expand Down Expand Up @@ -197,6 +197,15 @@
@OrderBy("createTime DESC NULLS LAST")
private List<CurationStatus> curationStatuses = new ArrayList<>();

@Transient
private Map<CurationStatus, Date> keyCache = curationStatuses.stream()
.collect(Collectors.toMap(
cs -> cs,
CurationStatus::getCreateTime,
(a, b) -> a,
IdentityHashMap::new
));

@Transient
private DatasetVersionDifference dvd;

Expand Down Expand Up @@ -2140,31 +2149,55 @@
* The code here assured both the DESC order and NULLS LAST.
*/
if (curationStatuses != null) {
curationStatuses.sort(Comparator.comparing(
CurationStatus::getCreateTime,
Comparator.nullsLast(Comparator.reverseOrder())
));
curationStatuses.sort(
Comparator.comparing(
keyCache::get,
Comparator.nullsLast(Comparator.reverseOrder())
)
);
}
return curationStatuses;
}

protected void setCurationStatuses(List<CurationStatus> curationStatuses) {
this.curationStatuses = curationStatuses;
keyCache = curationStatuses.stream()
.collect(Collectors.toMap(
cs -> cs,
CurationStatus::getCreateTime,
(a, b) -> a,
IdentityHashMap::new
));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you make this a method to avoid repeating the code several times? (I see it's one line, but it would be nice to not have to check that the multiple uses are all the same.)

}

public CurationStatus getCurrentCurationStatus() {
return !getCurationStatuses().isEmpty() ? getCurationStatuses().get(0) : null;
return !getCurationStatuses().isEmpty() ? getCurationStatuses().getFirst() : null;
}


public void addCurationStatus(CurationStatus status) {
status.setDatasetVersion(this);
curationStatuses.add(0, status); // Add the new status at the beginning of the list
curationStatuses.addFirst(status); // Add the new status at the beginning of the list
// After that cache the keys
keyCache = curationStatuses.stream()
.collect(Collectors.toMap(
cs -> cs,
CurationStatus::getCreateTime,
(a, b) -> a,
IdentityHashMap::new
));
}

public void removeCurationStatus(CurationStatus curationStatus) {
curationStatuses.remove(curationStatus);
curationStatus.setDatasetVersion(null);
keyCache = curationStatuses.stream()
.collect(Collectors.toMap(
cs -> cs,
CurationStatus::getCreateTime,
(a, b) -> a,
IdentityHashMap::new
));
}

public CurationStatus getCurationStatusAsOfDate(Date date) {
Expand Down
Loading