use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class ProvisioningTestUtil method checkRepoShadow.
public static void checkRepoShadow(PrismObject<ShadowType> repoShadow, ShadowKindType kind, Integer expectedNumberOfAttributes) {
ShadowType repoShadowType = repoShadow.asObjectable();
assertNotNull("No OID in repo shadow " + repoShadow, repoShadowType.getOid());
assertNotNull("No name in repo shadow " + repoShadow, repoShadowType.getName());
assertNotNull("No objectClass in repo shadow " + repoShadow, repoShadowType.getObjectClass());
assertEquals("Wrong kind in repo shadow " + repoShadow, kind, repoShadowType.getKind());
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
assertNotNull("No attributes in repo shadow " + repoShadow, attributesContainer);
List<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
assertFalse("Empty attributes in repo shadow " + repoShadow, attributes.isEmpty());
if (expectedNumberOfAttributes != null) {
assertEquals("Unexpected number of attributes in repo shadow " + repoShadow, (int) expectedNumberOfAttributes, attributes.size());
}
}
use of com.evolveum.midpoint.prism.Containerable 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.Containerable 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.Containerable 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;
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class TestDummy method createAccountShadow.
private PrismObject<ShadowType> createAccountShadow(String username) throws SchemaException {
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
ShadowType shadowType = new ShadowType();
PrismTestUtil.getPrismContext().adopt(shadowType);
shadowType.setName(PrismTestUtil.createPolyStringType(username));
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(resource.getOid());
shadowType.setResourceRef(resourceRef);
shadowType.setObjectClass(defaultAccountDefinition.getTypeName());
PrismObject<ShadowType> shadow = shadowType.asPrismObject();
PrismContainer<Containerable> attrsCont = shadow.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
PrismProperty<String> icfsNameProp = attrsCont.findOrCreateProperty(SchemaConstants.ICFS_NAME);
icfsNameProp.setRealValue(username);
return shadow;
}
Aggregations