@Test public void notFound() { when(utkastRepository.findById(anyString())).thenReturn(Optional.empty()); when(handelseRepository.findByIntygsId(anyString())).thenReturn(new ArrayList<>()); when(arendeService.getArendenInternal(anyString())).thenReturn(new ArrayList<>()); when(fragaSvarRepository.findByIntygsReferensIntygsId(anyString())).thenReturn(new ArrayList<>()); Optional<WcIntygInfo> intygInfo = testee.getIntygInfo("not_found"); assertFalse(intygInfo.isPresent()); verifyNoInteractions(moduleRegistry); verifyNoInteractions(relationService); }
@Transactional(readOnly = true) public Optional<WcIntygInfo> getIntygInfo(String intygId) { Utkast utkast = utkastRepository.findById(intygId).orElse(null); WcIntygInfo response = new WcIntygInfo(); boolean foundHandelser = addHandelse(intygId, response); boolean foundArenden = addArendeInformation(intygId, response); if (utkast == null) { if (foundHandelser || foundArenden) { response.setIntygId(intygId); return Optional.of(response); } return Optional.empty(); } response.setCreatedInWC(true); response.setIntygId(utkast.getIntygsId()); response.setIntygType(utkast.getIntygsTyp()); response.setIntygVersion(utkast.getIntygTypeVersion()); response.setTestCertificate(utkast.isTestIntyg()); response.setDraftCreated(utkast.getSkapad()); response.setSentToRecipient(utkast.getSkickadTillMottagareDatum()); response.setCareUnitHsaId(utkast.getEnhetsId()); response.setCareUnitName(utkast.getEnhetsNamn()); response.setCareGiverHsaId(utkast.getVardgivarId()); response.setCareGiverName(utkast.getVardgivarNamn()); if (utkast.getSignatur() != null) { Signatur signatur = utkast.getSignatur(); response.setSignedDate(signatur.getSigneringsDatum()); response.setSignedByHsaId(signatur.getSigneradAv()); try { ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp(), utkast.getIntygTypeVersion()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(utkast.getModel()); response.setSignedByName(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn()); } catch (ModuleNotFoundException | ModuleException | IOException e) { LOG.error("Module not found for intyg " + intygId, e); } } addEvents(utkast, response); addRelations(intygId, response); return Optional.of(response); }
IntygInfoService { @Transactional(readOnly = true) public Optional<WcIntygInfo> getIntygInfo(String intygId) { Utkast utkast = utkastRepository.findById(intygId).orElse(null); WcIntygInfo response = new WcIntygInfo(); boolean foundHandelser = addHandelse(intygId, response); boolean foundArenden = addArendeInformation(intygId, response); if (utkast == null) { if (foundHandelser || foundArenden) { response.setIntygId(intygId); return Optional.of(response); } return Optional.empty(); } response.setCreatedInWC(true); response.setIntygId(utkast.getIntygsId()); response.setIntygType(utkast.getIntygsTyp()); response.setIntygVersion(utkast.getIntygTypeVersion()); response.setTestCertificate(utkast.isTestIntyg()); response.setDraftCreated(utkast.getSkapad()); response.setSentToRecipient(utkast.getSkickadTillMottagareDatum()); response.setCareUnitHsaId(utkast.getEnhetsId()); response.setCareUnitName(utkast.getEnhetsNamn()); response.setCareGiverHsaId(utkast.getVardgivarId()); response.setCareGiverName(utkast.getVardgivarNamn()); if (utkast.getSignatur() != null) { Signatur signatur = utkast.getSignatur(); response.setSignedDate(signatur.getSigneringsDatum()); response.setSignedByHsaId(signatur.getSigneradAv()); try { ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp(), utkast.getIntygTypeVersion()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(utkast.getModel()); response.setSignedByName(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn()); } catch (ModuleNotFoundException | ModuleException | IOException e) { LOG.error("Module not found for intyg " + intygId, e); } } addEvents(utkast, response); addRelations(intygId, response); return Optional.of(response); } }
IntygInfoService { @Transactional(readOnly = true) public Optional<WcIntygInfo> getIntygInfo(String intygId) { Utkast utkast = utkastRepository.findById(intygId).orElse(null); WcIntygInfo response = new WcIntygInfo(); boolean foundHandelser = addHandelse(intygId, response); boolean foundArenden = addArendeInformation(intygId, response); if (utkast == null) { if (foundHandelser || foundArenden) { response.setIntygId(intygId); return Optional.of(response); } return Optional.empty(); } response.setCreatedInWC(true); response.setIntygId(utkast.getIntygsId()); response.setIntygType(utkast.getIntygsTyp()); response.setIntygVersion(utkast.getIntygTypeVersion()); response.setTestCertificate(utkast.isTestIntyg()); response.setDraftCreated(utkast.getSkapad()); response.setSentToRecipient(utkast.getSkickadTillMottagareDatum()); response.setCareUnitHsaId(utkast.getEnhetsId()); response.setCareUnitName(utkast.getEnhetsNamn()); response.setCareGiverHsaId(utkast.getVardgivarId()); response.setCareGiverName(utkast.getVardgivarNamn()); if (utkast.getSignatur() != null) { Signatur signatur = utkast.getSignatur(); response.setSignedDate(signatur.getSigneringsDatum()); response.setSignedByHsaId(signatur.getSigneradAv()); try { ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp(), utkast.getIntygTypeVersion()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(utkast.getModel()); response.setSignedByName(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn()); } catch (ModuleNotFoundException | ModuleException | IOException e) { LOG.error("Module not found for intyg " + intygId, e); } } addEvents(utkast, response); addRelations(intygId, response); return Optional.of(response); }  }
IntygInfoService { @Transactional(readOnly = true) public Optional<WcIntygInfo> getIntygInfo(String intygId) { Utkast utkast = utkastRepository.findById(intygId).orElse(null); WcIntygInfo response = new WcIntygInfo(); boolean foundHandelser = addHandelse(intygId, response); boolean foundArenden = addArendeInformation(intygId, response); if (utkast == null) { if (foundHandelser || foundArenden) { response.setIntygId(intygId); return Optional.of(response); } return Optional.empty(); } response.setCreatedInWC(true); response.setIntygId(utkast.getIntygsId()); response.setIntygType(utkast.getIntygsTyp()); response.setIntygVersion(utkast.getIntygTypeVersion()); response.setTestCertificate(utkast.isTestIntyg()); response.setDraftCreated(utkast.getSkapad()); response.setSentToRecipient(utkast.getSkickadTillMottagareDatum()); response.setCareUnitHsaId(utkast.getEnhetsId()); response.setCareUnitName(utkast.getEnhetsNamn()); response.setCareGiverHsaId(utkast.getVardgivarId()); response.setCareGiverName(utkast.getVardgivarNamn()); if (utkast.getSignatur() != null) { Signatur signatur = utkast.getSignatur(); response.setSignedDate(signatur.getSigneringsDatum()); response.setSignedByHsaId(signatur.getSigneradAv()); try { ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp(), utkast.getIntygTypeVersion()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(utkast.getModel()); response.setSignedByName(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn()); } catch (ModuleNotFoundException | ModuleException | IOException e) { LOG.error("Module not found for intyg " + intygId, e); } } addEvents(utkast, response); addRelations(intygId, response); return Optional.of(response); }  @Transactional(readOnly = true) Optional<WcIntygInfo> getIntygInfo(String intygId); }
IntygInfoService { @Transactional(readOnly = true) public Optional<WcIntygInfo> getIntygInfo(String intygId) { Utkast utkast = utkastRepository.findById(intygId).orElse(null); WcIntygInfo response = new WcIntygInfo(); boolean foundHandelser = addHandelse(intygId, response); boolean foundArenden = addArendeInformation(intygId, response); if (utkast == null) { if (foundHandelser || foundArenden) { response.setIntygId(intygId); return Optional.of(response); } return Optional.empty(); } response.setCreatedInWC(true); response.setIntygId(utkast.getIntygsId()); response.setIntygType(utkast.getIntygsTyp()); response.setIntygVersion(utkast.getIntygTypeVersion()); response.setTestCertificate(utkast.isTestIntyg()); response.setDraftCreated(utkast.getSkapad()); response.setSentToRecipient(utkast.getSkickadTillMottagareDatum()); response.setCareUnitHsaId(utkast.getEnhetsId()); response.setCareUnitName(utkast.getEnhetsNamn()); response.setCareGiverHsaId(utkast.getVardgivarId()); response.setCareGiverName(utkast.getVardgivarNamn()); if (utkast.getSignatur() != null) { Signatur signatur = utkast.getSignatur(); response.setSignedDate(signatur.getSigneringsDatum()); response.setSignedByHsaId(signatur.getSigneradAv()); try { ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp(), utkast.getIntygTypeVersion()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(utkast.getModel()); response.setSignedByName(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn()); } catch (ModuleNotFoundException | ModuleException | IOException e) { LOG.error("Module not found for intyg " + intygId, e); } } addEvents(utkast, response); addRelations(intygId, response); return Optional.of(response); }  @Transactional(readOnly = true) Optional<WcIntygInfo> getIntygInfo(String intygId);  }