Search in sources :

Example 11 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class IntygModuleApiController method createRenewal.

/**
 * Create a copy that is a renewal of an existing certificate.
 *
 * @param request
 * @param intygsTyp
 * @param orgIntygsId
 * @return
 */
@POST
@Path("/{intygsTyp}/{intygsId}/fornya")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
    validateCopyAuthority(intygsTyp);
    LOG.debug("Attempting to create a renewal of {} with id '{}'", intygsTyp, orgIntygsId);
    WebCertUser user = userService.getUser();
    boolean copyOkParam = user.getParameters() == null || user.getParameters().isCopyOk();
    if (!copyOkParam) {
        LOG.info("User is not allowed to request a copy for id '{}' due to false kopieraOK-parameter", orgIntygsId);
        final String message = "Authorization failed due to false kopieraOK-parameter";
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, message);
    }
    if (!request.isValid()) {
        LOG.error("Request to create renewal of '{}' is not valid", orgIntygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    CreateRenewalCopyRequest serviceRequest = createRenewalCopyRequest(orgIntygsId, intygsTyp, request);
    CreateRenewalCopyResponse serviceResponse = copyUtkastService.createRenewalCopy(serviceRequest);
    LOG.debug("Created a new draft with id: '{}' and type: {}, renewing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
    CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
    return Response.ok().entity(response).build();
}
Also used : CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 12 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class IntygModuleApiController method createCompletion.

/**
 * Create a copy that completes an existing certificate.
 */
@POST
@Path("/{intygsTyp}/{intygsId}/komplettera")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createCompletion(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_FORNYA_INTYG).privilege(AuthoritiesConstants.PRIVILEGE_SVARA_MED_NYTT_INTYG).orThrow();
    LOG.debug("Attempting to create a completion of {} with id '{}'", intygsTyp, orgIntygsId);
    if (!request.isValid()) {
        LOG.error("Request to create completion of '{}' is not valid", orgIntygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    String meddelandeId = arendeService.getLatestMeddelandeIdForCurrentCareUnit(orgIntygsId);
    CreateCompletionCopyRequest serviceRequest = createCompletionCopyRequest(orgIntygsId, intygsTyp, meddelandeId, request);
    CreateCompletionCopyResponse serviceResponse = copyUtkastService.createCompletion(serviceRequest);
    LOG.debug("Created a new draft with id: '{}' and type: {}, completing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
    CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
    return Response.ok().entity(response).build();
}
Also used : CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 13 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastModuleApiController method signeraUtkast.

/**
 * Skapa signeringshash.
 *
 * @param intygsId intyg id
 * @return SignaturTicketResponse
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{version}/signeringshash")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse signeraUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).orThrow();
    SignaturTicket ticket;
    try {
        ticket = signaturService.createDraftHash(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    return new SignaturTicketResponse(ticket);
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) OptimisticLockException(javax.persistence.OptimisticLockException) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) SignaturTicketResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 14 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException 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 15 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class CopyUtkastServiceImpl method refreshPatientDetailsFromPUService.

private Person refreshPatientDetailsFromPUService(AbstractCreateCopyRequest copyRequest) {
    Personnummer personnummer;
    if (copyRequest.containsNyttPatientPersonnummer()) {
        LOG.debug("Request contained a new personnummer to use for the copy");
        personnummer = copyRequest.getNyttPatientPersonnummer();
    } else {
        personnummer = copyRequest.getPatient().getPersonId();
    }
    LOG.debug("Refreshing person data to use for the copy");
    PersonSvar personSvar = getPersonSvar(personnummer);
    if (PersonSvar.Status.ERROR.equals(personSvar.getStatus())) {
        LOG.error("An error occured when using '{}' to lookup person data", personnummer.getPersonnummerHash());
        return null;
    } else if (PersonSvar.Status.NOT_FOUND.equals(personSvar.getStatus())) {
        LOG.error("No person data was found using '{}' to lookup person data", personnummer.getPersonnummerHash());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "No person data found using '" + personnummer.getPersonnummerHash() + "'");
    }
    return personSvar.getPerson();
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Aggregations

WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)85 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)35 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)16 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)14 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)14 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)13 OptimisticLockException (javax.persistence.OptimisticLockException)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)10 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)9 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 POST (javax.ws.rs.POST)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 LocalDateTime (java.time.LocalDateTime)5