use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.
the class TestFilterReportExecutor method generateData.
@Override
@SuppressWarnings("rawtypes")
protected IdmAttachmentDto generateData(RptReportDto report) {
try {
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
//
List usernames = (List) formInstance.toPersistentValues(IdmIdentity_.username.getName());
List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
return ObjectUtils.isEmpty(usernames) || usernames.contains(identity.getUsername());
}).collect(Collectors.toList());
return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
} catch (FileNotFoundException | JsonProcessingException ex) {
throw new ReportGenerateException(report.getName(), ex);
}
}
use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.
the class IdentityReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// prepare temp file for json stream
File temp = getAttachmentManager().createTempFile();
//
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
// write into json stream
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// json will be array of identities
jGenerator.writeStartArray();
// form instance has useful methods to transform form values
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
// initialize filter by given form - transform to multi value map
// => form attribute defined above will be automaticaly mapped to identity filter
IdmIdentityFilter filter = new IdmIdentityFilter(formInstance.toMultiValueMap());
// report extends long running task - show progress by count and counter lrt attributes
counter = 0L;
// find a first page of identities
Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
do {
Page<IdmIdentityDto> identities = identityService.find(filter, pageable, IdmBasePermission.READ);
if (count == null) {
// report extends long running task - show progress by count and counter lrt attributes
count = identities.getTotalElements();
}
boolean canContinue = true;
for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
// write single identity into json
getMapper().writeValue(jGenerator, i.next());
//
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
}
// iterate while next page of identities is available
pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
} while (pageable != null);
//
// close array of identities
jGenerator.writeEndArray();
} finally {
// close json stream
jGenerator.close();
}
// save create temp file with array of identities in json as attachment
return createAttachment(report, new FileInputStream(temp));
} catch (IOException ex) {
throw new ReportGenerateException(report.getName(), ex);
} finally {
FileUtils.deleteQuietly(temp);
}
}
use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.
the class IdentityEavReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// prepare temp file for json stream
File temp = getAttachmentManager().createTempFile();
//
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
// write into json stream
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
jGenerator.writeStartArray();
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
counter = 0L;
// take configuration
Serializable eavValueSerializable = formInstance.toSinglePersistentValue(PARAMETER_EAV_VALUE);
String eavValue = eavValueSerializable != null ? eavValueSerializable.toString() : null;
Serializable disabledSerializable = formInstance.toSinglePersistentValue(IdmIdentityFilter.PARAMETER_DISABLED);
String disabled = disabledSerializable != null ? disabledSerializable.toString() : null;
UUID definitionUUID = UUID.fromString(formInstance.toSinglePersistentValue(PARAMETER_FORM_DEFINITION).toString());
IdmFormDefinitionDto definition = formService.getDefinition(definitionUUID);
//
if (!definition.getType().equals(IdmIdentity.class.getName())) {
throw new ResultCodeException(RptResultCode.REPORT_WRONG_DEFINITION, ImmutableMap.of("firstType", definition.getType(), "secondType", IdmIdentity.class.getName()));
}
//
String eavCode = (String) formInstance.toMultiValueMap().getFirst(PARAMETER_FORM_ATTRIBUTE);
if (eavCode == null) {
throw new ResultCodeException(RptResultCode.REPORT_NO_FORM_ATTRIBUTE, ImmutableMap.of("code", "null"));
}
IdmFormAttributeDto formAttribute = definition.getMappedAttributeByCode(eavCode);
if (formAttribute == null) {
throw new ResultCodeException(RptResultCode.REPORT_NO_FORM_ATTRIBUTE, ImmutableMap.of("code", eavCode));
}
//
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
if (disabled != null) {
identityFilter.setDisabled(Boolean.valueOf(disabled));
}
// find a first page of identities
Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
do {
Page<IdmIdentityDto> identities = identityService.find(identityFilter, pageable, IdmBasePermission.READ);
//
if (count == null) {
// report extends long running task - show progress by count and counter lrt attributes
count = identities.getTotalElements();
}
//
boolean canContinue = true;
for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
writeValues(i.next(), formAttribute, eavValue, jGenerator);
canContinue = updateState();
if (!canContinue) {
break;
}
}
pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
} while (pageable != null);
//
jGenerator.writeEndArray();
} finally {
// close json stream
jGenerator.close();
}
// save create temp file with array of identities in json as attachment
return createAttachment(report, new FileInputStream(temp));
} catch (IOException ex) {
throw new ReportGenerateException(report.getName(), ex);
} finally {
FileUtils.deleteQuietly(temp);
}
}
use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.
the class IdentityIncompatibleRoleReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// prepare temp file for json stream
File temp = getAttachmentManager().createTempFile();
//
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
// write into json stream
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// json will be array of identities
jGenerator.writeStartArray();
// form instance has useful methods to transform form values
Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
//
counter = 0L;
do {
Page<IdmIdentityDto> identities = identityService.find(null, pageable, IdmBasePermission.READ);
if (count == null) {
count = identities.getTotalElements();
}
boolean canContinue = true;
for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
IdmIdentityDto identity = i.next();
// search assigned roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
// direct roles only
filter.setDirectRole(Boolean.TRUE);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null, IdmBasePermission.READ).getContent();
// search incompatible roles
Set<ResolvedIncompatibleRoleDto> incompatibleRoles = incompatibleRoleService.resolveIncompatibleRoles(identityRoles.stream().map(ir -> ir.getRole()).collect(Collectors.toList()));
for (ResolvedIncompatibleRoleDto resolvedIncompatibleRole : incompatibleRoles) {
// add item into report
RptIdentityIncompatibleRoleDto reportItem = new RptIdentityIncompatibleRoleDto();
reportItem.setIdentity(identity);
reportItem.setDirectRole(resolvedIncompatibleRole.getDirectRole());
reportItem.setIncompatibleRole(resolvedIncompatibleRole.getIncompatibleRole());
// dtos in embedded cannot be parsed from json automatically as objects => aaet them into report dto directly
IdmRoleDto superior = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.superior);
IdmRoleDto sub = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.sub);
reportItem.setSuperior(superior);
reportItem.setSub(sub);
//
getMapper().writeValue(jGenerator, reportItem);
}
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
}
// iterate while next page of identities is available
pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
} while (pageable != null);
//
// close array of identities
jGenerator.writeEndArray();
} finally {
// close json stream
jGenerator.close();
}
// save create temp file with array of identities in json as attachment
return createAttachment(report, new FileInputStream(temp));
} catch (IOException ex) {
throw new ReportGenerateException(report.getName(), ex);
} finally {
FileUtils.deleteQuietly(temp);
}
}
use of eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// get system related configuration
MultiValueMap<String, UUID> configuration = parseAttributeConfig(report);
SysSystemDto systemDto = getSystemById(configuration.getFirst(PARAMETER_SYSTEM));
SysSystemMappingDto systemMapping = getSystemMappingById(configuration.getFirst(PARAMETER_SYSTEM_MAPPING));
List<SysSystemAttributeMappingDto> attributes = getAttributesById(configuration.get(PARAMETER_MAPPING_ATTRIBUTES), systemMapping);
List<String> selectedAttributeNames = getSelectedAttributeNames(attributes).stream().sorted().collect(Collectors.toList());
// list of identities to report
Set<UUID> identities = getReportedIdentities(report);
boolean skipUnchangedMultivalue = getSkipUnchangedValues(report);
AccAccountFilter filterAccount = new AccAccountFilter();
filterAccount.setSystemId(systemDto.getId());
filterAccount.setEntityType(SystemEntityType.IDENTITY);
File temp = getAttachmentManager().createTempFile();
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// start of root object
jGenerator.writeStartObject();
// write attribute names
jGenerator.writeFieldName(ATTRIBUTE_NAME_JSON_KEY);
getMapper().writeValue(jGenerator, selectedAttributeNames);
// create and write records
jGenerator.writeFieldName(RECORDS_JSON_KEY);
jGenerator.writeStartArray();
createReportData(jGenerator, filterAccount, identities, systemDto.getId(), selectedAttributeNames, skipUnchangedMultivalue);
jGenerator.writeEndArray();
// end of root object
jGenerator.writeEndObject();
} finally {
jGenerator.close();
}
return createAttachment(report, new FileInputStream(temp));
} catch (IOException e) {
throw new ReportGenerateException(report.getName(), e);
} finally {
FileUtils.deleteQuietly(temp);
}
}
Aggregations