Search in sources :

Example 46 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class SignaturServiceImpl method createAndPersistSignature.

private SignaturTicket createAndPersistSignature(Utkast utkast, SignaturTicket ticket, String rawSignature, WebCertUser user) {
    validateUniqueIntyg(user, utkast.getIntygsTyp(), utkast.getPatientPersonnummer());
    PagaendeSignering pagaendeSignering = pagaendeSigneringRepository.findOne(ticket.getPagaendeSigneringId());
    if (pagaendeSignering == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can't complete signing of certificate, no PagaendeSignering found for interreferens " + ticket.getPagaendeSigneringId());
    }
    String payload = pagaendeSignering.getIntygData();
    if (!pagaendeSignering.getIntygsId().equals(utkast.getIntygsId())) {
        LOG.error("Signing of utkast '{}' failed since the intygsId ({}) on the Utkast is different from the one " + "on the signing operation ({})", utkast.getIntygsId(), pagaendeSignering.getIntygsId());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
    }
    if (!ticket.getHash().equals(createHash(payload))) {
        LOG.error("Signing of utkast '{}' failed since the payload has been modified since signing was initialized", utkast.getIntygsId());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
    }
    if (utkast.getVersion() != ticket.getVersion()) {
        LOG.error("Signing of utkast '{}' failed since the version on the utkast ({}) differs from when the signing was initialized ({})", utkast.getIntygsId(), utkast.getVersion(), ticket.getVersion());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, "Cannot complete signing, Utkast version differs from signature ticket version.");
    }
    Signatur signatur = new Signatur(ticket.getSigneringstid(), user.getHsaId(), ticket.getIntygsId(), payload, ticket.getHash(), rawSignature);
    // Update user information ("senast sparat av")
    // Add signature to the utkast and set status as signed
    utkast.setSenastSparadAv(new VardpersonReferens(pagaendeSignering.getSigneradAvHsaId(), pagaendeSignering.getSigneradAvNamn()));
    utkast.setModel(payload);
    utkast.setSignatur(signatur);
    utkast.setStatus(UtkastStatus.SIGNED);
    // Persist utkast with added signature
    Utkast savedUtkast = utkastRepository.save(utkast);
    // Send to Intygstjanst
    intygService.storeIntyg(savedUtkast);
    // Remove PagaendeSignering
    pagaendeSigneringRepository.delete(ticket.getPagaendeSigneringId());
    return ticket;
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Example 47 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class GrpSignaturServiceImpl method startGrpAuthentication.

@Override
public SignaturTicket startGrpAuthentication(String intygId, long version) {
    Utkast utkast = utkastRepository.findOne(intygId);
    validateUtkast(intygId, utkast);
    WebCertUser webCertUser = webCertUserService.getUser();
    validateWebCertUser(webCertUser);
    String personId = webCertUser.getPersonId();
    validatePersonId(personId);
    SignaturTicket draftHash = signaturService.createDraftHash(intygId, utkast.getVersion());
    AuthenticateRequestType authRequest = buildAuthRequest(personId, draftHash);
    OrderResponseType orderResponse;
    try {
        orderResponse = grpService.authenticate(authRequest);
    } catch (GrpFault grpFault) {
        signaturTicketTracker.updateStatus(draftHash.getId(), SignaturTicket.Status.OKAND);
        Optional<FaultStatusType> status = Optional.ofNullable(grpFault.getFaultInfo()).map(GrpFaultType::getFaultStatus);
        if (status.isPresent()) {
            LOG.warn("Fault signing utkast with id {} with GRP. FaultStatus: {}", intygId, status.get().name());
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.GRP_PROBLEM, status.get().name());
        } else {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, grpFault.getMessage());
        }
    }
    // If we could init the authentication, we create a SignaturTicket, reusing
    // the mechanism already present for SITHS
    String orderRef = orderResponse.getOrderRef();
    String transactionId = validateOrderResponseTxId(authRequest, orderResponse);
    startAsyncCollectPoller(orderRef, transactionId);
    return draftHash;
}
Also used : Optional(java.util.Optional) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OrderResponseType(se.funktionstjanster.grp.v1.OrderResponseType) AuthenticateRequestType(se.funktionstjanster.grp.v1.AuthenticateRequestType) GrpFault(se.funktionstjanster.grp.v1.GrpFault) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 48 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method openArendeAsUnhandled.

@Override
public ArendeConversationView openArendeAsUnhandled(String meddelandeId) {
    Arende arende = lookupArende(meddelandeId);
    boolean arendeIsAnswered = !arendeRepository.findBySvarPaId(meddelandeId).isEmpty();
    // Enforce business rule FS-011, from FK + answer should remain closed
    if (!FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv()) && arendeIsAnswered) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FS-011: Cant revert status for question " + meddelandeId);
    }
    NotificationEvent notificationEvent = determineNotificationEvent(arende, arendeIsAnswered);
    if (arendeIsAnswered) {
        arende.setStatus(Status.ANSWERED);
    } else {
        if (FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv())) {
            arende.setStatus(Status.PENDING_EXTERNAL_ACTION);
        } else {
            arende.setStatus(Status.PENDING_INTERNAL_ACTION);
        }
    }
    Arende openedArende = arendeRepository.save(arende);
    sendNotification(openedArende, notificationEvent);
    return arendeViewConverter.convertToArendeConversationView(openedArende, arendeRepository.findBySvarPaId(meddelandeId).stream().findFirst().orElse(null), null, arendeRepository.findByPaminnelseMeddelandeId(meddelandeId), null);
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 49 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class ArendeServiceImpl method processIncomingMessage.

@Override
public Arende processIncomingMessage(Arende arende) {
    if (arendeRepository.findOneByMeddelandeId(arende.getMeddelandeId()) != null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "meddelandeId not unique");
    }
    Utkast utkast = utkastRepository.findOne(arende.getIntygsId());
    validateArende(arende.getIntygsId(), utkast);
    ArendeConverter.decorateArendeFromUtkast(arende, utkast, LocalDateTime.now(systemClock), hsaEmployeeService);
    updateRelated(arende);
    monitoringLog.logArendeReceived(arende.getIntygsId(), utkast.getIntygsTyp(), utkast.getEnhetsId(), arende.getAmne(), arende.getKomplettering().stream().map(MedicinsktArende::getFrageId).collect(Collectors.toList()), arende.getSvarPaId() != null);
    Arende saved = arendeRepository.save(arende);
    if (ArendeAmne.PAMINN == saved.getAmne() || saved.getSvarPaId() == null) {
        notificationService.sendNotificationForQuestionReceived(saved);
    } else {
        notificationService.sendNotificationForAnswerRecieved(saved);
    }
    return saved;
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 50 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateNewRenewWithCopyOkParamFalse.

@Test
public void testCreateNewRenewWithCopyOkParamFalse() {
    // Given
    final boolean copyOk = false;
    final String intygsTyp = "fk7263";
    setupUser(AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG, intygsTyp, true, copyOk, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    // When
    try {
        moduleApiController.createRenewal(new CopyIntygRequest(), intygsTyp, "");
    } catch (WebCertServiceException wcse) {
        // Then an exception is thrown
        assertEquals(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, wcse.getErrorCode());
        assertEquals("Authorization failed due to false kopieraOK-parameter", wcse.getMessage());
        return;
    }
    fail("No or wrong exception was thrown");
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

Aggregations

WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)85 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)35 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)16 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)14 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)14 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)13 OptimisticLockException (javax.persistence.OptimisticLockException)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)10 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)9 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 POST (javax.ws.rs.POST)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 LocalDateTime (java.time.LocalDateTime)5