use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.
@Test
@Transactional
public void testDisabledIdentity() throws IOException {
// prepare test identities
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityDisabled = getHelper().createIdentity((GuardedString) null);
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);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportService method saveInternal.
@Override
@Transactional
public RptReportDto saveInternal(RptReportDto report) {
boolean isNew = isNew(report);
IdmFormDto filter = report.getFilter();
report = super.saveInternal(report);
// save report filter
if (filter != null) {
if (isNew) {
// clone filter - filter template can be given
// TODO: clone filter properly
filter.setId(null);
DtoUtils.clearAuditFields(filter);
filter.getValues().forEach(formValue -> {
formValue.setId(null);
DtoUtils.clearAuditFields(formValue);
});
}
filter.setName(report.getName());
filter.setOwnerCode(report.getExecutorName());
report.setFilter(commonFormService.saveForm(report, filter));
} else {
// TODO: remove previous filter - find and destroy
}
//
return report;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultReportManager method saveTaskProperties.
/**
* Transfer report filter parameter (eav) to task properties.
*
* @param task
* @param report
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void saveTaskProperties(RptReportDto report) {
UUID longRunningTaskId = report.getLongRunningTask();
IdmFormDto reportFilter = report.getFilter();
if (reportFilter == null || longRunningTaskId == null) {
// no properties
return;
}
//
Map<String, Object> taskProperties = new HashMap<>();
reportFilter.getValues().stream().filter(value -> !value.isEmpty()).forEach(value -> {
IdmFormAttributeDto formAttribute = lookupService.lookupEmbeddedDto(value, IdmFormValueDto.PROPERTY_FORM_ATTRIBUTE);
//
String attributeCode = formAttribute.getCode();
if (taskProperties.containsKey(attributeCode)) {
// multiple properties are supported
Object propertyValue = taskProperties.get(attributeCode);
List propertyValues;
if (propertyValue instanceof List) {
propertyValues = (List) propertyValue;
} else {
propertyValues = Lists.newArrayList(propertyValue);
}
propertyValues.add(value.getValue());
taskProperties.put(formAttribute.getCode(), propertyValues);
} else {
// single property
taskProperties.put(formAttribute.getCode(), value.getValue());
}
});
// save filled task properties
if (!taskProperties.isEmpty()) {
IdmLongRunningTaskDto task = taskManager.getLongRunningTask(longRunningTaskId);
task.setTaskProperties(taskProperties);
taskManager.saveLongRunningTask(task);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultReportManager method initFormTask.
/**
* Transfer task properties to report filter parameter (eav).
*
* @param task
* @param report
*/
@SuppressWarnings("rawtypes")
private RptReportDto initFormTask(RptReportDto report, ReportExecutor reportExecutor) {
UUID longRunningTaskId = report.getLongRunningTask();
if (longRunningTaskId == null) {
// no lrt
return report;
}
IdmFormDefinitionDto formDefinition = reportExecutor.getFormDefinition();
IdmLongRunningTaskDto task = taskManager.getLongRunningTask(longRunningTaskId);
//
// publish new event and stop current LRT process (event has to be initialized at first)
task.setRunning(false);
task = taskManager.saveLongRunningTask(task);
//
List<IdmFormValueDto> values = new ArrayList<>();
for (Entry<String, Object> property : task.getTaskProperties().entrySet()) {
String propertyKey = property.getKey();
Object propertyValue = property.getValue();
//
if (propertyValue == null) {
continue;
}
//
IdmFormAttributeDto formAttribute = formDefinition.getMappedAttributeByCode(propertyKey);
if (formAttribute == null) {
continue;
}
//
if (!(propertyValue instanceof Serializable)) {
LOG.warn("Long running task property [{}] is not serializable, cannot be used in report parameters.", propertyKey);
continue;
}
if (propertyValue instanceof List) {
// multiple values are stored in List (see bellow)
for (Object singlePropertyValue : (List) propertyValue) {
IdmFormValueDto value = toFilledFormValue(formAttribute, propertyKey, singlePropertyValue);
if (value != null) {
values.add(value);
}
}
} else {
// single value
IdmFormValueDto value = toFilledFormValue(formAttribute, propertyKey, propertyValue);
if (value != null) {
values.add(value);
}
}
}
//
if (values.isEmpty()) {
// no filled values
return report;
}
//
IdmFormDto reportFilter = new IdmFormDto();
reportFilter.setFormDefinition(formDefinition.getId());
reportFilter.setValues(values);
report.setFilter(reportFilter);
//
return reportService.save(report);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class ReportGenerateEndSendNotificationProcessor method process.
@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
RptReportDto report = event.getContent();
UUID creatorId = report.getCreatorId();
//
if (report.getResult() == null) {
return new DefaultEventResult<>(event, this);
}
//
boolean success = report.getResult().getState() == OperationState.EXECUTED;
List<IdmIdentityDto> recipients = new ArrayList<>(1);
if (creatorId != null) {
// default recipient is logged user, but can be overriden by topic configuration
recipients.add(identityService.get(creatorId));
}
//
Builder message = new IdmMessageDto.Builder(success ? NotificationLevel.SUCCESS : NotificationLevel.WARNING).addParameter("url", configurationService.getFrontendUrl(String.format("rpt/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())));
//
if (success) {
// rendered reports as email attachments
List<String> rendererNames = reportManager.getRenderers(report.getExecutorName()).stream().filter(// default json will be ignored
renderer -> !renderer.getName().equals(DefaultJsonRenderer.RENDERER_NAME)).map(RptReportRendererDto::getName).collect(Collectors.toList());
List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(report, null).stream().filter(attachment -> StringUtils.isNotEmpty(attachment.getAttachmentType()) && rendererNames.contains(attachment.getAttachmentType())).collect(Collectors.toList());
//
// load topic configuration
String topic = null;
IdmFormDto filter = report.getFilter();
if (filter != null) {
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, formService.getDefinition(filter.getFormDefinition()), report.getFilter());
Serializable configuredTopic = formInstance.toSinglePersistentValue(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS);
if (configuredTopic != null) {
topic = configuredTopic.toString();
}
} else {
// Backward compatibility => reports generated from code (without UI form + filter).
topic = RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS;
}
// topic is optional => notification will not be sent, if default value is cleared / not given.
if (StringUtils.isEmpty(topic)) {
LOG.debug("Report result will be not sent, topic is not configured [{}].");
} else {
LOG.debug("Report result will be sent to topic [{}]", topic);
//
notificationManager.send(topic, message.build(), null, recipients, attachments);
}
} else if (creatorId != null) {
notificationManager.send(RptModuleDescriptor.TOPIC_REPORT_GENERATE_FAILED, message.build(), identityService.get(creatorId));
}
//
return new DefaultEventResult<>(event, this);
}
Aggregations