Search in sources :

Example 1 with PrismContainerable

use of com.evolveum.midpoint.prism.PrismContainerable 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)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)1 Item (com.evolveum.midpoint.prism.Item)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismContainerable (com.evolveum.midpoint.prism.PrismContainerable)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 PrismReference (com.evolveum.midpoint.prism.PrismReference)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 Referencable (com.evolveum.midpoint.prism.Referencable)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JRException (net.sf.jasperreports.engine.JRException)1