Search in sources :

Example 66 with ReferenceDelta

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

the class AbstractModelIntegrationTest method modifyUserAddAccount.

protected void modifyUserAddAccount(String userOid, File accountFile, Task task, OperationResult result) throws SchemaException, IOException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(accountFile);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, null, task, result);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 67 with ReferenceDelta

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

the class ResourceManager method applyDefinition.

public void applyDefinition(ObjectDelta<ResourceType> delta, ResourceType resourceWhenNoOid, GetOperationOptions options, Task task, OperationResult objectResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (delta.isAdd()) {
        PrismObject<ResourceType> resource = delta.getObjectToAdd();
        applyConnectorSchemaToResource(resource, task, objectResult);
        return;
    } else if (delta.isModify()) {
    // Go on
    } else {
        return;
    }
    if (delta.hasCompleteDefinition()) {
        //nothing to do, all modifications has definitions..just aplly this deltas..
        return;
    }
    PrismObject<ResourceType> resource;
    String resourceOid = delta.getOid();
    if (resourceOid == null) {
        Validate.notNull(resourceWhenNoOid, "Resource oid not specified in the object delta, and resource is not specified as well. Could not apply definition.");
        resource = resourceWhenNoOid.asPrismObject();
    } else {
        resource = getResource(resourceOid, options, task, objectResult);
    }
    ResourceType resourceType = resource.asObjectable();
    //		ResourceType resourceType = completeResource(resource.asObjectable(), null, objectResult);
    //TODO TODO TODO FIXME FIXME FIXME copied from ObjectImprted..union this two cases
    PrismContainer<ConnectorConfigurationType> configurationContainer = ResourceTypeUtil.getConfigurationContainer(resourceType);
    if (configurationContainer == null || configurationContainer.isEmpty()) {
        // Nothing to check
        objectResult.recordWarning("The resource has no configuration");
        return;
    }
    // Check the resource configuration. The schema is in connector, so fetch the connector first
    String connectorOid = resourceType.getConnectorRef().getOid();
    if (StringUtils.isBlank(connectorOid)) {
        objectResult.recordFatalError("The connector reference (connectorRef) is null or empty");
        return;
    }
    //ItemDelta.findItemDelta(delta.getModifications(), ResourceType.F_SCHEMA, ContainerDelta.class) == null || 
    ReferenceDelta connectorRefDelta = ReferenceDelta.findReferenceModification(delta.getModifications(), ResourceType.F_CONNECTOR_REF);
    if (connectorRefDelta != null) {
        Item<PrismReferenceValue, PrismReferenceDefinition> connectorRefNew = connectorRefDelta.getItemNewMatchingPath(null);
        if (connectorRefNew.getValues().size() == 1) {
            PrismReferenceValue connectorRefValue = connectorRefNew.getValues().iterator().next();
            if (connectorRefValue.getOid() != null && !connectorOid.equals(connectorRefValue.getOid())) {
                connectorOid = connectorRefValue.getOid();
            }
        }
    }
    PrismObject<ConnectorType> connector = null;
    ConnectorType connectorType = null;
    try {
        connector = repositoryService.getObject(ConnectorType.class, connectorOid, null, objectResult);
        connectorType = connector.asObjectable();
    } catch (ObjectNotFoundException e) {
        // No connector, no fun. We can't check the schema. But this is referential integrity problem.
        // Mark the error ... there is nothing more to do
        objectResult.recordFatalError("Connector (OID:" + connectorOid + ") referenced from the resource is not in the repository", e);
        return;
    } catch (SchemaException e) {
        // Probably a malformed connector. To be kind of robust, lets allow the import.
        // Mark the error ... there is nothing more to do
        objectResult.recordPartialError("Connector (OID:" + connectorOid + ") referenced from the resource has schema problems: " + e.getMessage(), e);
        LOGGER.error("Connector (OID:{}) referenced from the imported resource \"{}\" has schema problems: {}", new Object[] { connectorOid, resourceType.getName(), e.getMessage(), e });
        return;
    }
    Element connectorSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(connector);
    PrismSchema connectorSchema = null;
    if (connectorSchemaElement == null) {
        // No schema to validate with
        return;
    }
    try {
        connectorSchema = PrismSchemaImpl.parse(connectorSchemaElement, true, "schema for " + connector, prismContext);
    } catch (SchemaException e) {
        objectResult.recordFatalError("Error parsing connector schema for " + connector + ": " + e.getMessage(), e);
        return;
    }
    QName configContainerQName = new QName(connectorType.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart());
    PrismContainerDefinition<ConnectorConfigurationType> configContainerDef = connectorSchema.findContainerDefinitionByElementName(configContainerQName);
    if (configContainerDef == null) {
        objectResult.recordFatalError("Definition of configuration container " + configContainerQName + " not found in the schema of of " + connector);
        return;
    }
    try {
        configurationContainer.applyDefinition(configContainerDef);
    } catch (SchemaException e) {
        objectResult.recordFatalError("Configuration error in " + resource + ": " + e.getMessage(), e);
        return;
    }
    PrismContainer configContainer = resourceType.asPrismObject().findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    configContainer.applyDefinition(configContainerDef);
    for (ItemDelta<?, ?> itemDelta : delta.getModifications()) {
        applyItemDefinition(itemDelta, configContainerDef, objectResult);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 68 with ReferenceDelta

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

the class TestConnectorDummyFake method test200UpgradeModelReplace.

@Test
public void test200UpgradeModelReplace() throws Exception {
    final String TEST_NAME = "test200UpgradeModelReplace";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ResourceType> dummyResourceModelBefore = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
    ObjectDelta<ResourceType> resourceDelta = ObjectDelta.createEmptyModifyDelta(ResourceType.class, RESOURCE_DUMMY_FAKE_OID, prismContext);
    ReferenceDelta connectorRefDeltaReplace = ReferenceDelta.createModificationReplace(ResourceType.F_CONNECTOR_REF, getResourceDefinition(), connectorDummyOid);
    resourceDelta.addModification(connectorRefDeltaReplace);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    display("executeChanges result", result);
    TestUtil.assertSuccess("executeChanges result", result);
    assertUpgrade(dummyResourceModelBefore);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 69 with ReferenceDelta

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

the class TestConnectorDummyFake method test350DowngradeRawAddDelete.

@Test
public void test350DowngradeRawAddDelete() throws Exception {
    final String TEST_NAME = "test350DowngradeRawAddDelete";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ResourceType> dummyResourceModelBefore = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
    ObjectDelta<ResourceType> resourceDelta = ObjectDelta.createEmptyModifyDelta(ResourceType.class, RESOURCE_DUMMY_FAKE_OID, prismContext);
    ReferenceDelta connectorRefDeltaDel = ReferenceDelta.createModificationDelete(ResourceType.F_CONNECTOR_REF, getResourceDefinition(), connectorDummyOid);
    resourceDelta.addModification(connectorRefDeltaDel);
    ReferenceDelta connectorRefDeltaAdd = ReferenceDelta.createModificationAdd(ResourceType.F_CONNECTOR_REF, getResourceDefinition(), connectorDummyFakeOid);
    resourceDelta.addModification(connectorRefDeltaAdd);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);
    ModelExecuteOptions options = ModelExecuteOptions.createRaw();
    // WHEN
    modelService.executeChanges(deltas, options, task, result);
    // THEN
    result.computeStatus();
    display("executeChanges result", result);
    TestUtil.assertSuccess("executeChanges result", result);
    assertDowngrade(dummyResourceModelBefore);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 70 with ReferenceDelta

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

the class TestPreviewChanges method modifyUserAddAccountImplicitExplicitSame.

private void modifyUserAddAccountImplicitExplicitSame(String bundleName, ObjectSource<PrismObject<ShadowType>> accountSource, ObjectChecker<ModelContext<UserType>> checker) throws Exception {
    final String TEST_NAME = bundleName + "ImplicitExplicitSame";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ShadowType> account = accountSource.get();
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountRefDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountRefDelta);
    ObjectDelta<ShadowType> accountDelta = account.createAddDelta();
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta);
    doPreview(deltas, checker, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)49 Task (com.evolveum.midpoint.task.api.Task)44 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)42 Test (org.testng.annotations.Test)41 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)27 Collection (java.util.Collection)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 ArrayList (java.util.ArrayList)12 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)11 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6