Search in sources :

Example 6 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class CaseImporterTest method testImportAllCases.

@Test
public void testImportAllCases() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    TestDataCreator creator = new TestDataCreator();
    TestDataCreator.RDCF rdcf = creator.createRDCF("Abia", "Umuahia North", "Urban Ward 2", "Anelechi Hospital");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    // Successful import of 5 cases
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_success.csv").toURI());
    CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
    ImportResultStatus importResult = caseImporter.runImport();
    assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
    assertEquals(5, getCaseFacade().count(null));
    // Failed import of 5 cases because of errors
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_errors.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user);
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
    assertEquals(5, getCaseFacade().count(null));
    // Similarity: skip
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            resultConsumer.accept((T) new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
        }
    };
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(5, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Similarity: pick
    List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
        }

        @Override
        protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.PICK));
        }
    };
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(5, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Similarity: cancel
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            resultConsumer.accept((T) new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CANCEL));
        }
    };
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.CANCELED, importResult);
    assertEquals(5, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Similarity: override
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
        }

        @Override
        protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.OVERRIDE));
        }
    };
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(5, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Similarity: create -> fail because of duplicate epid number
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
        }

        @Override
        protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CREATE));
        }
    };
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
    assertEquals(5, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Change epid number of the case in database to pass creation test
    CaseDataDto caze = getCaseFacade().getAllActiveCasesAfter(null).get(4);
    caze.setEpidNumber("ABC-DEF-GHI-19-99");
    getCaseFacade().save(caze);
    assertEquals("ABC-DEF-GHI-19-99", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
    // Similarity: create -> pass
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user);
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(6, getCaseFacade().count(null));
    assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(5).getEpidNumber());
    // Successful import of a case with different infrastructure combinations
    creator.createRDCF("R1", "D1", "C1", "F1");
    creator.createRDCF("R2", "D2", "C2", "F2");
    creator.createRDCF("R3", "D3", "C3", "F3");
    csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_test_different_infrastructure.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user);
    importResult = caseImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(7, getCaseFacade().count(null));
    // Successful import of 5 cases from a commented CSV file
    csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_comment_success.csv").toURI());
    caseImporter = new CaseImporterExtension(csvFile, true, user);
    importResult = caseImporter.runImport();
    assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
    assertEquals(12, getCaseFacade().count(null));
}
Also used : CaseImportSimilarityResult(de.symeda.sormas.ui.importer.CaseImportSimilarityResult) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) CaseImportSimilarityInput(de.symeda.sormas.ui.importer.CaseImportSimilarityInput) UI(com.vaadin.ui.UI) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 7 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporterTest method testImportEventParticipantSimilarityPick.

@Test
public void testImportEventParticipantSimilarityPick() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    EventParticipantFacadeEjbLocal eventParticipantFacade = getBean(EventParticipantFacadeEjbLocal.class);
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    EventDto event = creator.createEvent(EventStatus.SIGNAL, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 2), new Date(), user.toReference(), user.toReference(), Disease.EVD);
    EventReferenceDto eventRef = event.toReference();
    PersonDto person = creator.createPerson("Günther", "Heinz");
    creator.createCase(user.toReference(), person.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    // Person Similarity: pick
    List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_similarities.csv").toURI());
    EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
        }
    };
    ImportResultStatus importResult = eventParticipantImporter.runImport();
    EventParticipantIndexDto importedEventParticipant = eventParticipantFacade.getIndexList(new EventParticipantCriteria().withEvent(eventRef), null, null, null).get(0);
    PersonDto importedPerson = getPersonFacade().getPersonByUuid(importedEventParticipant.getPersonUuid());
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(1, eventParticipantFacade.count(new EventParticipantCriteria().withEvent(eventRef)));
    assertEquals(person.getUuid(), importedEventParticipant.getPersonUuid());
    assertEquals(person.getFirstName(), importedPerson.getFirstName());
    assertEquals(person.getLastName(), importedPerson.getLastName());
    assertEquals(1, getPersonFacade().getAllUuids().size());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ArrayList(java.util.ArrayList) Date(java.util.Date) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) Consumer(java.util.function.Consumer) UI(com.vaadin.ui.UI) BiFunction(java.util.function.BiFunction) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 8 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporterTest method testImportEventParticipantSimilarityPickEventParticipant.

@Test
public void testImportEventParticipantSimilarityPickEventParticipant() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    EventParticipantFacadeEjbLocal eventParticipantFacade = getBean(EventParticipantFacadeEjbLocal.class);
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    EventDto event = creator.createEvent(EventStatus.SIGNAL, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 2), new Date(), user.toReference(), user.toReference(), Disease.EVD);
    EventReferenceDto eventRef = event.toReference();
    PersonDto person = creator.createPerson("Günther", "Heinz");
    EventParticipantDto eventParticipant = creator.createEventParticipant(eventRef, person, "old desc", user.toReference());
    // Person Similarity: pick event participant
    List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_similarities.csv").toURI());
    EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
        }
    };
    ImportResultStatus importResult = eventParticipantImporter.runImport();
    EventParticipantIndexDto importedEventParticipant = eventParticipantFacade.getIndexList(new EventParticipantCriteria().withEvent(eventRef), null, null, null).get(0);
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(1, eventParticipantFacade.count(new EventParticipantCriteria().withEvent(eventRef)));
    assertEquals(person.getUuid(), importedEventParticipant.getPersonUuid());
    assertEquals(eventParticipant.getUuid(), importedEventParticipant.getUuid());
    assertEquals("description 1", importedEventParticipant.getInvolvementDescription());
    assertEquals(1, getPersonFacade().getAllUuids().size());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ArrayList(java.util.ArrayList) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) Date(java.util.Date) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) Consumer(java.util.function.Consumer) UI(com.vaadin.ui.UI) BiFunction(java.util.function.BiFunction) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 9 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class EventImporterTest method testImportAllEvents.

