use of eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportXlsxRenderer method render.
@Override
public InputStream render(RptReportDto report) {
try (JsonParser jParser = getMapper().getFactory().createParser(getReportData(report))) {
List<String> headerNames = new ArrayList<String>();
JsonToken token = null;
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(REPORT_SHEET_NAME);
sheet.setDefaultColumnWidth(15);
// parse and render attributes' name
token = getJsonNodeByName(jParser, ChangesOnSystemReportExecutor.ATTRIBUTE_NAME_JSON_KEY);
if (token != null) {
headerNames = getMapper().readValue(jParser, new TypeReference<List<String>>() {
});
}
Map<String, Integer> attributeOrder = renderHeader(sheet, headerNames);
// parse and render attribute record
token = getJsonNodeByName(jParser, ChangesOnSystemReportExecutor.RECORDS_JSON_KEY);
int recordIdx = 1;
while (token != null && token != JsonToken.END_ARRAY && !jParser.isClosed()) {
RptChangesOnSystemRecordDto record = getMapper().readValue(jParser, RptChangesOnSystemRecordDto.class);
renderRecord(recordIdx, sheet, record, attributeOrder);
token = jParser.nextValue();
recordIdx++;
}
// cell autofitting
for (int index = 0; index < attributeOrder.size() + 1; index++) {
sheet.autoSizeColumn(index);
}
// close and return input stream
return getInputStream(workbook);
} catch (Exception ex) {
throw new ReportRenderException(report.getName(), ex);
}
}
use of eu.bcvsolutions.idm.rpt.dto.RptChangesOnSystemRecordDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportExecutor method createReportData.
/**
* Creates report object for saving to output json file. It invokes record
* generating for every account/identity
*
* @param changeDataDto
* @param accountFilter
* @param identityIds
* @param systemId
* @param attributes
* @return
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
private void createReportData(JsonGenerator jGenerator, AccAccountFilter accountFilter, Set<UUID> identityIds, UUID systemId, List<String> selectedAttributeNames, boolean skipUnchangedMultivalue) throws IOException {
if (identityIds == null) {
// null indicates that no identity explicitly specified from report config
List<UUID> accountIds = accountService.findIds(accountFilter, null).getContent();
IdmIdentityDto identity = null;
String key = null;
for (UUID accountId : accountIds) {
Pair<AccAccountDto, IdmIdentityDto> pair = findIdentityAndAccount(systemId, accountId, null);
AccAccountDto account = pair.getLeft();
identity = pair.getRight();
key = createKey(account, identity);
RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
record.setIdentifier(key);
if (identity == null) {
record.setState(RptChangesOnSystemState.NO_ENTITY_FOR_ACCOUNT);
record.setAttributeDifferences(new ArrayList<SysAttributeDifferenceDto>());
// dry run provisioning cannot be performed without identity
} else {
try {
List<SysAttributeDifferenceDto> differences = createAccountDifferences(account, identity, selectedAttributeNames);
differences = removeUnchangedMultivalues(differences, skipUnchangedMultivalue);
record.setAttributeDifferences(differences);
record.setState(createRecordState(differences));
} catch (Exception e) {
record.setState(RptChangesOnSystemState.FAILED);
record.setIdentifier(key);
record.setError(ExceptionUtils.getStackTrace(e));
}
}
getMapper().writeValue(jGenerator, record);
}
} else {
for (UUID identityId : identityIds) {
IdmIdentityDto identity = identityService.get(identityId);
if (identity == null) {
LOG.info("Wrong user UUID [{}] inserted.", identityId);
continue;
}
accountFilter.setIdentityId(identityId);
List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
if (accounts.isEmpty()) {
String key = createKey(null, identity);
RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
record.setIdentifier(key);
record.setState(RptChangesOnSystemState.NO_ACCOUNT_FOR_ENTITY);
record.setAttributeDifferences(new ArrayList<SysAttributeDifferenceDto>());
getMapper().writeValue(jGenerator, record);
continue;
}
for (AccAccountDto account : accounts) {
String key = createKey(account, identity);
try {
List<SysAttributeDifferenceDto> differences = createAccountDifferences(account, identity, selectedAttributeNames);
differences = removeUnchangedMultivalues(differences, skipUnchangedMultivalue);
RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
record.setIdentifier(key);
record.setAttributeDifferences(differences);
record.setState(createRecordState(differences));
getMapper().writeValue(jGenerator, record);
} catch (Exception e) {
RptChangesOnSystemRecordDto record = new RptChangesOnSystemRecordDto();
record.setState(RptChangesOnSystemState.FAILED);
record.setIdentifier(key);
record.setError(ExceptionUtils.getStackTrace(e));
getMapper().writeValue(jGenerator, record);
}
}
}
}
}
Aggregations