use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method setForwarded.
@Override
@Transactional
public List<ArendeConversationView> setForwarded(String intygsId) {
WebCertUser user = webcertUserService.getUser();
List<Arende> arendenToForward = arendeRepository.save(arendeRepository.findByIntygsId(intygsId).stream().filter(isCorrectEnhet(user)).filter(isQuestion()).peek(arende -> authoritiesValidator.given(user, arende.getIntygTyp()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_FRAGASVAR).orThrow()).peek(Arende::setArendeToVidareBerordrat).collect(Collectors.toList()));
if (arendenToForward.isEmpty()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find any arende related to IntygsId: " + intygsId);
}
return getArendeConversationViewList(intygsId, arendenToForward);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method createMessage.
@Override
public ArendeConversationView createMessage(String intygId, ArendeAmne amne, String rubrik, String meddelande) {
if (!VALID_VARD_AMNEN.contains(amne)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
}
Utkast utkast = utkastRepository.findOne(intygId);
validateArende(intygId, utkast);
verifyEnhetsAuth(utkast.getEnhetsId(), false);
Arende arende = ArendeConverter.createArendeFromUtkast(amne, rubrik, meddelande, utkast, LocalDateTime.now(systemClock), webcertUserService.getUser().getNamn(), hsaEmployeeService);
Arende saved = processOutgoingMessage(arende, NotificationEvent.NEW_QUESTION_FROM_CARE);
arendeDraftService.delete(intygId, null);
return arendeViewConverter.convertToArendeConversationView(saved, null, null, new ArrayList<>(), null);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method answer.
@Override
public ArendeConversationView answer(String svarPaMeddelandeId, String meddelande) {
if (Strings.isNullOrEmpty(meddelande)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!");
}
Arende svarPaMeddelande = lookupArende(svarPaMeddelandeId);
verifyEnhetsAuth(svarPaMeddelande.getEnhetId(), false);
if (!Status.PENDING_INTERNAL_ACTION.equals(svarPaMeddelande.getStatus())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Arende with id " + svarPaMeddelandeId + " has invalid state for saving answer(" + svarPaMeddelande.getStatus() + ")");
}
// Implement Business Rule FS-007
if (ArendeAmne.PAMINN.equals(svarPaMeddelande.getAmne())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Arende with id " + svarPaMeddelandeId + " has invalid Amne(" + svarPaMeddelande.getAmne() + ") for saving answer");
}
if (ArendeAmne.KOMPLT.equals(svarPaMeddelande.getAmne())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Arende with id " + svarPaMeddelandeId + " has invalid Amne(" + svarPaMeddelande.getAmne() + ") for saving answer");
}
Arende arende = ArendeConverter.createAnswerFromArende(meddelande, svarPaMeddelande, LocalDateTime.now(systemClock), webcertUserService.getUser().getNamn());
Arende saved = processOutgoingMessage(arende, NotificationEvent.NEW_ANSWER_FROM_CARE);
arendeDraftService.delete(svarPaMeddelande.getIntygsId(), svarPaMeddelandeId);
return arendeViewConverter.convertToArendeConversationView(svarPaMeddelande, saved, null, arendeRepository.findByPaminnelseMeddelandeId(svarPaMeddelandeId), null);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method answerKomplettering.
@Override
@Transactional
public List<ArendeConversationView> answerKomplettering(final String intygsId, final String meddelande) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(intygsId));
Preconditions.checkArgument(!Strings.isNullOrEmpty(meddelande));
WebCertUser user = webcertUserService.getUser();
List<Arende> allArende = getArendeForIntygId(intygsId, user);
List<Arende> arendeList = filterKompletteringar(allArende);
Arende latestKomplArende = getLatestKomplArende(intygsId, arendeList);
verifyEnhetsAuth(latestKomplArende.getEnhetId(), false);
boolean verified = authoritiesValidator.given(user, latestKomplArende.getIntygTyp()).privilege(AuthoritiesConstants.PRIVILEGE_BESVARA_KOMPLETTERINGSFRAGA).isVerified();
if (!verified) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "Arende with id " + latestKomplArende.getId() + " and amne (" + latestKomplArende.getAmne() + ") can only be answered by user that is Lakare");
}
Arende answer = ArendeConverter.createAnswerFromArende(meddelande, latestKomplArende, LocalDateTime.now(systemClock), user.getNamn());
Arende saved = processOutgoingMessage(answer, NotificationEvent.NEW_ANSWER_FROM_CARE);
arendeList.stream().forEach(this::closeArendeAsHandled);
allArende.add(saved);
return getArendeConversationViewList(intygsId, allArende);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method processOutgoingMessage.
private Arende processOutgoingMessage(Arende arende, NotificationEvent notificationEvent) {
Arende saved = arendeRepository.save(arende);
monitoringLog.logArendeCreated(arende.getIntygsId(), arende.getIntygTyp(), arende.getEnhetId(), arende.getAmne(), arende.getSvarPaId() != null);
updateRelated(arende);
SendMessageToRecipientType request = SendMessageToRecipientTypeBuilder.build(arende, webcertUserService.getUser(), sendMessageToFKLogicalAddress);
// Send to recipient
try {
certificateSenderService.sendMessageToRecipient(arende.getIntygsId(), SendMessageToRecipientTypeConverter.toXml(request));
} catch (JAXBException | CertificateSenderException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, e.getMessage());
}
sendNotification(saved, notificationEvent);
return saved;
}
Aggregations