use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class NotificationTransformerTest method testSchemaVersion2Transformation.
@Test
public void testSchemaVersion2Transformation() throws Exception {
NotificationMessage notificationMessage = new NotificationMessage(INTYGS_ID, LUSE, LocalDateTime.now(), HandelsekodEnum.SKAPAT, LOGISK_ADRESS, "{ }", null, ArendeCount.getEmpty(), ArendeCount.getEmpty(), SchemaVersion.VERSION_3, "ref");
Message message = spy(new DefaultMessage());
message.setBody(notificationMessage);
ModuleApi moduleApi = mock(ModuleApi.class);
when(moduleRegistry.getModuleApi(eq(LUSE))).thenReturn(moduleApi);
Intyg intyg = new Intyg();
IntygId intygsId = new IntygId();
intygsId.setExtension(INTYGS_ID);
intyg.setIntygsId(intygsId);
HosPersonal hosPersonal = new HosPersonal();
Enhet enhet = new Enhet();
enhet.setArbetsplatskod(new ArbetsplatsKod());
enhet.setVardgivare(new Vardgivare());
hosPersonal.setEnhet(enhet);
intyg.setSkapadAv(hosPersonal);
when(moduleApi.getIntygFromUtlatande(any())).thenReturn(intyg);
transformer.process(message);
assertEquals(INTYGS_ID, ((se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType) message.getBody()).getIntyg().getIntygsId().getExtension());
assertEquals(HandelsekodEnum.SKAPAT.value(), message.getHeader(NotificationRouteHeaders.HANDELSE));
assertEquals(INTYGS_ID, message.getHeader(NotificationRouteHeaders.INTYGS_ID));
assertEquals(LOGISK_ADRESS, message.getHeader(NotificationRouteHeaders.LOGISK_ADRESS));
assertEquals(SchemaVersion.VERSION_3.name(), message.getHeader(NotificationRouteHeaders.VERSION));
verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.LOGISK_ADRESS), eq(LOGISK_ADRESS));
verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.INTYGS_ID), eq(INTYGS_ID));
verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.HANDELSE), eq(HandelsekodEnum.SKAPAT.value()));
verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.VERSION), eq(SchemaVersion.VERSION_3.name()));
verify(moduleRegistry, times(1)).getModuleApi(eq(LUSE));
verify(moduleApi, times(1)).getUtlatandeFromJson(any());
verify(moduleApi, times(1)).getIntygFromUtlatande(any());
verify(notificationPatientEnricher, times(1)).enrichWithPatient(any());
}
use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.
the class CertificateRevokeProcessorTest method testRevokeCertificateWhenWebServiceExceptionIsThrown.
@Test(expected = TemporaryException.class)
public void testRevokeCertificateWhenWebServiceExceptionIsThrown() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
doThrow(new WebServiceException()).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 testRevokeCertificateOnTransformationErrorResponse.
@Test(expected = PermanentException.class)
public void testRevokeCertificateOnTransformationErrorResponse() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.TRANSFORMATION_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 testRevokeCertificateOnValidationErrorResponse.
@Test(expected = PermanentException.class)
public void testRevokeCertificateOnValidationErrorResponse() throws Exception {
ModuleApi moduleApi = mock(ModuleApi.class);
when(registry.getModuleApi(eq(INTYGS_TYP))).thenReturn(moduleApi);
doThrow(new ExternalServiceCallException("message", ExternalServiceCallException.ErrorIdEnum.VALIDATION_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 UtkastServiceImpl method saveDraft.
@Override
@Transactional("jpaTransactionManager")
public SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent) {
LOG.debug("Saving and validating utkast '{}'", intygId);
Utkast utkast = utkastRepository.findOne(intygId);
if (utkast == null) {
LOG.warn("Utkast '{}' was not found", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The utkast could not be found");
}
// check that the draft hasn't been modified concurrently
if (utkast.getVersion() != version) {
LOG.debug("Utkast '{}' was concurrently modified", intygId);
throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
}
// check that the draft is still a draft
if (!isTheDraftStillADraft(utkast.getStatus())) {
LOG.error("Utkast '{}' can not be updated since it is no longer in draft mode", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "This utkast can not be updated since it is no longer in draft mode");
}
String intygType = utkast.getIntygsTyp();
// Keep persisted json for comparsion
String persistedJson = utkast.getModel();
// Update draft with user information
updateUtkastModel(utkast, draftAsJson);
// Is draft valid?
DraftValidation draftValidation = validateDraft(intygId, intygType, draftAsJson);
UtkastStatus utkastStatus = draftValidation.isDraftValid() ? UtkastStatus.DRAFT_COMPLETE : UtkastStatus.DRAFT_INCOMPLETE;
utkast.setStatus(utkastStatus);
// Save the updated draft
utkast = saveDraft(utkast);
LOG.debug("Utkast '{}' updated", utkast.getIntygsId());
if (createPdlLogEvent) {
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
logService.logUpdateIntyg(logRequest);
monitoringService.logUtkastEdited(utkast.getIntygsId(), utkast.getIntygsTyp());
}
// Notify stakeholders when a draft has been changed/updated
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
if (moduleApi.shouldNotify(persistedJson, draftAsJson)) {
LOG.debug("*** Detected changes in model, sending notification! ***");
sendNotification(utkast, Event.CHANGED);
}
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
// Flush JPA changes, to make sure the version attribute is updated
utkastRepository.flush();
return new SaveDraftResponse(utkast.getVersion(), utkastStatus);
}
Aggregations