@Test public void testCorrectErrorMessageForSendMessageToCare() { setupIds(); setupMockUpdate(); when(consumer.doLookup(anyString(), anyString(), eq(CERT_STATUS_V3_ID))).thenReturn(buildTakLogicalAddress("16")); when(consumer.doLookup(anyString(), anyString(), eq(SEND_MESSAGE_TO_CARE_ID))).thenReturn(new TakLogicalAddress[]{}); String hsa = HSAID_OK; TakResult result = impl.verifyTakningForCareUnit(hsa, "luse", SchemaVersion.VERSION_3, user); assertTrue(!result.getErrorMessages().isEmpty()); assertEquals(String.format(ERROR_STRING_ARENDEHANTERING, SEND_MESSAGE_TO_CARE_NS, hsa), result.getErrorMessages().get(0)); }
@Override public TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user) { LOG.info("Checking TAK-status for {}", intygsTyp); List<String> errors = new ArrayList<>(); boolean ret; try { ret = CompletableFuture.supplyAsync(() -> { boolean res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); if (!res) { update(); errors.clear(); res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); } return res; }).get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.warn("The overall timeout for this call was reached, draft creation allowed anyway."); ret = true; } catch (TakServiceException e) { LOG.error("Contacting TAK was unsuccessful", e); ret = true; } catch (ResourceAccessException e) { LOG.warn("Connection to TAK-api timed out, draft creation allowed anyway."); ret = true; } catch (Exception e) { LOG.warn("Unknown exception occured when communicating with TAK. Draft creation allowed anyway.", e); ret = true; } return new TakResult(ret, errors); }
TakServiceImpl implements TakService { @Override public TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user) { LOG.info("Checking TAK-status for {}", intygsTyp); List<String> errors = new ArrayList<>(); boolean ret; try { ret = CompletableFuture.supplyAsync(() -> { boolean res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); if (!res) { update(); errors.clear(); res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); } return res; }).get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.warn("The overall timeout for this call was reached, draft creation allowed anyway."); ret = true; } catch (TakServiceException e) { LOG.error("Contacting TAK was unsuccessful", e); ret = true; } catch (ResourceAccessException e) { LOG.warn("Connection to TAK-api timed out, draft creation allowed anyway."); ret = true; } catch (Exception e) { LOG.warn("Unknown exception occured when communicating with TAK. Draft creation allowed anyway.", e); ret = true; } return new TakResult(ret, errors); } }
TakServiceImpl implements TakService { @Override public TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user) { LOG.info("Checking TAK-status for {}", intygsTyp); List<String> errors = new ArrayList<>(); boolean ret; try { ret = CompletableFuture.supplyAsync(() -> { boolean res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); if (!res) { update(); errors.clear(); res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); } return res; }).get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.warn("The overall timeout for this call was reached, draft creation allowed anyway."); ret = true; } catch (TakServiceException e) { LOG.error("Contacting TAK was unsuccessful", e); ret = true; } catch (ResourceAccessException e) { LOG.warn("Connection to TAK-api timed out, draft creation allowed anyway."); ret = true; } catch (Exception e) { LOG.warn("Unknown exception occured when communicating with TAK. Draft creation allowed anyway.", e); ret = true; } return new TakResult(ret, errors); }  }
TakServiceImpl implements TakService { @Override public TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user) { LOG.info("Checking TAK-status for {}", intygsTyp); List<String> errors = new ArrayList<>(); boolean ret; try { ret = CompletableFuture.supplyAsync(() -> { boolean res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); if (!res) { update(); errors.clear(); res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); } return res; }).get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.warn("The overall timeout for this call was reached, draft creation allowed anyway."); ret = true; } catch (TakServiceException e) { LOG.error("Contacting TAK was unsuccessful", e); ret = true; } catch (ResourceAccessException e) { LOG.warn("Connection to TAK-api timed out, draft creation allowed anyway."); ret = true; } catch (Exception e) { LOG.warn("Unknown exception occured when communicating with TAK. Draft creation allowed anyway.", e); ret = true; } return new TakResult(ret, errors); }  @Scheduled(cron = "${tak.update.cron}") void initUpdate(); void update(); @Override TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user); }
TakServiceImpl implements TakService { @Override public TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user) { LOG.info("Checking TAK-status for {}", intygsTyp); List<String> errors = new ArrayList<>(); boolean ret; try { ret = CompletableFuture.supplyAsync(() -> { boolean res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); if (!res) { update(); errors.clear(); res = isTakConfiguredCorrectly(intygsTyp, user, errors, hsaId, schemaVersion); } return res; }).get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { LOG.warn("The overall timeout for this call was reached, draft creation allowed anyway."); ret = true; } catch (TakServiceException e) { LOG.error("Contacting TAK was unsuccessful", e); ret = true; } catch (ResourceAccessException e) { LOG.warn("Connection to TAK-api timed out, draft creation allowed anyway."); ret = true; } catch (Exception e) { LOG.warn("Unknown exception occured when communicating with TAK. Draft creation allowed anyway.", e); ret = true; } return new TakResult(ret, errors); }  @Scheduled(cron = "${tak.update.cron}") void initUpdate(); void update(); @Override TakResult verifyTakningForCareUnit(String hsaId, String intygsTyp, SchemaVersion schemaVersion, IntygUser user);  }