Search in sources :

Example 61 with ReferenceDelta

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

the class TestModelCrudService method test121ModifyUserAddAccountRef.

@Test
public void test121ModifyUserAddAccountRef() throws Exception {
    TestUtil.displayTestTile(this, "test121ModifyUserAddAccountRef");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test121ModifyUserAddAccountRef");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountOid);
    modifications.add(accountDelta);
    // WHEN
    modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
    // THEN
    // Check accountRef
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertUserJack(userJack);
    accountOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountOid, "jack");
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountOid, "jack", "Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount("jack", "Jack Sparrow", true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Test(org.testng.annotations.Test)

Example 62 with ReferenceDelta

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

the class TestModelCrudService method test128ModifyUserDeleteAccountRef.

@Test
public void test128ModifyUserDeleteAccountRef() throws Exception {
    TestUtil.displayTestTile(this, "test128ModifyUserDeleteAccountRef");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test128ModifyUserDeleteAccountRef");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountOid);
    modifications.add(accountDelta);
    // WHEN
    modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
    // THEN
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertUserJack(userJack);
    // Check accountRef
    assertUserNoAccountRefs(userJack);
    // Check shadow (if it is unchanged)
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountOid, "jack");
    // Check account (if it is unchanged)
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountOid, "jack", "Jack Sparrow");
    // Check account in dummy resource (if it is unchanged)
    assertDefaultDummyAccount("jack", "Jack Sparrow", true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Test(org.testng.annotations.Test)

Example 63 with ReferenceDelta

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

the class TestModelCrudService method test100ModifyUserAddAccount.

@Test
public void test100ModifyUserAddAccount() throws Exception {
    final String TEST_NAME = "test100ModifyUserAddAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    modifications.add(accountDelta);
    // WHEN
    modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
    // THEN
    // Check accountRef
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
    ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
    accountOid = accountRefType.getOid();
    assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
    PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
    assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
    assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountOid, "jack");
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountOid, "jack", "Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount("jack", "Jack Sparrow", true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Test(org.testng.annotations.Test)

Example 64 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 65 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)

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