Skip to content

Commit

Permalink
Merge pull request #89 from KPMP/KPMP-4577_TableCountsIncorrect
Browse files Browse the repository at this point in the history
KPMP-4577: Do better counting of files
  • Loading branch information
zwright authored Jun 29, 2023
2 parents fcd66a3 + 963a27e commit 3274973
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 644 deletions.
622 changes: 4 additions & 618 deletions .classpath

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
<projectDescription>
<name>pegasus-data</name>
<comment></comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments/>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<linkedResources/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1</id>
<id>1686668102644</id>
<name></name>
<type>30</type>
<name/>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
public class AtlasRepoSummaryResult {

private List<AtlasRepoSummaryRow> summaryRows;
private int totalFiles;
private Long totalFiles;

public AtlasRepoSummaryResult(List<AtlasRepoSummaryRow> summaryRows, int totalFiles) {
public AtlasRepoSummaryResult(List<AtlasRepoSummaryRow> summaryRows, Long totalFiles) {
this.summaryRows = summaryRows;
this.totalFiles = totalFiles;

Expand All @@ -26,11 +26,11 @@ public void setSummaryRows(List<AtlasRepoSummaryRow> summaryRows) {
this.summaryRows = summaryRows;
}

public int getTotalFiles() {
public Long getTotalFiles() {
return totalFiles;
}

public void setTotalFiles(int totalFiles) {
public void setTotalFiles(Long totalFiles) {
this.totalFiles = totalFiles;
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/kpmp/dataSummary/DataSummaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.kpmp.FullDataTypeEnum;
import org.kpmp.OmicsTypeEnum;
import org.kpmp.TissueTypeEnum;
import org.kpmp.file.ARFileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -26,18 +27,20 @@ public class DataSummaryService {

private DataSummaryRepository dataSummaryRepository;
private AtlasRepoSummaryRepository repoSummaryRepository;
private ARFileInfoService fileInfoService;

@Autowired
public DataSummaryService(DataSummaryRepository dataSummaryRepository,
AtlasRepoSummaryRepository repoSummaryRepository) {
AtlasRepoSummaryRepository repoSummaryRepository, ARFileInfoService fileInfoService) {
this.dataSummaryRepository = dataSummaryRepository;
this.repoSummaryRepository = repoSummaryRepository;
this.fileInfoService = fileInfoService;
}

public AtlasRepoSummaryResult getAtlasRepoSummary() throws Exception {
List<ExperimentalStrategyValue> experimentalStrategies = repoSummaryRepository.findAll();
Map<String, AtlasRepoSummaryRow> summaryMap = new HashMap<>();
int totalFiles = 0;

for (ExperimentalStrategyValue experimentalStrategyValue : experimentalStrategies) {
String experimentalStrategy = experimentalStrategyValue.getExperimentalStrategy();
if (experimentalStrategy.isEmpty()
Expand All @@ -50,13 +53,11 @@ public AtlasRepoSummaryResult getAtlasRepoSummary() throws Exception {
if (summaryMap.containsKey(experimentalStrategy)) {
AtlasRepoSummaryRow atlasRepoSummaryRow = summaryMap.get(experimentalStrategy);
setCounts(experimentalStrategyValue, atlasRepoSummaryRow);
totalFiles += experimentalStrategyValue.getCount();
} else {
AtlasRepoSummaryRow row = new AtlasRepoSummaryRow(experimentalStrategy,
getLinkInformation(experimentalStrategyValue));
setCounts(experimentalStrategyValue, row);
summaryMap.put(experimentalStrategy, row);
totalFiles += experimentalStrategyValue.getCount();
}
}

Expand All @@ -69,7 +70,7 @@ public int compare(AtlasRepoSummaryRow one, AtlasRepoSummaryRow two) {
}
});

return new AtlasRepoSummaryResult(results, totalFiles);
return new AtlasRepoSummaryResult(results, fileInfoService.getRepositoryTotalFileCount());
}

private AtlasRepoSummaryLinkInformation getLinkInformation(ExperimentalStrategyValue experimentalStrategy) {
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/org/kpmp/file/ARFileInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.kpmp.file;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "ar_file_info")
public class ARFileInfo {
@Id
private int arFileInfoId;
private int fileId;
private int releaseVersion;
private int releaseSunsetVersion;
private int metadataTypeId;

public int getMetadataTypeId() {
return metadataTypeId;
}

public void setMetadataTypeId(int metadataTypeId) {
this.metadataTypeId = metadataTypeId;
}

public int getArFileInfoId() {
return arFileInfoId;
}

public void setArFileInfoId(int arFileInfoId) {
this.arFileInfoId = arFileInfoId;
}

public int getFileId() {
return fileId;
}

public void setFileId(int fileId) {
this.fileId = fileId;
}

public int getReleaseVersion() {
return releaseVersion;
}

public void setReleaseVersion(int releaseVersion) {
this.releaseVersion = releaseVersion;
}

public int getReleaseSunsetVersion() {
return releaseSunsetVersion;
}

public void setReleaseSunsetVersion(int releaseSunsetVersion) {
this.releaseSunsetVersion = releaseSunsetVersion;
}

}
14 changes: 14 additions & 0 deletions src/main/java/org/kpmp/file/ARFileInfoRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.kpmp.file;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
interface ARFileInfoRepository extends CrudRepository<ARFileInfo, Integer>{

@Cacheable("totalFileCount")
@Query(value = "select count(distinct(file_id)) from ar_file_info where release_sunset_version is null" , nativeQuery = true)
Long getTotalFileCount();
}
20 changes: 20 additions & 0 deletions src/main/java/org/kpmp/file/ARFileInfoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.kpmp.file;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ARFileInfoService {

private ARFileInfoRepository repository;

@Autowired
public ARFileInfoService (ARFileInfoRepository repository) {
this.repository = repository;
}

public Long getRepositoryTotalFileCount() {
return repository.getTotalFileCount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public void tearDown() throws Exception {

@Test
public void testConstructor() throws Exception {
int totalFiles = 5;
Long totalFiles = 5l;
AtlasRepoSummaryResult constructorTest = new AtlasRepoSummaryResult(summaryRows, totalFiles);

assertEquals(summaryRows, constructorTest.getSummaryRows());
assertEquals(5, constructorTest.getTotalFiles());
assertEquals(totalFiles, constructorTest.getTotalFiles());

}

Expand All @@ -44,9 +44,10 @@ public void testSetSummaryRows() {

@Test
public void testSetTotalFiles() {
result.setTotalFiles(58);
Long totalFiles = 58l;
result.setTotalFiles(totalFiles);

assertEquals(58, result.getTotalFiles());
assertEquals(totalFiles, result.getTotalFiles());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.kpmp.DataTypeEnum;
import org.kpmp.FullDataTypeEnum;
import org.kpmp.TissueTypeEnum;
import org.kpmp.file.ARFileInfoService;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand All @@ -21,11 +22,13 @@ public class DataSummaryServiceTest {
private DataSummaryRepository dataSummaryRepository;
@Mock
private AtlasRepoSummaryRepository atlasRepoSummaryRepository;
@Mock
private ARFileInfoService fileInfoService;

@Before
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
dataSummaryService = new DataSummaryService(dataSummaryRepository, atlasRepoSummaryRepository);
dataSummaryService = new DataSummaryService(dataSummaryRepository, atlasRepoSummaryRepository, fileInfoService);
}

@After
Expand Down Expand Up @@ -71,6 +74,7 @@ public void testGetAtlasRepoSummary() throws Exception {
List<ExperimentalStrategyValue> strategyValues = Arrays.asList(clinicalData, biomarker1, biomarker2, other1,
other2);
when(atlasRepoSummaryRepository.findAll()).thenReturn(strategyValues);
when(fileInfoService.getRepositoryTotalFileCount()).thenReturn(36l);

AtlasRepoSummaryResult result = dataSummaryService.getAtlasRepoSummary();
List<AtlasRepoSummaryRow> summaryRows = result.getSummaryRows();
Expand All @@ -90,7 +94,7 @@ public void testGetAtlasRepoSummary() throws Exception {
assertEquals(10, summaryRows.get(2).getOpenCount());
assertEquals(new AtlasRepoSummaryLinkInformation("experimental_strategy", "strategy1"),
summaryRows.get(2).getLinkInformation());
assertEquals(36, result.getTotalFiles());
assertEquals(new Long(36), result.getTotalFiles());

}

Expand Down
36 changes: 36 additions & 0 deletions src/test/java/org/kpmp/file/ARFileInfoServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.kpmp.file;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class ARFileInfoServiceTest {

@Mock
ARFileInfoRepository fileInfoRepository;
private ARFileInfoService service;

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
service = new ARFileInfoService(fileInfoRepository);
}

@AfterEach
public void tearDown() throws Exception {

MockitoAnnotations.openMocks(this).close();
service = null;
}

@Test
void testGetRepositoryTotalFileCount() {
when(fileInfoRepository.getTotalFileCount()).thenReturn(2l);
assertEquals(new Long(2), service.getRepositoryTotalFileCount());
}
}
54 changes: 54 additions & 0 deletions src/test/java/org/kpmp/file/ARFileInfoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.kpmp.file;

import static org.junit.Assert.assertEquals;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ARFileInfoTest {

private ARFileInfo fileInfo;

@BeforeEach
public void setUp() throws Exception {
fileInfo = new ARFileInfo();
}

@AfterEach
public void tearDown() throws Exception {
fileInfo = null;
}

@Test
public void testSetArFileInfoId() {
fileInfo.setArFileInfoId(4);
assertEquals(4, fileInfo.getArFileInfoId());
}

@Test
public void testSetFileId() {
fileInfo.setFileId(12);
assertEquals(12, fileInfo.getFileId());
}

@Test
public void testSetReleaseVersion() {
fileInfo.setReleaseVersion(4);
assertEquals(4, fileInfo.getReleaseVersion());
}

@Test
public void testSetReleaseSunsetVersion() {
fileInfo.setReleaseSunsetVersion(45);
assertEquals(45, fileInfo.getReleaseSunsetVersion());
}

@Test
public void testSetMetadataTypeId() {
fileInfo.setMetadataTypeId(66);
assertEquals(66, fileInfo.getMetadataTypeId());
}
}


0 comments on commit 3274973

Please sign in to comment.