diff --git a/src/main/java/org/ohdsi/webapi/service/SourceService.java b/src/main/java/org/ohdsi/webapi/service/SourceService.java index 68a3085f84..45abacfa2f 100644 --- a/src/main/java/org/ohdsi/webapi/service/SourceService.java +++ b/src/main/java/org/ohdsi/webapi/service/SourceService.java @@ -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; @@ -18,6 +20,22 @@ @Component public class SourceService extends AbstractDaoService { + public class SortByKey implements Comparator + { + 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; @@ -33,6 +51,7 @@ public Collection getSources() { for (Source source : sourceRepository.findAll()) { sources.add(new SourceInfo(source)); } + Collections.sort(sources, new SortByKey()); cachedSources = sources; } return cachedSources;