From 2689cb6f34d8630deee97e298e6924b4abcf0187 Mon Sep 17 00:00:00 2001 From: Zach Wright Date: Wed, 8 Aug 2018 15:53:06 -0400 Subject: [PATCH] KPMP-217: add the protocol to metadata --- src/main/java/org/kpmp/dao/UploadPackageMetadata.java | 9 +++++++++ .../java/org/kpmp/dao/UploadPackageMetadataTest.java | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kpmp/dao/UploadPackageMetadata.java b/src/main/java/org/kpmp/dao/UploadPackageMetadata.java index f5445a36..1f532921 100755 --- a/src/main/java/org/kpmp/dao/UploadPackageMetadata.java +++ b/src/main/java/org/kpmp/dao/UploadPackageMetadata.java @@ -15,6 +15,7 @@ public class UploadPackageMetadata { private String experimentDate; private String createdAt; private String packageType; + private String protocol; private String submitterFirstName; private String submitterLastName; private String institution; @@ -81,6 +82,7 @@ public UploadPackageMetadata(UploadPackage uploadPackage) { demographics = fileSubmission.getInstitution(); } + this.protocol = uploadPackage.getProtocol().getProtocol(); this.submitterFirstName = submitter.getFirstName(); this.submitterLastName = submitter.getLastName(); this.institution = demographics.getInstitutionName(); @@ -163,4 +165,11 @@ public void setFiles(List files) { this.files = files; } + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } } diff --git a/src/test/java/org/kpmp/dao/UploadPackageMetadataTest.java b/src/test/java/org/kpmp/dao/UploadPackageMetadataTest.java index b699e297..e748c207 100755 --- a/src/test/java/org/kpmp/dao/UploadPackageMetadataTest.java +++ b/src/test/java/org/kpmp/dao/UploadPackageMetadataTest.java @@ -32,11 +32,14 @@ public void setUp() throws Exception { now = new Date(); uploadPackage = mock(UploadPackage.class); + Protocol protocol = mock(Protocol.class); + when(protocol.getProtocol()).thenReturn("The Protocol"); when(uploadPackage.getCreatedAt()).thenReturn(now); when(uploadPackage.getExperimentDate()).thenReturn(now); when(uploadPackage.getId()).thenReturn(1); when(uploadPackage.getSubjectId()).thenReturn("42"); when(uploadPackage.getUniversalId()).thenReturn("uuid-package"); + when(uploadPackage.getProtocol()).thenReturn(protocol); PackageType packageType = mock(PackageType.class); when(packageType.getPackageType()).thenReturn("Big Data"); @@ -82,6 +85,7 @@ public void testConstructor() throws Exception { assertEquals("42", uploadPackageMetadata.getSubjectId()); assertEquals("Mattie", uploadPackageMetadata.getSubmitterFirstName()); assertEquals("Dayta", uploadPackageMetadata.getSubmitterLastName()); + assertEquals("The Protocol", uploadPackageMetadata.getProtocol()); } @Test @@ -99,7 +103,7 @@ public void testGenerateJSON() throws JsonProcessingException { String date = dateFormat.format(now); String expected = "{\"id\":\"uuid-package\",\"subjectId\":\"42\",\"experimentDate\":\"" + date + "\",\"createdAt\":\"" + date - + "\",\"packageType\":\"Big Data\",\"submitterFirstName\":\"Mattie\",\"submitterLastName\":\"Dayta\"," + + "\",\"packageType\":\"Big Data\",\"protocol\":\"The Protocol\",\"submitterFirstName\":\"Mattie\",\"submitterLastName\":\"Dayta\"," + "\"institution\":\"Mars University\",\"files\":[{\"path\":\"/package1/filename\",\"size\":12345,\"fileName\":\"filename\",\"description\":\"file description\",\"universalId\":\"uuid-file\"}]}"; assertEquals(expected, actual); } @@ -114,6 +118,7 @@ public void testSetters() throws Exception { uploadPackageMetadata.setSubjectId("242"); uploadPackageMetadata.setSubmitterFirstName("Zap"); uploadPackageMetadata.setSubmitterLastName("Branigan"); + uploadPackageMetadata.setProtocol("The Protocol"); assertEquals("2014-04-16", uploadPackageMetadata.getCreatedAt()); assertEquals("2017-07-08", uploadPackageMetadata.getExperimentDate()); @@ -123,6 +128,7 @@ public void testSetters() throws Exception { assertEquals("242", uploadPackageMetadata.getSubjectId()); assertEquals("Zap", uploadPackageMetadata.getSubmitterFirstName()); assertEquals("Branigan", uploadPackageMetadata.getSubmitterLastName()); + assertEquals("The Protocol", uploadPackageMetadata.getProtocol()); }