@Test public void testUpdateDraftFromCandidate() throws Exception { String fromIntygId = INTYG_ID; String fromIntygType = INTYG_TYPE2; String toIntygId = "ghi789"; String toIntygType = "ag7804"; VardpersonReferens vardperson = setupVardperson(hoSPerson); signedUtkast = createUtkast(fromIntygId, INTYG_VERSION, fromIntygType, UtkastStatus.SIGNED, LocalDateTime.parse("2018-04-23T00:00:00"), INTYG_JSON, vardperson, PERSONNUMMER); utkast = createUtkast(toIntygId, 0, toIntygType, UtkastStatus.DRAFT_INCOMPLETE, null, INTYG_JSON, vardperson, PERSONNUMMER); Utkast savedUtkast = utkast; savedUtkast.setVersion(utkast.getVersion() + 1); Utlatande utlatande = mock(Utlatande.class); GrundData grunddata = new GrundData(); grunddata.setSkapadAv(new HoSPersonal()); grunddata.setPatient(defaultPatient); Mapper mapper = mock(Mapper.class); when(utlatande.getGrundData()).thenReturn(grunddata); when(mapper.map(any(), any())).thenReturn(mapper); when(mapper.json()).thenReturn(INTYG_JSON); when(utkastRepository.findByIntygsIdAndIntygsTyp(toIntygId, toIntygType)).thenReturn(utkast); when(moduleRegistry.getModuleApi(toIntygType, INTYG_TYPE_VERSION)).thenReturn(moduleApi); when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande); when(utkastRepository.save(utkast)).thenReturn(savedUtkast); when(moduleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true); when(userService.getUser()).thenReturn(createUser()); when(utkastServiceHelper.getUtlatandeForCandidateFromIT(fromIntygId, fromIntygType, false, true)).thenReturn(utlatande); when(moduleApi.getMapper()).thenReturn(Optional.of(mapper)); when(moduleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}"); SaveDraftResponse res = utkastService.updateDraftFromCandidate(fromIntygId, fromIntygType, toIntygId, toIntygType); verify(utkastRepository).save(any(Utkast.class)); verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class)); verify(logService).logUpdateIntyg(any(LogRequest.class)); verify(monitoringService).logUtkastEdited(toIntygId, toIntygType); assertNotNull("An DraftValidation should be returned", res); assertEquals("The status should still be incomplete", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus()); assertTrue("The saved draft version should be greater than zero", res.getVersion() > 0); }
@Override public SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType) { Utkast toUtkast = getIntygAsDraft(toUtkastId, toUtkastType); verifyUtkastExists(toUtkast, toUtkastId, toUtkastType, "The draft with id '" + toUtkastId + "' cannot be updated since it could not be found"); return updateDraftFromCandidate(fromIntygId, fromIntygType, toUtkast); }
UtkastServiceImpl implements UtkastService { @Override public SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType) { Utkast toUtkast = getIntygAsDraft(toUtkastId, toUtkastType); verifyUtkastExists(toUtkast, toUtkastId, toUtkastType, "The draft with id '" + toUtkastId + "' cannot be updated since it could not be found"); return updateDraftFromCandidate(fromIntygId, fromIntygType, toUtkast); } }
UtkastServiceImpl implements UtkastService { @Override public SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType) { Utkast toUtkast = getIntygAsDraft(toUtkastId, toUtkastType); verifyUtkastExists(toUtkast, toUtkastId, toUtkastType, "The draft with id '" + toUtkastId + "' cannot be updated since it could not be found"); return updateDraftFromCandidate(fromIntygId, fromIntygType, toUtkast); }  }
UtkastServiceImpl implements UtkastService { @Override public SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType) { Utkast toUtkast = getIntygAsDraft(toUtkastId, toUtkastType); verifyUtkastExists(toUtkast, toUtkastId, toUtkastType, "The draft with id '" + toUtkastId + "' cannot be updated since it could not be found"); return updateDraftFromCandidate(fromIntygId, fromIntygType, toUtkast); }  static boolean isUtkast(Utkast utkast); static boolean isEditableUtkast(Utkast utkast); @Override @Transactional() // , readOnly=true int countFilterIntyg(UtkastFilter filter); @Override Utkast createNewDraft(CreateNewDraftRequest request); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, Utkast toUtkast); @Override String getQuestions(String intygsTyp, String version); @Override @Transactional void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType); @Override Map<String, Map<String, PreviousIntyg>> checkIfPersonHasExistingIntyg(final Personnummer personnummer,
                                                                                 final IntygUser user,
                                                                                 final String currentDraftId); @Override @Transactional void deleteUnsignedDraft(String intygId, long version); @Override @Transactional(readOnly = true) List<Utkast> filterIntyg(UtkastFilter filter); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType, boolean createPdlLogEvent); @Override @Transactional(readOnly = true) List<Lakare> getLakareWithDraftsByEnhet(String enhetsId); @Override @Transactional(readOnly = true) Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds); @Override @Transactional SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent); @Override void updatePatientOnDraft(UpdatePatientOnDraftRequest request); @Override @Transactional Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified); @Override DraftValidation validateDraft(String intygId, String intygType, String draftAsJson); @Override @Transactional int lockOldDrafts(int lockedAfterDay, LocalDate today); @Override void revokeLockedDraft(String intygId, String intygTyp, String revokeMessage, String reason); @Override boolean isDraftCreatedFromReplacement(String certificateId); }
UtkastServiceImpl implements UtkastService { @Override public SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType) { Utkast toUtkast = getIntygAsDraft(toUtkastId, toUtkastType); verifyUtkastExists(toUtkast, toUtkastId, toUtkastType, "The draft with id '" + toUtkastId + "' cannot be updated since it could not be found"); return updateDraftFromCandidate(fromIntygId, fromIntygType, toUtkast); }  static boolean isUtkast(Utkast utkast); static boolean isEditableUtkast(Utkast utkast); @Override @Transactional() // , readOnly=true int countFilterIntyg(UtkastFilter filter); @Override Utkast createNewDraft(CreateNewDraftRequest request); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, String toUtkastId, String toUtkastType); @Override SaveDraftResponse updateDraftFromCandidate(String fromIntygId, String fromIntygType, Utkast toUtkast); @Override String getQuestions(String intygsTyp, String version); @Override @Transactional void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType); @Override Map<String, Map<String, PreviousIntyg>> checkIfPersonHasExistingIntyg(final Personnummer personnummer,
                                                                                 final IntygUser user,
                                                                                 final String currentDraftId); @Override @Transactional void deleteUnsignedDraft(String intygId, long version); @Override @Transactional(readOnly = true) List<Utkast> filterIntyg(UtkastFilter filter); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType); @Override @Transactional(readOnly = true) Utkast getDraft(String intygId, String intygType, boolean createPdlLogEvent); @Override @Transactional(readOnly = true) List<Lakare> getLakareWithDraftsByEnhet(String enhetsId); @Override @Transactional(readOnly = true) Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds); @Override @Transactional SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent); @Override void updatePatientOnDraft(UpdatePatientOnDraftRequest request); @Override @Transactional Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified); @Override DraftValidation validateDraft(String intygId, String intygType, String draftAsJson); @Override @Transactional int lockOldDrafts(int lockedAfterDay, LocalDate today); @Override void revokeLockedDraft(String intygId, String intygTyp, String revokeMessage, String reason); @Override boolean isDraftCreatedFromReplacement(String certificateId);  }