Search in sources :

Example 6 with IntygPdf

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testGetIntygAsPdf.

@Test
public void testGetIntygAsPdf() {
    final String intygType = "fk7263";
    setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygType, false, true, AuthoritiesConstants.FEATURE_UTSKRIFT);
    IntygPdf pdfResponse = new IntygPdf(PDF_DATA, PDF_NAME);
    when(intygService.fetchIntygAsPdf(CERTIFICATE_ID, intygType, false)).thenReturn(pdfResponse);
    Response response = moduleApiController.getIntygAsPdf(intygType, CERTIFICATE_ID);
    verify(intygService).fetchIntygAsPdf(CERTIFICATE_ID, intygType, false);
    assertEquals(OK.getStatusCode(), response.getStatus());
    assertEquals(PDF_DATA, response.getEntity());
    assertNotNull(response.getHeaders().get(CONTENT_DISPOSITION));
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) Test(org.junit.Test)

Example 7 with IntygPdf

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testGetIntygAsPdfForEmployer.

@Test
public void testGetIntygAsPdfForEmployer() {
    final String intygType = "fk7263";
    setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygType, false, true, AuthoritiesConstants.FEATURE_ARBETSGIVARUTSKRIFT);
    IntygPdf pdfResponse = new IntygPdf(PDF_DATA, PDF_NAME);
    when(intygService.fetchIntygAsPdf(CERTIFICATE_ID, intygType, true)).thenReturn(pdfResponse);
    Response response = moduleApiController.getIntygAsPdfForEmployer(intygType, CERTIFICATE_ID);
    verify(intygService).fetchIntygAsPdf(CERTIFICATE_ID, intygType, true);
    assertEquals(OK.getStatusCode(), response.getStatus());
    assertEquals(PDF_DATA, response.getEntity());
    assertNotNull(response.getHeaders().get(CONTENT_DISPOSITION));
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) Test(org.junit.Test)

Example 8 with IntygPdf

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygAsPdfFromWebCert.

@SuppressWarnings("unchecked")
@Test
public void testFetchIntygAsPdfFromWebCert() throws IOException, IntygModuleFacadeException {
    when(utkastRepository.findOne(CERTIFICATE_ID)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), null));
    when(moduleFacade.convertFromInternalToPdfDocument(anyString(), anyString(), anyList(), anyBoolean())).thenReturn(buildPdfDocument());
    IntygPdf intygPdf = intygService.fetchIntygAsPdf(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertNotNull(intygPdf);
    verify(utkastRepository, times(1)).findOne(anyString());
    verify(logservice).logPrintIntygAsPDF(any(LogRequest.class));
    verifyNoMoreInteractions(logservice);
    verify(moduleFacade, times(0)).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
    // Verify that the enhetsAuth verification was performed.
    verify(webCertUserService, times(1)).isAuthorizedForUnit(anyString(), anyString(), anyBoolean());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) Test(org.junit.Test)

Example 9 with IntygPdf

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.

the class IntygServiceTest method testFetchRevokedIntygAsPdfFromWebCert.

@SuppressWarnings("unchecked")
@Test
public void testFetchRevokedIntygAsPdfFromWebCert() throws IOException, IntygModuleFacadeException {
    when(utkastRepository.findOne(CERTIFICATE_ID)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), LocalDateTime.now()));
    when(moduleFacade.convertFromInternalToPdfDocument(anyString(), anyString(), anyList(), anyBoolean())).thenReturn(buildPdfDocument());
    IntygPdf intygPdf = intygService.fetchIntygAsPdf(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertNotNull(intygPdf);
    verify(utkastRepository, times(1)).findOne(anyString());
    verify(logservice).logPrintRevokedIntygAsPDF(any(LogRequest.class));
    verifyNoMoreInteractions(logservice);
    verify(moduleFacade, times(0)).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) Test(org.junit.Test)

Example 10 with IntygPdf

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.

the class IntygModuleFacadeImpl method convertFromInternalToPdfDocument.

@Override
public IntygPdf convertFromInternalToPdfDocument(String intygType, String internalIntygJsonModel, List<Status> statuses, boolean isEmployer) throws IntygModuleFacadeException {
    boolean isUtkast = isUtkast(statuses);
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        PdfResponse pdfResponse;
        if (!isEmployer) {
            pdfResponse = moduleApi.pdf(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, isUtkast);
        } else {
            pdfResponse = moduleApi.pdfEmployer(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, Collections.emptyList(), isUtkast);
        }
        return new IntygPdf(pdfResponse.getPdfData(), pdfResponse.getFilename());
    } catch (ModuleException me) {
        LOG.error("ModuleException occured when when generating PDF document from internal");
        throw new IntygModuleFacadeException("ModuleException occured when generating PDF document from internal", me);
    } catch (ModuleNotFoundException e) {
        LOG.error("ModuleNotFoundException occured for intygstyp '{}' when generating PDF document from internal", intygType);
        throw new IntygModuleFacadeException("ModuleNotFoundException occured when registering certificate", e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) PdfResponse(se.inera.intyg.common.support.modules.support.api.dto.PdfResponse)

Aggregations

IntygPdf (se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf)10 Test (org.junit.Test)8 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)4 PdfResponse (se.inera.intyg.common.support.modules.support.api.dto.PdfResponse)3 Response (javax.ws.rs.core.Response)2 Status (se.inera.intyg.common.support.model.Status)2 ApplicationOrigin (se.inera.intyg.common.support.modules.support.ApplicationOrigin)2 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)2 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)2 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)2 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)2 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)2 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)1 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 IntygModuleFacadeException (se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException)1 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)1