Search in sources :

Example 61 with WebCertServiceException

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

the class UtkastModuleApiController method serverSigneraUtkast.

/**
 * Signera utkast. Endast fejkinloggning.
 *
 * @param intygsId intyg id
 * @return SignaturTicketResponse
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{version}/signeraserver")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse serverSigneraUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) {
    verifyIsAuthorizedToSignIntyg(intygsTyp);
    SignaturTicket ticket;
    try {
        ticket = signaturService.serverSignature(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    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 62 with WebCertServiceException

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

the class UtkastModuleApiController method serverSigneraUtkastMedNias.

/**
 * Signera utkast mha NetiD Access Server (nias).
 *
 * @param intygsId intyg id
 * @return SignaturTicketResponse
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{version}/nias/signeraserver")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse serverSigneraUtkastMedNias(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) {
    verifyIsAuthorizedToSignIntyg(intygsTyp);
    SignaturTicket ticket;
    try {
        ticket = niasSignaturService.startNiasAuthentication(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    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 63 with WebCertServiceException

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

the class UtkastModuleApiController method verifySekretessmarkering.

private void verifySekretessmarkering(String intygsTyp, String enhetsId, Patient resolvedPatient) {
    WebCertUser user = getWebCertUserService().getUser();
    authoritiesValidator.given(user, intygsTyp).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, resolvedPatient != null && resolvedPatient.isSekretessmarkering()).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
    // som utkastet tillhör
    if (resolvedPatient != null && resolvedPatient.isSekretessmarkering() && !getWebCertUserService().userIsLoggedInOnEnhetOrUnderenhet(enhetsId)) {
        LOG.debug("User not logged in on same unit as draft unit for sekretessmarkerad patient.");
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING_ENHET, "User not logged in on same unit as draft unit for sekretessmarkerad patient.");
    }
}
Also used : WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 64 with WebCertServiceException

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

the class UtkastModuleApiController method discardDraft.

/**
 * Deletes a draft certificate identified by the certificateId.
 *
 * @param intygsId The id of the certificate
 */
@DELETE
@Path("/{intygsTyp}/{intygsId}/{version}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response discardDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    LOG.debug("Deleting draft with id {}", intygsId);
    try {
        utkastService.deleteUnsignedDraft(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    return Response.ok().build();
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 65 with WebCertServiceException

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

the class UtkastModuleApiController method saveDraft.

/**
 * Persists the supplied draft certificate using the intygId as key.
 *
 * @param intygsId The id of the certificate.
 * @param payload  Object holding the certificate and its current status.
 */
@PUT
@Path("/{intygsTyp}/{intygsId}/{version}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response saveDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @DefaultValue("false") @QueryParam("autoSave") boolean autoSave, byte[] payload, @Context HttpServletRequest request) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    LOG.debug("Saving utkast with id '{}', autosave is {}", intygsId, autoSave);
    String draftAsJson = fromBytesToString(payload);
    LOG.debug("---- intyg : " + draftAsJson);
    boolean firstSave = false;
    HttpSession session = request.getSession(true);
    String lastSavedDraft = (String) session.getAttribute(LAST_SAVED_DRAFT);
    if (!intygsId.equals(lastSavedDraft)) {
        firstSave = true;
    }
    session.setAttribute(LAST_SAVED_DRAFT, intygsId);
    try {
        SaveDraftResponse saveResponse = utkastService.saveDraft(intygsId, version, draftAsJson, firstSave);
        return Response.ok().entity(saveResponse).build();
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) HttpSession(javax.servlet.http.HttpSession) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

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