Search in sources :

Example 96 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class TaskQuartzImpl method addExtensionPropertyAndPrepareDelta.

private ItemDelta<?, ?> addExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException {
    ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, itemName), definition, getPrismContext());
    delta.addValuesToAdd(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 97 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class TaskQuartzImpl method storeExtensionDeltas.

private void storeExtensionDeltas(List<ItemDeltaType> result, Collection<ItemDelta<?, ?>> extensionDeltas) {
    for (ItemDelta itemDelta : extensionDeltas) {
        Collection<ItemDeltaType> deltaTypes = null;
        try {
            deltaTypes = DeltaConvertor.toItemDeltaTypes(itemDelta);
        } catch (SchemaException e) {
            throw new SystemException("Unexpected SchemaException when converting extension ItemDelta to ItemDeltaType", e);
        }
        result.addAll(deltaTypes);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 98 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class AddGetObjectTest method addGetCompare.

private void addGetCompare(File file) throws Exception {
    List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects();
    List<String> oids = new ArrayList<String>();
    OperationResult result = new OperationResult("Simple Add Get Test");
    long time = System.currentTimeMillis();
    for (int i = 0; i < elements.size(); i++) {
        PrismObject object = elements.get(i);
        LOGGER.info("Adding object {}, type {}", new Object[] { (i + 1), object.getCompileTimeClass().getSimpleName() });
        oids.add(repositoryService.addObject(object, null, result));
    }
    LOGGER.info("Time to add objects ({}): {}", new Object[] { elements.size(), (System.currentTimeMillis() - time) });
    int count = 0;
    elements = prismContext.parserFor(file).parseObjects();
    for (int i = 0; i < elements.size(); i++) {
        try {
            PrismObject object = elements.get(i);
            object.asObjectable().setOid(oids.get(i));
            Class<? extends ObjectType> clazz = object.getCompileTimeClass();
            Collection o = null;
            if (UserType.class.equals(clazz)) {
                o = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
            } else if (LookupTableType.class.equals(clazz)) {
                o = SelectorOptions.createCollection(LookupTableType.F_ROW, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
            } else if (AccessCertificationCampaignType.class.equals(clazz)) {
                o = SelectorOptions.createCollection(AccessCertificationCampaignType.F_CASE, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
            }
            PrismObject<? extends ObjectType> newObject = repositoryService.getObject(clazz, oids.get(i), o, result);
            LOGGER.info("Old\n{}\nnew\n{}", new Object[] { object.debugDump(3), newObject.debugDump(3) });
            checkContainersSize(newObject, object);
            System.out.println("OLD: " + object.findProperty(ObjectType.F_NAME).getValue());
            System.out.println("NEW: " + newObject.findProperty(ObjectType.F_NAME).getValue());
            ObjectDelta delta = object.diff(newObject);
            if (delta == null) {
                continue;
            }
            count += delta.getModifications().size();
            if (delta.getModifications().size() > 0) {
                if (delta.getModifications().size() == 1) {
                    ItemDelta d = (ItemDelta) delta.getModifications().iterator().next();
                    if (ShadowType.F_DEAD.equals(d.getElementName())) {
                        count -= delta.getModifications().size();
                        continue;
                    }
                }
                LOGGER.error(">>> {} Found {} changes for {}\n{}", new Object[] { (i + 1), delta.getModifications().size(), newObject.toString(), delta.debugDump(3) });
                ItemDelta id = (ItemDelta) delta.getModifications().iterator().next();
                if (id.isReplace()) {
                    System.out.println(id.getValuesToReplace().iterator().next());
                }
                LOGGER.error("{}", prismContext.serializeObjectToString(newObject, PrismContext.LANG_XML));
            }
        } catch (Exception ex) {
            LOGGER.error("Exception occurred", ex);
            throw ex;
        }
    }
    AssertJUnit.assertEquals("Found changes during add/get test " + count, 0, count);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 99 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class CertificationTest method test210ModifyCaseProperties.

@Test
public void test210ModifyCaseProperties() throws Exception {
    OperationResult result = new OperationResult("test210ModifyCaseProperties");
    List<ItemDelta<?, ?>> modifications = new ArrayList<>();
    ItemPath case1 = new ItemPath(F_CASE).subPath(new IdItemPathSegment(1L));
    modifications.add(createModificationReplaceProperty(case1.subPath(F_CURRENT_STAGE_OUTCOME), campaignDef, SchemaConstants.MODEL_CERTIFICATION_OUTCOME_REDUCE));
    modifications.add(createModificationReplaceProperty(case1.subPath(AccessCertificationCaseType.F_STAGE_NUMBER), campaignDef, 300));
    executeAndCheckModification(modifications, result, 0);
    checksCountsStandard(result);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 100 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class CertificationTest method test200ModifyCampaignProperties.

@Test
public void test200ModifyCampaignProperties() throws Exception {
    OperationResult result = new OperationResult("test200ModifyCampaignProperties");
    List<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add(createModificationReplaceProperty(F_NAME, campaignDef, new PolyString("Campaign 1+", "campaign 1")));
    modifications.add(createModificationReplaceProperty(F_STATE, campaignDef, IN_REVIEW_STAGE));
    executeAndCheckModification(modifications, result, 1);
    checksCountsStandard(result);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Test(org.testng.annotations.Test)

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