use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TextFormatter method explainPaths.
private void explainPaths(StringBuilder sb, List<ItemDelta> deltas, PrismObjectDefinition objectDefinition, PrismObject objectOld, PrismObject objectNew, List<ItemPath> hiddenPaths, boolean showOperationalAttributes) {
if (objectOld == null && objectNew == null) {
// no data - no point in trying
return;
}
boolean first = true;
List<ItemPath> alreadyExplained = new ArrayList<>();
for (ItemDelta itemDelta : deltas) {
ItemPath pathToExplain = getPathToExplain(itemDelta);
if (pathToExplain == null || ItemPath.containsSubpathOrEquivalent(alreadyExplained, pathToExplain)) {
// null or already processed
continue;
}
PrismObject source = null;
Object item = null;
if (objectNew != null) {
item = objectNew.find(pathToExplain);
source = objectNew;
}
if (item == null && objectOld != null) {
item = objectOld.find(pathToExplain);
source = objectOld;
}
if (item == null) {
LOGGER.warn("Couldn't find {} in {} nor {}, no explanation could be created.", pathToExplain, objectNew, objectOld);
continue;
}
if (first) {
sb.append("\nNotes:\n");
first = false;
}
String label = getItemPathLabel(pathToExplain, itemDelta.getDefinition(), objectDefinition);
// the item should be a PrismContainerValue
if (item instanceof PrismContainerValue) {
sb.append(" - ").append(label).append(":\n");
formatContainerValue(sb, " ", (PrismContainerValue) item, false, hiddenPaths, showOperationalAttributes);
} else {
LOGGER.warn("{} in {} was expected to be a PrismContainerValue; it is {} instead", pathToExplain, source, item.getClass());
if (item instanceof PrismContainer) {
formatPrismContainer(sb, " ", (PrismContainer) item, false, hiddenPaths, showOperationalAttributes);
} else if (item instanceof PrismReference) {
formatPrismReference(sb, " ", (PrismReference) item, false);
} else if (item instanceof PrismProperty) {
formatPrismProperty(sb, " ", (PrismProperty) item);
} else {
sb.append("Unexpected item: ").append(item).append("\n");
}
}
alreadyExplained.add(pathToExplain);
}
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createReplaceAccountConstructionUserDelta.
protected ObjectDelta<UserType> createReplaceAccountConstructionUserDelta(String userOid, Long id, ConstructionType newValue) throws SchemaException {
PrismContainerDefinition pcd = getAssignmentDefinition().findContainerDefinition(AssignmentType.F_CONSTRUCTION);
ContainerDelta<ConstructionType> acDelta = new ContainerDelta<ConstructionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), pcd, prismContext);
// ContainerDelta.createDelta(prismContext, ConstructionType.class, AssignmentType.F_CONSTRUCTION);
acDelta.setValueToReplace(newValue.asPrismContainerValue());
// PropertyDelta.createModificationReplaceProperty(
// new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
// ppd,
// newValue);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add(acDelta);
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
return userDelta;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class AbstractOrgClosureTest method _test390CyclePrevention.
protected void _test390CyclePrevention() throws Exception {
OperationResult opResult = new OperationResult("===[ test390CyclePrevention ]===");
// we hope it exists
String childOid = orgsByLevels.get(1).get(0);
OrgType child = repositoryService.getObject(OrgType.class, childOid, null, opResult).asObjectable();
// we hope it exists too
ObjectReferenceType parentOrgRef = child.getParentOrgRef().get(0);
String parentOid = parentOrgRef.getOid();
System.out.println("Adding cycle-introducing link from " + parentOid + " to " + childOid);
List<ItemDelta> modifications = new ArrayList<>();
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(childOid);
ort.setType(OrgType.COMPLEX_TYPE);
ItemDelta addParent = ReferenceDelta.createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, prismContext, ort.asReferenceValue());
modifications.add(addParent);
try {
repositoryService.modifyObject(OrgType.class, parentOid, modifications, opResult);
throw new AssertionError("Cycle-introducing link from " + parentOid + " to " + childOid + " was successfully added!");
} catch (Exception e) {
// ok, expected
// would be fine to check the kind of exception...
System.out.println("Got exception (as expected): " + e);
}
checkClosure(getVertices());
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TaskQuartzImpl method deleteExtensionPropertyAndPrepareDelta.
private ItemDelta<?, ?> deleteExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException {
ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, itemName), definition, getPrismContext());
delta.addValuesToDelete(values);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
modifications.add(delta);
// i.e. here we apply changes only locally (in memory)
PropertyDelta.applyTo(modifications, taskPrism);
return isPersistent() ? delta : null;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TaskQuartzImpl method setExtensionPropertyValueTransient.
@Override
public <T> void setExtensionPropertyValueTransient(QName propertyName, T value) throws SchemaException {
PrismPropertyDefinition propertyDef = getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(propertyName);
if (propertyDef == null) {
throw new SchemaException("Unknown property " + propertyName);
}
ArrayList<PrismPropertyValue<T>> values = new ArrayList(1);
if (value != null) {
values.add(new PrismPropertyValue<T>(value));
}
ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, propertyName), propertyDef, getPrismContext());
delta.setValuesToReplace(values);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
modifications.add(delta);
PropertyDelta.applyTo(modifications, taskPrism);
}
Aggregations