Search in sources :

Example 31 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class SchemaDebugUtil method prettyPrint.

public static String prettyPrint(ItemDeltaType change) throws SchemaException {
    if (change == null) {
        return "null";
    }
    StringBuilder sb = new StringBuilder("ProperyModification(");
    sb.append(change.getModificationType());
    sb.append(",");
    if (change.getPath() != null) {
        //FIXME : xpath vs itemPath
        XPathHolder xpath = new XPathHolder(change.getPath().getItemPath());
        sb.append(xpath.toString());
    } else {
        sb.append("xpath=null");
    }
    sb.append(",");
    List<RawType> values = change.getValue();
    for (RawType value : values) {
        // todo implement correctly...
        sb.append(prettyPrint(value.serializeToXNode()));
        sb.append(",");
    }
    return sb.toString();
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 32 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class ModelWebServiceTest method nonExistingUidModify.

@Test(expectedExceptions = FaultMessage.class)
public void nonExistingUidModify() throws FaultMessage, ObjectNotFoundException, SchemaException, JAXBException, IOException {
    final String oid = "1";
    ObjectDeltaType objectDeltaType = new ObjectDeltaType();
    objectDeltaType.setChangeType(ChangeTypeType.MODIFY);
    objectDeltaType.setObjectType(UserType.COMPLEX_TYPE);
    objectDeltaType.setOid(oid);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.ADD);
    //        ItemDeltaType.Value value = new ItemDeltaType.Value();
    //        value.getAny().add(DOMUtil.createElement(DOMUtil.getDocument(), new QName(SchemaConstants.NS_C, "fullName")));
    mod1.setPath(new ItemPathType(new ItemPath(UserType.F_FULL_NAME)));
    objectDeltaType.getItemDelta().add(mod1);
    when(repositoryService.getObject(any(Class.class), eq(oid), any(Collection.class), any(OperationResult.class))).thenThrow(new ObjectNotFoundException("Oid '" + oid + "' not found."));
    final UserType user = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
    setSecurityContext(user);
    ObjectDeltaListType deltaListType = new ObjectDeltaListType();
    deltaListType.getDelta().add(objectDeltaType);
    try {
        modelService.executeChanges(deltaListType, null);
    } catch (FaultMessage ex) {
        ModelTUtil.assertObjectNotFoundFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 33 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class TestModelWebServiceNegative method createShadowReplaceChange.

// TODO: more negative tests
private ObjectDeltaType createShadowReplaceChange(String oid, String path, final String value, QName type) {
    ObjectDeltaType objectChange = new ObjectDeltaType();
    objectChange.setOid(oid);
    objectChange.setChangeType(ChangeTypeType.MODIFY);
    objectChange.setObjectType(ObjectTypes.SHADOW.getTypeQName());
    ItemDeltaType itemDeltaType = new ItemDeltaType();
    itemDeltaType.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType itemPath = new ItemPathType(path);
    itemDeltaType.setPath(itemPath);
    PrimitiveXNode<String> xnode = new PrimitiveXNode<>();
    ValueParser<String> valueParser = new ValueParser<String>() {

        @Override
        public String parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
            return value;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public String getStringValue() {
            return value;
        }

        @Override
        public Map<String, String> getPotentiallyRelevantNamespaces() {
            throw new UnsupportedOperationException();
        }
    };
    xnode.setValueParser(valueParser);
    if (type != null) {
        xnode.setExplicitTypeDeclaration(true);
        xnode.setTypeQName(type);
    }
    RawType rawValue = new RawType(xnode, prismContext);
    itemDeltaType.getValue().add(rawValue);
    objectChange.getItemDelta().add(itemDeltaType);
    return objectChange;
}
Also used : XNodeProcessorEvaluationMode(com.evolveum.midpoint.prism.marshaller.XNodeProcessorEvaluationMode) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ValueParser(com.evolveum.midpoint.prism.xnode.ValueParser) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 34 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class AbstractManualResourceTest method findPendingOperation.

private PendingOperationType findPendingOperation(PrismObject<ShadowType> shadow, OperationResultStatusType expectedResult, ItemPath itemPath) {
    List<PendingOperationType> pendingOperations = shadow.asObjectable().getPendingOperation();
    for (PendingOperationType pendingOperation : pendingOperations) {
        OperationResultStatusType result = pendingOperation.getResultStatus();
        if (result == null) {
            result = OperationResultStatusType.IN_PROGRESS;
        }
        if (pendingOperation.getResultStatus() != expectedResult) {
            continue;
        }
        if (itemPath == null) {
            return pendingOperation;
        }
        ObjectDeltaType delta = pendingOperation.getDelta();
        assertNotNull("No delta in pending operation in " + shadow, delta);
        for (ItemDeltaType itemDelta : delta.getItemDelta()) {
            ItemPath deltaPath = itemDelta.getPath().getItemPath();
            if (itemPath.equivalent(deltaPath)) {
                return pendingOperation;
            }
        }
    }
    return null;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PendingOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType) OperationResultStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 35 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class ReportUtils method printDelta.

public static String printDelta(ObjectDeltaType delta, String objectName, String resourceName) {
    StringBuilder sb = new StringBuilder();
    switch(delta.getChangeType()) {
        case MODIFY:
            Collection<ItemDeltaType> modificationDeltas = delta.getItemDelta();
            if (modificationDeltas != null && !modificationDeltas.isEmpty()) {
                sb.append(printChangeType(objectName, delta, "Modify", resourceName));
            }
            for (ItemDeltaType itemDelta : modificationDeltas) {
                sb.append(prettyPrintForReport(itemDelta));
            }
            sb.setLength(Math.max(sb.length() - 1, 0));
            break;
        case ADD:
            ObjectType objectToAdd = (ObjectType) delta.getObjectToAdd();
            if (objectToAdd != null) {
                sb.append(printChangeType(objectName, delta, "Add", resourceName));
                if (objectToAdd.getName() != null) {
                    sb.append(prettyPrintForReport(objectToAdd.getClass().getSimpleName()));
                    sb.append("=");
                    sb.append(objectToAdd.getName().toString());
                }
                sb.append(" {");
                sb.append(prettyPrintForReport(objectToAdd));
                sb.append("}");
            }
            break;
        case DELETE:
            sb.append(printChangeType(objectName, delta, "Delete", resourceName));
            break;
    }
    return sb.toString();
}
Also used : ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Aggregations

ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)39 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)28 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)11 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)11 Test (org.testng.annotations.Test)11 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 QName (javax.xml.namespace.QName)8 Document (org.w3c.dom.Document)8 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)6 XNode (com.evolveum.midpoint.prism.xnode.XNode)4 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)4 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)4 ResourceObjectShadowChangeDescriptionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType)4