use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.
the class SynchronizationStep method savePerformed.
private void savePerformed() {
PrismObject<ResourceType> oldResource;
PrismObject<ResourceType> newResource = resourceModel.getObject();
Task task = getPageBase().createSimpleTask(OPERATION_SAVE_SYNC);
OperationResult result = task.getResult();
ModelService modelService = getPageBase().getModelService();
boolean saved = false;
removeEmptyContainers(newResource.asObjectable());
try {
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, newResource.getOid(), getPageBase(), task, result);
if (oldResource != null) {
ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, newResource);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_SYNC), result);
parentPage.resetModels();
syncDtoModel.reset();
saved = true;
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource synchronization.", e);
result.recordFatalError(getString("SynchronizationStep.message.cantSave", e));
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
getPageBase().showResult(result);
}
}
use of com.evolveum.midpoint.model.api.ModelService in project midpoint by Evolveum.
the class ProgressPanel method executeChangesAsync.
private void executeChangesAsync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
MidPointApplication application = MidPointApplication.get();
final ModelInteractionService modelInteraction = application.getModelInteractionService();
final ModelService model = application.getModel();
final SecurityContextManager secManager = application.getSecurityContextManager();
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
Callable<Void> execution = new SecurityContextAwareCallable<Void>(secManager, auth, connInfo) {
@Override
public Void callWithContextPrepared() throws Exception {
try {
LOGGER.debug("Execution start");
reporter.recordExecutionStart();
if (previewOnly) {
ModelContext previewResult = modelInteraction.previewChanges(deltas, options, task, Collections.singleton(reporter), result);
reporter.setPreviewResult(previewResult);
} else if (deltas != null && deltas.size() > 0) {
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = model.executeChanges(deltas, options, task, Collections.singleton(reporter), result);
reporter.setObjectDeltaOperation(executedDeltas);
}
} 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);
}
} finally {
LOGGER.debug("Execution finish {}", result);
}
reporter.recordExecutionStop();
// signals that the operation has finished
reporter.setAsyncOperationResult(result);
return null;
}
};
// to disable showing not-final results (why does it work? and why is the result shown otherwise?)
result.setInProgress();
AsyncWebProcessManager manager = application.getAsyncWebProcessManager();
manager.submit(reporterModel.getId(), execution);
}
use of com.evolveum.midpoint.model.api.ModelService 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.ModelService in project midpoint by Evolveum.
the class AssignmentEditorPanel method getTargetObject.
// protected IModel<RelationTypes> getRelationModel() {
// return new IModel<RelationTypes>() {
// private static final long serialVersionUID = 1L;
//
// @Override
// public RelationTypes getObject() {
// if (getModelObject().getTargetRef() == null) {
// return RelationTypes.MEMBER;
// }
// return RelationTypes.getRelationType(getModelObject().getTargetRef().getRelation());
// }
//
// @Override
// public void setObject(RelationTypes newValue) {
// ObjectReferenceType ref = getModelObject().getTargetRef();
// if (ref != null){
// ref.setRelation(newValue.getRelation());
// }
// }
//
// @Override
// public void detach() {
//
// }
// };
// }
private <O extends ObjectType> PrismObject<O> getTargetObject(AssignmentEditorDto dto) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
PrismContainerValue<AssignmentType> assignment = dto.getOldValue();
PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
if (targetRef == null) {
return null;
}
PrismReferenceValue refValue = targetRef.getValue();
if (refValue != null && refValue.getObject() != null) {
PrismObject object = refValue.getObject();
return object;
}
String oid = targetRef.getOid();
OperationResult result = new OperationResult(OPERATION_LOAD_OBJECT);
PageBase page = getPageBase();
ModelService model = page.getMidpointApplication().getModel();
Task task = page.createSimpleTask(OPERATION_LOAD_OBJECT);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
Class<O> type = (Class<O>) ObjectType.class;
if (refValue.getTargetType() != null) {
type = getPageBase().getPrismContext().getSchemaRegistry().determineCompileTimeClass(refValue.getTargetType());
}
PrismObject<O> object = model.getObject(type, oid, options, task, result);
refValue.setObject(object);
return object;
}
Aggregations