SormasToSormasFacadeEjb implements SormasToSormasFacade { @Override public void shareCase(String uuid, SormasToSormasOptionsDto options) throws SormasToSormasException { User currentUser = userService.getCurrentUser(); Case caze = caseService.getByUuid(uuid); Pseudonymizer pseudonymizer = createPseudonymizer(options); PersonDto personDto = getPersonDto(caze.getPerson(), pseudonymizer, options); CaseDataDto cazeDto = getCazeDto(caze, pseudonymizer); SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(currentUser, options); SormasToSormasCaseDto entityToSend = new SormasToSormasCaseDto(personDto, cazeDto, originInfo); List<Contact> associatedContacts = Collections.emptyList(); if (options.isWithAssociatedContacts()) { associatedContacts = contactService.findBy(new ContactCriteria().caze(caze.toReference()), userService.getCurrentUser()); entityToSend.setAssociatedContacts(getAssociatedContactDtos(associatedContacts, pseudonymizer, options)); } sendEntityToSormas(entityToSend, SAVE_SHARED_CASE_ENDPOINT, options); saveNewShareInfo(currentUser.toReference(), options, caze, null); associatedContacts.forEach((contact) -> saveNewShareInfo(currentUser.toReference(), options, null, contact)); } SormasToSormasFacadeEjb(); @Override @Transactional void saveSharedCase(SormasToSormasEncryptedDataDto encryptedData); @Override @Transactional void saveSharedContact(SormasToSormasEncryptedDataDto sharedData); @Override void shareCase(String uuid, SormasToSormasOptionsDto options); @Override void shareContact(String uuid, SormasToSormasOptionsDto options); @Override List<ServerAccessDataReferenceDto> getAvailableOrganizations(); @Override List<SormasToSormasShareInfoDto> getShareInfoIndexList(SormasToSormasShareInfoCriteria criteria, Integer first, Integer max); @Override boolean isFeatureEnabled(); @Override ServerAccessDataReferenceDto getOrganizationRef(String id); SormasToSormasOriginInfo fromSormasToSormasOriginInfoDto(SormasToSormasOriginInfoDto source); static SormasToSormasOriginInfoDto toSormasToSormasOriginInfoDto(SormasToSormasOriginInfo source); SormasToSormasShareInfoDto toSormasToSormasShareInfoDto(SormasToSormasShareInfo source); static final String SAVE_SHARED_CASE_ENDPOINT; }
@Test public void testShareCase() throws SormasToSormasException, JsonProcessingException, NoSuchAlgorithmException, KeyManagementException { RDCF rdcf = creator.createRDCF(); useSurveillanceOfficerLogin(rdcf); PersonDto person = creator.createPerson(); UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference(); CaseDataDto caze = creator.createCase(officer, rdcf, dto -> { dto.setPerson(person.toReference()); dto.setSurveillanceOfficer(officer); dto.setClassificationUser(officer); }); SormasToSormasOptionsDto options = new SormasToSormasOptionsDto(); options.setOrganization(new ServerAccessDataReferenceDto(SECOND_SERVER_ACCESS_CN)); options.setComment("Test comment"); Mockito.when(MockProducer.getSormasToSormasClient().post(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.any())) .thenAnswer(invocation -> { assertThat(invocation.getArgumentAt(0, String.class), is(SECOND_SERVER_REST_URL)); assertThat(invocation.getArgumentAt(1, String.class), is("/sormasToSormas/case")); String authToken = invocation.getArgumentAt(2, String.class); assertThat(authToken, startsWith("Basic ")); String credentials = new String(Base64.getDecoder().decode(authToken.replace("Basic ", "")), StandardCharsets.UTF_8); assertThat(credentials, is(StartupShutdownService.SORMAS_TO_SORMAS_USER_NAME + ":" + SECOND_SERVER_REST_PASSWORD)); SormasToSormasEncryptedDataDto encryptedData = invocation.getArgumentAt(3, SormasToSormasEncryptedDataDto.class); assertThat(encryptedData.getOrganizationId(), is(DEFAULT_SERVER_ACCESS_CN)); SormasToSormasCaseDto sharedCase = decryptSharesData(encryptedData.getData(), SormasToSormasCaseDto.class); assertThat(sharedCase.getPerson().getFirstName(), is(person.getFirstName())); assertThat(sharedCase.getPerson().getLastName(), is(person.getLastName())); assertThat(sharedCase.getCaze().getUuid(), is(caze.getUuid())); assertThat(sharedCase.getCaze().getReportingUser(), is(nullValue())); assertThat(sharedCase.getCaze().getSurveillanceOfficer(), is(nullValue())); assertThat(sharedCase.getCaze().getClassificationUser(), is(nullValue())); assertThat(sharedCase.getOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ACCESS_CN)); assertThat(sharedCase.getOriginInfo().getSenderName(), is("Surv Off")); assertThat(sharedCase.getOriginInfo().getComment(), is("Test comment")); return Response.noContent().build(); }); getSormasToSormasFacade().shareCase(caze.getUuid(), options); List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasFacade().getShareInfoIndexList(new SormasToSormasShareInfoCriteria().caze(caze.toReference()), 0, 100); assertThat(shareInfoList.size(), is(1)); assertThat(shareInfoList.get(0).getTarget().getUuid(), is(SECOND_SERVER_ACCESS_CN)); assertThat(shareInfoList.get(0).getSender().getCaption(), is("Surv OFF - Surveillance Officer")); assertThat(shareInfoList.get(0).getComment(), is("Test comment")); }
@Test public void testShareCaseWithPseudonymizePersonalData() throws SormasToSormasException, JsonProcessingException, NoSuchAlgorithmException, KeyManagementException { RDCF rdcf = creator.createRDCF(); useSurveillanceOfficerLogin(rdcf); PersonDto person = creator.createPerson(); UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference(); CaseDataDto caze = creator.createCase(officer, rdcf, dto -> { dto.setPerson(person.toReference()); dto.setSurveillanceOfficer(officer); dto.setClassificationUser(officer); dto.setAdditionalDetails("Test additional details"); }); SormasToSormasOptionsDto options = new SormasToSormasOptionsDto(); options.setOrganization(new ServerAccessDataReferenceDto(SECOND_SERVER_ACCESS_CN)); options.setPseudonymizePersonalData(true); Mockito.when(MockProducer.getSormasToSormasClient().post(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.any())) .thenAnswer(invocation -> { SormasToSormasEncryptedDataDto encryptedData = invocation.getArgumentAt(3, SormasToSormasEncryptedDataDto.class); SormasToSormasCaseDto sharedCase = decryptSharesData(encryptedData.getData(), SormasToSormasCaseDto.class); assertThat(sharedCase.getPerson().getFirstName(), is("Confidential")); assertThat(sharedCase.getPerson().getLastName(), is("Confidential")); assertThat(sharedCase.getCaze().getAdditionalDetails(), is("Test additional details")); return Response.noContent().build(); }); getSormasToSormasFacade().shareCase(caze.getUuid(), options); }
@Test public void testShareCaseWithPseudonymizeSensitiveData() throws SormasToSormasException, JsonProcessingException, NoSuchAlgorithmException, KeyManagementException { RDCF rdcf = creator.createRDCF(); useSurveillanceOfficerLogin(rdcf); PersonDto person = creator.createPerson(); UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference(); CaseDataDto caze = creator.createCase(officer, rdcf, dto -> { dto.setPerson(person.toReference()); dto.setSurveillanceOfficer(officer); dto.setClassificationUser(officer); dto.setAdditionalDetails("Test additional details"); }); SormasToSormasOptionsDto options = new SormasToSormasOptionsDto(); options.setOrganization(new ServerAccessDataReferenceDto(SECOND_SERVER_ACCESS_CN)); options.setPseudonymizeSensitiveData(true); Mockito.when(MockProducer.getSormasToSormasClient().post(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.any())) .thenAnswer(invocation -> { SormasToSormasEncryptedDataDto encryptedData = invocation.getArgumentAt(3, SormasToSormasEncryptedDataDto.class); SormasToSormasCaseDto sharedCase = decryptSharesData(encryptedData.getData(), SormasToSormasCaseDto.class); assertThat(sharedCase.getPerson().getFirstName(), is("Confidential")); assertThat(sharedCase.getPerson().getLastName(), is("Confidential")); assertThat(sharedCase.getCaze().getAdditionalDetails(), isEmptyString()); return Response.noContent().build(); }); getSormasToSormasFacade().shareCase(caze.getUuid(), options); }