Skip to content

Commit

Permalink
[HWORKS-320] Pypi library versions not sorted correctly (logicalclock…
Browse files Browse the repository at this point in the history
  • Loading branch information
robzor92 authored Feb 22, 2023
1 parent 23645cc commit 5759eef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.ejb.TransactionAttributeType;
import javax.ws.rs.core.UriInfo;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -101,8 +102,8 @@ private LibrarySearchDTO buildItems(LibrarySearchDTO dto, UriInfo uriInfo,
Collection<PythonDep> installedDeps = project.getPythonDepCollection();
if (libVersions != null && !libVersions.isEmpty()) {
libVersions.forEach((k, v) -> dto.addItem(build(uriInfo, v, k, installedDeps, url)));
libVersions.forEach((k, v) -> Collections.sort(v));
}
return dto;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Objects;

@XmlRootElement
public class LibraryVersionDTO {
public class LibraryVersionDTO implements Comparable {

private String version;
private Date uploadTime;
Expand Down Expand Up @@ -71,4 +71,13 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(version);
}

@Override
public int compareTo(Object o) {
LibraryVersionDTO otherVersion = (LibraryVersionDTO)o;
if (otherVersion.getUploadTime() == null && this.getUploadTime() == null) return 0;
if (otherVersion.getUploadTime() == null) return -1;
if (this.getUploadTime() == null) return 1;
return this.getUploadTime().compareTo(otherVersion.getUploadTime());
}
}

0 comments on commit 5759eef

Please sign in to comment.