diff --git a/README.md b/README.md index 821d0e8..ba734ed 100755 --- a/README.md +++ b/README.md @@ -42,3 +42,8 @@ If you have already followed these steps and are still having trouble connecting 1. Start up your atlas/knowledge-environment server 2. Open a tool like GraphQLPlayground and connect to "http://localhost:3030/graphql" 3. Write and execute your query + +# Buyer BEWARE +Notes to ourselves about the non-dynamic nature of some things in the app (this is not exhaustive) + +1. The endpoint `getDataTypeInformationByParticipant` is only partially dynamic. If we add new data types to the Spatial Viewer, it will pick those up without an issue, BUT if/when we add new data types to the Explorer, we will need to update the code that gets counts for data types in Explorer to include the new one. diff --git a/src/main/java/org/kpmp/Query.java b/src/main/java/org/kpmp/Query.java index be63d44..e5aaa72 100755 --- a/src/main/java/org/kpmp/Query.java +++ b/src/main/java/org/kpmp/Query.java @@ -13,14 +13,14 @@ import org.kpmp.dataSummary.AtlasRepoSummaryResult; import org.kpmp.dataSummary.DataSummaryService; import org.kpmp.dataSummary.DataTypeSummary; -import org.kpmp.gene.GeneService; -import org.kpmp.gene.MyGeneInfoHit; import org.kpmp.geneExpression.RTExpressionByTissueType; import org.kpmp.geneExpression.RTExpressionData; import org.kpmp.geneExpression.RTExpressionDataService; import org.kpmp.geneExpressionSummary.GeneExpressionSummary; import org.kpmp.geneExpressionSummary.GeneExpressionSummaryService; import org.kpmp.participant.ParticipantDataTypeSummary; +import org.kpmp.participant.ParticipantRepoDataTypeInformation; +import org.kpmp.participant.ParticipantRepoDataTypeSummary; import org.kpmp.participant.ParticipantService; import org.kpmp.participant.ParticipantSummaryDataset; import org.kpmp.participant.ParticipantTissueTypeSummary; @@ -36,7 +36,6 @@ @Component public class Query implements GraphQLQueryResolver { - private GeneService geneService; private AutocompleteService autocompleteService; private CellTypeService cellTypeService; private GeneExpressionSummaryService geneExpressionSummaryService; @@ -48,12 +47,11 @@ public class Query implements GraphQLQueryResolver { private Logger logger = LoggerFactory.getLogger(Query.class); @Autowired - public Query(GeneService geneService, AutocompleteService autocompleteService, CellTypeService cellTypeService, + public Query(AutocompleteService autocompleteService, CellTypeService cellTypeService, UmapDataService umapService, GeneExpressionSummaryService geneExpressionSummaryService, DataSummaryService dataSummaryService, ClusterHierarchyService clusterHierarchyService, RTExpressionDataService rtExpressionDataService, ParticipantService participantService) { - this.geneService = geneService; this.autocompleteService = autocompleteService; this.cellTypeService = cellTypeService; this.umapService = umapService; @@ -64,10 +62,6 @@ public Query(GeneService geneService, AutocompleteService autocompleteService, C this.participantService = participantService; } - public List genes(String symbol) throws IOException, Exception { - return geneService.querySymbolAndAlias(symbol); - } - public List autocomplete(String searchTerm) throws IOException, Exception { return autocompleteService.query(searchTerm); } @@ -152,6 +146,10 @@ public ParticipantDataTypeSummary getDataTypeInformationByParticipant(String red return participantService.getExperimentCounts(redcapId); } + public ParticipantRepoDataTypeSummary getRepoDataTypeInformationByParticipant(String redcapId) { + return participantService.getDataTypeCounts(redcapId); + } + public ParticipantSummaryDataset participantSummaryDataset(String redcap_id) throws Exception { try { return participantService.getParticipantSummaryDataset(redcap_id); @@ -168,6 +166,15 @@ public ParticipantSummaryDataset participantClinicalDataset(String redcap_id) th return this.participantSummaryDataset(redcap_id); } + public ParticipantRepoDataTypeInformation getTotalParticipantFilesCount(String redcap_id) throws Exception { + try { + return this.participantService.getTotalFilesCount(redcap_id); + } catch (Exception e) { + logger.error(e.getMessage()); + throw e; + } + } + public List getTissueTypeSummaryData() throws Exception { try { return participantService.getTissueData(); diff --git a/src/main/java/org/kpmp/cache/CacheController.java b/src/main/java/org/kpmp/cache/CacheController.java new file mode 100644 index 0000000..12c1650 --- /dev/null +++ b/src/main/java/org/kpmp/cache/CacheController.java @@ -0,0 +1,34 @@ +package org.kpmp.cache; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Collection; + +@Controller +public class CacheController { + + @Autowired + private CacheManager cacheManager; + + @RequestMapping(value = "/v1/clearCache", method = RequestMethod.GET) + public @ResponseBody CacheResponse clearCache(){ + Collection cacheNames = cacheManager.getCacheNames(); + CacheResponse clearCacheResponse = new CacheResponse(); + clearCacheResponse.setMessage("Caches successfully cleared!"); + for(String name:cacheNames){ + if (cacheManager.getCache(name) != null) { + cacheManager.getCache(name).clear(); + } else { + clearCacheResponse.setMessage("There was a problem getting the " + name + " cache."); + break; + } + } + clearCacheResponse.setCacheNames(cacheNames); + return clearCacheResponse; + } +} diff --git a/src/main/java/org/kpmp/cache/CacheResponse.java b/src/main/java/org/kpmp/cache/CacheResponse.java new file mode 100644 index 0000000..77265dd --- /dev/null +++ b/src/main/java/org/kpmp/cache/CacheResponse.java @@ -0,0 +1,25 @@ +package org.kpmp.cache; + +import java.util.Collection; + +public class CacheResponse { + + private String message; + private Collection cacheNames; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Collection getCacheNames() { + return cacheNames; + } + + public void setCacheNames(Collection cacheNames) { + this.cacheNames = cacheNames; + } +} diff --git a/src/main/java/org/kpmp/dataSummary/AtlasRepoSummaryLinkInformation.java b/src/main/java/org/kpmp/dataSummary/AtlasRepoSummaryLinkInformation.java index 0c94d87..e4e1edb 100644 --- a/src/main/java/org/kpmp/dataSummary/AtlasRepoSummaryLinkInformation.java +++ b/src/main/java/org/kpmp/dataSummary/AtlasRepoSummaryLinkInformation.java @@ -38,12 +38,11 @@ public int hashCode() { public boolean equals(Object obj) { if (obj instanceof AtlasRepoSummaryLinkInformation) { final AtlasRepoSummaryLinkInformation other = (AtlasRepoSummaryLinkInformation) obj; - return new EqualsBuilder().append(linkType, other.getLinkType()).append(linkValue, other.getLinkValue()) - .isEquals(); - } else { + return new EqualsBuilder().append(linkType, other.getLinkType()).append(linkValue, other.getLinkValue()).isEquals(); + } + else { return false; } - } } diff --git a/src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java b/src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java index a0f4d87..cda6f40 100755 --- a/src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java +++ b/src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java @@ -1,5 +1,7 @@ package org.kpmp.dataSummary; +import java.util.List; + import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; @@ -35,4 +37,22 @@ public interface DataSummaryRepository extends CrudRepository getRepoDataTypes(); + + @Cacheable("participantIDFromRedcapID") + @Query(value = "SELECT participant_id FROM participant WHERE redcap_id= :redcap_id LIMIT 1", nativeQuery = true) + String getParticipantIDString(@Param("redcap_id") String redcapId); + + @Cacheable("participantTotalFileCount") + @Query(value = "SELECT count(DISTINCT fp.file_id) FROM file_participant fp JOIN ar_file_info ar ON fp.file_id = ar.file_id " + + "WHERE fp.participant_id= :participant_id AND ar.release_sunset_version IS NULL", nativeQuery = true) + Integer getParticipantTotalFileCount(@Param("participant_id") String participantId); + } diff --git a/src/main/java/org/kpmp/participant/ParticipantDataTypeSummary.java b/src/main/java/org/kpmp/participant/ParticipantDataTypeSummary.java index 51ba482..a3c3383 100755 --- a/src/main/java/org/kpmp/participant/ParticipantDataTypeSummary.java +++ b/src/main/java/org/kpmp/participant/ParticipantDataTypeSummary.java @@ -8,6 +8,7 @@ public class ParticipantDataTypeSummary { private List spatialViewerDataTypes; private List explorerDataTypes; + public List getSpatialViewerDataTypes() { return spatialViewerDataTypes; } diff --git a/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeInformation.java b/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeInformation.java new file mode 100644 index 0000000..14bef60 --- /dev/null +++ b/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeInformation.java @@ -0,0 +1,40 @@ +package org.kpmp.participant; + +import org.kpmp.dataSummary.AtlasRepoSummaryLinkInformation; + +public class ParticipantRepoDataTypeInformation { + + private String dataType; + private Integer count; + private AtlasRepoSummaryLinkInformation linkInformation; + + public ParticipantRepoDataTypeInformation(String dataType, Integer count, AtlasRepoSummaryLinkInformation linkInformation) { + this.dataType = dataType; + this.count = count; + this.linkInformation = linkInformation; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public AtlasRepoSummaryLinkInformation getLinkInformation() { + return linkInformation; + } + + public void setLinkInformation(AtlasRepoSummaryLinkInformation linkInformation) { + this.linkInformation = linkInformation; + } +} diff --git a/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeSummary.java b/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeSummary.java new file mode 100644 index 0000000..3e09743 --- /dev/null +++ b/src/main/java/org/kpmp/participant/ParticipantRepoDataTypeSummary.java @@ -0,0 +1,15 @@ +package org.kpmp.participant; + +import java.util.List; + +public class ParticipantRepoDataTypeSummary { + private List repositoryDataTypes; + + public List getRepositoryDataTypes() { + return repositoryDataTypes; + } + + public void setRepositoryDataTypes(List repositoryDataTypes) { + this.repositoryDataTypes = repositoryDataTypes; + } +} diff --git a/src/main/java/org/kpmp/participant/ParticipantService.java b/src/main/java/org/kpmp/participant/ParticipantService.java index 2ace761..2c63ac7 100755 --- a/src/main/java/org/kpmp/participant/ParticipantService.java +++ b/src/main/java/org/kpmp/participant/ParticipantService.java @@ -5,6 +5,7 @@ import org.kpmp.FullDataTypeEnum; import org.kpmp.TissueTypeEnum; +import org.kpmp.dataSummary.AtlasRepoSummaryLinkInformation; import org.kpmp.dataSummary.DataSummaryRepository; import org.kpmp.geneExpressionSummary.RTParticipantRepository; import org.slf4j.Logger; @@ -37,22 +38,28 @@ public ParticipantService(DataSummaryRepository dataSummaryRepo, SpatialViewerTy this.rtParticipantRepo = rtParticipantRepo; this.participantSummaryDatasetRepository = participantSummaryDatasetRepository; } - + public ParticipantSummaryDataset getParticipantSummaryDataset(String redcapId) { return participantSummaryDatasetRepository.findByRedcapId(redcapId); } - public List getTissueData(){ + public List getTissueData() { List tissueData = new ArrayList<>(); tissueData.add(new ParticipantTissueTypeSummary( - participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType()), - participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType()), - participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType()), - participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType()))); + participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType()), + participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType()), + participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType()), + participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType()))); return tissueData; } + public ParticipantRepoDataTypeSummary getDataTypeCounts(String redcapId) { + ParticipantRepoDataTypeSummary summaryData = new ParticipantRepoDataTypeSummary(); + summaryData.setRepositoryDataTypes(getRepositoryCounts(redcapId)); + return summaryData; + } + public ParticipantDataTypeSummary getExperimentCounts(String redcapId) { ParticipantDataTypeSummary summaryData = new ParticipantDataTypeSummary(); summaryData.setSpatialViewerDataTypes(getSpatialViewerCounts(redcapId)); @@ -61,6 +68,15 @@ public ParticipantDataTypeSummary getExperimentCounts(String redcapId) { return summaryData; } + public ParticipantRepoDataTypeInformation getTotalFilesCount(String redcapId) { + String participant_id = dataSummaryRepo.getParticipantIDString(redcapId); + Integer totalCount = dataSummaryRepo.getParticipantTotalFileCount(participant_id); + AtlasRepoSummaryLinkInformation linkInfo = new AtlasRepoSummaryLinkInformation("redcap_id", redcapId); + ParticipantRepoDataTypeInformation res = new ParticipantRepoDataTypeInformation("", totalCount, linkInfo); + + return res; + } + private List getExplorerCounts(String redcapId) { List explorerExperiments = new ArrayList<>(); int scCount = 0; @@ -114,4 +130,17 @@ private List getSpatialViewerCounts(String redca } return spatialViewerExperiments; } + + private List getRepositoryCounts(String redcapId) { + List repoCounts = new ArrayList<>(); + + List repoDataTypes = dataSummaryRepo.getRepoDataTypes(); + for (String repoDataType : repoDataTypes) { + Integer count = dataSummaryRepo.getParticipantRepoFileDataTypeCount(redcapId, repoDataType); + AtlasRepoSummaryLinkInformation linkInformation = new AtlasRepoSummaryLinkInformation("data_type", repoDataType); + ParticipantRepoDataTypeInformation dataTypeInfo = new ParticipantRepoDataTypeInformation(repoDataType, count, linkInformation); + repoCounts.add(dataTypeInfo); + } + return repoCounts; + } } \ No newline at end of file diff --git a/src/main/resources/knowledge_environment.graphqls b/src/main/resources/knowledge_environment.graphqls index 1fa925a..ddbece8 100755 --- a/src/main/resources/knowledge_environment.graphqls +++ b/src/main/resources/knowledge_environment.graphqls @@ -1,5 +1,4 @@ type Query { - genes(symbol: String): [MyGeneInfoHit] autocomplete(searchTerm: String): [AutoCompleteResult] cellTypeHierarchy: CellTypeHierarchy geneExpressionSummary(dataType: String, geneSymbol: String, cellType: String, tissueType: String) : [GeneExpressionSummary] @@ -11,8 +10,10 @@ type Query { getRTGeneExpressionByStructure(structure: String): [RTGeneExpression] getSummaryData: [GeneDatasetInformation] getDataTypeInformationByParticipant(redcapId: String!): ParticipantDataTypeSummary + getRepoDataTypeInformationByParticipant(redcapId: String!): ParticipantRepoDataTypeSummary participantSummaryDataset(redcapId: String): ParticipantSummaryDataset participantClinicalDataset(redcapId: String): ParticipantSummaryDataset + getTotalParticipantFilesCount(redcapId: String): ParticipantRepoDataTypeInformation getTissueTypeSummaryData: [ParticipantTissueTypeSummary] getAtlasSummaryRows: AtlasRepoSummaryResult } @@ -52,6 +53,15 @@ type ParticipantDataTypeInformation { isAggregatedData: Boolean } +type ParticipantRepoDataTypeSummary { + repositoryDataTypes: [ParticipantRepoDataTypeInformation] +} + +type ParticipantRepoDataTypeInformation { + dataType: String + count: Long + linkInformation: AtlasRepoSummaryLinkInformation +} type GeneDatasetInformation { omicsType: String @@ -64,14 +74,6 @@ type GeneDatasetInformation { participantCount: Long } -type MyGeneInfoHit { - id: ID - symbol: String - name: String - entrezgene: String - alias: [String] -} - type AutoCompleteResult { value: String name: String diff --git a/src/test/java/org/kpmp/QueryTest.java b/src/test/java/org/kpmp/QueryTest.java index 050236a..f713d7d 100755 --- a/src/test/java/org/kpmp/QueryTest.java +++ b/src/test/java/org/kpmp/QueryTest.java @@ -24,8 +24,6 @@ import org.kpmp.dataSummary.AtlasRepoSummaryResult; import org.kpmp.dataSummary.DataSummaryService; import org.kpmp.dataSummary.DataTypeSummary; -import org.kpmp.gene.GeneService; -import org.kpmp.gene.MyGeneInfoHit; import org.kpmp.geneExpression.RTExpressionByTissueType; import org.kpmp.geneExpression.RTExpressionDataAllSegments; import org.kpmp.geneExpression.RTExpressionDataService; @@ -33,6 +31,7 @@ import org.kpmp.geneExpressionSummary.SCRNAGeneExpressionExpressionSummaryValue; import org.kpmp.geneExpressionSummary.SNRNAGeneExpressionExpressionSummaryValue; import org.kpmp.participant.ParticipantDataTypeSummary; +import org.kpmp.participant.ParticipantRepoDataTypeSummary; import org.kpmp.participant.ParticipantService; import org.kpmp.participant.ParticipantSummaryDataset; import org.kpmp.participant.ParticipantTissueTypeSummary; @@ -50,8 +49,6 @@ public class QueryTest { @Mock private AutocompleteService autocompleteService; @Mock - private GeneService geneService; - @Mock private GeneExpressionSummaryService geneExpressionService; @Mock private DataSummaryService dataSummaryService; @@ -70,7 +67,7 @@ public class QueryTest { @Before public void setUp() throws Exception { MockitoAnnotations.openMocks(this); - query = new Query(geneService, autocompleteService, cellTypeService, umapDataService, geneExpressionService, + query = new Query(autocompleteService, cellTypeService, umapDataService, geneExpressionService, dataSummaryService, clusterHierarchyService, rtExpressionDataService, participantService); } @@ -100,14 +97,6 @@ public void testGetAtlasSummaryRows_throwsException() throws Exception { } } - @Test - public void testGenes() throws Exception { - List expectedResult = Arrays.asList(new MyGeneInfoHit()); - when(geneService.querySymbolAndAlias("query")).thenReturn(expectedResult); - - assertEquals(expectedResult, query.genes("query")); - } - @Test public void testAutocomplete() throws Exception { List expectedResults = Arrays.asList(new AutocompleteResult()); @@ -259,6 +248,17 @@ public void testGetDataTypeInformationByParticipant() throws Exception { } + @Test + public void testGetRepoDataTypeInformationByParticipant() throws Exception { + ParticipantRepoDataTypeSummary expected = mock(ParticipantRepoDataTypeSummary.class); + when(participantService.getDataTypeCounts("123")).thenReturn(expected); + + ParticipantRepoDataTypeSummary result = query.getRepoDataTypeInformationByParticipant("123"); + + assertEquals(expected, result); + + } + public void testParticipantSummaryDataset() throws Exception { ParticipantSummaryDataset expected = new ParticipantSummaryDataset(); when(participantService.getParticipantSummaryDataset("participant_id")).thenReturn(expected); diff --git a/src/test/java/org/kpmp/autocomplete/AutocompleteServiceTest.java b/src/test/java/org/kpmp/autocomplete/AutocompleteServiceTest.java index 95332e8..33f2ab8 100755 --- a/src/test/java/org/kpmp/autocomplete/AutocompleteServiceTest.java +++ b/src/test/java/org/kpmp/autocomplete/AutocompleteServiceTest.java @@ -1,6 +1,6 @@ package org.kpmp.autocomplete; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; import java.io.IOException; @@ -12,6 +12,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; import org.kpmp.cellType.CellType; import org.kpmp.cellType.CellTypeRepository; import org.kpmp.cellType.CellTypeSynonym; @@ -20,6 +22,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; +@TestInstance(Lifecycle.PER_CLASS) class AutocompleteServiceTest { private AutocompleteService autocompleteService; @@ -31,7 +34,7 @@ class AutocompleteServiceTest { private CellTypeRepository cellTypeRepository; @BeforeEach - void setUp() { + void setUp() throws Exception { MockitoAnnotations.openMocks(this); autocompleteService = new AutocompleteService(geneService, cellTypeRepository); } @@ -92,42 +95,52 @@ void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForCellTypeResult List cellTypes = new ArrayList<>(); cellTypes.add(ct1); cellTypes.add(ct2); + List regions = new ArrayList<>(); + List subregions = new ArrayList<>(); assertEquals(ct1, ct2); List autocompleteResults = autocompleteService - .convertCellTypesToAutocompleteResults(cellTypes, null, null); + .convertCellTypesToAutocompleteResults(cellTypes, regions, subregions); assertEquals(1, autocompleteResults.size()); } @Test void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForStructureRegionResults() throws Exception { CellType ct1 = new CellType(); + ct1.setCellType("abc"); ct1.setStructureRegion("same name"); CellType ct2 = new CellType(); + ct2.setCellType("abc"); ct2.setStructureRegion("same name"); List regions = new ArrayList<>(); regions.add(ct1); regions.add(ct2); + List subregions = new ArrayList<>(); + List cellTypes = new ArrayList<>(); assertEquals(ct1, ct2); - List autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(null, - regions, null); + List autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(cellTypes, + regions, subregions); assertEquals(1, autocompleteResults.size()); } @Test void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForStructureSubregionResults() throws Exception { CellType ct1 = new CellType(); + ct1.setCellType("abc"); ct1.setStructureSubregion("same name"); CellType ct2 = new CellType(); + ct2.setCellType("abc"); ct2.setStructureSubregion("same name"); List subregions = new ArrayList<>(); subregions.add(ct1); subregions.add(ct2); + List regions = new ArrayList<>(); + List cellTypes = new ArrayList<>(); assertEquals(ct1, ct2); - List autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(null, - null, subregions); + List autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(cellTypes, + regions, subregions); assertEquals(1, autocompleteResults.size()); } diff --git a/src/test/java/org/kpmp/geneExpressionSummary/RTParticipantValueTest.java b/src/test/java/org/kpmp/geneExpressionSummary/RTParticipantValueTest.java index 030f4b9..2325927 100755 --- a/src/test/java/org/kpmp/geneExpressionSummary/RTParticipantValueTest.java +++ b/src/test/java/org/kpmp/geneExpressionSummary/RTParticipantValueTest.java @@ -1,21 +1,24 @@ package org.kpmp.geneExpressionSummary; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; import static org.junit.jupiter.api.Assertions.*; +@TestInstance(Lifecycle.PER_CLASS) class RTParticipantValueTest { RTParticipantValue rtParticipantValue; - @Before + @BeforeAll public void setUp() throws Exception { rtParticipantValue = new RTParticipantValue(); } - @After + @AfterAll public void tearDown() throws Exception { rtParticipantValue = null; } diff --git a/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeInformationTest.java b/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeInformationTest.java new file mode 100644 index 0000000..83d8de6 --- /dev/null +++ b/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeInformationTest.java @@ -0,0 +1,46 @@ +package org.kpmp.participant; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.kpmp.dataSummary.AtlasRepoSummaryLinkInformation; + +public class ParticipantRepoDataTypeInformationTest { + + private ParticipantRepoDataTypeInformation info; + + @Before + public void setUp() throws Exception { + info = new ParticipantRepoDataTypeInformation("abc", 1, mock(AtlasRepoSummaryLinkInformation.class)); + } + + @After + public void tearDown() throws Exception { + info = null; + } + + @Test + public void testSetDataType() { + String dataType = "123"; + info.setDataType(dataType); + assertEquals(dataType, info.getDataType()); + } + + @Test + public void testSetCount() { + Integer count = 0; + info.setCount(count); + assertEquals(count, info.getCount()); + } + + @Test + public void testSetLinkInformation() { + AtlasRepoSummaryLinkInformation linkInfo = mock(AtlasRepoSummaryLinkInformation.class); + info.setLinkInformation(linkInfo); + assertEquals(linkInfo, info.getLinkInformation()); + } + +} diff --git a/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeSummaryTest.java b/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeSummaryTest.java new file mode 100644 index 0000000..0892198 --- /dev/null +++ b/src/test/java/org/kpmp/participant/ParticipantRepoDataTypeSummaryTest.java @@ -0,0 +1,36 @@ +package org.kpmp.participant; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ParticipantRepoDataTypeSummaryTest { + + private ParticipantRepoDataTypeSummary summary; + + @Before + public void setUp() throws Exception { + summary = new ParticipantRepoDataTypeSummary(); + } + + @After + public void tearDown() throws Exception { + summary = null; + } + + @Test + public void testSetRepositoryDataTypes() { + List experimentInfo = Arrays.asList(mock(ParticipantRepoDataTypeInformation.class)); + + summary.setRepositoryDataTypes(experimentInfo); + + assertEquals(experimentInfo, summary.getRepositoryDataTypes()); + } + +} diff --git a/src/test/java/org/kpmp/participant/ParticipantServiceTest.java b/src/test/java/org/kpmp/participant/ParticipantServiceTest.java index 4e168a6..2324497 100755 --- a/src/test/java/org/kpmp/participant/ParticipantServiceTest.java +++ b/src/test/java/org/kpmp/participant/ParticipantServiceTest.java @@ -124,6 +124,27 @@ public void testGetExperimentCounts() { } + @Test + public void testGetDataTypeCounts() throws Exception { + String dataType1 = "Transcriptomics", dataType2 = "Imaging"; + when(dataSummaryRepo.getRepoDataTypes()).thenReturn(Arrays.asList(dataType1, dataType2)); + when(dataSummaryRepo.getParticipantRepoFileDataTypeCount("redcapId", dataType1)).thenReturn(3); + when(dataSummaryRepo.getParticipantRepoFileDataTypeCount("redcapId", dataType2)).thenReturn(4); + + ParticipantRepoDataTypeSummary result = participantService.getDataTypeCounts("redcapId"); + + List repositoryDataTypes = result.getRepositoryDataTypes(); + assertEquals(2, repositoryDataTypes.size()); + for (ParticipantRepoDataTypeInformation participantDataTypeInformation : repositoryDataTypes) { + if(participantDataTypeInformation.getDataType().equals("Transcriptomics")) { + assertEquals(new Integer(3), participantDataTypeInformation.getCount()); + } + else if (participantDataTypeInformation.getDataType().equals("Imaging")) { + assertEquals(new Integer(4), participantDataTypeInformation.getCount()); + } + } + } + @Test public void testGetTissueCounts() throws Exception { when(participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType())).thenReturn(Long .valueOf(4)); @@ -140,4 +161,16 @@ public void testGetTissueCounts() throws Exception { assertEquals(Long.valueOf(5), resultDataCkd.getCkdCount()); assertEquals(Long.valueOf(6), resultDataHrt.getHrtCount()); } + + @Test + public void testGetTotalFilesCount() throws Exception { + when(dataSummaryRepo.getParticipantIDString("123")).thenReturn("abc"); + when(dataSummaryRepo.getParticipantTotalFileCount("abc")).thenReturn(5); + + ParticipantRepoDataTypeInformation result = participantService.getTotalFilesCount("123"); + + assertEquals(new Integer(5), result.getCount()); + assertEquals("redcap_id", result.getLinkInformation().getLinkType()); + assertEquals("123", result.getLinkInformation().getLinkValue()); + } } \ No newline at end of file diff --git a/src/test/java/org/kpmp/participant/ParticipantSummaryDatasetTest.java b/src/test/java/org/kpmp/participant/ParticipantSummaryDatasetTest.java index b2a228a..eb6eef5 100755 --- a/src/test/java/org/kpmp/participant/ParticipantSummaryDatasetTest.java +++ b/src/test/java/org/kpmp/participant/ParticipantSummaryDatasetTest.java @@ -1,21 +1,23 @@ package org.kpmp.participant; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; import static org.junit.jupiter.api.Assertions.*; +@TestInstance(Lifecycle.PER_CLASS) class ParticipantSummaryDatasetTest { ParticipantSummaryDataset participantSummaryDataset; - @Before - + @BeforeAll public void setUp() throws Exception { - participantSummaryDataset = new ParticipantSummaryDataset(); + this.participantSummaryDataset = new ParticipantSummaryDataset(); } - @After + @AfterAll public void tearDown() throws Exception { participantSummaryDataset = null; }