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);
}
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;
}
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;
}
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");
}
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);
}
Aggregations