Skip to content

Commit

Permalink
Merge pull request #1489 from phac-nml/fix-metadata-uploader-removing…
Browse files Browse the repository at this point in the history
…-existing-data

Fix for metadata uploader overwriting existing data
  • Loading branch information
ericenns committed May 9, 2023
2 parents 3719474 + 36ee360 commit a9cd759
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 46 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

# Changelog
## [23.01.3]
* [Developer]: Fixed issue with metadata uploader removing exiting data. See [PR 1489](https://github.com/phac-nml/irida/pull/1489)

## [23.01.2]
## [23.01.2] - 2023/04/17
* [UI]: Fixed bug that caused all metadata fields to be removed when single field was removed from a template. See [PR 1482](https://github.com/phac-nml/irida/pull/1482)
* [Developer]: Fixed bug which allowed duplicated entries in the user_group_project table which prevented the user group from being removed. Fixed bug which was preventing analyses with `html` file outputs from completing. See [PR 1483](https://github.com/phac-nml/irida/pull/1483)
* [Developer]: Fixed flaky PipelinesPhylogenomicsPageIT test. See [PR 1482](https://github.com/phac-nml/irida/pull/1482)
* [REST]: Fixed issues with syncing between newer IRIDA (>22.09) and older IRIDA (<=20.09) by disabling requests for `application/xml` for some of the REST requests and only requesting data as `application/json`. See [PR 1484](https://github.com/phac-nml/irida/pull/1484).


## [23.01.1] - 2023/03/21
* [UI]: Fixed issue where template order was not applied when applying a linelist template. See [PR 1479](https://github.com/phac-nml/irida/pull/1479)
* [UI]: Added select all to associated projects filter on project > samples page. See [PR 1479](https://github.com/phac-nml/irida/pull/1479)
Expand Down Expand Up @@ -187,8 +188,9 @@

## [...previous](https://github.com/phac-nml/irida/blob/21.09.2/CHANGELOG.md)

[Unreleased]: https://github.com/phac-nml/irida/compare/23.01.2...HEAD
[Unreleased]: https://github.com/phac-nml/irida/compare/23.01.3...HEAD

[23.01.3]: https://github.com/phac-nml/irida/compare/23.01.2...23.01.3
[23.01.2]: https://github.com/phac-nml/irida/compare/23.01.1...23.01.2
[23.01.1]: https://github.com/phac-nml/irida/compare/23.01...23.01.1
[23.01]: https://github.com/phac-nml/irida/compare/22.09.7...23.01
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
}

group = "ca.corefacility.bioinformatics"
version = "23.01.2"
version = "23.01.3"
description = "irida"

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public Sample updateSample(UpdateSampleRequest request)
}
if (request.getMetadata() != null) {
Set<MetadataEntry> metadataEntrySet = createMetadata(request.getMetadata());
sampleService.updateSampleMetadata(sample, metadataEntrySet);
sampleService.mergeSampleMetadata(sample, metadataEntrySet);
}
return sampleService.update(sample);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.Test;

import ca.corefacility.bioinformatics.irida.ria.integration.AbstractIridaUIITChromeDriver;
import ca.corefacility.bioinformatics.irida.ria.integration.components.SampleDetailsViewer;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.LoginPage;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.ProjectMembersPage;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.projects.ProjectDeletePage;
Expand All @@ -30,6 +31,8 @@ public class ProjectSampleMetadataImportPageIT extends AbstractIridaUIITChromeDr
private static final String EMPTY_AND_DUPLICATE_HEADERS_FILE_PATH = "src/test/resources/files/metadata-upload/empty_and_duplicate_headers.xlsx";
private static final String DUPLICATE_HEADERS_FILE_PATH = "src/test/resources/files/metadata-upload/duplicate_headers.xlsx";
private static final String SAMPLE_NAME_COLUMN = "NLEP #";

private static final String SAMPLE_NAME = "sample1";
private static final Long PROJECT_ID = 1L;

@BeforeEach
Expand Down Expand Up @@ -189,4 +192,25 @@ public void testFailedUploadByRemovingPrivileges() {
page.clickUploadButton();
assertTrue(page.isErrorNotificationDisplayed(), "Error notification did not display");
}

@Test
public void testUploadDoesNotOverwriteExistingSampleMetadata() {
ProjectSampleMetadataImportPage page = ProjectSampleMetadataImportPage.goToPage(driver());
page.uploadMetadataFile(GOOD_FILE_PATH);
page.selectSampleNameColumn(SAMPLE_NAME_COLUMN);
page.goToReviewPage();
page.goToCompletePage();
assertTrue(page.isSuccessDisplayed(), "Successful upload did not happen");
ProjectSamplesPage samplePage = ProjectSamplesPage.goToPage(driver(), PROJECT_ID);
samplePage.clickSampleName(SAMPLE_NAME);
SampleDetailsViewer sampleDetailsViewer = SampleDetailsViewer.getSampleDetails(driver());
sampleDetailsViewer.clickMetadataTabLink();
assertTrue(sampleDetailsViewer.addNewMetadataButtonVisible());
sampleDetailsViewer.getNumberOfMetadataEntries();
assertEquals(10, sampleDetailsViewer.getNumberOfMetadataEntries(),
"Should have the proper number of metadata entries");
assertEquals("Sneezing", sampleDetailsViewer.getValueForMetadataField("symptom"),
"Should have existing metadata");
assertEquals("AB", sampleDetailsViewer.getValueForMetadataField("Province"), "Should have uploaded metadata");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

public class UIProjectSampleServiceTest {
private UIProjectSampleService service;
private ProjectService projectService;
private SampleService sampleService;
private MetadataTemplateService metadataTemplateService;
private MessageSource messageSource;

private Sample sample;
private Join<Project, Sample> join;

// DATA
private final Long PROJECT_1_ID = 1L;
Expand All @@ -44,20 +50,20 @@ public class UIProjectSampleServiceTest {

@BeforeEach
public void setUp() {
ProjectService projectService = mock(ProjectService.class);
SampleService sampleService = mock(SampleService.class);
MetadataTemplateService metadataTemplateService = mock(MetadataTemplateService.class);
MessageSource messageSource = mock(MessageSource.class);
projectService = mock(ProjectService.class);
sampleService = mock(SampleService.class);
metadataTemplateService = mock(MetadataTemplateService.class);
messageSource = mock(MessageSource.class);

service = new UIProjectSampleService(projectService, sampleService, metadataTemplateService, messageSource);

when(projectService.read(PROJECT_1_ID)).thenReturn(PROJECT_1);
when(sampleService.read(SAMPLE_1_ID)).thenReturn(SAMPLE_1);
when(sampleService.getSampleBySampleName(PROJECT_1, GOOD_NAME)).thenThrow(
new EntityNotFoundException("Sample not found"));
Sample sample = new Sample(GOOD_NAME);
sample = new Sample(GOOD_NAME);
sample.setId(SAMPLE_1_ID);
Join<Project, Sample> join = new ProjectSampleJoin(PROJECT_1, sample, true);
join = new ProjectSampleJoin(PROJECT_1, sample, true);
when(projectService.addSampleToProject(any(Project.class), any(Sample.class), any(Boolean.class))).thenReturn(
join);
when(projectService.addSampleToProjectWithoutEvent(any(Project.class), any(Sample.class),
Expand Down Expand Up @@ -135,6 +141,7 @@ public void testCreateSampleWithMetadata() {
.stream()
.filter(response -> ((SampleResponse) response.getValue()).isError())
.count();
verify(sampleService, times(1)).mergeSampleMetadata(any(), any());
assertEquals(0, errorCount, "Sample should be created");
}

Expand All @@ -149,6 +156,8 @@ public void testUpdateSampleWithMetadata() {
.stream()
.filter(response -> ((SampleErrorResponse) response.getValue()).isError())
.count();
verify(sampleService, times(1)).mergeSampleMetadata(any(), any());
assertEquals(0, errorCount, "Sample should be updated");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,16 @@
<sample id="3" createdDate="2013-07-03 14:02:19.0" modifiedDate="2015-07-02 14:00:19.0" description="description3" sampleName="sample3" organism="E. coli" />
<sample id="4" createdDate="2013-07-04 14:03:19.0" modifiedDate="2015-07-03 14:00:19.0" description="description4" sampleName="sample4" organism="Listeria" />
<sample id="5" createdDate="2013-07-06 14:05:19.0" modifiedDate="2015-07-06 14:00:19.0" description="description5" sampleName="sample523423" />
<sample id="6" createdDate="2013-07-07 14:06:19.0" modifiedDate="2015-07-07 14:00:19.0" description="description5" sampleName="sample534534" />
<sample id="7" createdDate="2013-07-08 14:07:19.0" modifiedDate="2015-07-08 14:00:19.0" description="description5" sampleName="sample589789" />
<sample id="8" createdDate="2013-07-09 14:08:19.0" modifiedDate="2015-07-09 14:00:19.0" description="description5" sampleName="sample52342" />
<sample id="9" createdDate="2013-07-10 14:09:19.0" modifiedDate="2015-07-10 14:00:19.0" description="description5" sampleName="sample565" />
<sample id="10" createdDate="2013-07-11 14:10:19.0" modifiedDate="2015-07-11 14:00:19.0" description="description5" sampleName="sample6735" />
<sample id="11" createdDate="2013-07-12 14:11:19.0" modifiedDate="2015-07-12 14:00:19.0" description="description5" sampleName="sample3452345" />
<sample id="12" createdDate="2013-07-13 14:12:19.0" modifiedDate="2015-07-13 14:00:19.0" description="description5" sampleName="sample3643225" />
<sample id="13" createdDate="2013-07-14 14:13:19.0" modifiedDate="2015-07-14 14:00:19.0" description="description5" sampleName="sample64565" />
<sample id="14" createdDate="2013-07-15 14:14:19.0" modifiedDate="2015-07-15 14:00:19.0" description="description5" sampleName="sample57567" />
<sample id="15" createdDate="2013-07-16 14:15:19.0" modifiedDate="2015-07-16 14:00:19.0" description="description5" sampleName="sample55422r" />
<sample id="16" createdDate="2013-07-17 14:16:19.0" modifiedDate="2015-07-17 14:00:19.0" description="description5" sampleName="sample5dt5" />
<sample id="17" createdDate="2013-07-18 14:17:19.0" modifiedDate="2015-07-18 14:00:19.0" description="description5" sampleName="sample5ddfg4" />
<sample id="18" createdDate="2013-07-19 14:18:19.0" modifiedDate="2015-07-19 14:00:19.0" description="description5" sampleName="sample554sg5" />
<sample id="19" createdDate="2013-07-20 14:19:19.0" modifiedDate="2015-07-20 14:00:19.0" description="description5" sampleName="sample5fdgr" />
<sample id="20" createdDate="2013-07-21 14:20:19.0" modifiedDate="2015-07-22 14:00:19.0" description="description5" sampleName="sample5fg44" />
<sample id="21" createdDate="2013-07-22 14:20:19.0" modifiedDate="2015-07-22 14:00:19.0" description="description22" sampleName="sample5fg22" />

<metadata_field id="1" label="symptom" type="text" DTYPE="MetadataTemplateField"/>

<metadata_entry id="1" value="Sneezing" type="text" sample_id="1" field_id="1"/>

<project_sample id="1" project_id="1" sample_id="1" createdDate="2013-07-10 14:21:19.0" />
<project_sample id="2" project_id="1" sample_id="2" createdDate="2013-07-12 14:22:19.0" />
<project_sample id="3" project_id="1" sample_id="3" createdDate="2013-07-14 14:23:19.0" />
<project_sample id="4" project_id="1" sample_id="4" createdDate="2013-07-16 14:24:19.0" />
<project_sample id="5" project_id="1" sample_id="5" createdDate="2013-07-18 14:26:19.0" />
<project_sample id="6" project_id="1" sample_id="6" createdDate="2013-07-18 14:27:19.0" />
<project_sample id="7" project_id="1" sample_id="7" createdDate="2013-07-18 14:28:19.0" />
<project_sample id="8" project_id="1" sample_id="8" createdDate="2013-07-18 14:29:19.0" />
<project_sample id="9" project_id="1" sample_id="9" createdDate="2013-07-18 14:31:19.0" />
<project_sample id="10" project_id="1" sample_id="10" createdDate="2013-07-18 14:32:19.0" />
<project_sample id="11" project_id="1" sample_id="11" createdDate="2013-07-18 14:33:19.0" />
<project_sample id="12" project_id="1" sample_id="12" createdDate="2013-07-18 14:34:19.0" />
<project_sample id="13" project_id="1" sample_id="13" createdDate="2013-07-18 14:35:19.0" />
<project_sample id="14" project_id="1" sample_id="14" createdDate="2013-07-18 14:36:19.0" />
<project_sample id="15" project_id="1" sample_id="15" createdDate="2013-07-18 14:37:19.0" />
<project_sample id="16" project_id="1" sample_id="16" createdDate="2013-07-18 14:38:19.0" />
<project_sample id="17" project_id="1" sample_id="17" createdDate="2013-07-18 14:39:19.0" />
<project_sample id="18" project_id="1" sample_id="18" createdDate="2013-07-18 14:40:19.0" />
<project_sample id="19" project_id="1" sample_id="19" createdDate="2013-07-18 14:41:19.0" />
<project_sample id="20" project_id="1" sample_id="20" createdDate="2013-07-18 14:42:19.0" />
<project_sample id="21" project_id="6" sample_id="20" createdDate="2013-07-18 14:42:19.0" />
<project_sample id="22" project_id="3" sample_id="20" createdDate="2013-07-18 14:42:19.0" />

<sequence_file id="1" created_date="2013-07-18 14:20:19.0" file_path="src/test/resources/files/test_file.fastq" />
<sequence_file id="2" created_date="2013-07-18 14:20:19.0" file_path="/sequenceFile2" />
Expand Down

0 comments on commit a9cd759

Please sign in to comment.