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);
}
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);
}
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.");
}
}
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();
}
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());
}
}
Aggregations