-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Sikina
committed
Jan 11, 2024
1 parent
9038861
commit e1a48cb
Showing
7 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
uploader/src/main/java/edu/harvard/dbmi/avillach/dataupload/site/SiteConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package edu.harvard.dbmi.avillach.dataupload.site; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
@Configuration | ||
public class SiteConfiguration { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SiteConfiguration.class); | ||
|
||
@Value("${aws.s3.institution:}") | ||
private List<String> allSites; | ||
|
||
@Value("${institution.name}") | ||
private String home; | ||
|
||
@Value("${institution.short-display}") | ||
private String display; | ||
|
||
@Autowired | ||
private ConfigurableApplicationContext context; | ||
|
||
@Bean | ||
public SiteListing getSiteInfo() { | ||
List<String> otherSites = allSites.stream().filter(Predicate.not(home::equals)).toList(); | ||
if (otherSites.size() == allSites.size()) { | ||
LOG.error("Home site {} not present in listing of institutions: {}", home, allSites); | ||
context.close(); | ||
return new SiteListing(List.of(), "", ""); | ||
} | ||
|
||
// we want the home inst first. Makes frontend display a bit nicer | ||
List<String> sites = Stream.concat(Stream.of(home), otherSites.stream()).toList(); | ||
|
||
return new SiteListing(sites, home, display); | ||
} | ||
} |
12 changes: 5 additions & 7 deletions
12
...ach/dataupload/upload/SiteController.java → ...llach/dataupload/site/SiteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
package edu.harvard.dbmi.avillach.dataupload.upload; | ||
package edu.harvard.dbmi.avillach.dataupload.site; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
import java.util.List; | ||
|
||
@Controller | ||
public class SiteController { | ||
|
||
@Value("${aws.s3.institution:}") | ||
private List<String> institutions; | ||
@Autowired | ||
private SiteListing institutions; | ||
|
||
@GetMapping("/sites") | ||
public ResponseEntity<List<String>> listSites() { | ||
public ResponseEntity<SiteListing> listSites() { | ||
return ResponseEntity.ok(institutions); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
uploader/src/main/java/edu/harvard/dbmi/avillach/dataupload/site/SiteListing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.harvard.dbmi.avillach.dataupload.site; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A Site is an organization participating in GIC. Don't say institute! | ||
* These names should be all lower case abbreviations for the site: | ||
* bch, cchmc, pitt, washu, chop, uthsc, etc | ||
* @param sites A list of all sites participating in data uploading | ||
* @param homeSite The site where this application is installed | ||
*/ | ||
public record SiteListing(List<String> sites, String homeSite, String homeDisplay) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
uploader/src/test/java/edu/harvard/dbmi/avillach/dataupload/site/SiteConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.harvard.dbmi.avillach.dataupload.site; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest | ||
class SiteConfigurationTest { | ||
|
||
@Mock | ||
ConfigurableApplicationContext context; | ||
|
||
@InjectMocks | ||
SiteConfiguration subject; | ||
|
||
@Test | ||
void shouldGetSiteInfo() { | ||
ReflectionTestUtils.setField(subject, "allSites", List.of("cchmc", "bch")); | ||
ReflectionTestUtils.setField(subject, "home", "bch"); | ||
ReflectionTestUtils.setField(subject, "display", "BCH"); | ||
|
||
SiteListing actual = subject.getSiteInfo(); | ||
SiteListing expected = new SiteListing(List.of("bch", "cchmc"), "bch", "BCH"); | ||
|
||
Assertions.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void shouldNotGetSiteInfo() { | ||
ReflectionTestUtils.setField(subject, "allSites", List.of("cchmc", "narnia")); | ||
ReflectionTestUtils.setField(subject, "home", "bch"); | ||
ReflectionTestUtils.setField(subject, "display", "BCH"); | ||
|
||
subject.getSiteInfo(); | ||
|
||
Mockito.verify(context, Mockito.times(1)).close(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
uploader/src/test/java/edu/harvard/dbmi/avillach/dataupload/site/SiteControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package edu.harvard.dbmi.avillach.dataupload.site; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class SiteControllerTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters