use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class TestMiscellaneous method test105RequesterCommentImmediate.
@Test
public void test105RequesterCommentImmediate() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
given();
dummyAuditService.clear();
OperationBusinessContextType businessContext = new OperationBusinessContextType();
final String REQUESTER_COMMENT = "req.comment";
businessContext.setComment(REQUESTER_COMMENT);
ObjectDelta<UserType> userDelta = createAssignmentUserDelta(userJackOid, ROLE_CAPTAIN.oid, RoleType.COMPLEX_TYPE, null, null, null, true);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
ModelExecuteOptions options = executeOptions().requestBusinessContext(businessContext);
options.executeImmediatelyAfterApproval(true);
modelService.executeChanges(deltas, options, task, result);
assertNotAssignedRole(userJackOid, ROLE_CAPTAIN.oid, result);
CaseWorkItemType workItem = getWorkItem(task, result);
display("Work item", workItem);
when();
caseManager.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext).comment("OK"), null, task, result);
then();
CaseType aCase = getCase(CaseWorkItemUtil.getCaseRequired(workItem).getOid());
display("workflow context", aCase.getApprovalContext());
List<? extends CaseEventType> events = aCase.getEvent();
assertEquals("Wrong # of events", 2, events.size());
CaseCreationEventType event1 = (CaseCreationEventType) events.get(0);
display("Event 1", event1);
assertEquals("Wrong requester comment", REQUESTER_COMMENT, ApprovalContextUtil.getBusinessContext(aCase).getComment());
WorkItemEventType event2 = (WorkItemEventType) events.get(1);
display("Event 2", event2);
assertNotNull("Original assignee is null", event2.getOriginalAssigneeRef());
assertEquals("Wrong original assignee OID", USER_SCOTT.oid, event2.getOriginalAssigneeRef().getOid());
displayDumpable("audit", dummyAuditService);
List<AuditEventRecord> records = dummyAuditService.getRecordsOfType(AuditEventType.WORKFLOW_PROCESS_INSTANCE);
assertEquals("Wrong # of process instance audit records", 2, records.size());
for (int i = 0; i < records.size(); i++) {
AuditEventRecord record = records.get(i);
assertEquals("Wrong requester comment in audit record #" + i, Collections.singleton(REQUESTER_COMMENT), record.getPropertyValues(AuditingConstants.AUDIT_REQUESTER_COMMENT));
}
CaseType parentCase = getCase(aCase.getParentRef().getOid());
waitForCaseClose(parentCase);
AssignmentType assignment = assertAssignedRole(userJackOid, ROLE_CAPTAIN.oid, result);
display("assignment after creation", assignment);
MetadataType metadata = assignment.getMetadata();
assertNotNull("Null request timestamp in metadata", metadata.getRequestTimestamp());
assertRefEquals("Wrong requestorRef in metadata", ObjectTypeUtil.createObjectRef(userAdministrator, prismContext), metadata.getRequestorRef());
assertEquals("Wrong requestorComment in metadata", REQUESTER_COMMENT, metadata.getRequestorComment());
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageDebugView method savePerformed.
public void savePerformed(AjaxRequestTarget target) {
if (StringUtils.isEmpty(objectViewDtoModel.getObject().getXml())) {
error(getString("pageDebugView.message.cantSaveEmpty"));
target.add(getFeedbackPanel());
return;
}
Task task = createSimpleTask(OPERATION_SAVE_OBJECT);
OperationResult result = task.getResult();
try {
PrismObject<? extends ObjectType> oldObject = objectViewDtoModel.getObject().getObject();
oldObject.revive(getPrismContext());
Holder<? extends ObjectType> objectHolder = new Holder<>(null);
validateObject(result, (Holder) objectHolder);
if (result.isAcceptable()) {
PrismObject<? extends ObjectType> newObject = objectHolder.getValue().asPrismObject();
ObjectDelta<? extends ObjectType> delta = oldObject.diff((PrismObject) newObject, EquivalenceStrategy.LITERAL);
if (delta.getPrismContext() == null) {
LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
delta.revive(getPrismContext());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta to be applied:\n{}", delta.debugDump());
}
// quick fix for now (MID-1910), maybe it should be somewhere in objectViewModel..
// if (isReport(oldObject)){
// ReportTypeUtil.applyConfigurationDefinition((PrismObject)newObject, delta, getPrismContext());
// }
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
ModelExecuteOptions options = ModelExecuteOptions.create(getPrismContext());
if (isTrue(DebugViewOptions.ID_SAVE_AS_RAW)) {
options.raw(true);
}
if (isTrue(DebugViewOptions.ID_REEVALUATE_SEARCH_FILTERS)) {
options.reevaluateSearchFilters(true);
}
if (!isTrue(DebugViewOptions.ID_ENCRYPT)) {
options.noCrypt(true);
}
getModelService().executeChanges(deltas, options, task, result);
result.computeStatus();
}
} catch (Exception ex) {
result.recordFatalError(getString("WebModelUtils.couldntSaveObject"), ex);
}
if (result.isError()) {
showResult(result);
target.add(getFeedbackPanel());
} else {
showResult(result);
// to handle returning back to list objects page instead of edit object page
if (getBreadcrumbs().size() >= 3) {
redirectBack(3);
} else {
redirectBack();
}
}
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class ProgressAwareChangesExecutorImpl method executeChanges.
public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, Task task, OperationResult result, AjaxRequestTarget target) {
ModelExecuteOptions options = createOptions(executeOptions, previewOnly);
LOGGER.debug("Using execute options {}.", options);
if (executeOptions.isSaveInBackground() && !previewOnly) {
return executeChangesInBackground(deltas, options, task, result, target);
}
return executeChanges(deltas, previewOnly, options, task, result, target);
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageUser method getDelegationPreviewOptions.
private ModelExecuteOptions getDelegationPreviewOptions() {
ModelExecuteOptions options = getProgressPanel().getExecuteOptions().createOptions(getPrismContext());
options.getOrCreatePartialProcessing().setApprovals(PartialProcessingTypeType.PROCESS);
return options;
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class AbstractRoleMemberPanel method executeMemberOperation.
protected void executeMemberOperation(Task operationalTask, QName type, ObjectQuery memberQuery, ObjectDelta delta, String category, AjaxRequestTarget target) {
OperationResult parentResult = operationalTask.getResult();
try {
ModelExecuteOptions options = TaskCategory.EXECUTE_CHANGES.equals(category) ? // This was originally in ExecuteChangesTaskHandler, now it's transferred through task extension.
ModelExecuteOptions.createReconcile() : null;
TaskType task = WebComponentUtil.createSingleRecurrenceTask(parentResult.getOperation(), type, memberQuery, delta, options, category, getPageBase());
WebModelServiceUtils.runTask(task, operationalTask, parentResult, getPageBase());
} catch (SchemaException e) {
parentResult.recordFatalError(parentResult.getOperation(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Failed to execute operation " + parentResult.getOperation(), e);
target.add(getPageBase().getFeedbackPanel());
}
target.add(getPageBase().getFeedbackPanel());
}
Aggregations