use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class TestAbstractAssignmentEvaluator method test142RoleVisitorDisabledAssignment.
@Test
public void test142RoleVisitorDisabledAssignment() throws Exception {
final String TEST_NAME = "test142RoleVisitorDisabledAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_VISITOR_FILE);
assignmentType.setActivation(ActivationUtil.createDisabled());
ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userTypeJack.asPrismObject(), null, null);
userOdo.recompute();
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
assignmentIdi.recompute();
// WHEN
TestUtil.displayWhen(TEST_NAME);
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, TEST_NAME, task, result);
evaluatedAssignment.evaluateConstructions(userOdo, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertNotNull(evaluatedAssignment);
display("Evaluated assignment", evaluatedAssignment.debugDump());
assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
assertNoConstruction(evaluatedAssignment, PLUS, "title");
assertNoConstruction(evaluatedAssignment, MINUS, "title");
assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
assertNoConstruction(evaluatedAssignment, PLUS, "location");
assertNoConstruction(evaluatedAssignment, MINUS, "location");
assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createParametricAssignmentDelta.
protected ObjectDelta<UserType> createParametricAssignmentDelta(String userOid, String roleOid, String orgOid, String tenantOid, boolean adding) throws SchemaException {
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
if (adding) {
assignmentDelta.addValueToAdd(cval);
} else {
assignmentDelta.addValueToDelete(cval);
}
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(roleOid);
targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
if (orgOid != null) {
PrismReference orgRef = cval.findOrCreateReference(AssignmentType.F_ORG_REF);
orgRef.getValue().setOid(orgOid);
}
if (tenantOid != null) {
PrismReference tenantRef = cval.findOrCreateReference(AssignmentType.F_TENANT_REF);
tenantRef.getValue().setOid(tenantOid);
}
modifications.add(assignmentDelta);
return ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class MidPointDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
if (currentObject.getParent() instanceof PrismObject) {
return ((PrismObject) currentObject.getParent()).getOid();
} else {
throw new IllegalStateException("oid property is not supported for " + currentObject.getClass());
}
} else if (PARENT_NAME.equals(fieldName)) {
PrismContainerable parent1 = currentObject.getParent();
if (!(parent1 instanceof PrismContainer)) {
return null;
}
return ((PrismContainer) parent1).getParent();
} else if (THIS_NAME.equals(fieldName)) {
return currentObject;
}
ItemPathType itemPathType = new ItemPathType(fieldName);
ItemPath path = itemPathType.getItemPath();
Item i = currentObject.findItem(path);
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return normalize(((PrismProperty) i).getRealValue(), jrField.getValueClass());
}
List normalized = new ArrayList<>();
for (Object real : ((PrismProperty) i).getRealValues()) {
normalized.add(normalize(real, jrField.getValueClass()));
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ObjectTypeUtil.createObjectRef(((PrismReference) i).getValue());
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(ObjectTypeUtil.createObjectRef(refVal));
}
return refs;
} else if (i instanceof PrismContainer) {
if (i.isSingleValue()) {
return ((PrismContainer) i).getValue().asContainerable();
}
List<Containerable> containers = new ArrayList<Containerable>();
for (Object pcv : i.getValues()) {
if (pcv instanceof PrismContainerValue) {
containers.add(((PrismContainerValue) pcv).asContainerable());
}
}
return containers;
} else
throw new JRException("Could not get value of the fileld: " + fieldName);
// return
// throw new UnsupportedOperationException("dataSource.getFiledValue() not supported");
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class MidPointQueryExecutor method createDatasource.
@Override
public JRDataSource createDatasource() throws JRException {
try {
if (query == null && script == null) {
throw new JRException("Neither query, nor script defined in the report.");
}
if (query != null) {
Collection<PrismObject<? extends ObjectType>> results;
results = searchObjects(query, SelectorOptions.createCollection(GetOperationOptions.createRaw()));
return createDataSourceFromObjects(results);
} else {
if (script.contains("AuditEventRecord")) {
Collection<AuditEventRecord> audtiEventRecords = searchAuditRecords(script, getPromptingParameters());
Collection<AuditEventRecordType> auditEventRecordsType = new ArrayList<>();
for (AuditEventRecord aer : audtiEventRecords) {
AuditEventRecordType aerType = aer.createAuditEventRecordType(true);
auditEventRecordsType.add(aerType);
}
return new JRBeanCollectionDataSource(auditEventRecordsType);
} else {
Collection<PrismContainerValue<? extends Containerable>> results;
results = evaluateScript(script, getParameters());
return createDataSourceFromContainerValues(results);
}
}
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw new JRException(e);
}
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class ReportServiceImpl method evaluateScript.
public Collection<PrismContainerValue<? extends Containerable>> evaluateScript(String script, Map<QName, Object> parameters) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
List<PrismContainerValue<? extends Containerable>> results = new ArrayList<>();
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinitions(parameters);
// special variable for audit report
variables.addVariableDefinition(new QName("auditParams"), getConvertedParams(parameters));
Task task = taskManager.createTaskInstance(ReportService.class.getName() + ".evaluateScript");
OperationResult parentResult = task.getResult();
Collection<FunctionLibrary> functions = createFunctionLibraries();
Jsr223ScriptEvaluator scripts = new Jsr223ScriptEvaluator("Groovy", prismContext, prismContext.getDefaultProtector());
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, task.getResult()));
Object o = null;
try {
o = scripts.evaluateReportScript(script, variables, objectResolver, functions, "desc", parentResult);
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
if (o != null) {
if (Collection.class.isAssignableFrom(o.getClass())) {
Collection resultSet = (Collection) o;
if (resultSet != null && !resultSet.isEmpty()) {
for (Object obj : resultSet) {
results.add(convertResultingObject(obj));
}
}
} else {
results.add(convertResultingObject(o));
}
}
return results;
}
Aggregations