diff --git a/src/fr/cirad/io/brapi/BrapiService.java b/src/fr/cirad/io/brapi/BrapiService.java index e3eeb5c..a9f68bc 100644 --- a/src/fr/cirad/io/brapi/BrapiService.java +++ b/src/fr/cirad/io/brapi/BrapiService.java @@ -39,6 +39,7 @@ public interface BrapiService { public static final String BRAPI_FIELD_germplasmDbId = "germplasmDbId"; public static final String BRAPI_FIELD_sampleDbId = "sampleDbId"; public static final String BRAPI_FIELD_extGermplasmDbId = "extGermplasmDbId"; + public static final String BRAPI_FIELD_extSampleDbId = "extSampleDbId"; public static final String BRAPI_FIELD_externalReferenceId = "extRefId"; public static final String BRAPI_FIELD_externalReferenceSource = "extRefSrc"; diff --git a/src/fr/cirad/mgdb/importing/IndividualMetadataImport.java b/src/fr/cirad/mgdb/importing/IndividualMetadataImport.java index 58ea02f..3a941dc 100644 --- a/src/fr/cirad/mgdb/importing/IndividualMetadataImport.java +++ b/src/fr/cirad/mgdb/importing/IndividualMetadataImport.java @@ -278,7 +278,7 @@ else if (wr.getUpserts().size() > 0) } } - public static int importBrapiMetadata(String sModule, HttpSession session, String endpointUrl, HashMap externalToInternalIdMap, String username, String authToken, ProgressIndicator progress, String metadataType) throws Exception { + public static int importBrapiMetadata(String sModule, HttpSession session, String endpointUrl, HashMap> externalToInternalIdMap, String username, String authToken, ProgressIndicator progress, String metadataType) throws Exception { if (externalToInternalIdMap == null || externalToInternalIdMap.isEmpty()) { return 0; // we must know which individuals to update } @@ -355,7 +355,7 @@ private static int importBrapiV1Germplasm( String sModule, HttpSession session, String endpointUrl, - HashMap germplasmDbIdToIndividualMap, + HashMap> germplasmDbIdToIndividualMap, String username, String authToken, ProgressIndicator progress, @@ -395,37 +395,37 @@ private static int importBrapiV1Germplasm( int i = 0; for (String germplasmId : germplasmMap.keySet()) { Map aiMap = germplasmMap.get(germplasmId); + aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId); //remove brapi germplasmDbId to avoid confusion between external and internal germplasmDbId + for (String indName : germplasmDbIdToIndividualMap.get(germplasmId)) { + progress.setCurrentStepProgress((long) (++i * 100f / germplasmMap.keySet().size())); - progress.setCurrentStepProgress((long) (++i * 100f / germplasmMap.keySet().size())); - - if (aiMap.isEmpty()) { - LOG.warn("Found no metadata to import for germplasm " + germplasmId); - continue; - } - aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId)); // use a dedicated field name to avoid confusion + if (aiMap.isEmpty()) { + LOG.warn("Found no metadata to import for germplasm " + germplasmId); + continue; + } + aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, germplasmId); // use a dedicated field to keep external germplasmDbId - String indName = germplasmDbIdToIndividualMap.get(germplasmId); - - Update update = new Update(); - if (username == null) { // global metadata - aiMap.forEach((k, v) -> update.set(Individual.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.updateMulti(new Query(Criteria.where("_id").is(indName)), update); - } else if (!fIsAnonymous) { // persistent user-level metadata - aiMap.forEach((k, v) -> update.set(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.upsert(new Query(Criteria.where("_id").is(new CustomIndividualMetadata.CustomIndividualMetadataId(indName, username))), update); - } else { - LinkedHashMap existingEntityMetadata = sessionObject.get(indName); - if (existingEntityMetadata == null) { - existingEntityMetadata = new LinkedHashMap<>(); - sessionObject.put(indName, existingEntityMetadata); - } - existingEntityMetadata.putAll(aiMap); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + Update update = new Update(); + if (username == null) { // global metadata + aiMap.forEach((k, v) -> update.set(Individual.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.updateMulti(new Query(Criteria.where("_id").is(indName)), update); + } else if (!fIsAnonymous) { // persistent user-level metadata + aiMap.forEach((k, v) -> update.set(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.upsert(new Query(Criteria.where("_id").is(new CustomIndividualMetadata.CustomIndividualMetadataId(indName, username))), update); + } else { + LinkedHashMap existingEntityMetadata = sessionObject.get(indName); + if (existingEntityMetadata == null) { + existingEntityMetadata = new LinkedHashMap<>(); + sessionObject.put(indName, existingEntityMetadata); + } + existingEntityMetadata.putAll(aiMap); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + } } } @@ -445,7 +445,7 @@ private static int importBrapiV2Germplasm( String sModule, HttpSession session, String endpointUrl, - HashMap germplasmDbIdToIndividualMap, + HashMap> germplasmDbIdToIndividualMap, String username, String authToken, ProgressIndicator progress, @@ -484,37 +484,37 @@ private static int importBrapiV2Germplasm( int i = 0; for (String germplasmId : germplasmMap.keySet()) { Map aiMap = germplasmMap.get(germplasmId); + aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId); //remove brapi germplasmDbId to avoid confusion between external and internal germplasmDbId + for (String indName : germplasmDbIdToIndividualMap.get(germplasmId)) { + progress.setCurrentStepProgress((long) (++i * 100f / germplasmMap.keySet().size())); - progress.setCurrentStepProgress((long) (++i * 100f / germplasmMap.keySet().size())); + if (aiMap.isEmpty()) { + LOG.warn("Found no metadata to import for germplasm " + germplasmId); + continue; + } + aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, germplasmId); // use a dedicated field to keep external germplasmDbId - if (aiMap.isEmpty()) { - LOG.warn("Found no metadata to import for germplasm " + germplasmId); - continue; - } - aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId)); // use a dedicated field name to avoid confusion - - String indName = germplasmDbIdToIndividualMap.get(germplasmId); - - Update update = new Update(); - if (username == null) { // global metadata - aiMap.forEach((k, v) -> update.set(Individual.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.updateMulti(new Query(Criteria.where("_id").is(indName)), update); - } else if (!fIsAnonymous) { // persistent user-level metadata - aiMap.forEach((k, v) -> update.set(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.upsert(new Query(Criteria.where("_id").is(new CustomIndividualMetadata.CustomIndividualMetadataId(indName, username))), update); - } else { - LinkedHashMap existingEntityMetadata = sessionObject.get(indName); - if (existingEntityMetadata == null) { - existingEntityMetadata = new LinkedHashMap<>(); - sessionObject.put(indName, existingEntityMetadata); - } - existingEntityMetadata.putAll(aiMap); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + Update update = new Update(); + if (username == null) { // global metadata + aiMap.forEach((k, v) -> update.set(Individual.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(Individual.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.updateMulti(new Query(Criteria.where("_id").is(indName)), update); + } else if (!fIsAnonymous) { // persistent user-level metadata + aiMap.forEach((k, v) -> update.set(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(CustomIndividualMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.upsert(new Query(Criteria.where("_id").is(new CustomIndividualMetadata.CustomIndividualMetadataId(indName, username))), update); + } else { + LinkedHashMap existingEntityMetadata = sessionObject.get(indName); + if (existingEntityMetadata == null) { + existingEntityMetadata = new LinkedHashMap<>(); + sessionObject.put(indName, existingEntityMetadata); + } + existingEntityMetadata.putAll(aiMap); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + } } } @@ -534,7 +534,7 @@ private static int importBrapiV1Samples( String sModule, HttpSession session, String endpointUrl, - HashMap externalToInternalIdMap, + HashMap> externalToInternalIdMap, String username, String authToken, ProgressIndicator progress, @@ -610,23 +610,20 @@ private static int importBrapiV1Samples( // Inserting samples (also germplasm and attributes) information in DB as additional info BulkOperations bulkOperations = mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, username == null ? GenotypingSample.class : CustomSampleMetadata.class); - for (int i = 0; i < sampleList.size(); i++) { + for (int i = 0; i < sampleList.size(); i++) { BrapiSample sample = sampleList.get(i); Map aiMap = mapper.convertValue(sample, Map.class); - //Map gMap = germplasmMap.get(sample.getGermplasmDbId()); - //merging 2 maps - //aiMap.putAll(gMap); - - progress.setCurrentStepProgress((long) (i * 100f / sampleList.size())); - - if (aiMap.isEmpty()) { - LOG.warn("Found no metadata to import for sample " + sample.getSampleDbId()); - continue; - } aiMap.remove(BrapiService.BRAPI_FIELD_sampleDbId); // we don't want to persist this field as it's internal to the remote source but not to the present system + for (String internalId : externalToInternalIdMap.get(sample.getSampleDbId())) { + progress.setCurrentStepProgress((long) (i * 100f / sampleList.size())); + + if (aiMap.isEmpty()) { + LOG.warn("Found no metadata to import for sample " + sample.getSampleDbId()); + continue; + } + aiMap.put(BrapiService.BRAPI_FIELD_extSampleDbId, sample.getSampleDbId()); // use a dedicated field to keep external sampleDbId - String internalId = externalToInternalIdMap.get(sample.getSampleDbId()); - Integer spId = null; + Integer spId = null; try { spId = mongoTemplate.findDistinct(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), "_id", GenotypingSample.class, Integer.class).get(0); } @@ -635,25 +632,26 @@ private static int importBrapiV1Samples( } Update update = new Update(); - if (username == null) { // global metadata - aiMap.forEach((k, v) -> update.set(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + k, v)); - bulkOperations.updateMulti(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), update); - update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - } else if (!fIsAnonymous) { // persistent user-level metadata - aiMap.forEach((k, v) -> update.set(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.upsert(new Query(new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_USER).is(username), new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_SAMPLE_ID).is(spId)))), update); - } else { - LinkedHashMap existingEntityMetadata = sessionObject.get(spId); - if (existingEntityMetadata == null) { - existingEntityMetadata = new LinkedHashMap<>(); - sessionObject.put(spId, existingEntityMetadata); - } - existingEntityMetadata.putAll(aiMap); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + if (username == null) { // global metadata + aiMap.forEach((k, v) -> update.set(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + k, v)); + bulkOperations.updateMulti(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), update); + update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + } else if (!fIsAnonymous) { // persistent user-level metadata + aiMap.forEach((k, v) -> update.set(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.upsert(new Query(new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_USER).is(username), new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_SAMPLE_ID).is(spId)))), update); + } else { + LinkedHashMap existingEntityMetadata = sessionObject.get(spId); + if (existingEntityMetadata == null) { + existingEntityMetadata = new LinkedHashMap<>(); + sessionObject.put(spId, existingEntityMetadata); + } + existingEntityMetadata.putAll(aiMap); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + } } } @@ -673,7 +671,7 @@ private static int importBrapiV2Samples( String sModule, HttpSession session, String endpointUrl, - HashMap externalToInternalIdMap, + HashMap> externalToInternalIdMap, String username, String authToken, ProgressIndicator progress, @@ -771,48 +769,50 @@ private static int importBrapiV2Samples( for (int i = 0; i < sampleList.size(); i++) { Sample sample = sampleList.get(i); Map aiMap = mapper.convertValue(sample, Map.class); - //Map gMap = germplasmMap.get(sample.getGermplasmDbId()); - //merging 2 maps - //aiMap.putAll(gMap); + aiMap.remove(BrapiService.BRAPI_FIELD_sampleDbId); // we don't want to persist this field as it's internal to the remote source but not to the present system + for (String internalId : externalToInternalIdMap.get(sample.getSampleDbId())) { + //Map gMap = germplasmMap.get(sample.getGermplasmDbId()); + //merging 2 maps + //aiMap.putAll(gMap); - progress.setCurrentStepProgress((long) (i * 100f / sampleList.size())); + progress.setCurrentStepProgress((long) (i * 100f / sampleList.size())); - if (aiMap.isEmpty()) { - LOG.warn("Found no metadata to import for sample " + sample.getSampleDbId()); - continue; - } - aiMap.remove(BrapiService.BRAPI_FIELD_sampleDbId); // we don't want to persist this field as it's internal to the remote source but not to the present system - //aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId)); - - String internalId = externalToInternalIdMap.get(sample.getSampleDbId()); - Integer spId = null; - try { - spId = mongoTemplate.findDistinct(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), "_id", GenotypingSample.class, Integer.class).get(0); - } - catch (IndexOutOfBoundsException ioobe) { - throw new Exception("Unexisting sample: " + internalId); - } + if (aiMap.isEmpty()) { + LOG.warn("Found no metadata to import for sample " + sample.getSampleDbId()); + continue; + } + aiMap.put(BrapiService.BRAPI_FIELD_extSampleDbId, sample.getSampleDbId()); // use a dedicated field to keep external sampleDbId + //aiMap.put(BrapiService.BRAPI_FIELD_extGermplasmDbId, aiMap.remove(BrapiService.BRAPI_FIELD_germplasmDbId)); - Update update = new Update(); - if (username == null) { // global metadata - aiMap.forEach((k, v) -> update.set(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.updateMulti(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), update); - } else if (!fIsAnonymous) { // persistent user-level metadata - aiMap.forEach((k, v) -> update.set(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); - update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); - update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); - bulkOperations.upsert(new Query(new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_USER).is(username), new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_SAMPLE_ID).is(spId)))), update); - } else { - LinkedHashMap existingEntityMetadata = sessionObject.get(spId); - if (existingEntityMetadata == null) { - existingEntityMetadata = new LinkedHashMap<>(); - sessionObject.put(spId, existingEntityMetadata); - } - existingEntityMetadata.putAll(aiMap); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); - existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + Integer spId = null; + try { + spId = mongoTemplate.findDistinct(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), "_id", GenotypingSample.class, Integer.class).get(0); + } + catch (IndexOutOfBoundsException ioobe) { + throw new Exception("Unexisting sample: " + internalId); + } + + Update update = new Update(); + if (username == null) { // global metadata + aiMap.forEach((k, v) -> update.set(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(GenotypingSample.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.updateMulti(new Query(Criteria.where(GenotypingSample.FIELDNAME_NAME).is(internalId)), update); + } else if (!fIsAnonymous) { // persistent user-level metadata + aiMap.forEach((k, v) -> update.set(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + k, v)); + update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceId); + update.unset(CustomSampleMetadata.SECTION_ADDITIONAL_INFO + "." + BrapiService.BRAPI_FIELD_externalReferenceSource); + bulkOperations.upsert(new Query(new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_USER).is(username), new Criteria().andOperator(Criteria.where("_id." + CustomSampleMetadataId.FIELDNAME_SAMPLE_ID).is(spId)))), update); + } else { + LinkedHashMap existingEntityMetadata = sessionObject.get(spId); + if (existingEntityMetadata == null) { + existingEntityMetadata = new LinkedHashMap<>(); + sessionObject.put(spId, existingEntityMetadata); + } + existingEntityMetadata.putAll(aiMap); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceId); + existingEntityMetadata.remove(BrapiService.BRAPI_FIELD_externalReferenceSource); + } } } diff --git a/src/fr/cirad/mgdb/importing/IntertekImport.java b/src/fr/cirad/mgdb/importing/IntertekImport.java index f8c6168..58f4d85 100644 --- a/src/fr/cirad/mgdb/importing/IntertekImport.java +++ b/src/fr/cirad/mgdb/importing/IntertekImport.java @@ -311,7 +311,7 @@ public Integer importToMongo(String sModule, String sProject, String sRun, Strin break; } - GenotypingSample sample = m_providedIdToSampleMap.get(sIndividual); + GenotypingSample sample = m_providedIdToSampleMap.get(sIndOrSpId); if (sample == null) { Individual ind = mongoTemplate.findById(sIndividual, Individual.class); if (ind == null) @@ -320,7 +320,7 @@ public Integer importToMongo(String sModule, String sProject, String sRun, Strin int sampleId = AutoIncrementCounter.getNextSequence(mongoTemplate, MongoTemplateManager.getMongoCollectionName(GenotypingSample.class)); sample = new GenotypingSample(sampleId, project.getId(), sRun, sIndividual, sampleToIndividualMap == null ? null : sIndOrSpId); sample.getAdditionalInfo().put("masterPlate", masterPlate); - m_providedIdToSampleMap.put(sIndividual, sample); + m_providedIdToSampleMap.put(sIndOrSpId, sample); } SampleGenotype sampleGt = new SampleGenotype(gtCode);