use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class AccCertUpdateHelper method modifyObjectViaModel.
<T extends ObjectType> void modifyObjectViaModel(Class<T> objectClass, String oid, Collection<ItemDelta<?, ?>> itemDeltas, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
ObjectDelta<T> objectDelta = ObjectDelta.createModifyDelta(oid, itemDeltas, objectClass, prismContext);
try {
ModelExecuteOptions options = ModelExecuteOptions.createRaw().setPreAuthorized();
modelService.executeChanges(Collections.singletonList(objectDelta), options, task, result);
} catch (SecurityViolationException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException e) {
throw new SystemException("Unexpected exception when modifying " + objectClass.getSimpleName() + " " + oid + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class TestPreviewChanges method doPreview.
private void doPreview(Collection<ObjectDelta<? extends ObjectType>> deltas, ObjectChecker<ModelContext<UserType>> checker, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
display("Input deltas: ", deltas);
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
display("Preview context", modelContext);
checker.check(modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class TestPreviewChanges method doPreviewFail.
private void doPreviewFail(Collection<ObjectDelta<? extends ObjectType>> deltas, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
display("Input deltas: ", deltas);
try {
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
AssertJUnit.fail("Expected exception, but it haven't come");
} catch (SchemaException e) {
// This is expected
display("Expected exception", e);
}
result.computeStatus();
TestUtil.assertFailure(result);
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class ResourceContentPanel method deleteAccountConfirmedPerformed.
private void deleteAccountConfirmedPerformed(AjaxRequestTarget target, OperationResult result, List<ShadowType> selected) {
Task task = getPageBase().createSimpleTask(OPERATION_DELETE_OBJECT);
ModelExecuteOptions opts = createModelOptions();
for (ShadowType shadow : selected) {
try {
ObjectDelta<ShadowType> deleteDelta = getPageBase().getPrismContext().deltaFactory().object().createDeleteDelta(ShadowType.class, shadow.getOid());
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(deleteDelta), opts, task, result);
} catch (Throwable e) {
result.recordPartialError("Could not delete " + shadow + ", reason: " + e.getMessage(), e);
LOGGER.error("Could not delete {}, using option {}", shadow, opts, e);
}
}
result.computeStatusIfUnknown();
getPageBase().showResult(result);
getTable().refreshTable(target);
target.add(getPageBase().getFeedbackPanel());
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class ResourceContentPanel method updateResourceObjectStatusPerformed.
protected void updateResourceObjectStatusPerformed(ShadowType selected, AjaxRequestTarget target, boolean enabled) {
List<ShadowType> selectedShadow = getSelectedShadowsList(selected);
OperationResult result = new OperationResult(OPERATION_UPDATE_STATUS);
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_STATUS);
if (selectedShadow == null || selectedShadow.isEmpty()) {
result.recordWarning(createStringResource("updateResourceObjectStatusPerformed.warning").getString());
getPageBase().showResult(result);
target.add(getPageBase().getFeedbackPanel());
return;
}
ModelExecuteOptions opts = createModelOptions();
for (ShadowType shadow : selectedShadow) {
ActivationStatusType status = enabled ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED;
try {
ObjectDelta<ShadowType> deleteDelta = getPageBase().getPrismContext().deltaFactory().object().createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, status);
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(deleteDelta), opts, task, result);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
result.recordPartialError(getPageBase().createStringResource("ResourceContentPanel.message.updateResourceObjectStatusPerformed.partialError", status, shadow).getString(), e);
LOGGER.error("Could not update status (to {}) for {}, using option {}", status, shadow, opts, e);
}
}
result.computeStatusIfUnknown();
getPageBase().showResult(result);
getTable().refreshTable(target);
target.add(getPageBase().getFeedbackPanel());
}
Aggregations