Search in sources :

Example 1 with RptReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.

the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.

@Test
@Transactional
public void testDisabledIdentity() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = helper.createIdentity();
    IdmIdentityDto identityDisabled = helper.createIdentity();
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
    disabled.setValue(false);
    filter.getValues().add(disabled);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
    });
    // 
    // test
    Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
    Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) Before(org.junit.Before) InitTestData(eu.bcvsolutions.idm.InitTestData) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RptReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.

the class AbstractReportExecutor method process.

@Override
public RptReportDto process() {
    if (event != null) {
        // generate report
        return generate(event.getContent());
    }
    // event is empty - publish new event and stop current LRT process (event has to be initialized at first)
    if (getLongRunningTaskId() != null) {
        IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId());
        if (task != null) {
            task.setRunning(false);
            getLongRunningTaskService().save(task);
        }
    }
    // executed from scheduler => we propagate new event for creating report
    RptReportDto report = new RptReportDto();
    report.setExecutorName(getName());
    report.setLongRunningTask(getLongRunningTaskId());
    reportManager.generate(report);
    return report;
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)

Example 3 with RptReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.

the class ReportGenerateEndProcessor method process.

@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
    RptReportDto report = event.getContent();
    report = reportService.saveInternal(report);
    event.setContent(report);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)

Example 4 with RptReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.

the class ReportGenerateEndSendNotificationProcessor method process.

@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
    RptReportDto report = event.getContent();
    // TODO: can be improved by some configuration (specially for LRT)
    if (report.getCreatorId() != null && report.getResult() != null) {
        boolean success = report.getResult().getState() == OperationState.EXECUTED;
        notificationManager.send(success ? RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS : RptModuleDescriptor.TOPIC_REPORT_GENERATE_FAILED, new IdmMessageDto.Builder(success ? NotificationLevel.SUCCESS : NotificationLevel.WARNING).addParameter("url", configurationService.getFrontendUrl(String.format("report/reports?id=%s", report.getId()))).addParameter("report", report).setModel(new DefaultResultModel(success ? RptResultCode.REPORT_GENERATE_SUCCESS : RptResultCode.REPORT_GENERATE_FAILED, ImmutableMap.of("reportName", report.getName()))).build(), identityService.get(report.getCreatorId()));
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)

Example 5 with RptReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.

the class RptReportController method renderReport.

@ResponseBody
@RequestMapping(value = "/{backendId}/render", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> renderReport(@ApiParam(value = "Report's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Renderer's identifier.", required = true) @RequestParam(required = true, name = "renderer") @NotNull String rendererName) {
    // 
    RptReportDto report = getDto(backendId);
    if (report == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    try {
        RptRenderedReportDto result = reportManager.render(report, rendererName);
        InputStream is = result.getRenderedReport();
        // 
        String reportName = report.getExecutorName() + "-" + report.getCreated().toString("yyyyMMddHHmmss");
        return ResponseEntity.ok().contentLength(is.available()).contentType(result.getRenderer().getFormat()).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s.%s\"", reportName, result.getRenderer().getExtension())).body(new InputStreamResource(is));
    } catch (Exception ex) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, ex);
    }
}
Also used : RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) InputStreamResource(org.springframework.core.io.InputStreamResource) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)15 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Test (org.junit.Test)9 UUID (java.util.UUID)5 Transactional (org.springframework.transaction.annotation.Transactional)5 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)4 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)4 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 List (java.util.List)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InitTestData (eu.bcvsolutions.idm.InitTestData)2 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)2 AttachmentManager (eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)2