Search in sources :

Example 81 with ItemDelta

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);
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 82 with ItemDelta

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;
}
Also used : ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ArrayList(java.util.ArrayList) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 83 with ItemDelta

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());
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 84 with ItemDelta

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;
}
Also used : ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 85 with ItemDelta

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);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) F_WORKFLOW_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT) F_MODEL_OPERATION_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_MODEL_OPERATION_CONTEXT) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)185 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)87 Test (org.testng.annotations.Test)66 ArrayList (java.util.ArrayList)64 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 Task (com.evolveum.midpoint.task.api.Task)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)33 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)30 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)26 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)21 QName (javax.xml.namespace.QName)21 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)20 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)19 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)14 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)12