Search in sources :

Example 21 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class SchemaProcessor method createContainerFieldGetterBody.

private void createContainerFieldGetterBody(JFieldVar field, ClassOutline classOutline, JMethod method) {
    JBlock body = method.body();
    List<JAnnotationUse> existingAnnotations = (List<JAnnotationUse>) getAnnotations(method);
    for (JAnnotationUse annotation : existingAnnotations) {
        if (isAnnotationTypeOf(annotation, XmlElement.class)) {
            Field mfield = getField(JAnnotationUse.class, "memberValues");
            mfield.setAccessible(true);
            Map<String, Object> map;
            try {
                map = (Map<String, Object>) mfield.get(annotation);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
            mfield.setAccessible(false);
            map.remove("name");
            annotation.param("name", normalizeFieldName(field.name()));
        }
    }
    if (isList(field.type())) {
        //JClass list = (JClass) field.type();
        //JClass listType = list.getTypeParameters().get(0);
        // PrismContainerValue pcv = asPrismContainerValue()
        JVar pcvVar = body.decl(CLASS_MAP.get(PrismContainerValue.class), "pcv", JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
        // PrismContainer container = PrismForJAXBUtil.getContainer(pcv, F_ASSIGNMENT);
        JInvocation invocation = CLASS_MAP.get(PrismForJAXBUtil.class).staticInvoke(METHOD_PRISM_UTIL_GET_CONTAINER);
        invocation.arg(pcvVar);
        invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())));
        JVar containerVar = body.decl(CLASS_MAP.get(PrismContainer.class), "container", invocation);
        // anonymous class (e.g. FocusType.AnonAssignment and its methods)
        JDefinedClass anonymousClass = createFieldContainerGetterListAnon(field, classOutline);
        createFieldContainerCreateItemBody(field, findMethod(anonymousClass, "createItem"));
        createFieldContainerGetValueFrom(field, findMethod(anonymousClass, "getValueFrom"));
        // return new FocusType.AnonAssignment(container, pcv);
        JInvocation newList = JExpr._new(anonymousClass);
        newList.arg(containerVar);
        newList.arg(pcvVar);
        body._return(newList);
        return;
    }
    JInvocation invocation = CLASS_MAP.get(PrismForJAXBUtil.class).staticInvoke(METHOD_PRISM_UTIL_GET_FIELD_SINGLE_CONTAINERABLE);
    invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE));
    invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name())));
    invocation.arg(JExpr.dotclass((JClass) field.type()));
    body._return(invocation);
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) Field(java.lang.reflect.Field) PrismForJAXBUtil(com.evolveum.midpoint.prism.xjc.PrismForJAXBUtil) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReferenceArrayList(com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PrismContainerArrayList(com.evolveum.midpoint.prism.xjc.PrismContainerArrayList) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 22 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PrismIdentifierGenerator method generate.

public IdGeneratorResult generate(Containerable containerable, Operation operation) {
    IdGeneratorResult result = new IdGeneratorResult();
    if (!(containerable instanceof AccessCertificationCaseType)) {
        return result;
    }
    AccessCertificationCaseType aCase = (AccessCertificationCaseType) containerable;
    List<PrismContainer<?>> containers = new ArrayList<>();
    CollectionUtils.addIgnoreNull(containers, aCase.asPrismContainerValue().findContainer(AccessCertificationCaseType.F_WORK_ITEM));
    generateContainerIds(containers, result, operation);
    return result;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) PrismContainer(com.evolveum.midpoint.prism.PrismContainer)

Example 23 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class RawTypeUtil method getParsedItem.

public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
    Item<IV, ID> subItem = null;
    List<IV> parsedValues = new ArrayList<IV>();
    for (RawType rawValue : values) {
        if (itemDefinition == null && containerDef != null) {
            itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
        }
        IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
        if (parsed != null) {
            parsedValues.add(parsed);
        }
    }
    PrismContext prismContext = null;
    if (containerDef != null) {
        prismContext = containerDef.getPrismContext();
    }
    if (prismContext == null && itemDefinition != null) {
        prismContext = itemDefinition.getPrismContext();
    }
    if (itemDefinition == null) {
        PrismProperty property = new PrismProperty(elementQName, prismContext);
        property.addAll(PrismValue.cloneCollection(parsedValues));
        return property;
    }
    if (itemDefinition instanceof PrismPropertyDefinition<?>) {
        // property
        PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            property.add((PrismPropertyValue) val.clone());
        }
        subItem = (Item<IV, ID>) property;
    } else if (itemDefinition instanceof PrismContainerDefinition<?>) {
        PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            container.add((PrismContainerValue) val.clone());
        }
        subItem = (Item<IV, ID>) container;
    } else if (itemDefinition instanceof PrismReferenceDefinition) {
        // TODO
        PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            PrismReferenceValue ref;
            if (val instanceof PrismReferenceValue) {
                ref = (PrismReferenceValue) val.clone();
            } else if (val instanceof PrismContainerValue) {
                // this is embedded (full) object
                Containerable c = ((PrismContainerValue) val).asContainerable();
                if (!(c instanceof Objectable)) {
                    throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
                }
                Objectable o = (Objectable) c;
                ref = new PrismReferenceValue();
                ref.setObject(o.asPrismObject());
            } else {
                throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
            }
            reference.merge(ref);
        }
        subItem = (Item<IV, ID>) reference;
    } else {
        throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
    }
    return subItem;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) 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) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 24 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer 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 25 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PageReport method runReportPerformed.

public static void runReportPerformed(AjaxRequestTarget target, PrismObject<ReportType> report, PageBase pageBase) {
    if (hasNotParameters(report.asObjectable())) {
        runConfirmPerformed(target, report, null, pageBase);
        return;
    }
    RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(pageBase.getMainPopupBodyId(), report.asObjectable()) {

        private static final long serialVersionUID = 1L;

        protected void runConfirmPerformed(AjaxRequestTarget target, PrismObject<ReportType> reportType, PrismContainer<ReportParameterType> reportParam) {
            PageReport.runConfirmPerformed(target, reportType, reportParam, pageBase);
            pageBase.hideMainPopup(target);
        }
    };
    pageBase.showMainPopup(runReportPopupPanel, target);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) RunReportPopupPanel(com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)

Aggregations

PrismContainer (com.evolveum.midpoint.prism.PrismContainer)28 PrismObject (com.evolveum.midpoint.prism.PrismObject)12 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 RunReportPopupPanel (com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 Item (com.evolveum.midpoint.prism.Item)4 PrismReference (com.evolveum.midpoint.prism.PrismReference)4 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ArrayList (java.util.ArrayList)4 Task (com.evolveum.midpoint.task.api.Task)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 Containerable (com.evolveum.midpoint.prism.Containerable)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 Referencable (com.evolveum.midpoint.prism.Referencable)2