use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class CertificateRevokeProcessor method process.
public void process(@Body String xmlBody, @Header(Constants.INTYGS_ID) String intygsId, @Header(Constants.LOGICAL_ADDRESS) String logicalAddress, @Header(Constants.INTYGS_TYP) String intygsTyp) throws TemporaryException, PermanentException {
checkArgument(!Strings.isNullOrEmpty(intygsId), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_ID);
checkArgument(!Strings.isNullOrEmpty(logicalAddress), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.LOGICAL_ADDRESS);
checkArgument(!Strings.isNullOrEmpty(intygsTyp), "Message of type %s does not have a %s header.", Constants.REVOKE_MESSAGE, Constants.INTYGS_TYP);
try {
ModuleApi moduleApi = registry.getModuleApi(intygsTyp);
moduleApi.revokeCertificate(xmlBody, logicalAddress);
} catch (ExternalServiceCallException e) {
switch(e.getErroIdEnum()) {
case TECHNICAL_ERROR:
case APPLICATION_ERROR:
throw new TemporaryException(e.getMessage());
default:
throw new PermanentException(e.getMessage());
}
} catch (ModuleException e) {
throw new PermanentException(e.getMessage());
} catch (WebServiceException e) {
throw new TemporaryException(e.getMessage());
} catch (Exception e) {
throw new PermanentException(e.getMessage());
}
}
use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class CertificateRevokeProcessorTest method testRevokeCertificateOnApplicationErrorResponse.
@Test(expected = TemporaryException.class)
public void testRevokeCertificateOnApplicationErrorResponse() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.APPLICATION_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class CertificateRevokeProcessorTest method testRevokeCertificateOnTechnicalErrorResponse.
@Test(expected = TemporaryException.class)
public void testRevokeCertificateOnTechnicalErrorResponse() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.TECHNICAL_ERROR)).when(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
}
use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class CertificateRevokeProcessorTest method testRevokeCertificate.
@Test
public void testRevokeCertificate() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
certificateRevokeProcessor.process(BODY, INTYGS_ID1, LOGICAL_ADDRESS1, INTYGS_TYP);
verify(moduleApi).revokeCertificate(eq(BODY), eq(LOGICAL_ADDRESS1));
}
use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class IntygServiceImpl method listCertificatesForCareWithQA.
@Override
public List<IntygWithNotificationsResponse> listCertificatesForCareWithQA(IntygWithNotificationsRequest request) {
List<Utkast> utkastList;
if (request.shouldUseEnhetId()) {
utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getEnhetId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
} else {
utkastList = utkastRepository.findDraftsByPatientAndVardgivareAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getVardgivarId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
}
List<IntygWithNotificationsResponse> res = new ArrayList<>();
for (Utkast utkast : utkastList) {
List<Handelse> notifications = notificationService.getNotifications(utkast.getIntygsId());
String ref = referensService.getReferensForIntygsId(utkast.getIntygsId());
notifications = notifications.stream().filter(handelse -> {
if (request.getStartDate() != null && handelse.getTimestamp().isBefore(request.getStartDate())) {
return false;
}
if (request.getEndDate() != null && handelse.getTimestamp().isAfter(request.getEndDate())) {
return false;
}
return true;
}).collect(Collectors.toList());
// this time span
if ((request.getStartDate() != null || request.getEndDate() != null) && notifications.isEmpty()) {
continue;
}
try {
ModuleApi api = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
Intyg intyg = api.getIntygFromUtlatande(api.getUtlatandeFromJson(utkast.getModel()));
Pair<ArendeCount, ArendeCount> arenden = fragorOchSvarCreator.createArenden(utkast.getIntygsId(), utkast.getIntygsTyp());
res.add(new IntygWithNotificationsResponse(intyg, notifications, arenden.getLeft(), arenden.getRight(), ref));
} catch (ModuleNotFoundException | ModuleException | IOException e) {
LOG.error("Could not convert intyg {} to external format", utkast.getIntygsId());
}
}
return res;
}
Aggregations