Search in sources :

Example 6 with PagaendeSignering

use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.

the class SignaturServiceImplTest method setup.

@Before
public void setup() throws Exception {
    hoSPerson = new HoSPersonal();
    hoSPerson.setPersonId("AAA");
    hoSPerson.setFullstandigtNamn("Dr Dengroth");
    VardpersonReferens vardperson = new VardpersonReferens();
    vardperson.setHsaId(hoSPerson.getPersonId());
    vardperson.setNamn(hoSPerson.getFullstandigtNamn());
    utkast = createUtkast(INTYG_ID, 1, INTYG_TYPE, UtkastStatus.DRAFT_INCOMPLETE, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    completedUtkast = createUtkast(INTYG_ID, 2, INTYG_TYPE, UtkastStatus.DRAFT_COMPLETE, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    signedUtkast = createUtkast(INTYG_ID, 3, INTYG_TYPE, UtkastStatus.SIGNED, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    vardenhet = new Vardenhet(ENHET_ID, "testNamn");
    vardgivare = new Vardgivare("123", "vardgivare");
    vardgivare.setVardenheter(Collections.singletonList(vardenhet));
    user = createWebCertUser(true);
    when(webcertUserService.getUser()).thenReturn(user);
    when(moduleRegistry.getModuleApi(any())).thenReturn(moduleApi);
    when(moduleApi.updateBeforeSigning(any(), any(), any())).thenReturn(INTYG_JSON);
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    when(utlatande.getGrundData()).thenReturn(grunddata);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    setTypedField(intygSignatureService, new SignaturTicketTracker());
    pagaendeSignering = mock(PagaendeSignering.class);
    when(pagaendeSignering.getInternReferens()).thenReturn(PAGAENDE_SIGN_ID);
    when(pagaendeSignering.getIntygData()).thenReturn(INTYG_JSON);
    when(pagaendeSignering.getIntygsId()).thenReturn(INTYG_ID);
    when(pagaendeSignering.getSigneradAvHsaId()).thenReturn(hoSPerson.getPersonId());
    when(pagaendeSignering.getSigneradAvNamn()).thenReturn(hoSPerson.getFullstandigtNamn());
    when(pagaendeSigneringRepository.findOne(any())).thenReturn(pagaendeSignering);
    when(pagaendeSigneringRepository.save(any(PagaendeSignering.class))).thenReturn(pagaendeSignering);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) Before(org.junit.Before)

Example 7 with PagaendeSignering

use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.

the class PagaendeSigneringCleanupServiceImpl method cleanup.

@Scheduled(cron = "${signature.cleanup.cron}")
public void cleanup() {
    List<PagaendeSignering> all = pagaendeSigneringRepository.findAll();
    if (all == null || all.isEmpty()) {
        return;
    }
    LOG.info("Running stale signature cleanup. There are currently {} ongoing signatures.", all.size());
    LocalDateTime evictIfOlderThan = LocalDateTime.now().minusMinutes(EVICT_OLDER_THAN_MINUTES);
    Iterator<PagaendeSignering> iterator = all.stream().filter(ps -> ps.getSigneringsDatum().isBefore(evictIfOlderThan)).iterator();
    while (iterator.hasNext()) {
        PagaendeSignering pagaendeSignering = iterator.next();
        Long id = pagaendeSignering.getInternReferens();
        String intygsId = pagaendeSignering.getIntygsId();
        pagaendeSigneringRepository.delete(pagaendeSignering.getInternReferens());
        LOG.info("Removed stale PagaendeSignering with id '{}' for intygs-id '{}'. " + "This is perfectly normal if the signing user didn't complete the signing.", id, intygsId);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Scheduled(org.springframework.scheduling.annotation.Scheduled) Profile(org.springframework.context.annotation.Profile) PagaendeSigneringRepository(se.inera.intyg.webcert.persistence.utkast.repository.PagaendeSigneringRepository) List(java.util.List) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) Service(org.springframework.stereotype.Service) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) Transactional(org.springframework.transaction.annotation.Transactional) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

PagaendeSignering (se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering)7 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)3 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Before (org.junit.Before)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Profile (org.springframework.context.annotation.Profile)1 EnableScheduling (org.springframework.scheduling.annotation.EnableScheduling)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 Service (org.springframework.stereotype.Service)1 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)1