use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test070UserModifyAssignment.
@Test(enabled = true)
public void test070UserModifyAssignment() throws Exception {
TestUtil.displayTestTile(this, "test070UserModifyAssignment");
login(userAdministrator);
removeAllAssignments(USER_JACK_OID, new OperationResult("dummy"));
assignRoleRaw(USER_JACK_OID, ROLE_R1_OID);
final XMLGregorianCalendar validFrom = XmlTypeConverter.createXMLGregorianCalendar(2015, 2, 25, 10, 0, 0);
final XMLGregorianCalendar validTo = XmlTypeConverter.createXMLGregorianCalendar(2015, 3, 25, 10, 0, 0);
executeTest("test070UserModifyAssignment", USER_JACK_OID, new TestDetails() {
@Override
int subtaskCount() {
return 1;
}
@Override
boolean immediate() {
return false;
}
@Override
boolean checkObjectOnSubtasks() {
return true;
}
@Override
boolean removeAssignmentsBeforeTest() {
return false;
}
@Override
public LensContext createModelContext(Task task, OperationResult result) throws Exception {
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
UserType jack = context.getFocusContext().getObjectOld().asObjectable();
modifyAssignmentValidity(context, jack, validFrom, validTo);
return context;
}
@Override
public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
UserType jack = getUser(USER_JACK_OID).asObjectable();
checkNoAssignmentValidity(jack);
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
UserType jack = getUser(USER_JACK_OID).asObjectable();
checkAssignmentValidity(jack, validFrom, validTo);
// TODO
//checkDummyTransportMessages("simpleUserNotifier", 1);
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(R1BOSS_OID));
return true;
}
});
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestGeneralChangeProcessor method executeTest.
private void executeTest(String testName, String oid, int subtaskCount, boolean immediate, boolean checkObjectOnSubtasks, ContextCreator contextCreator) throws Exception {
int workflowSubtaskCount = immediate ? subtaskCount - 1 : subtaskCount;
// GIVEN
prepareNotifications();
dummyAuditService.clear();
OperationResult result = new OperationResult("execution");
Task modelTask = taskManager.createTaskInstance(TestGeneralChangeProcessor.class.getName() + "." + testName);
display("Model task after creation", modelTask);
LensContext<UserType> context = (LensContext<UserType>) contextCreator.createModelContext(result);
modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
display("Input context", context);
assertFocusModificationSanity(context);
// WHEN
HookOperationMode mode = clockwork.run(context, modelTask, result);
// THEN
contextCreator.assertsAfterClockworkRun(context, modelTask, result);
assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.BACKGROUND, mode);
modelTask.refresh(result);
display("Model task after clockwork runs", modelTask);
Task rootTask = taskManager.getTask(wfTaskUtil.getRootTaskOid(modelTask), result);
display("Workflow root task created by clockwork run", rootTask);
assertTrue("Workflow root task is not persistent", rootTask.isPersistent());
assertEquals("Invalid current handler", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, rootTask.getHandlerUri());
ModelContext taskModelContext = immediate ? null : wfTaskUtil.getModelContext(rootTask, result);
assertNotNull("Model context is not present in root task", taskModelContext);
List<Task> subtasks = rootTask.listSubtasks(result);
assertEquals("Incorrect number of subtasks", subtaskCount, subtasks.size());
for (int subtaskIndex = 0; subtaskIndex < subtasks.size(); subtaskIndex++) {
Task subtask = subtasks.get(subtaskIndex);
// now check the workflow state
String pid = wfTaskUtil.getProcessId(subtask);
assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
/*
WfProcessInstanceType processInstance = null; //workflowServiceImpl.getProcessInstanceById(pid, false, true, result);
assertNotNull("Process instance information cannot be retrieved", processInstance);
assertEquals("Incorrect number of work items", 1, processInstance.getWorkItems().size());
String taskId = processInstance.getWorkItems().get(0).getWorkItemId();
//WorkItemNewType workItem = workflowServiceImpl.getWorkItemDetailsById(taskId, result);
WorkItemNewType workItem = null; // TODO
org.activiti.engine.task.Task t = activitiEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
assertNotNull("activiti task not found", t);
String executionId = t.getExecutionId();
LOGGER.trace("Task id = " + taskId + ", execution id = " + executionId);
contextCreator.completeWorkItem(workItem, taskId, result);
*/
}
waitForTaskClose(rootTask, 60000);
contextCreator.assertsRootTaskFinishes(rootTask, result);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestInfrastructure method test100SerializeContext.
@Test(enabled = true)
public void test100SerializeContext() throws Exception {
final String TEST_NAME = "test100SerializeContext";
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
LensContext<UserType> context = new LensContext<UserType>(UserType.class, prismContext, provisioningService);
PrismObject<UserType> bill = prismContext.parseObject(USER_BARBOSSA_FILE);
CryptoUtil.encryptValues(protector, bill);
ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(bill);
LensFocusContext<UserType> focusContext = context.getOrCreateFocusContext();
focusContext.setPrimaryDelta(userDelta);
LensContextType contextType = context.toLensContextType();
JaxbValueContainer<LensContextType> container = new JaxbValueContainer<LensContextType>(contextType, prismContext);
container.clearActualValue();
System.out.println("XML value = " + container.getXmlValue());
LensContextType contextTypeRetrieved = container.getValue();
LensContext<UserType> contextRetrieved = LensContext.fromLensContextType(contextTypeRetrieved, prismContext, provisioningService, task, result);
assertEquals("Context after serialization/deserialization does not match context before it (object to add is changed)", context.getFocusContext().getPrimaryDelta().getObjectToAdd(), contextRetrieved.getFocusContext().getPrimaryDelta().getObjectToAdd());
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class WfPrepareRootOperationTaskHandler method run.
//endregion
//region run method
@Override
public TaskRunResult run(Task task) {
TaskRunResultStatus status = TaskRunResultStatus.FINISHED;
try {
OperationResult result = task.getResult();
WfTask rootWfTask = wfTaskController.recreateRootWfTask(task);
List<WfTask> children = rootWfTask.listChildren(result);
LensContext rootContext = (LensContext) rootWfTask.retrieveModelContext(result);
boolean changed = false;
for (WfTask child : children) {
if (child.getTaskExecutionStatus() != TaskExecutionStatus.CLOSED) {
throw new IllegalStateException("Child task " + child + " is not in CLOSED state; its state is " + child.getTaskExecutionStatus());
}
if (child.hasModelContext()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} has model context present - skipping fetching deltas from it.", child);
}
} else {
ObjectTreeDeltas deltas = child.retrieveResultingDeltas();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Child job {} returned {} deltas", child, deltas != null ? deltas.getDeltaList().size() : 0);
}
if (deltas != null) {
LensFocusContext focusContext = rootContext.getFocusContext();
ObjectDelta focusDelta = deltas.getFocusChange();
if (focusDelta != null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding delta from job {} to root model context; delta = {}", child, focusDelta.debugDump(0));
}
if (focusContext.getPrimaryDelta() != null && !focusContext.getPrimaryDelta().isEmpty()) {
focusContext.addPrimaryDelta(focusDelta);
} else {
focusContext.setPrimaryDelta(focusDelta);
}
changed = true;
}
Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltas.getProjectionChangeMapEntries();
for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding projection delta from job {} to root model context; rsd = {}, delta = {}", child, entry.getKey(), entry.getValue().debugDump());
}
ModelProjectionContext projectionContext = rootContext.findProjectionContext(entry.getKey());
if (projectionContext == null) {
// TODO more liberal treatment?
throw new IllegalStateException("No projection context for " + entry.getKey());
}
if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
projectionContext.addPrimaryDelta(entry.getValue());
} else {
projectionContext.setPrimaryDelta(entry.getValue());
}
changed = true;
}
}
}
}
if (!rootContext.hasAnyPrimaryChange()) {
// deletes the model context
rootContext = null;
// regardless of whether rootContext was changed or not
changed = true;
}
if (changed) {
rootWfTask.storeModelContext(rootContext);
rootWfTask.commitChanges(result);
}
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks due to schema exception", e);
status = TaskRunResultStatus.PERMANENT_ERROR;
} catch (CommunicationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks", e);
status = TaskRunResultStatus.TEMPORARY_ERROR;
}
TaskRunResult runResult = new TaskRunResult();
runResult.setRunResultStatus(status);
return runResult;
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class PrimaryChangeProcessor method submitRootTask.
private WfTask submitRootTask(ModelContext context, ObjectTreeDeltas changesWithoutApproval, Task taskFromModel, ExecutionMode executionMode, WfConfigurationType wfConfigurationType, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
LensContext lensContextForRootTask = determineLensContextForRootTask(context, changesWithoutApproval, executionMode);
WfTaskCreationInstruction instructionForRoot = baseModelInvocationProcessingHelper.createInstructionForRoot(this, context, taskFromModel, lensContextForRootTask, result);
if (executionMode != ALL_IMMEDIATELY) {
// gather all deltas from child objects
instructionForRoot.setHandlersBeforeModelOperation(WfPrepareRootOperationTaskHandler.HANDLER_URI);
}
return baseModelInvocationProcessingHelper.submitRootTask(instructionForRoot, taskFromModel, wfConfigurationType, result);
}
Aggregations