Skip to content

Commit 65304cc

Browse files
committed
Sort source service /sources result by SourceKey.
1 parent 0e9eb71 commit 65304cc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/org/ohdsi/webapi/service/SourceService.java

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5+
import java.util.Collections;
6+
import java.util.Comparator;
57
import javax.ws.rs.GET;
68
import javax.ws.rs.Path;
79
import javax.ws.rs.PathParam;
@@ -18,6 +20,22 @@
1820
@Component
1921
public class SourceService extends AbstractDaoService {
2022

23+
public class SortByKey implements Comparator<SourceInfo>
24+
{
25+
private boolean isAscending;
26+
27+
public SortByKey(boolean ascending) {
28+
isAscending = ascending;
29+
}
30+
31+
public SortByKey() {
32+
this(true);
33+
}
34+
35+
public int compare(SourceInfo s1, SourceInfo s2) {
36+
return s1.sourceKey.compareTo(s2.sourceKey) * (isAscending ? 1 : -1);
37+
}
38+
}
2139
@Autowired
2240
private SourceRepository sourceRepository;
2341

@@ -33,6 +51,7 @@ public Collection<SourceInfo> getSources() {
3351
for (Source source : sourceRepository.findAll()) {
3452
sources.add(new SourceInfo(source));
3553
}
54+
Collections.sort(sources, new SortByKey());
3655
cachedSources = sources;
3756
}
3857
return cachedSources;

0 commit comments

Comments
 (0)