Skip to content

Commit

Permalink
[ALS-4774] Add details to site info
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Jan 11, 2024
1 parent 9038861 commit e1a48cb
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 8 deletions.
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);
}
}
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);
}
}
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) {
}
3 changes: 3 additions & 0 deletions uploader/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ aws.kms.key_ids=${AWS_KEY_ID}
production=true
enable_file_sharing=true
file_sharing_root=${FILE_SHARING_ROOT}
institution.name=${HOME_INSTITUTION_NAME}
institution.short-display=${HOME_INSTITUTION_DISPLAY}
institution.long-display=${HOME_INSTITUTION_LONG_DISPLAY}
server.port=80
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();
}
}
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 {

}
7 changes: 6 additions & 1 deletion uploader/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

production=false

aws.region=us-east-1
aws.s3.institution=bch

aws.region=us-east-1
institution.name=bch
institution.short-display=BCH
institution.long-display=Boston Children's Hospital

0 comments on commit e1a48cb

Please sign in to comment.