Search in sources :

Example 21 with ModelContext

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);
        }
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommonException(com.evolveum.midpoint.util.exception.CommonException) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 22 with ModelContext

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);
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ModelOperationStatusDto(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusDto) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) ModelOperationStatusPanel(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusPanel)

Example 23 with ModelContext

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();
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Date(java.util.Date)

Aggregations

ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Task (com.evolveum.midpoint.task.api.Task)11 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)8 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 JAXBException (javax.xml.bind.JAXBException)6 Test (org.testng.annotations.Test)6 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelService (com.evolveum.midpoint.model.api.ModelService)4 CommonException (com.evolveum.midpoint.util.exception.CommonException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)3 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)2 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)2 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)2