use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class AbstractOrgClosureTest method addOrgParent.
// TODO generalzie to addObjectParent
protected void addOrgParent(OrgType org, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
List<ItemDelta> modifications = new ArrayList<>();
PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
ItemDelta itemDelta;
if (!useReplace) {
itemDelta = ReferenceDelta.createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
} else {
List<PrismReferenceValue> newValues = new ArrayList<>();
for (ObjectReferenceType ort : org.getParentOrgRef()) {
newValues.add(ort.asReferenceValue().clone());
}
newValues.add(existingValue.clone());
PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class);
itemDelta = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
}
modifications.add(itemDelta);
repositoryService.modifyObject(OrgType.class, org.getOid(), modifications, opResult);
orgGraph.addEdge(org.getOid(), existingValue.getOid());
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class ConsistencyTest method test124AddAccountDirectAlreadyExists.
//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
TestUtil.displayTestTile(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
Task task = taskManager.createTaskInstance();
SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
try {
// we will reapply this schema handling after this test finish
ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
assertNotNull("null definition for sync delta", syncDef);
ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
// LOGGER.trace("resource schema handling after modify: {}",
// prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
assertUserNoAccountRef(USER_ABOM_OID, parentResult);
try {
repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
fail("Expected that shadow abom does not exist, but it is");
} catch (ObjectNotFoundException ex) {
// this is expected
} catch (Exception ex) {
fail("Expected object not found exception but got " + ex);
}
LOGGER.info("starting second execution request for user abomba");
OperationResult result = new OperationResult("Add account already exist result.");
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
result.computeStatus();
LOGGER.info("Displaying execute changes result");
display(result);
// return the previous changes of resource back
Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
((Collection) schemaHandlingDelta).add(syncDelta);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
} catch (Exception ex) {
LOGGER.info("error: " + ex.getMessage(), ex);
throw ex;
}
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class TestTolerantAttributes method test100ModifyUserAddAccount.
@Test
public void test100ModifyUserAddAccount() throws Exception {
TestUtil.displayTestTile(this, "test100ModifyUserAddAccount");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test100ModifyUserAddAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(ACCOUNT_JACK_DUMMY_BLACK_FILENAME));
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, 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);
getDummyResource().purgeScriptHistory();
dummyAuditService.clear();
dummyTransport.clearMessages();
notificationManager.setDisabled(false);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
// 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);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
accountDefinition = accountModel.getDefinition();
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class TestTolerantAttributes method test102modifyAddAttributeTolerantPattern.
@Test
public void test102modifyAddAttributeTolerantPattern() throws Exception {
TestUtil.displayTestTile(this, "test102modifyAddAttributeTolerantPattern");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test102modifyAddAttributeTolerantPattern");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(new ItemPath(UserType.F_DESCRIPTION), getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "res-thiIsOk");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Check value in "quote attribute"
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);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
// Check value of quote attribute
assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", "res-thiIsOk");
}
use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.
the class TestTolerantAttributes method test101modifyAddAttributesIntolerantPattern.
@Test
public void test101modifyAddAttributesIntolerantPattern() throws Exception {
TestUtil.displayTestTile(this, "test101modifyAddAttributesIntolerantPattern");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test101modifyAddAttributesIntolerantPattern");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(new ItemPath(UserType.F_DESCRIPTION), getUserDefinition().findPropertyDefinition(UserType.F_DESCRIPTION), "This value will be not added");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Check value in "quote attribute"
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);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
// Check value of quote attribute
assertDummyAccountAttribute(RESOURCE_DUMMY_BLACK_NAME, "jack", "quote", null);
}
Aggregations