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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations