Search in sources :

Example 1 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class RouteTest method testTransformationExceptionNotificationVersion2.

@Test
public void testTransformationExceptionNotificationVersion2() throws Exception {
    // Given
    when(moduleRegistry.getModuleApi(anyString())).thenThrow(new ModuleNotFoundException("Testing checked exception"));
    notificationWSClient.expectedMessageCount(0);
    notificationWSClientV3.expectedMessageCount(0);
    permanentErrorHandlerEndpoint.expectedMessageCount(1);
    temporaryErrorHandlerEndpoint.expectedMessageCount(0);
    // When
    producerTemplate.sendBody(createNotificationMessage(SchemaVersion.VERSION_3, "fk7263"));
    // Then
    assertIsSatisfied(notificationWSClient);
    assertIsSatisfied(notificationWSClientV3);
    assertIsSatisfied(permanentErrorHandlerEndpoint);
    assertIsSatisfied(temporaryErrorHandlerEndpoint);
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Test(org.junit.Test)

Example 2 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class CopyUtkastServiceImpl method createReplacementCopy.

@Override
@Transactional("jpaTransactionManager")
public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) {
    String originalIntygId = replacementRequest.getOriginalIntygId();
    WebCertUser user = userService.getUser();
    LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId);
    try {
        if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) {
            LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked");
        }
        verifyNotReplaced(replacementRequest.getOriginalIntygId(), "create replacement");
        verifyNotComplementedWithSigned(replacementRequest.getOriginalIntygId(), "create replacement");
        CopyUtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId);
        if (replacementRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateReplacementCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class CopyUtkastServiceImpl method createCompletion.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastService#createCopy(se.inera.intyg.webcert.web.service.utkast.
     * dto.
     * CreateNewDraftCopyRequest)
     */
@Override
public CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating completion to intyg '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) {
            LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        CopyUtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateCompletionCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 4 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class CopyUtkastServiceImpl method createRenewalCopy.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastService#createCopy(se.inera.intyg.webcert.web.service.utkast.
     * dto.
     * CreateRenewalCopyRequest)
     */
@Override
public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating renewal for intyg '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
            LOG.debug("Cannot renew certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        verifyNotComplementedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        CopyUtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateRenewalCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 5 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException 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);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)26 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)16 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)14 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 Test (org.junit.Test)5 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)4 ArrayList (java.util.ArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)3 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)3 LocalDateTime (java.time.LocalDateTime)2 Map (java.util.Map)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Status (se.inera.intyg.common.support.model.Status)2