@@ -232,7 +232,7 @@ public void saveSharedCases(SormasToSormasEncryptedDataDto encryptedData) throws
232232 }
233233
234234 if (samples != null ) {
235- Map <String , Map < String , List < String >> > sampleErrors = processSamples (samples );
235+ Map <String , ValidationErrors > sampleErrors = processSamples (samples );
236236 validationErrors .putAll (sampleErrors );
237237 }
238238
@@ -302,7 +302,7 @@ public void saveSharedContacts(SormasToSormasEncryptedDataDto sharedData) throws
302302 }
303303
304304 if (samples != null ) {
305- Map <String , Map < String , List < String >> > sampleErrors = processSamples (samples );
305+ Map <String , ValidationErrors > sampleErrors = processSamples (samples );
306306 validationErrors .putAll (sampleErrors );
307307 }
308308
@@ -580,40 +580,54 @@ private Map<String, ValidationErrors> processAssociatedContacts(
580580 SormasToSormasOriginInfoDto originInfo ) {
581581 Map <String , ValidationErrors > validationErrors = new HashMap <>();
582582
583- associatedContacts . forEach ( associatedContact -> {
583+ for ( SormasToSormasCaseDto . AssociatedContactDto associatedContact : associatedContacts ) {
584584 ContactDto contact = associatedContact .getContact ();
585+ ValidationErrors contactErrors = new ValidationErrors ();
585586
586- ValidationErrors contactErrors = processContactData (contact , associatedContact .getPerson (), originInfo );
587+ if (contactFacade .exists (contact .getUuid ())) {
588+ contactErrors
589+ .add (I18nProperties .getCaption (Captions .Contact ), I18nProperties .getValidationError (Validations .sormasToSormasContactExists ));
590+ continue ;
591+ }
592+
593+ ValidationErrors contactProcessingErrors = processContactData (contact , associatedContact .getPerson (), originInfo );
594+ contactErrors .addAll (contactProcessingErrors );
587595
588596 if (contactErrors .hasError ()) {
589597 validationErrors .put (buildContactValidationGroupName (contact ), contactErrors );
590598 }
591- });
599+ }
592600
593601 return validationErrors ;
594602 }
595603
596- private Map <String , Map < String , List < String >> > processSamples (List <SormasToSormasSampleDto > samples ) {
597- Map <String , Map < String , List < String >> > validationErrors = new HashMap <>();
604+ private Map <String , ValidationErrors > processSamples (List <SormasToSormasSampleDto > samples ) {
605+ Map <String , ValidationErrors > validationErrors = new HashMap <>();
598606
599607 samples .forEach (sormasToSormasSample -> {
600608 SampleDto sample = sormasToSormasSample .getSample ();
609+ ValidationErrors sampleErrors = new ValidationErrors ();
610+
611+ if (sampleFacade .exists (sample .getUuid ())) {
612+ sampleErrors
613+ .add (I18nProperties .getCaption (Captions .Sample ), I18nProperties .getValidationError (Validations .sormasToSormasSampleExists ));
614+ }
601615
602616 sample .setReportingUser (userService .getCurrentUser ().toReference ());
603617
604618 DataHelper .Pair <InfrastructureData , List <String >> infrastructureAndErrors =
605619 loadLocalInfrastructure (null , null , null , null , sample .getLab (), null );
606620
607- ValidationErrors sampleErrors = new ValidationErrors ();
608621 handleInfraStructure (infrastructureAndErrors , Captions .Sample_lab , sampleErrors , (infrastructureData -> {
609622 sample .setLab (infrastructureData .facility );
610623 }));
611624 if (sampleErrors .hasError ()) {
612- validationErrors .put (buildSampleValidationGroupName (sample ), sampleErrors . getErrors () );
625+ validationErrors .put (buildSampleValidationGroupName (sample ), sampleErrors );
613626 }
614627
615628 sormasToSormasSample .getPathogenTests ().forEach (pathogenTest -> {
616629 pathogenTest .setUuid (DataHelper .createUuid ());
630+
617631 DataHelper .Pair <InfrastructureData , List <String >> ptInfrastructureAndErrors =
618632 loadLocalInfrastructure (null , null , null , FacilityType .LABORATORY , pathogenTest .getLab (), null );
619633
@@ -623,7 +637,7 @@ private Map<String, Map<String, List<String>>> processSamples(List<SormasToSorma
623637 }));
624638
625639 if (pathogenTestErrors .hasError ()) {
626- validationErrors .put (buildPathogenTestValidationGroupName (pathogenTest ), pathogenTestErrors . getErrors () );
640+ validationErrors .put (buildPathogenTestValidationGroupName (pathogenTest ), pathogenTestErrors );
627641 }
628642 });
629643
0 commit comments