use of eu.bcvsolutions.idm.core.api.domain.RequestOperationType in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method getChanges.
@Override
public List<IdmRequestItemAttributeDto> getChanges(AbstractDto currentDto, AbstractDto changedDto, RequestOperationType itemOperation) {
List<IdmRequestItemAttributeDto> resultAttributes = new ArrayList<>();
Map<String, Object> currentFieldsValues = this.dtoToMap(currentDto);
Map<String, Object> changedFieldsValues = this.dtoToMap(changedDto);
// First add all new attributes
changedFieldsValues.keySet().stream().forEach(changedAttribute -> {
if (!currentFieldsValues.containsKey(changedAttribute)) {
Object value = changedFieldsValues.get(changedAttribute);
IdmRequestItemAttributeDto attribute = new IdmRequestItemAttributeDto(changedAttribute, value instanceof List, true);
if (attribute.isMultivalue()) {
if (value instanceof List) {
((List<?>) value).forEach(v -> {
attribute.getValues().add(new IdmRequestAttributeValueDto(v, null, RequestOperationType.ADD));
});
}
} else {
attribute.setValue(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
}
resultAttributes.add(attribute);
}
});
// Second add all already exists attributes
currentFieldsValues.keySet().forEach(currentAttribute -> {
Object changedValue = changedFieldsValues.get(currentAttribute);
IdmRequestItemAttributeDto attribute;
Object currentValue = currentFieldsValues.get(currentAttribute);
attribute = new IdmRequestItemAttributeDto(currentAttribute, changedValue instanceof List, false);
if (attribute.isMultivalue()) {
if (changedValue instanceof List) {
((List<?>) changedValue).forEach(value -> {
if (currentValue instanceof List && ((List<?>) currentValue).contains(value)) {
attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, null));
} else {
attribute.setChanged(true);
attribute.getValues().add(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
}
});
}
if (currentValue instanceof List) {
((List<?>) currentValue).forEach(value -> {
if (changedValue == null || !((List<?>) changedValue).contains(value)) {
attribute.setChanged(true);
attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, RequestOperationType.REMOVE));
}
});
}
} else {
if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentValue)) || (currentValue != null && currentValue.equals(changedValue))) {
attribute.setChanged(RequestOperationType.UPDATE == itemOperation ? false : true);
attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, RequestOperationType.UPDATE == itemOperation ? null : itemOperation));
} else {
attribute.setChanged(true);
attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, itemOperation));
}
}
resultAttributes.add(attribute);
});
// Make all values nicer
//
resultAttributes.stream().filter(//
attribute -> attribute.getValue() != null).forEach(attribute -> {
//
attribute.getValue().setValue(this.makeNiceValue(attribute.getValue().getValue()));
attribute.getValue().setOldValue(this.makeNiceValue(attribute.getValue().getOldValue()));
List<IdmRequestAttributeValueDto> attributeValues = attribute.getValues();
attributeValues.forEach(attributeValue -> {
attributeValue.setValue(this.makeNiceValue(attributeValue.getValue()));
attributeValue.setOldValue(this.makeNiceValue(attributeValue.getOldValue()));
});
});
return resultAttributes;
}
use of eu.bcvsolutions.idm.core.api.domain.RequestOperationType in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method resolveItem.
private void resolveItem(IdmRequestItemDto item) throws ClassNotFoundException, IOException {
Assert.notNull(item, "Item is mandatory!");
RequestOperationType type = item.getOperation();
// Get DTO service
@SuppressWarnings("unchecked") Class<? extends Requestable> dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
// Get service
@SuppressWarnings("unchecked") ReadWriteDtoService<Requestable, BaseFilter> dtoService = (ReadWriteDtoService<Requestable, BaseFilter>) this.getServiceByItem(item, dtoClass);
// Create or Update DTO
if (RequestOperationType.ADD == type || RequestOperationType.UPDATE == type) {
Requestable dto = this.convertItemToDto(item, dtoClass);
// confidential storage
if (dto instanceof IdmFormValueDto) {
IdmFormValueDto formValueDto = (IdmFormValueDto) dto;
if (formValueDto.isConfidential()) {
formValueDto.setValue(this.getConfidentialPersistentValue(item));
}
}
// Save without check a permissions
dto = dtoService.save(dto);
item.setResult(new OperationResultDto(OperationState.EXECUTED));
item.setState(RequestState.EXECUTED);
requestItemService.save(item);
return;
}
// Delete DTO
if (RequestOperationType.REMOVE == type) {
Assert.notNull(item.getOwnerId(), "Id in item is required for delete!");
Requestable dtoToDelete = dtoService.get(item.getOwnerId());
if (dtoToDelete == null) {
item.setResult(new //
OperationResultDto.Builder(//
OperationState.NOT_EXECUTED).setException(new ResultCodeException(CoreResultCode.NOT_FOUND, //
ImmutableMap.of("entity", item.getOriginalCreatorId()))).build());
requestItemService.save(item);
return;
}
// Delete without check a permissions
dtoService.deleteById(dtoToDelete.getId());
item.setResult(new OperationResultDto(OperationState.EXECUTED));
item.setState(RequestState.EXECUTED);
requestItemService.save(item);
return;
}
}
use of eu.bcvsolutions.idm.core.api.domain.RequestOperationType in project CzechIdMng by bcvsolutions.
the class DefaultIdmImportLogService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<IdmImportLog> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmImportLogFilter filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
if (StringUtils.isNotEmpty(filter.getText())) {
predicates.add(builder.like(builder.lower(root.get(IdmImportLog_.type)), "%" + filter.getText().toLowerCase() + "%"));
}
UUID batchId = filter.getBatchId();
if (batchId != null) {
predicates.add(builder.equal(root.get(IdmImportLog_.batch).get(IdmExportImport_.id), batchId));
}
UUID parentId = filter.getParent();
if (parentId != null) {
predicates.add(builder.equal(root.get(IdmImportLog_.parentId), parentId));
}
UUID dtoId = filter.getDtoId();
if (dtoId != null) {
predicates.add(builder.equal(root.get(IdmImportLog_.dtoId), dtoId));
}
Boolean roots = filter.getRoots();
if (roots != null && roots) {
if (filter.getBatchId() == null) {
predicates.add(builder.equal(root.get(IdmImportLog_.batch).get(IdmExportImport_.id), ExportManager.BLANK_UUID));
}
predicates.add(builder.isNull(root.get(IdmImportLog_.parentId)));
}
RequestOperationType operation = filter.getOperation();
if (operation != null) {
predicates.add(builder.equal(root.get(IdmImportLog_.operation), operation));
}
OperationState operationState = filter.getOperationState();
if (operationState != null) {
predicates.add(builder.equal(root.get(IdmImportLog_.result).get(OperationResult_.state), operationState));
}
return predicates;
}
use of eu.bcvsolutions.idm.core.api.domain.RequestOperationType in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method getChanges.
@SuppressWarnings("unchecked")
@Override
public IdmRequestItemChangesDto getChanges(IdmRequestItemDto item, BasePermission... permission) {
LOG.debug(MessageFormat.format("Start read request item with changes [{0}].", item));
Assert.notNull(item, "Idm request item cannot be null!");
if (Strings.isNullOrEmpty(item.getOwnerType()) || item.getOwnerId() == null) {
return null;
}
Class<? extends Requestable> dtoClass;
try {
dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
ReadDtoService<?, ?> readService = getServiceByItem(item, dtoClass);
Requestable currentDto = (Requestable) readService.get(item.getOwnerId(), permission);
if (currentDto == null) {
try {
currentDto = (Requestable) dtoClass.getDeclaredConstructor().newInstance();
currentDto.setId(item.getOwnerId());
} catch (ReflectiveOperationException e) {
throw new CoreException(e);
}
}
Requestable changedDto = this.get(item.getRequest(), currentDto);
RequestOperationType itemOperation = item.getOperation();
List<IdmRequestItemAttributeDto> resultAttributes = getChanges((AbstractDto) currentDto, (AbstractDto) changedDto, itemOperation);
IdmRequestItemChangesDto result = new IdmRequestItemChangesDto();
result.setRequestItem(item);
result.getAttributes().addAll(resultAttributes);
LOG.debug(MessageFormat.format("End of reading the request item with changes [{0}].", item));
return result;
}
Aggregations