use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class PageFocusDetails method finishPreviewProcessing.
private void finishPreviewProcessing(AjaxRequestTarget target, OperationResult result) {
showResult(result);
target.add(getFeedbackPanel());
Map<PrismObject<F>, ModelContext<? extends ObjectType>> modelContextMap = new LinkedHashMap<>();
collectObjectsForPreview(modelContextMap);
DetailsFragment detailsFragment = createDetailsFragment();
replace(detailsFragment);
target.add(detailsFragment);
navigateToNext(new PageFocusPreviewChanges(modelContextMap));
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class TaskOperationPanel method initLayout.
protected void initLayout() {
final LensContextType lensContextType = getLensContextType();
LoadableModel<ModelOperationStatusDto> operationStatusModel = null;
if (lensContextType != null) {
operationStatusModel = new LoadableModel<ModelOperationStatusDto>() {
@Override
protected ModelOperationStatusDto load() {
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_SCENE_DTO);
OperationResult result = task.getResult();
ModelContext ctx;
try {
ctx = ModelContextUtil.unwrapModelContext(lensContextType, getPageBase().getModelInteractionService(), task, result);
} catch (ObjectNotFoundException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Unexpected error, cannot get real value for model context", e, e.getMessage());
return null;
}
return new ModelOperationStatusDto(ctx, getPageBase().getModelInteractionService(), task, result);
}
};
}
ModelOperationStatusPanel panel = new ModelOperationStatusPanel(ID_MODEL_OPERATION_STATUS_PANEL, operationStatusModel);
panel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return lensContextType != null;
}
});
add(panel);
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class AbstractWfTestLegacy method executeTest.
protected void executeTest(String testName, String oid, TestDetails testDetails) throws Exception {
// GIVEN
prepareNotifications();
dummyAuditService.clear();
Task modelTask = taskManager.createTaskInstance(AbstractWfTestLegacy.class.getName() + "." + testName);
OperationResult result = new OperationResult("execution");
modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
if (oid != null && testDetails.removeAssignmentsBeforeTest()) {
removeAllAssignments(oid, result);
}
LensContext<UserType> context = (LensContext<UserType>) testDetails.createModelContext(modelTask, result);
display("Input context", context);
assertFocusModificationSanity(context);
// WHEN
HookOperationMode mode = clockwork.run(context, modelTask, result);
// THEN
assertEquals("Unexpected state of the context", ModelState.PRIMARY, context.getState());
assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.BACKGROUND, mode);
modelTask.refresh(result);
String rootTaskOid = wfTaskUtil.getRootTaskOid(modelTask);
assertNotNull("Root task OID is not set in model task", rootTaskOid);
Task rootTask = taskManager.getTask(rootTaskOid, result);
// trivial ;)
assertTrue("Root task is not persistent", rootTask.isPersistent());
if (!testDetails.approvedAutomatically()) {
UriStack uriStack = rootTask.getOtherHandlersUriStack();
if (!testDetails.immediate()) {
assertEquals("Invalid handler at stack position 0", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, uriStack.getUriStackEntry().get(0).getHandlerUri());
} else {
assertTrue("There should be no handlers for root tasks with immediate execution mode", uriStack == null || uriStack.getUriStackEntry().isEmpty());
}
ModelContext taskModelContext = testDetails.immediate() ? null : wfTaskUtil.getModelContext(rootTask, result);
if (!testDetails.immediate()) {
assertNotNull("Model context is not present in root task", taskModelContext);
} else {
assertFalse("Model context is present in root task (execution mode = immediate)", wfTaskUtil.hasModelContext(rootTask));
}
List<Task> subtasks = rootTask.listSubtasks(result);
assertEquals("Incorrect number of subtasks", testDetails.subtaskCount(), subtasks.size());
Task task0 = extractTask0(subtasks, testDetails);
testDetails.assertsAfterClockworkRun(rootTask, subtasks, result);
if (testDetails.immediate()) {
waitForTaskClose(task0, 20000);
//TestUtil.assertSuccess(task0.getResult()); // todo enable this
testDetails.assertsAfterImmediateExecutionFinished(rootTask, result);
}
for (int i = 0; i < subtasks.size(); i++) {
Task subtask = subtasks.get(i);
//assertEquals("Subtask #" + i + " is not recurring: " + subtask, TaskRecurrence.RECURRING, subtask.getRecurrenceStatus());
//assertEquals("Incorrect execution status of subtask #" + i + ": " + subtask, TaskExecutionStatus.RUNNABLE, subtask.getExecutionStatus());
PrismProperty<ObjectTreeDeltasType> deltas = subtask.getTaskPrismObject().findProperty(new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, F_DELTAS_TO_PROCESS));
assertNotNull("There are no modifications in subtask #" + i + ": " + subtask, deltas);
assertEquals("Incorrect number of modifications in subtask #" + i + ": " + subtask, 1, deltas.getRealValues().size());
// todo check correctness of the modification?
// now check the workflow state
String pid = wfTaskUtil.getProcessId(subtask);
assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
// WfProcessInstanceType processInstance = 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();
//WorkItemDetailed workItemDetailed = wfDataAccessor.getWorkItemDetailsById(taskId, result);
org.activiti.engine.task.Task t = activitiEngine.getTaskService().createTaskQuery().processInstanceId(pid).singleResult();
assertNotNull("activiti task not found", t);
String executionId = t.getExecutionId();
LOGGER.trace("Execution id = {}", executionId);
boolean approve = testDetails.decideOnApproval(executionId);
workflowManager.completeWorkItem(t.getId(), approve, null, null, null, result);
login(userAdministrator);
}
}
waitForTaskClose(rootTask, 60000);
List<Task> subtasks = rootTask.listSubtasks(result);
extractTask0(subtasks, testDetails);
//TestUtil.assertSuccess(rootTask.getResult());
testDetails.assertsRootTaskFinishes(rootTask, subtasks, result);
if (oid == null) {
oid = testDetails.getObjectOid(rootTask, result);
}
assertNotNull("object oid is null after operation", oid);
if (!oid.equals(DONT_CHECK)) {
assertObjectInTaskTree(rootTask, oid, testDetails.checkObjectOnSubtasks(), result);
}
if (!testDetails.approvedAutomatically()) {
// ZZZ temporarily disabled
// checkDummyTransportMessages("simpleWorkflowNotifier-Processes", workflowSubtaskCount * 2);
// checkDummyTransportMessages("simpleWorkflowNotifier-WorkItems", workflowSubtaskCount * 2);
}
notificationManager.setDisabled(true);
// Check audit
display("Audit", dummyAuditService);
display("Output context", context);
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test040UserModifyPasswordChangeBlocked.
@Test(enabled = true)
public void test040UserModifyPasswordChangeBlocked() throws Exception {
TestUtil.displayTestTile(this, "test040UserModifyPasswordChangeBlocked");
login(userAdministrator);
PrismObject<UserType> jack = getUser(USER_JACK_OID);
final ProtectedStringType originalPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password before test = " + originalPasswordValue);
executeTest("test040UserModifyPasswordChangeBlocked", USER_JACK_OID, new TestDetails() {
@Override
int subtaskCount() {
return 1;
}
@Override
boolean immediate() {
return false;
}
@Override
boolean checkObjectOnSubtasks() {
return true;
}
@Override
public LensContext createModelContext(Task task, OperationResult result) throws Exception {
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
encryptAndAddFocusModificationToContext(context, REQ_USER_JACK_MODIFY_CHANGE_PASSWORD);
//context.setOptions(ModelExecuteOptions.createNoCrypt());
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());
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
PrismObject<UserType> jack = getUser(USER_JACK_OID);
ProtectedStringType afterTestPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password after test = " + afterTestPasswordValue);
//assertNotNull("password was not set", afterTestPasswordValue.getEncryptedData());
assertTrue("password was changed", originalPasswordValue.getEncryptedDataType().equals(afterTestPasswordValue.getEncryptedDataType()));
checkDummyTransportMessages("simpleUserNotifier", 0);
// we don't check for modifyApproverRef because in this test the value was not changed (no change was executed)
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(USER_ADMINISTRATOR_OID));
return false;
}
});
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test095UserModifyModifyResourceAssignmentConstruction.
/**
* User modification: modifying attribute of single security-sensitive resource assignment.
*
* User primary delta:
* ObjectDelta<UserType>(UserType:377205db-33d1-47e5-bf96-bbe2a7d1222e,MODIFY):
* assignment/[1]/construction/attribute
* ADD: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
* DELETE: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
*
*/
@Test(enabled = true)
public void test095UserModifyModifyResourceAssignmentConstruction() throws Exception {
final String TEST_NAME = "test095UserModifyModifyResourceAssignmentConstruction";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
executeTest(TEST_NAME, 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();
modifyAssignmentConstruction(context, jack, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "water", true);
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();
checkNoAssignmentConstruction(jack, "drink");
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
assertAssignedResource(USER_JACK_OID, RESOURCE_DUMMY_OID, task, result);
UserType jack = getUser(USER_JACK_OID).asObjectable();
checkAssignmentConstruction(jack, "drink", "water");
checkDummyTransportMessages("simpleUserNotifier", 1);
//checkWorkItemAuditRecords(createResultMap(ROLE_R1_OID, WorkflowResult.APPROVED));
checkUserApprovers(USER_JACK_OID, Arrays.asList(DUMMYBOSS_OID), result);
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(DUMMYBOSS_OID));
return true;
}
});
}
Aggregations