Search in sources :

Example 26 with Containerable

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());
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Containerable(com.evolveum.midpoint.prism.Containerable)

Example 27 with Containerable

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");
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) JRException(net.sf.jasperreports.engine.JRException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) PrismObject(com.evolveum.midpoint.prism.PrismObject) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) ArrayList(java.util.ArrayList) List(java.util.List) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerable(com.evolveum.midpoint.prism.PrismContainerable) Containerable(com.evolveum.midpoint.prism.Containerable) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 28 with Containerable

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) JRException(net.sf.jasperreports.engine.JRException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ArrayList(java.util.ArrayList) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Containerable(com.evolveum.midpoint.prism.Containerable) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 29 with Containerable

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;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Jsr223ScriptEvaluator(com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 30 with Containerable

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;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Containerable(com.evolveum.midpoint.prism.Containerable)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Test (org.testng.annotations.Test)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)9 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 QName (javax.xml.namespace.QName)7 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 Task (com.evolveum.midpoint.task.api.Task)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 Item (com.evolveum.midpoint.prism.Item)4 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 Collection (java.util.Collection)4