use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportExecutor method createAccountDifferences.
/**
* Starts the provisioning in the dry run for single account. Results of the
* calculated provisioning is used for differences evaluation and highlight.
*
* @param account
* @param identity
* @param selectedAttributeNames
* @return
*/
private List<SysAttributeDifferenceDto> createAccountDifferences(AccAccountDto account, IdmIdentityDto identity, List<String> selectedAttributeNames) {
EventContext<AccAccountDto> eventCtx = provisioningService.doProvisioning(account, identity, ImmutableMap.of(ProvisioningService.DRY_RUN_PROPERTY_NAME, Boolean.TRUE));
EventResult<AccAccountDto> result = eventCtx.getLastResult();
if (result == null) {
throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
}
ProvisioningOperation provisioningOperation = (ProvisioningOperation) result.getEvent().getProperties().get(EventResult.EVENT_PROPERTY_RESULT);
if (provisioningOperation == null) {
throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
}
ProvisioningContext context = provisioningOperation.getProvisioningContext();
context = filterAttributes(context, selectedAttributeNames);
if (context == null) {
throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", account.getId(), "system", account.getSystem(), "operationType", "DRY_RUN", "objectClass", ""));
}
List<SysAttributeDifferenceDto> differences = provisioningArchiveService.evaluateProvisioningDifferences(context.getSystemConnectorObject(), context.getConnectorObject());
return differences;
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportExecutor method removeUnchangedMultivalues.
/*
* Method removes unchanged values of multivalue attributes.
* It increases clarity of the output.
*/
private List<SysAttributeDifferenceDto> removeUnchangedMultivalues(List<SysAttributeDifferenceDto> differences, boolean removeUnchanged) {
if (CollectionUtils.isEmpty(differences) || !removeUnchanged) {
return differences;
}
List<SysAttributeDifferenceDto> result = new ArrayList<>();
for (SysAttributeDifferenceDto value : differences) {
if (!value.isMultivalue()) {
result.add(value);
continue;
}
if (!value.isChanged()) {
value.setValues(new ArrayList<SysAttributeDifferenceValueDto>());
result.add(value);
continue;
}
List<SysAttributeDifferenceValueDto> subValues = value.getValues();
subValues = subValues.stream().filter(val -> {
return val.getChange() != null;
}).collect(Collectors.toList());
value.setValues(subValues);
result.add(value);
}
return result;
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportXlsxRenderer method renderMultiValueCell.
/**
* Multi value cell renderer.
*/
private Cell renderMultiValueCell(Cell cell, SysAttributeDifferenceDto attribute) {
XSSFRichTextString content = new XSSFRichTextString();
// also defines the order of change types
SysValueChangeType[] changeTypes = { SysValueChangeType.ADDED, SysValueChangeType.REMOVED, null };
List<List<SysAttributeDifferenceValueDto>> valueList = Arrays.stream(changeTypes).map(type -> {
return attribute.getValues().stream().filter(val -> type == val.getChange()).collect(Collectors.toList());
}).collect(Collectors.toList());
for (int i = 0; i < changeTypes.length; i++) {
SysValueChangeType changeType = changeTypes[i];
List<SysAttributeDifferenceValueDto> values = valueList.get(i);
for (int j = 0; j < values.size(); ++j) {
SysAttributeDifferenceValueDto value = values.get(j);
content.append(Objects.toString(value.getValue()), getTextFont(cell, changeType));
if (j >= values.size() - 1 && i >= changeTypes.length - 1) {
continue;
}
content.append(NEW_LINE);
}
}
cell.setCellValue(content);
return cell;
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class ChangesOnSystemReportXlsxRenderer method renderRecord.
/**
* Methods renders single record
*/
private void renderRecord(int lineIdx, Sheet sheet, RptChangesOnSystemRecordDto record, Map<String, Integer> attributeOrder) {
if (record == null) {
LOG.warn("Trying to render null record!");
return;
}
Row row = sheet.createRow(lineIdx);
row.setHeight((short) -1);
int cellIdx;
// render status
XSSFRichTextString content = new XSSFRichTextString();
RptChangesOnSystemState state = record.getState();
cellIdx = attributeOrder.get(STATUS_COLUMN_NAME);
Cell cell = row.createCell(cellIdx);
content.append(state.toString());
cell.setCellValue(content);
cell.setCellStyle(getStatusCellStyle(sheet, state));
// render record key/identifier
XSSFFont boldFont = ((XSSFWorkbook) sheet.getWorkbook()).createFont();
boldFont.setBold(true);
String key = record.getIdentifier();
content = new XSSFRichTextString();
cellIdx = attributeOrder.get(KEY_COLUMN_NAME);
cell = row.createCell(cellIdx);
content.append(Objects.toString(key, ""), boldFont);
cell.setCellValue(content);
if (state == RptChangesOnSystemState.FAILED) {
cellIdx++;
cell = row.createCell(cellIdx);
content = new XSSFRichTextString();
XSSFFont font = getTextFont(cell, SysValueChangeType.REMOVED);
content.append(Objects.toString(record.getError(), ""), font);
cell.setCellValue(content);
return;
}
List<SysAttributeDifferenceDto> differences = record.getAttributeDifferences();
if (CollectionUtils.isEmpty(differences)) {
return;
}
for (SysAttributeDifferenceDto diff : differences) {
Integer colIdx = attributeOrder.get(diff.getName());
if (colIdx == null) {
continue;
}
cell = row.createCell(colIdx);
if (diff.isMultivalue()) {
renderMultiValueCell(cell, diff);
} else {
renderSingleValueCell(cell, diff, state);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto 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