use of com.evolveum.midpoint.schema.RelationalValueSearchQuery in project midpoint by Evolveum.
the class LookupTableHelper method updateLoadedLookupTable.
<T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
return;
}
LOGGER.debug("Loading lookup table data.");
GetOperationOptions getOption = findLookupTableGetOption(options);
RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
Query query = setupLookupTableRowsQuery(session, queryDef, object.getOid());
if (queryDef != null && queryDef.getPaging() != null) {
ObjectPaging paging = queryDef.getPaging();
if (paging.getOffset() != null) {
query.setFirstResult(paging.getOffset());
}
if (paging.getMaxSize() != null) {
query.setMaxResults(paging.getMaxSize());
}
}
// noinspection unchecked
List<RLookupTableRow> rows = query.list();
if (CollectionUtils.isNotEmpty(rows)) {
LookupTableType lookup = (LookupTableType) object.asObjectable();
List<LookupTableRowType> jaxbRows = lookup.getRow();
for (RLookupTableRow row : rows) {
LookupTableRowType jaxbRow = row.toJAXB(prismContext);
jaxbRows.add(jaxbRow);
}
PrismContainer<LookupTableRowType> rowContainer = object.findContainer(LookupTableType.F_ROW);
rowContainer.setIncomplete(false);
} else {
PrismContainer<LookupTableRowType> rowContainer = object.findContainer(LookupTableType.F_ROW);
if (rowContainer != null) {
// just in case
rowContainer.clear();
rowContainer.setIncomplete(false);
}
}
}
use of com.evolveum.midpoint.schema.RelationalValueSearchQuery in project midpoint by Evolveum.
the class QLookupTableMapping method appendLookupTableRows.
private void appendLookupTableRows(UUID ownerOid, LookupTableType base, GetOperationOptions rowOptions, JdbcSession session) {
try {
RelationalValueSearchQuery queryDef = rowOptions == null ? null : rowOptions.getRelationalValueSearchQuery();
QLookupTableRowMapping rowMapping = QLookupTableRowMapping.get();
QLookupTableRow alias = rowMapping.defaultAlias();
BooleanExpression whereQuery = appendConditions(alias, alias.ownerOid.eq(ownerOid), queryDef);
SQLQuery<MLookupTableRow> query = session.newQuery().from(alias).select(alias).where(whereQuery);
query = pagingAndOrdering(query, queryDef, rowMapping, alias);
List<MLookupTableRow> result = query.fetch();
for (MLookupTableRow r : result) {
LookupTableRowType lookupRow = new LookupTableRowType().key(r.key);
if (r.labelOrig != null || r.labelNorm != null) {
lookupRow.label(PolyString.toPolyStringType(new PolyString(r.labelOrig, r.labelNorm)));
}
lookupRow.lastChangeTimestamp(MiscUtil.asXMLGregorianCalendar(r.lastChangeTimestamp));
lookupRow.value(r.value);
lookupRow.asPrismContainerValue().setId(r.cid);
base.getRow().add(lookupRow);
}
} catch (QueryException e) {
throw new SystemException("Unable to fetch nested table rows", e);
}
}
Aggregations