use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastServiceImpl method deleteUnsignedDraft.
@Override
@Transactional
public void deleteUnsignedDraft(String intygId, long version) {
LOG.debug("Deleting utkast '{}'", intygId);
Utkast utkast = utkastRepository.findOne(intygId);
// check that the draft exists
if (utkast == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The draft could not be deleted since it 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 unsigned
if (!isTheDraftStillADraft(utkast.getStatus())) {
LOG.error("Intyg '{}' can not be deleted since it is no longer a draft", intygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "The draft can not be deleted since it is no longer a draft");
}
// Delete draft from repository
utkastRepository.delete(utkast);
LOG.debug("Deleted draft '{}'", utkast.getIntygsId());
// Audit log
monitoringService.logUtkastDeleted(utkast.getIntygsId(), utkast.getIntygsTyp());
// Notify stakeholders when a draft is deleted
sendNotification(utkast, Event.DELETED);
LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
logService.logDeleteIntyg(logRequest);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastServiceImpl method setNotifiedOnDraft.
@Override
@Transactional
public Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified) {
Utkast utkast = utkastRepository.findOne(intygsId);
if (utkast == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find Utkast with id: " + intygsId);
}
// check that the draft hasn't been modified concurrently
if (utkast.getVersion() != version) {
LOG.debug("Utkast '{}' was concurrently modified", intygsId);
throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
}
utkast.setVidarebefordrad(notified);
return saveDraft(utkast);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastServiceImpl method getIntygAsDraft.
private Utkast getIntygAsDraft(String intygsId, String intygType) {
LOG.debug("Fetching utkast '{}'", intygsId);
Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygsId, intygType);
if (utkast == null) {
LOG.warn("Utkast '{}' of type {} was not found", intygsId, intygType);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Utkast could not be found");
}
return utkast;
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastServiceImpl method validateDraft.
@Override
public DraftValidation validateDraft(String intygId, String intygType, String draftAsJson) {
LOG.debug("Validating Intyg '{}' with type '{}'", intygId, intygType);
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
ValidateDraftResponse validateDraftResponse = moduleApi.validateDraft(draftAsJson);
return convertToDraftValidation(validateDraftResponse);
} catch (ModuleException | ModuleNotFoundException me) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
}
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class UtkastApiController method createUtkast.
/**
* Create a new draft.
*/
@POST
@Path("/{intygsTyp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request) {
try {
if (moduleRegistry.getIntygModule(intygsTyp).isDeprecated()) {
LOG.error("Request for deprecated module {}", intygsTyp);
return Response.status(Status.BAD_REQUEST).build();
}
} catch (ModuleNotFoundException e) {
LOG.error("Request for unknown module {}", intygsTyp);
return Response.status(Status.BAD_REQUEST).build();
}
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(request.getPatientPersonnummer());
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
}
// INTYG-4086: If the patient is sekretessmarkerad, we need an additional check.
boolean sekr = sekretessStatus == SekretessStatus.TRUE;
if (sekr) {
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
}
if (!request.isValid()) {
LOG.error("Request is invalid: " + request.toString());
return Response.status(Status.BAD_REQUEST).build();
}
LOG.debug("Attempting to create draft of type '{}'", intygsTyp);
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(request.getPatientPersonnummer(), getWebCertUserService().getUser());
Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
if (utkastExists != null && utkastExists) {
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
}
}
if (intygExists != null) {
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
} else if (intygExists && authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
}
}
}
CreateNewDraftRequest serviceRequest = createServiceRequest(request);
Utkast utkast = utkastService.createNewDraft(serviceRequest);
LOG.debug("Created a new draft of type '{}' with id '{}'", intygsTyp, utkast.getIntygsId());
return Response.ok().entity(utkast).build();
}
Aggregations