use of se.inera.intyg.webcert.persistence.utkast.model.Utkast 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.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class UtkastServiceImpl method createNewDraft.
@Override
public Utkast createNewDraft(CreateNewDraftRequest request) {
populateRequestWithIntygId(request);
request.setStatus(UtkastStatus.DRAFT_INCOMPLETE);
String intygType = request.getIntygType();
CreateNewDraftHolder draftRequest = createModuleRequest(request);
String intygJsonModel = getPopulatedModelFromIntygModule(intygType, draftRequest);
Utkast savedUtkast = persistNewDraft(request, intygJsonModel);
// Persist the referens if supplied
if (!Strings.isNullOrEmpty(request.getReferens())) {
referensService.saveReferens(request.getIntygId(), request.getReferens());
}
monitoringService.logUtkastCreated(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getEnhetsId(), savedUtkast.getSkapadAv().getHsaId());
// Notify stakeholders when a draft has been created
sendNotification(savedUtkast, Event.CREATED);
// Create a PDL log for this action
LogUser logUser = createLogUser(request);
logCreateDraftPDL(savedUtkast, logUser);
return savedUtkast;
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast 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.persistence.utkast.model.Utkast in project webcert by sklintyg.
the class UtkastServiceImpl method setKlarForSigneraAndSendStatusMessage.
@Override
@Transactional
public void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType) {
validateUserAllowedToSendKFSignNotification(intygsId, intygType);
Utkast utkast = getIntygAsDraft(intygsId, intygType);
if (utkast.getKlartForSigneringDatum() == null) {
notificationService.sendNotificationForDraftReadyToSign(utkast);
utkast.setKlartForSigneringDatum(LocalDateTime.now());
monitoringService.logUtkastMarkedAsReadyToSignNotificationSent(intygsId, intygType);
saveDraft(utkast);
LOG.debug("Sent, saved and logged utkast '{}' ready to sign", intygsId);
}
}
use of se.inera.intyg.webcert.persistence.utkast.model.Utkast 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;
}
Aggregations