Skip to content

Commit

Permalink
Sort source service /sources result by SourceKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisknoll committed Jul 27, 2016
1 parent 0e9eb71 commit 65304cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/ohdsi/webapi/service/SourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -18,6 +20,22 @@
@Component
public class SourceService extends AbstractDaoService {

public class SortByKey implements Comparator<SourceInfo>
{
private boolean isAscending;

public SortByKey(boolean ascending) {
isAscending = ascending;
}

public SortByKey() {
this(true);
}

public int compare(SourceInfo s1, SourceInfo s2) {
return s1.sourceKey.compareTo(s2.sourceKey) * (isAscending ? 1 : -1);
}
}
@Autowired
private SourceRepository sourceRepository;

Expand All @@ -33,6 +51,7 @@ public Collection<SourceInfo> getSources() {
for (Source source : sourceRepository.findAll()) {
sources.add(new SourceInfo(source));
}
Collections.sort(sources, new SortByKey());
cachedSources = sources;
}
return cachedSources;
Expand Down

0 comments on commit 65304cc

Please sign in to comment.