use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestIteration method test200JackAssignAccountDummyPinkConflicting.
@Test
public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
final String TEST_NAME = "test200JackAssignAccountDummyPinkConflicting";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and also a shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Pinky");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Red Sea");
dummyResourcePink.addAccount(account);
repoAddObject(createShadow(resourceDummyPink, ACCOUNT_JACK_DUMMY_USERNAME), result);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
// assignment with weapon := 'pistol' (test for
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
AssignmentType assignmentType = createConstructionAssignment(RESOURCE_DUMMY_PINK_OID, ShadowKindType.ACCOUNT, null);
ConstructionType constructionType = assignmentType.getConstruction();
ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
attributeDefinitionType.setRef(new ItemPathType(new ItemPath(dummyResourceCtlPink.getAttributeWeaponQName())));
MappingType mappingType = new MappingType();
mappingType.setStrength(MappingStrengthType.STRONG);
ExpressionType expressionType = new ExpressionType();
expressionType.getExpressionEvaluator().add(new ObjectFactory().createValue(RawType.create("pistol", prismContext)));
mappingType.setExpression(expressionType);
attributeDefinitionType.setOutbound(mappingType);
constructionType.getAttribute().add(attributeDefinitionType);
modifications.add(createAssignmentModification(assignmentType, true));
ObjectDelta<UserType> accountAssignmentUserDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
assertLinks(userJack, 2);
assertAccount(userJack, RESOURCE_DUMMY_OID);
assertAccount(userJack, RESOURCE_DUMMY_PINK_OID);
String accountPinkOid = getLinkRefOid(userJack, RESOURCE_DUMMY_PINK_OID);
// Check shadow
PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
assertAccountShadowRepo(accountPinkShadow, accountPinkOid, "jack1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
assertAccountShadowModel(accountPinkModel, accountPinkOid, "jack1", resourceDummyPinkType);
display("accountPinkModel", accountPinkModel);
PrismAsserts.assertPropertyValue(accountPinkModel, dummyResourceCtlPink.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "pistol");
// Check account in dummy resource
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
// The original conflicting account should still remain
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Pinky", true);
// The new account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "jack1", "Jack Sparrow", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test004TaskProperties.
@Test(enabled = false)
public void test004TaskProperties() throws Exception {
String test = "004TaskProperties";
OperationResult result = createResult(test);
addObjectFromFile(taskFilename(test));
TaskQuartzImpl task = (TaskQuartzImpl) taskManager.getTask(taskOid(test), result);
System.out.println("Task extension = " + task.getExtension());
PrismPropertyDefinition delayDefinition = new PrismPropertyDefinitionImpl(SchemaConstants.NOOP_DELAY_QNAME, DOMUtil.XSD_INT, taskManager.getPrismContext());
System.out.println("property definition = " + delayDefinition);
PrismProperty<Integer> property = (PrismProperty<Integer>) delayDefinition.instantiate();
property.setRealValue(100);
PropertyDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), property.getDefinition(), prismContext);
//delta.addV(property.getValues());
delta.setValuesToReplace(PrismValue.cloneCollection(property.getValues()));
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
modifications.add(delta);
// TODO fix this code
// Collection<ItemDeltaType> idts = DeltaConvertor.toPropertyModificationTypes(delta);
// for (ItemDeltaType idt : idts) {
// String idtxml = prismContext.getParserDom().marshalElementToString(idt, new QName("http://a/", "A"));
// System.out.println("item delta type = " + idtxml);
//
// ItemDeltaType idt2 = prismContext.getPrismJaxbProcessor().unmarshalObject(idtxml, ItemDeltaType.class);
// ItemDelta id2 = DeltaConvertor.createItemDelta(idt2, TaskType.class, prismContext);
// System.out.println("unwrapped item delta = " + id2.debugDump());
//
// task.modifyExtension(id2);
// }
task.savePendingModifications(result);
System.out.println("Task = " + task.debugDump());
PrismObject<UserType> owner2 = repositoryService.getObject(UserType.class, TASK_OWNER2_OID, null, result);
task.setBindingImmediate(TaskBinding.LOOSE, result);
// other properties will be set in batched mode
String newname = "Test task, name changed";
task.setName(PrismTestUtil.createPolyStringType(newname));
task.setProgress(10);
long currentTime = System.currentTimeMillis();
long currentTime1 = currentTime + 10000;
long currentTime2 = currentTime + 25000;
task.setLastRunStartTimestamp(currentTime);
task.setLastRunFinishTimestamp(currentTime1);
task.setExecutionStatus(TaskExecutionStatus.SUSPENDED);
task.setHandlerUri("http://no-handler.org/");
//task.setOwner(owner2);
ScheduleType st0 = task.getSchedule();
ScheduleType st1 = new ScheduleType();
st1.setInterval(1);
st1.setMisfireAction(MisfireActionType.RESCHEDULE);
task.pushHandlerUri("http://no-handler.org/1", st1, TaskBinding.TIGHT, ((TaskQuartzImpl) task).createExtensionDelta(delayDefinition, 1));
ScheduleType st2 = new ScheduleType();
st2.setInterval(2);
st2.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
task.pushHandlerUri("http://no-handler.org/2", st2, TaskBinding.LOOSE, ((TaskQuartzImpl) task).createExtensionDelta(delayDefinition, 2));
task.setRecurrenceStatus(TaskRecurrence.RECURRING);
// to be compared with later
OperationResultType ort = result.createOperationResultType();
task.setResult(result);
//PrismObject<UserType> requestee = task.getOwner();
//task.setRequesteeRef(requestee); does not work
//task.setRequesteeOid(requestee.getOid());
ObjectReferenceType objectReferenceType = new ObjectReferenceType();
objectReferenceType.setType(UserType.COMPLEX_TYPE);
String objectOid = "some-oid...";
objectReferenceType.setOid(objectOid);
task.setObjectRef(objectReferenceType);
logger.trace("Saving modifications...");
task.savePendingModifications(result);
logger.trace("Retrieving the task (second time) and comparing its properties...");
Task task001 = taskManager.getTask(taskOid(test), result);
logger.trace("Task from repo: " + task001.debugDump());
AssertJUnit.assertEquals(TaskBinding.LOOSE, task001.getBinding());
PrismAsserts.assertEqualsPolyString("Name not", newname, task001.getName());
// AssertJUnit.assertEquals(newname, task001.getName());
AssertJUnit.assertTrue(10 == task001.getProgress());
AssertJUnit.assertNotNull(task001.getLastRunStartTimestamp());
// e.g. MySQL cuts off millisecond information
AssertJUnit.assertEquals("Start time is not correct", (Long) (currentTime / 1000L), (Long) (task001.getLastRunStartTimestamp() / 1000L));
AssertJUnit.assertNotNull(task001.getLastRunFinishTimestamp());
AssertJUnit.assertEquals("Finish time is not correct", (Long) (currentTime1 / 1000L), (Long) (task001.getLastRunFinishTimestamp() / 1000L));
// AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task001.getExclusivityStatus());
AssertJUnit.assertEquals(TaskExecutionStatus.SUSPENDED, task001.getExecutionStatus());
AssertJUnit.assertEquals("Handler after 2xPUSH is not OK", "http://no-handler.org/2", task001.getHandlerUri());
AssertJUnit.assertEquals("Schedule after 2xPUSH is not OK", st2, task001.getSchedule());
AssertJUnit.assertEquals("Number of handlers is not OK", 3, task.getHandlersCount());
UriStack us = task.getOtherHandlersUriStack();
AssertJUnit.assertEquals("First handler from the handler stack does not match", "http://no-handler.org/", us.getUriStackEntry().get(0).getHandlerUri());
AssertJUnit.assertEquals("First schedule from the handler stack does not match", st0, us.getUriStackEntry().get(0).getSchedule());
AssertJUnit.assertEquals("Second handler from the handler stack does not match", "http://no-handler.org/1", us.getUriStackEntry().get(1).getHandlerUri());
AssertJUnit.assertEquals("Second schedule from the handler stack does not match", st1, us.getUriStackEntry().get(1).getSchedule());
AssertJUnit.assertTrue(task001.isCycle());
OperationResult r001 = task001.getResult();
AssertJUnit.assertNotNull(r001);
//AssertJUnit.assertEquals("Owner OID is not correct", TASK_OWNER2_OID, task001.getOwner().getOid());
PrismProperty<?> d = task001.getExtensionProperty(SchemaConstants.NOOP_DELAY_QNAME);
AssertJUnit.assertNotNull("delay extension property was not found", d);
AssertJUnit.assertEquals("delay extension property has wrong value", (Integer) 100, d.getRealValue(Integer.class));
OperationResultType ort1 = r001.createOperationResultType();
// handling of operation result in tasks is extremely fragile now...
// in case of problems, just uncomment the following line ;)
AssertJUnit.assertEquals(ort, ort1);
//AssertJUnit.assertEquals("RequesteeRef was not stored/retrieved correctly", requestee.getOid(), task001.getRequesteeRef().getOid());
//AssertJUnit.assertEquals("RequesteeOid was not stored/retrieved correctly", requestee.getOid(), task001.getRequesteeOid());
AssertJUnit.assertEquals("ObjectRef OID was not stored/retrieved correctly", objectReferenceType.getOid(), task001.getObjectRef().getOid());
AssertJUnit.assertEquals("ObjectRef ObjectType was not stored/retrieved correctly", objectReferenceType.getType(), task001.getObjectRef().getType());
// now pop the handlers
((TaskQuartzImpl) task001).finishHandler(result);
task001.refresh(result);
AssertJUnit.assertEquals("Handler URI after first POP is not correct", "http://no-handler.org/1", task001.getHandlerUri());
AssertJUnit.assertEquals("Schedule after first POP is not correct", st1, task001.getSchedule());
AssertJUnit.assertEquals("Binding after first POP is not correct", TaskBinding.TIGHT, task001.getBinding());
AssertJUnit.assertNotSame("Task state after first POP should not be CLOSED", TaskExecutionStatus.CLOSED, task001.getExecutionStatus());
AssertJUnit.assertEquals("Extension element value is not correct after first POP", (Integer) 2, task001.getExtensionProperty(SchemaConstants.NOOP_DELAY_QNAME).getRealValue(Integer.class));
((TaskQuartzImpl) task001).finishHandler(result);
task001.refresh(result);
AssertJUnit.assertEquals("Handler URI after second POP is not correct", "http://no-handler.org/", task001.getHandlerUri());
AssertJUnit.assertEquals("Schedule after second POP is not correct", st0, task001.getSchedule());
AssertJUnit.assertEquals("Binding after second POP is not correct", TaskBinding.LOOSE, task001.getBinding());
AssertJUnit.assertNotSame("Task state after second POP should not be CLOSED", TaskExecutionStatus.CLOSED, task001.getExecutionStatus());
AssertJUnit.assertEquals("Extension element value is not correct after second POP", (Integer) 1, task001.getExtensionProperty(SchemaConstants.NOOP_DELAY_QNAME).getRealValue(Integer.class));
((TaskQuartzImpl) task001).finishHandler(result);
task001.refresh(result);
//AssertJUnit.assertNull("Handler URI after third POP is not null", task001.getHandlerUri());
AssertJUnit.assertEquals("Handler URI after third POP is not correct", "http://no-handler.org/", task001.getHandlerUri());
AssertJUnit.assertEquals("Task state after third POP is not CLOSED", TaskExecutionStatus.CLOSED, task001.getExecutionStatus());
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class PageRequestRole method handleModifyAssignmentDelta.
private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<UserType> focusDelta) throws SchemaException {
LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
PrismValue oldValue = assDto.getOldValue();
Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
for (ItemDelta delta : deltas) {
ItemPath deltaPath = delta.getPath().rest();
ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
delta.applyDefinition(deltaDef);
focusDelta.addModification(delta);
}
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class AssignmentTablePanel method handleModifyAssignmentDelta.
private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<T> userDelta) throws SchemaException {
LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
PrismValue oldValue = assDto.getOldValue();
Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
for (ItemDelta delta : deltas) {
ItemPath deltaPath = delta.getPath().rest();
ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
delta.applyDefinition(deltaDef);
userDelta.addModification(delta);
}
}
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);
}
Aggregations