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) {
File temp = null;
FileOutputStream outputStream = null;
try {
// prepare temp file for json stream
temp = getAttachmentManager().createTempFile();
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 = new PageRequest(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 {
// just for sure - jGenerator should close stream itself
IOUtils.closeQuietly(outputStream);
FileUtils.deleteQuietly(temp);
}
}
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 IdentityRoleByIdentityDeduplicationExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
IdmIdentityFilter filter = new IdmIdentityFilter();
UUID treeNode = getTreeNode(report);
if (treeNode != null) {
filter.setTreeNode(treeNode);
filter.setRecursively(true);
} else {
LOG.info("Tree node id isn't filled. Report will be done for all identities.");
}
// 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();
counter = 0L;
List<UUID> identities = identityService.findIds(filter, null, IdmBasePermission.READ).getContent();
if (count == null) {
count = Long.valueOf(identities.size());
}
boolean canContinue = true;
for (UUID identityId : identities) {
List<IdmIdentityContractDto> contracts = identityContractService.findAllValidForDate(identityId, LocalDate.now(), null);
for (IdmIdentityContractDto contract : contracts) {
RptIdentityRoleByRoleDeduplicationDto newRecord = createRecordForContracts(contract);
if (newRecord != null) {
getMapper().writeValue(jGenerator, newRecord);
}
}
++counter;
canContinue = updateState();
if (!canContinue) {
break;
}
}
// 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 MonitoringReportExecutor 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();
//
List<IdmMonitoringResultDto> lastResults = monitoringManager.getLastResults(null, null, IdmBasePermission.READ).getContent();
counter = 0L;
count = Long.valueOf(lastResults.size());
boolean canContinue = true;
for (IdmMonitoringResultDto result : lastResults) {
IdmMonitoringDto monitoring = getLookupService().lookupEmbeddedDto(result, IdmMonitoringResult_.monitoring);
//
RptMonitoringResultDto resultDto = new RptMonitoringResultDto(result);
resultDto.setResultMessage(result.getResult().getModel() == null ? null : result.getResult().getModel().getMessage());
resultDto.setOwnerType(result.getOwnerType());
resultDto.setOwnerId(result.getOwnerId());
resultDto.setValue(result.getValue());
resultDto.setLevel(result.getLevel() == null ? NotificationLevel.SUCCESS : result.getLevel());
resultDto.setEvaluatorType(result.getEvaluatorType());
resultDto.setEvaluatorDescription(monitoring.getDescription());
resultDto.setInstanceId(result.getInstanceId());
//
// write dto into json
getMapper().writeValue(jGenerator, resultDto);
//
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
if (!canContinue) {
break;
}
}
//
// 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 ProvisioningOperationReportExecutor 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());
Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, SysProvisioningOperation_.created.getName()));
SysProvisioningOperationFilter filterOperations = new SysProvisioningOperationFilter();
Serializable systemId = formInstance.toSinglePersistentValue(PARAMETER_SYSTEM);
if (systemId != null) {
filterOperations.setSystemId(getParameterConverter().toEntityUuid(systemId.toString(), SysSystemDto.class));
}
//
counter = 0L;
do {
Page<SysProvisioningOperationDto> operations = provisioningOperationService.find(filterOperations, pageable, IdmBasePermission.READ);
if (count == null) {
count = operations.getTotalElements();
}
boolean canContinue = true;
for (Iterator<SysProvisioningOperationDto> i = operations.iterator(); i.hasNext() && canContinue; ) {
// transfer SysProvisioningOperationDto to IdmProvisioningOperationDto and write IdmProvisioningOperationDto into json
RptProvisioningOperationDto idmProvisioningOperationDto = transferSysProvisioningOperationDto(i.next());
getMapper().writeValue(jGenerator, idmProvisioningOperationDto);
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
}
// iterate while next page of identities is available
pageable = operations.hasNext() && canContinue ? operations.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);
}
}
Aggregations