@Test public void testLockOldDrafts() { int lockedAfterDay = 14; Utkast utkast1 = new Utkast(); utkast1.setIntygsId("id1"); utkast1.setRelationIntygsId("id2"); utkast1.setRelationKod(RelationKod.ERSATT); Utkast utkast2 = new Utkast(); utkast2.setIntygsId("id2"); LocalDate today = LocalDate.now(); List<Utkast> utkastList = Arrays.asList(utkast1, utkast2); when(utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(any())).thenReturn(utkastList); int changed = utkastService.lockOldDrafts(lockedAfterDay, today); assertEquals(2, changed); verify(utkastRepository, times(2)).save(any(Utkast.class)); verify(utkastRepository, times(2)).removeRelationsToDraft(anyString()); assertNull(utkast1.getRelationIntygsId()); assertNull(utkast1.getRelationKod()); assertEquals(UtkastStatus.DRAFT_LOCKED, utkast1.getStatus()); assertEquals(UtkastStatus.DRAFT_LOCKED, utkast2.getStatus()); }
@Override @Transactional public int lockOldDrafts(int lockedAfterDay, LocalDate today) { LocalDate lastCreatedDate = today.minusDays(lockedAfterDay); LocalDateTime lastCreatedDateTime = lastCreatedDate.atStartOfDay(); List<Utkast> utkasts = utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(lastCreatedDateTime); utkasts.forEach(utkast -> { utkastRepository.removeRelationsToDraft(utkast.getIntygsId()); utkast.setRelationKod(null); utkast.setRelationIntygsId(null); utkast.setStatus(UtkastStatus.DRAFT_LOCKED); utkastRepository.save(utkast); certificateEventService .createCertificateEvent(utkast.getIntygsId(), "UtkastLockJob", EventCode.LAST, "Draft locked after 14 days"); monitoringService.logUtkastLocked(utkast.getIntygsId(), utkast.getIntygsTyp()); }); return utkasts.size(); }
UtkastServiceImpl implements UtkastService { @Override @Transactional public int lockOldDrafts(int lockedAfterDay, LocalDate today) { LocalDate lastCreatedDate = today.minusDays(lockedAfterDay); LocalDateTime lastCreatedDateTime = lastCreatedDate.atStartOfDay(); List<Utkast> utkasts = utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(lastCreatedDateTime); utkasts.forEach(utkast -> { utkastRepository.removeRelationsToDraft(utkast.getIntygsId()); utkast.setRelationKod(null); utkast.setRelationIntygsId(null); utkast.setStatus(UtkastStatus.DRAFT_LOCKED); utkastRepository.save(utkast); certificateEventService .createCertificateEvent(utkast.getIntygsId(), "UtkastLockJob", EventCode.LAST, "Draft locked after 14 days"); monitoringService.logUtkastLocked(utkast.getIntygsId(), utkast.getIntygsTyp()); }); return utkasts.size(); } }
UtkastServiceImpl implements UtkastService { @Override @Transactional public int lockOldDrafts(int lockedAfterDay, LocalDate today) { LocalDate lastCreatedDate = today.minusDays(lockedAfterDay); LocalDateTime lastCreatedDateTime = lastCreatedDate.atStartOfDay(); List<Utkast> utkasts = utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(lastCreatedDateTime); utkasts.forEach(utkast -> { utkastRepository.removeRelationsToDraft(utkast.getIntygsId()); utkast.setRelationKod(null); utkast.setRelationIntygsId(null); utkast.setStatus(UtkastStatus.DRAFT_LOCKED); utkastRepository.save(utkast); certificateEventService .createCertificateEvent(utkast.getIntygsId(), "UtkastLockJob", EventCode.LAST, "Draft locked after 14 days"); monitoringService.logUtkastLocked(utkast.getIntygsId(), utkast.getIntygsTyp()); }); return utkasts.size(); }  }
UtkastServiceImpl implements UtkastService { @Override @Transactional public int lockOldDrafts(int lockedAfterDay, LocalDate today) { LocalDate lastCreatedDate = today.minusDays(lockedAfterDay); LocalDateTime lastCreatedDateTime = lastCreatedDate.atStartOfDay(); List<Utkast> utkasts = utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(lastCreatedDateTime); utkasts.forEach(utkast -> { utkastRepository.removeRelationsToDraft(utkast.getIntygsId()); utkast.setRelationKod(null); utkast.setRelationIntygsId(null); utkast.setStatus(UtkastStatus.DRAFT_LOCKED); utkastRepository.save(utkast); certificateEventService .createCertificateEvent(utkast.getIntygsId(), "UtkastLockJob", EventCode.LAST, "Draft locked after 14 days"); monitoringService.logUtkastLocked(utkast.getIntygsId(), utkast.getIntygsTyp()); }); return utkasts.size(); }  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 @Transactional public int lockOldDrafts(int lockedAfterDay, LocalDate today) { LocalDate lastCreatedDate = today.minusDays(lockedAfterDay); LocalDateTime lastCreatedDateTime = lastCreatedDate.atStartOfDay(); List<Utkast> utkasts = utkastRepository.findDraftsByNotLockedOrSignedAndSkapadBefore(lastCreatedDateTime); utkasts.forEach(utkast -> { utkastRepository.removeRelationsToDraft(utkast.getIntygsId()); utkast.setRelationKod(null); utkast.setRelationIntygsId(null); utkast.setStatus(UtkastStatus.DRAFT_LOCKED); utkastRepository.save(utkast); certificateEventService .createCertificateEvent(utkast.getIntygsId(), "UtkastLockJob", EventCode.LAST, "Draft locked after 14 days"); monitoringService.logUtkastLocked(utkast.getIntygsId(), utkast.getIntygsTyp()); }); return utkasts.size(); }  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);  }