SormasToSormasFacadeEjb implements SormasToSormasFacade { @Override public void shareContact(String uuid, SormasToSormasOptionsDto options) throws SormasToSormasException { User currentUser = userService.getCurrentUser(); Contact contact = contactService.getByUuid(uuid); Pseudonymizer pseudonymizer = createPseudonymizer(options); PersonDto personDto = getPersonDto(contact.getPerson(), pseudonymizer, options); ContactDto contactDto = getContactDto(contact, pseudonymizer); contactDto.setSormasToSormasOriginInfo(createSormasToSormasOriginInfo(currentUser, options)); sendEntityToSormas(new SormasToSormasContactDto(personDto, contactDto), SAVE_SHARED_CONTACT_ENDPOINT, options); 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 testShareContact() throws SormasToSormasException, JsonProcessingException, NoSuchAlgorithmException, KeyManagementException { RDCF rdcf = creator.createRDCF(); useSurveillanceOfficerLogin(rdcf); PersonDto person = creator.createPerson(); UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference(); ContactDto contact = creator.createContact(officer, officer, person.toReference(), null, new Date(), null, null, rdcf, dto -> { dto.setResultingCaseUser(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/contact")); 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); SormasToSormasContactDto sharedContact = decryptSharesData(encryptedData.getData(), SormasToSormasContactDto.class); assertThat(sharedContact.getPerson().getFirstName(), is(person.getFirstName())); assertThat(sharedContact.getPerson().getLastName(), is(person.getLastName())); assertThat(sharedContact.getContact().getUuid(), is(contact.getUuid())); assertThat(sharedContact.getContact().getReportingUser(), is(nullValue())); assertThat(sharedContact.getContact().getContactOfficer(), is(nullValue())); assertThat(sharedContact.getContact().getResultingCaseUser(), is(nullValue())); assertThat(sharedContact.getContact().getSormasToSormasOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ACCESS_CN)); assertThat(sharedContact.getContact().getSormasToSormasOriginInfo().getSenderName(), is("Surv Off")); assertThat(sharedContact.getContact().getSormasToSormasOriginInfo().getComment(), is("Test comment")); return Response.noContent().build(); }); getSormasToSormasFacade().shareContact(contact.getUuid(), options); List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasFacade().getShareInfoIndexList(new SormasToSormasShareInfoCriteria().contact(contact.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")); }