-
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.
Merge pull request #89 from KPMP/KPMP-4577_TableCountsIncorrect
KPMP-4577: Do better counting of files
- Loading branch information
Showing
11 changed files
with
219 additions
and
644 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,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; | ||
} | ||
|
||
} |
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,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(); | ||
} |
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,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(); | ||
} | ||
|
||
} |
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
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
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,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()); | ||
} | ||
} |
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,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()); | ||
} | ||
} | ||
|
||
|