@Test
public void testImportAllEvents() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    TestDataCreator creator = new TestDataCreator();
    TestDataCreator.RDCF rdcf = creator.createRDCF("Bourgogne-Franche-Comté", "Côte d'Or", "Dijon", "CHU Dijon Bourgogne");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    // Successful import of 5 cases
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_success.csv").toURI());
    EventImporterExtension eventImporter = new EventImporterExtension(csvFile, true, user);
    ImportResultStatus importResult = eventImporter.runImport();
    assertEquals(eventImporter.errors.toString(), ImportResultStatus.COMPLETED, importResult);
    assertEquals(4, getEventFacade().count(null));
    assertEquals(3, getPersonFacade().count(null));
    List<EventDto> events = getEventFacade().getAllAfter(null);
    Optional<EventDto> optionalEventWith2Participants = events.stream().filter(event -> "Event title with 2 participants".equals(event.getEventTitle())).findFirst();
    assertTrue(optionalEventWith2Participants.isPresent());
    optionalEventWith2Participants.ifPresent(event -> {
        List<EventParticipantDto> participants = getEventParticipantFacade().getAllActiveEventParticipantsByEvent(event.getUuid());
        assertEquals(2, participants.size());
    });
    // Similarity: skip
    csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
    eventImporter = new EventImporterExtension(csvFile, true, user) {

        @Override
        protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP));
        }
    };
    importResult = eventImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(4, getEventFacade().count(null));
    assertEquals(3, getPersonFacade().count(null));
    // Similarity: pick
    List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
    csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
    eventImporter = new EventImporterExtension(csvFile, true, user) {

        @Override
        protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept(new PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
        }
    };
    importResult = eventImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(6, getEventFacade().count(null));
    assertEquals(3, getPersonFacade().count(null));
    // Similarity: cancel
    csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
    eventImporter = new EventImporterExtension(csvFile, true, user) {

        @Override
        protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CANCEL));
        }
    };
    importResult = eventImporter.runImport();
    assertEquals(ImportResultStatus.CANCELED, importResult);
    assertEquals(6, getEventFacade().count(null));
    assertEquals(3, getPersonFacade().count(null));
    // Similarity: create
    csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
    eventImporter = new EventImporterExtension(csvFile, true, user) {

        @Override
        protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
            resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
        }
    };
    importResult = eventImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(8, getEventFacade().count(null));
    assertEquals(6, getPersonFacade().count(null));
    // Successful import of 5 cases from a commented CSV file
    csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_comment_success.csv").toURI());
    eventImporter = new EventImporterExtension(csvFile, true, user);
    importResult = eventImporter.runImport();
    assertEquals(eventImporter.errors.toString(), ImportResultStatus.COMPLETED, importResult);
    assertEquals(10, getEventFacade().count(null));
}
Also used : FacadeProvider(de.symeda.sormas.api.FacadeProvider) ValueSeparator(de.symeda.sormas.api.importexport.ValueSeparator) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) PersonDto(de.symeda.sormas.api.person.PersonDto) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) ArrayList(java.util.ArrayList) StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) UserRole(de.symeda.sormas.api.user.UserRole) Path(java.nio.file.Path) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) CsvValidationException(com.opencsv.exceptions.CsvValidationException) UserDto(de.symeda.sormas.api.user.UserDto) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) EventDto(de.symeda.sormas.api.event.EventDto) PersonHelper(de.symeda.sormas.api.person.PersonHelper) File(java.io.File) EventImporter(de.symeda.sormas.ui.events.importer.EventImporter) Consumer(java.util.function.Consumer) List(java.util.List) Paths(java.nio.file.Paths) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) Writer(java.io.Writer) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonSimilarityCriteria (de.symeda.sormas.api.person.PersonSimilarityCriteria)9 Test (org.junit.Test)7 PersonDto (de.symeda.sormas.api.person.PersonDto)6 UserDto (de.symeda.sormas.api.user.UserDto)6 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)5 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)5 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 UI (com.vaadin.ui.UI)4 EventDto (de.symeda.sormas.api.event.EventDto)4 Date (java.util.Date)4 List (java.util.List)4 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)3 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)3 ImportSimilarityResultOption (de.symeda.sormas.ui.importer.ImportSimilarityResultOption)3 PersonImportSimilarityResult (de.symeda.sormas.ui.importer.PersonImportSimilarityResult)3 Consumer (java.util.function.Consumer)3 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)2