use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class StudyWithDonorsServiceTest method testReadWithChildren.
@Test
public void testReadWithChildren() {
// Create random isolated study
val studyId = studyGenerator.createRandomStudy();
// Generate Random SequencingRead analyses
val analysisGenerator = createAnalysisGenerator(studyId, analysisService, randomGenerator);
val numAnalysis = 11;
val analysisMap = Maps.<String, SequencingReadAnalysis>newHashMap();
for (int i = 0; i < numAnalysis; i++) {
val sequencingReadAnalysis = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
analysisMap.put(sequencingReadAnalysis.getAnalysisId(), sequencingReadAnalysis);
}
// Extract expected donors and verify
val expectedDonors = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getDonor).collect(toSet());
assertThat(expectedDonors).hasSize(numAnalysis);
assertThat(expectedDonors.stream().map(Donor::getDonorSubmitterId).distinct().count()).isEqualTo(numAnalysis);
assertThat(expectedDonors.stream().filter(x -> x.getStudyId().equals(studyId)).count()).isEqualTo(numAnalysis);
// Extract expected specimens and verify
val expectedSpecimens = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getSpecimen).collect(toSet());
assertThat(expectedSpecimens).hasSize(numAnalysis);
assertThat(expectedSpecimens.stream().map(Specimen::getSpecimenSubmitterId).distinct().count()).isEqualTo(numAnalysis);
// Extract expected samples and verify
val expectedSamples = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).collect(toSet());
val expectedSampleSubmitterIds = expectedSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
assertThat(expectedSamples).hasSize(numAnalysis);
assertThat(expectedSampleSubmitterIds).hasSize(numAnalysis);
// Run the target method to test, readWithChildren
val studyWithDonors = studyWithDonorsService.readWithChildren(studyId);
// Extract actual donors
val actualDonors = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::createDonor).collect(toSet());
// Extract actual specimens
val actualSpecimens = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSpecimen).collect(toSet());
// Extract actual samples
val actualSamples = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSamples).flatMap(Collection::stream).collect(toSet());
val actualSampleSubmitterIds = actualSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
// Verify expected donors and actual donors match
assertSetsMatch(expectedDonors, actualDonors);
// Verify expected specimens and actual specimens match
assertSetsMatch(expectedSpecimens, actualSpecimens);
// Verify expected sampleSubmitterIds and actual sampleSubmitterIds match
assertSetsMatch(expectedSampleSubmitterIds, actualSampleSubmitterIds);
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorService method save.
public String save(@NonNull String studyId, @NonNull Donor donor) {
donor.setStudyId(studyId);
String donorId = donorRepository.findByBusinessKey(studyId, donor.getDonorSubmitterId());
val donorWithSpecimens = new DonorWithSpecimens();
donorWithSpecimens.setDonor(donor);
donorWithSpecimens.setDonorId(donorId);
if (isNull(donorId)) {
donorId = create(donorWithSpecimens);
} else {
val updateDonor = donorWithSpecimens.createDonor();
update(updateDonor);
}
return donorId;
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorServiceTest method testSave.
@Test
public void testSave() {
val studyId = DEFAULT_STUDY_ID;
val donorSubmitterId = randomGenerator.generateRandomUUIDAsString();
val d = new DonorWithSpecimens();
d.setDonorId("");
d.setDonorSubmitterId(donorSubmitterId);
d.setStudyId(studyId);
d.setDonorGender("male");
val donorId = service.save(studyId, d);
val initialDonor = service.read(donorId);
assertThat(initialDonor.getDonorGender()).isEqualTo("male");
assertThat(service.isDonorExist(donorId)).isTrue();
val dUpdate = new DonorWithSpecimens();
dUpdate.setDonorSubmitterId(donorSubmitterId);
dUpdate.setStudyId(studyId);
dUpdate.setDonorGender("female");
val donorId2 = service.save(studyId, dUpdate);
assertThat(service.isDonorExist(donorId2)).isTrue();
assertThat(donorId2).isEqualTo(donorId);
val updateDonor = service.read(donorId2);
assertThat(updateDonor.getDonorGender()).isEqualTo("female");
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorServiceTest method testCreateAndDeleteDonor.
@Test
public void testCreateAndDeleteDonor() {
val json = JsonUtils.mapper().createObjectNode();
val studyId = "XYZ234";
json.put("donorId", "");
json.put("donorSubmitterId", "Subject X21-Alpha");
json.put("studyId", studyId);
json.put("donorGender", "unspecified");
json.put("species", "human");
DonorWithSpecimens d = JsonUtils.mapper().convertValue(json, DonorWithSpecimens.class);
assertThat(d.getDonorId()).isNull();
val status = service.create(d);
val id = d.getDonorId();
assertThat(id).startsWith("DO");
assertThat(status).isEqualTo(id);
DonorWithSpecimens check = service.readWithSpecimens(id);
assertThat(d).isEqualToComparingFieldByField(check);
service.delete("XYZ234", id);
assertThat(service.isDonorExist(id)).isFalse();
val status2 = service.create(d);
assertThat(status2).isEqualTo(id);
service.delete("XYZ234", newArrayList(id));
assertThat(service.isDonorExist(id)).isFalse();
}
use of org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens in project SONG by overture-stack.
the class DonorServiceTest method testSaveStudyDNE.
@Test
public void testSaveStudyDNE() {
val studyId = DEFAULT_STUDY_ID;
val randomStudyId = randomGenerator.generateRandomUUIDAsString();
assertThat(studyService.isStudyExist(randomStudyId)).isFalse();
val donorSubmitterId = randomGenerator.generateRandomUUIDAsString();
val d = new DonorWithSpecimens();
d.setDonorId("");
d.setDonorSubmitterId(donorSubmitterId);
d.setStudyId(studyId);
d.setDonorGender("male");
val donorId = service.create(d);
assertThat(service.isDonorExist(donorId)).isTrue();
assertSongError(() -> service.save(randomStudyId, d), STUDY_ID_DOES_NOT_EXIST);
val d2 = new DonorWithSpecimens();
d2.setDonorId("");
d2.setDonorSubmitterId(randomGenerator.generateRandomUUIDAsString());
d2.setStudyId(randomStudyId);
d2.setDonorGender("female");
assertSongError(() -> service.save(randomStudyId, d2), STUDY_ID_DOES_NOT_EXIST);
}
Aggregations