use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ObjectWrapperFactory method addContainerWrappers.
private <O extends ObjectType, C extends Containerable> void addContainerWrappers(List<ContainerWrapper<? extends Containerable>> containerWrappers, ObjectWrapper<O> oWrapper, PrismContainer<C> parentContainer, ItemPath path, OperationResult result) throws SchemaException {
PrismContainerDefinition<C> parentContainerDefinition = parentContainer.getDefinition();
List<ItemPathSegment> segments = new ArrayList<>();
if (path != null) {
segments.addAll(path.getSegments());
}
ItemPath parentPath = new ItemPath(segments);
for (ItemDefinition def : (Collection<ItemDefinition>) parentContainerDefinition.getDefinitions()) {
if (!(def instanceof PrismContainerDefinition)) {
continue;
}
if (isIgnoreContainer(def.getTypeName())) {
continue;
}
LOGGER.trace("ObjectWrapper.createContainerWrapper processing definition: {}", def);
PrismContainerDefinition<?> containerDef = (PrismContainerDefinition) def;
//todo this oWrapper.isShowAssignments() value is not set when initialization occurs (only default is there) [lazyman]
if (!oWrapper.isShowAssignments() && AssignmentType.COMPLEX_TYPE.equals(containerDef.getTypeName())) {
continue;
}
//todo this oWrapper.isShowInheritedObjectAttributes() value is not set when initialization occurs (only default is there) [lazyman]
if (!oWrapper.isShowInheritedObjectAttributes()) {
boolean res = INHERITED_OBJECT_SUBCONTAINERS.contains(containerDef.getName());
LOGGER.info("checking " + containerDef.getName() + ", result = " + res);
if (res) {
continue;
}
}
ItemPath newPath = createPropertyPath(parentPath, containerDef.getName());
// skip it.
if (parentContainer.size() <= 1) {
// the same check as in getValue() implementation
boolean isMultiValued = parentContainer.getDefinition() != null && !parentContainer.getDefinition().isDynamic() && !parentContainer.getDefinition().isSingleValue();
if (!isMultiValued) {
ContainerWrapperFactory cwf = new ContainerWrapperFactory(modelServiceLocator);
PrismContainer prismContainer = parentContainer.findContainer(def.getName());
ContainerWrapper container;
if (prismContainer != null) {
container = cwf.createContainerWrapper(oWrapper, prismContainer, ContainerStatus.MODIFYING, newPath);
} else {
prismContainer = containerDef.instantiate();
container = cwf.createContainerWrapper(oWrapper, prismContainer, ContainerStatus.ADDING, newPath);
}
result.addSubresult(cwf.getResult());
containerWrappers.add(container);
if (!AssignmentType.COMPLEX_TYPE.equals(containerDef.getTypeName()) || !ShadowType.F_ASSOCIATION.equals(parentContainer.getElementName())) {
// do not show internals of Assignments (e.g. activation)
addContainerWrappers(containerWrappers, oWrapper, prismContainer, newPath, result);
}
}
}
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class PrismAsserts method assertPathEqualsExceptForPrefixes.
public static void assertPathEqualsExceptForPrefixes(String message, ItemPath expected, ItemPath actual) {
assertEquals(message + ": wrong path size", expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
ItemPathSegment expectedSegment = expected.getSegments().get(i);
ItemPathSegment actualSegment = actual.getSegments().get(i);
if (expectedSegment instanceof NameItemPathSegment) {
QName qnameExpected = ((NameItemPathSegment) expectedSegment).getName();
QName qnameActual = ((NameItemPathSegment) actualSegment).getName();
assertEquals(message + ": wrong NS in path segment #" + (i + 1), qnameExpected.getNamespaceURI(), qnameActual.getNamespaceURI());
assertEquals(message + ": wrong local part in path segment #" + (i + 1), qnameExpected.getLocalPart(), qnameActual.getLocalPart());
} else {
assertEquals(message + ": wrong path segment #" + (i + 1), expectedSegment, actualSegment);
}
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class PrismReferenceValue method find.
@Override
public Object find(ItemPath path) {
if (path == null || path.isEmpty()) {
return this;
}
ItemPathSegment first = path.first();
if (!(first instanceof NameItemPathSegment)) {
throw new IllegalArgumentException("Attempt to resolve inside the reference value using a non-name path " + path + " in " + this);
}
QName subName = ((NameItemPathSegment) first).getName();
if (compareLocalPart(F_OID, subName)) {
return this.getOid();
} else if (compareLocalPart(F_TYPE, subName)) {
return this.getTargetType();
} else if (compareLocalPart(F_RELATION, subName)) {
return this.getRelation();
} else {
throw new IllegalArgumentException("Attempt to resolve inside the reference value using a unrecognized path " + path + " in " + this);
}
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class ContainerDelta method getSubDelta.
@Override
public ItemDelta<?, ?> getSubDelta(ItemPath path) {
if (path.isEmpty()) {
return this;
}
Long id = null;
ItemPathSegment first = path.first();
if (first instanceof IdItemPathSegment) {
id = ((IdItemPathSegment) first).getId();
path = path.rest();
}
ItemDefinition itemDefinition = getDefinition().findItemDefinition(path);
if (itemDefinition == null) {
throw new IllegalStateException("No definition of " + path + " in " + getDefinition());
}
ItemDelta<?, ?> itemDelta = itemDefinition.createEmptyDelta(getPath().subPath(path));
itemDelta.addValuesToAdd(findItemValues(id, path, getValuesToAdd()));
itemDelta.addValuesToDelete(findItemValues(id, path, getValuesToDelete()));
itemDelta.setValuesToReplace(findItemValues(id, path, getValuesToReplace()));
if (itemDelta.isEmpty()) {
return null;
}
return itemDelta;
}
use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.
the class PathExpressionEvaluator method evaluate.
/* (non-Javadoc)
* @see com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java.util.Collection, java.util.Map, boolean, java.lang.String, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ItemDeltaItem<?, ?> resolveContext = null;
if (context.getSources() != null && context.getSources().size() == 1) {
Source<?, ?> source = context.getSources().iterator().next();
if (path.isEmpty()) {
PrismValueDeltaSetTriple<V> outputTriple = (PrismValueDeltaSetTriple<V>) source.toDeltaSetTriple();
return outputTriple.clone();
}
resolveContext = source;
}
Map<QName, Object> variablesAndSources = ExpressionUtil.compileVariablesAndSources(context);
ItemPath resolvePath = path;
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment && first.isVariable()) {
QName variableName = ((NameItemPathSegment) first).getName();
Object variableValue;
if (variablesAndSources.containsKey(variableName)) {
variableValue = variablesAndSources.get(variableName);
} else if (QNameUtil.matchAny(variableName, variablesAndSources.keySet())) {
QName fullVariableName = QNameUtil.resolveNs(variableName, variablesAndSources.keySet());
variableValue = variablesAndSources.get(fullVariableName);
} else {
throw new ExpressionEvaluationException("No variable with name " + variableName + " in " + context.getContextDescription());
}
if (variableValue == null) {
return null;
}
if (variableValue instanceof Item || variableValue instanceof ItemDeltaItem<?, ?>) {
resolveContext = ExpressionUtil.toItemDeltaItem(variableValue, objectResolver, "path expression in " + context.getContextDescription(), context.getResult());
} else if (variableValue instanceof PrismPropertyValue<?>) {
PrismValueDeltaSetTriple<V> outputTriple = new PrismValueDeltaSetTriple<>();
outputTriple.addToZeroSet((V) variableValue);
return ExpressionUtil.toOutputTriple(outputTriple, outputDefinition, context.getAdditionalConvertor(), null, protector, prismContext);
} else {
throw new ExpressionEvaluationException("Unexpected variable value " + variableValue + " (" + variableValue.getClass() + ")");
}
resolvePath = path.rest();
}
if (resolveContext == null) {
return null;
}
while (!resolvePath.isEmpty()) {
if (resolveContext.isContainer()) {
resolveContext = resolveContext.findIdi(resolvePath.head());
resolvePath = resolvePath.tail();
if (resolveContext == null) {
throw new ExpressionEvaluationException("Cannot find item using path " + path + " in " + context.getContextDescription());
}
} else if (resolveContext.isStructuredProperty()) {
// The output path does not really matter. The delta will be converted to triple anyway
// But the path cannot be null, oherwise the code will die
resolveContext = resolveContext.resolveStructuredProperty(resolvePath, (PrismPropertyDefinition) outputDefinition, new ItemPath());
break;
} else if (resolveContext.isNull()) {
break;
} else {
throw new ExpressionEvaluationException("Cannot resolve path " + resolvePath + " on " + resolveContext + " in " + context.getContextDescription());
}
}
PrismValueDeltaSetTriple<V> outputTriple = ItemDelta.toDeltaSetTriple((Item<V, D>) resolveContext.getItemOld(), (ItemDelta<V, D>) resolveContext.getDelta());
if (outputTriple == null) {
return null;
}
return ExpressionUtil.toOutputTriple(outputTriple, outputDefinition, context.getAdditionalConvertor(), null, protector, prismContext);
}
Aggregations