use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class ProgressPanel method executeChangesSync.
private void executeChangesSync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
try {
MidPointApplication application = MidPointApplication.get();
if (previewOnly) {
ModelInteractionService service = application.getModelInteractionService();
ModelContext previewResult = service.previewChanges(deltas, options, task, result);
reporter.setPreviewResult(previewResult);
} else {
ModelService service = application.getModel();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
reporter.setObjectDeltaOperation(executedDeltas);
}
result.computeStatusIfUnknown();
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
if (!result.isFatalError()) {
// just to be sure the exception is recorded into the result
result.recordFatalError(e.getMessage(), e);
}
}
}
use of com.evolveum.midpoint.model.api.context.ModelContext in project midpoint by Evolveum.
the class TaskOperationTabPanel method initLayout.
private 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 SimpleFocalObjectNotifier method getBody.
@Override
protected String getBody(ModelEvent event, SimpleFocalObjectNotifierType configuration, String transport, Task task, OperationResult result) throws SchemaException {
String typeName = event.getFocusTypeName();
String typeNameLower = typeName.toLowerCase();
boolean techInfo = Boolean.TRUE.equals(configuration.isShowTechnicalInformation());
// noinspection unchecked
ModelContext<AssignmentHolderType> modelContext = (ModelContext<AssignmentHolderType>) event.getModelContext();
ModelElementContext<AssignmentHolderType> focusContext = modelContext.getFocusContext();
PrismObject<AssignmentHolderType> focusObject = focusContext.getObjectNew() != null ? focusContext.getObjectNew() : focusContext.getObjectOld();
AssignmentHolderType focus = focusObject.asObjectable();
String oid = focusContext.getOid();
String fullName = emptyIfNull(getFullName(focus));
ObjectDelta<AssignmentHolderType> delta = ObjectDeltaCollectionsUtil.summarize(event.getFocusDeltas());
StringBuilder body = new StringBuilder();
String status = event.getStatusAsText();
String attemptedTo = event.isSuccess() ? "" : "(attempted to be) ";
body.append("Notification about ").append(typeNameLower).append("-related operation (status: ").append(status).append(")\n\n");
body.append(typeName).append(": ").append(fullName).append(" (").append(focus.getName()).append(", oid ").append(oid).append(")\n");
body.append("Notification created on: ").append(new Date()).append("\n\n");
final boolean watchAuxiliaryAttributes = isWatchAuxiliaryAttributes(configuration);
if (delta.isAdd()) {
body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("created with the following data:\n");
body.append(event.getContentAsFormattedList(watchAuxiliaryAttributes));
} else if (delta.isModify()) {
body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("modified. Modified attributes are:\n");
body.append(event.getContentAsFormattedList(watchAuxiliaryAttributes));
} else if (delta.isDelete()) {
body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("removed.\n");
}
body.append("\n");
if (!event.isSuccess()) {
body.append("More information about the status of the request was displayed and/or is present in log files.\n\n");
}
addRequesterAndChannelInformation(body, event, result);
if (techInfo) {
body.append("----------------------------------------\n");
body.append("Technical information:\n\n");
body.append(modelContext.debugDump(2));
}
return body.toString();
}
Aggregations