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