use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupPropertyModel method getObject.
@Override
@SuppressWarnings("unchecked")
public T getObject() {
final Object target = getInnermostModelOrObject();
if (target != null) {
Object value = PropertyResolver.getValue(expression, target);
if (value == null) {
return null;
}
String key = value.toString();
if (lookupTable != null) {
for (LookupTableRowType row : lookupTable.getRow()) {
if (key.equals(row.getKey())) {
return (T) WebComponentUtil.getOrigStringFromPoly(row.getLabel());
}
}
}
return (T) key;
}
return null;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class RunReportPopupPanel method createLookupTableRows.
private <O extends ObjectType> List<LookupTableRowType> createLookupTableRows(JasperReportParameterDto param, String input) {
ItemPath label = null;
ItemPath key = null;
List<LookupTableRowType> rows = new ArrayList<>();
JasperReportParameterPropertiesDto properties = param.getProperties();
if (properties == null) {
return null;
}
String pLabel = properties.getLabel();
if (pLabel != null) {
label = new ItemPath(pLabel);
}
String pKey = properties.getKey();
if (pKey != null) {
key = new ItemPath(pKey);
}
String pTargetType = properties.getTargetType();
Class<O> targetType = null;
if (pTargetType != null) {
try {
targetType = (Class<O>) Class.forName(pTargetType);
} catch (ClassNotFoundException e) {
error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
//e.printStackTrace();
}
}
if (label != null && targetType != null && input != null) {
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
Collection<PrismObject<O>> objects;
ObjectQuery query = QueryBuilder.queryFor(targetType, getPrismContext()).item(new QName(SchemaConstants.NS_C, pLabel)).startsWith(input).matching(new QName(SchemaConstants.NS_MATCHING_RULE, "origIgnoreCase")).maxSize(AUTO_COMPLETE_BOX_SIZE).build();
try {
objects = getPageBase().getModelService().searchObjects(targetType, query, SelectorOptions.createCollection(GetOperationOptions.createNoFetch()), task, result);
for (PrismObject<O> o : objects) {
Object realKeyValue = null;
PrismProperty labelItem = o.findProperty(label);
//TODO: e.g. support not only for property, but also ref, container..
if (labelItem == null || labelItem.isEmpty()) {
continue;
}
PrismProperty keyItem = o.findProperty(key);
if ("oid".equals(pKey)) {
realKeyValue = o.getOid();
}
if (realKeyValue == null && (keyItem == null || keyItem.isEmpty())) {
continue;
}
//TODO: support for single/multivalue value
if (!labelItem.isSingleValue()) {
continue;
}
Object realLabelValue = labelItem.getRealValue();
realKeyValue = (realKeyValue == null) ? keyItem.getRealValue() : realKeyValue;
// TODO: take definition into account
QName typeName = labelItem.getDefinition().getTypeName();
LookupTableRowType row = new LookupTableRowType();
if (realKeyValue != null) {
row.setKey(convertObjectToPolyStringType(realKeyValue).getOrig());
} else {
throw new SchemaException("Cannot create lookup table with null key for label: " + realLabelValue);
}
row.setLabel(convertObjectToPolyStringType(realLabelValue));
rows.add(row);
}
return rows;
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
//e.printStackTrace();
}
}
return rows;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupTableTest method test252DeleteNonexistingRow.
@Test
public void test252DeleteNonexistingRow() throws Exception {
OperationResult result = new OperationResult("test252DeleteNonexistingRow");
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("non-existing-key");
List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).delete(rowNoId).asItemDeltas();
executeAndCheckModification(modifications, result, 0, null);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupTableTest method test240AddRows.
@Test
public void test240AddRows() throws Exception {
OperationResult result = new OperationResult("test240AddRows");
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("key new");
rowNoId.setValue("value new");
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 4)));
LookupTableRowType rowNoId2 = new LookupTableRowType(prismContext);
rowNoId2.setKey("key new 2");
rowNoId2.setValue("value new 2");
LookupTableRowType row4 = new LookupTableRowType(prismContext);
row4.setId(4L);
row4.setKey("key 4");
row4.setValue("value 4");
List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).add(rowNoId, rowNoId2, row4).asItemDeltas();
executeAndCheckModification(modifications, result, 0, keysOf(rowNoId2, row4));
// beware, ID for row4 was re-generated -- using client-provided IDs is not recommended anyway
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupTableTest method test250DeleteRow.
@Test
public void test250DeleteRow() throws Exception {
OperationResult result = new OperationResult("test250DeleteRow");
LookupTableRowType row3 = new LookupTableRowType(prismContext);
row3.setId(3L);
List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).delete(row3).asItemDeltas();
executeAndCheckModification(modifications, result, 0, null);
}
Aggregations