use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class RecomputeExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && FocusType.class.isAssignableFrom(((PrismObjectValue) value).asPrismObject().getCompileTimeClass())) {
PrismObject<FocusType> focalPrismObject = ((PrismObjectValue) value).asPrismObject();
FocusType focusType = focalPrismObject.asObjectable();
long started = operationsHelper.recordStart(context, focusType);
Throwable exception = null;
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing object {} with dryRun={}: context:\n{}", focalPrismObject, dryRun);
}
ObjectDelta<? extends FocusType> emptyDelta = ObjectDelta.createEmptyDelta(focusType.getClass(), focusType.getOid(), prismContext, ChangeType.MODIFY);
operationsHelper.applyDelta(emptyDelta, ModelExecuteOptions.createReconcile(), dryRun, context, result);
LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
operationsHelper.recordEnd(context, focusType, started, null);
} catch (Throwable e) {
operationsHelper.recordEnd(context, focusType, started, e);
exception = processActionException(e, NAME, value, context);
}
context.println((exception != null ? "Attempted to recompute " : "Recomputed ") + focalPrismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<FocusType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class ResolveExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean noFetch = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_NO_FETCH, input, context, false, NAME, globalResult);
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismReferenceValue) {
PrismReferenceValue prismReferenceValue = (PrismReferenceValue) value;
String oid = prismReferenceValue.getOid();
QName targetTypeQName = prismReferenceValue.getTargetType();
if (targetTypeQName == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type is unknown: " + prismReferenceValue);
}
Class<? extends ObjectType> typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeQName);
if (typeClass == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type class is unknown for target type " + targetTypeQName);
}
try {
PrismObjectValue<? extends ObjectType> resolved = operationsHelper.getObject(typeClass, oid, noFetch, context, result).getValue();
output.add(new PipelineItem(resolved, item.getResult()));
} catch (Throwable e) {
//noinspection ThrowableNotThrown
processActionException(e, NAME, value, context);
// to keep track of failed item (may trigger exceptions downstream)
output.add(item);
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismReference"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return output;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test540SearchUserResolveNamesForRoleMembershipRef.
@Test
public void test540SearchUserResolveNamesForRoleMembershipRef() throws Exception {
final String TEST_NAME = "test540SearchUserResolveNamesForRoleMembershipRef";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_RESOLVE_NAMES_FOR_ROLE_MEMBERSHIP_REF_FILE);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
TestUtil.assertSuccess(result);
assertEquals(2, output.getFinalOutput().getData().size());
for (PipelineItem item : output.getFinalOutput().getData()) {
PrismAsserts.assertHasTargetName((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_ROLE_MEMBERSHIP_REF));
PrismAsserts.assertHasNoTargetName((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_LINK_REF));
}
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test510GeneratePasswords.
@Test
public void test510GeneratePasswords() throws Exception {
final String TEST_NAME = "test510GeneratePasswords";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
PrismProperty<ScriptingExpressionType> expression = parseAnyData(GENERATE_PASSWORDS_FILE);
addObject(PASSWORD_POLICY_GLOBAL_FILE);
List<ItemDelta<?, ?>> itemDeltas = DeltaBuilder.deltaFor(SecurityPolicyType.class, prismContext).item(SecurityPolicyType.F_CREDENTIALS, CredentialsPolicyType.F_PASSWORD, PasswordCredentialsPolicyType.F_PASSWORD_POLICY_REF).add(new PrismReferenceValue(PASSWORD_POLICY_GLOBAL_OID)).asItemDeltas();
modifySystemObjectInRepo(SecurityPolicyType.class, SECURITY_POLICY_OID, itemDeltas, result);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
TestUtil.assertSuccess(result);
PipelineData data = output.getFinalOutput();
assertEquals("Unexpected # of items in output", 5, data.getData().size());
Set<String> realOids = new HashSet<>();
for (PipelineItem item : data.getData()) {
PrismValue value = item.getValue();
UserType user = ((PrismObjectValue<UserType>) value).asObjectable();
ProtectedStringType passwordValue = user.getCredentials().getPassword().getValue();
assertNotNull("clearValue for password not set", passwordValue.getClearValue());
realOids.add(user.getOid());
}
assertEquals("Unexpected OIDs in output", Sets.newHashSet(Arrays.asList(USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids);
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test545SearchUserResolveRoleMembershipRef.
@Test
public void test545SearchUserResolveRoleMembershipRef() throws Exception {
final String TEST_NAME = "test545SearchUserResolveRoleMembershipRef";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_RESOLVE_ROLE_MEMBERSHIP_REF_FILE);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
TestUtil.assertSuccess(result);
assertEquals(2, output.getFinalOutput().getData().size());
for (PipelineItem item : output.getFinalOutput().getData()) {
PrismAsserts.assertHasObject((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_ROLE_MEMBERSHIP_REF));
PrismAsserts.assertHasNoObject((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_LINK_REF));
}
}
Aggregations