use of com.evolveum.midpoint.prism.query.OrderDirection in project midpoint by Evolveum.
the class LookupTableHelper method setupLookupTableRowsQuery.
private Query setupLookupTableRowsQuery(Session session, RelationalValueSearchQuery queryDef, String oid) throws SchemaException {
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<?> cq = cb.createQuery(RLookupTableRow.class);
Root<RLookupTableRow> root = cq.from(RLookupTableRow.class);
List<Predicate> where = new ArrayList<>();
where.add(cb.equal(root.get("ownerOid"), oid));
if (queryDef == null) {
appendWhereClause(cq, where, cb);
return session.createQuery(cq);
}
if (queryDef.getColumn() != null && queryDef.getSearchType() != null && StringUtils.isNotEmpty(queryDef.getSearchValue())) {
Path<String> param;
String value = queryDef.getSearchValue();
if (LookupTableRowType.F_LABEL.equals(queryDef.getColumn())) {
param = root.get("label").get("norm");
PolyString poly = new PolyString(value);
poly.recompute(prismContext.getDefaultPolyStringNormalizer());
value = poly.getNorm();
} else {
param = root.get(queryDef.getColumn().getLocalPart());
}
switch(queryDef.getSearchType()) {
case EXACT:
where.add(cb.equal(param, value));
break;
case STARTS_WITH:
where.add(cb.like(param, value + "%"));
break;
case SUBSTRING:
where.add(cb.like(param, "%" + value + "%"));
}
}
appendWhereClause(cq, where, cb);
ObjectPaging paging = queryDef.getPaging();
if (paging == null) {
return session.createQuery(cq);
}
ItemPath orderByPath = paging.getPrimaryOrderingPath();
OrderDirection direction = paging.getPrimaryOrderingDirection();
if (direction != null && orderByPath != null && !orderByPath.isEmpty()) {
if (orderByPath.size() > 1 || !orderByPath.startsWithName() && !orderByPath.startsWithIdentifier()) {
throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
}
Object first = orderByPath.first();
String orderBy = ItemPath.isName(first) ? ItemPath.toName(first).getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
Path[] orderByPaths = buildOrderByPaths(orderBy, root);
Order[] order;
switch(direction) {
case ASCENDING:
order = Arrays.stream(orderByPaths).map(item -> cb.asc(item)).toArray(Order[]::new);
break;
case DESCENDING:
order = Arrays.stream(orderByPaths).map(item -> cb.desc(item)).toArray(Order[]::new);
break;
default:
throw new AssertionError(direction);
}
cq.orderBy(order);
}
return session.createQuery(cq);
}
use of com.evolveum.midpoint.prism.query.OrderDirection in project midpoint by Evolveum.
the class TaskErrorsTabPanel method initLayoutNew.
private void initLayoutNew() {
var provider = new SelectableBeanContainerDataProvider<OperationExecutionType>(this, Model.of(), null, true) {
@Override
protected String getDefaultSortParam() {
return TaskErrorSelectableBeanImpl.F_ERROR_TIMESTAMP;
}
@Override
protected SortOrder getDefaultSortOrder() {
return SortOrder.DESCENDING;
}
@Override
public SelectableBean<OperationExecutionType> createDataObjectWrapper(OperationExecutionType obj) {
return new TaskErrorSelectableBeanImpl(obj);
}
@Override
public ObjectQuery getQuery() {
return createContentQuery(getModelObject().getOid(), getPageBase());
}
@NotNull
@Override
protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
if (sortParam != null && sortParam.getProperty() != null) {
OrderDirection order = sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING;
ItemPath ordering;
if (sortParam.getProperty().equals(TaskErrorSelectableBeanImpl.F_ERROR_TIMESTAMP)) {
ordering = ItemPath.create(OperationExecutionType.F_TIMESTAMP);
} else if (sortParam.getProperty().equals("name")) {
// TODO why is this "name" and not TaskErrorSelectableBeanImpl.F_OBJECT_REF_NAME?
ordering = ItemPath.create(PrismConstants.T_PARENT, ObjectType.F_NAME);
} else {
// TODO this is actually not used
ordering = ItemPath.create(new QName(SchemaConstantsGenerated.NS_COMMON, sortParam.getProperty()));
}
return Collections.singletonList(getPrismContext().queryFactory().createOrdering(ordering, order));
} else {
return Collections.emptyList();
}
}
@Override
public Class<OperationExecutionType> getType() {
return OperationExecutionType.class;
}
};
BoxedTablePanel<?> table = new BoxedTablePanel<>(ID_TASK_ERRORS, provider, initColumns());
table.setOutputMarkupId(true);
add(table);
}
use of com.evolveum.midpoint.prism.query.OrderDirection in project midpoint by Evolveum.
the class TaskErrorsPanel method initLayoutNew.
private void initLayoutNew() {
var provider = new SelectableBeanContainerDataProvider<OperationExecutionType>(this, Model.of(), null, true) {
@Override
protected String getDefaultSortParam() {
return TaskErrorSelectableBeanImpl.F_ERROR_TIMESTAMP;
}
@Override
protected SortOrder getDefaultSortOrder() {
return SortOrder.DESCENDING;
}
@Override
public SelectableBean<OperationExecutionType> createDataObjectWrapper(OperationExecutionType obj) {
return new TaskErrorSelectableBeanImpl(obj);
}
@Override
public ObjectQuery getQuery() {
return createContentQuery(getObjectWrapper().getOid(), getPageBase());
}
@NotNull
@Override
protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
if (sortParam != null && sortParam.getProperty() != null) {
OrderDirection order = sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING;
ItemPath ordering;
if (sortParam.getProperty().equals(TaskErrorSelectableBeanImpl.F_ERROR_TIMESTAMP)) {
ordering = ItemPath.create(OperationExecutionType.F_TIMESTAMP);
} else if (sortParam.getProperty().equals("name")) {
// TODO why is this "name" and not TaskErrorSelectableBeanImplNew.F_OBJECT_REF_NAME?
ordering = ItemPath.create(PrismConstants.T_PARENT, ObjectType.F_NAME);
} else {
// TODO this is actually not used
ordering = ItemPath.create(new QName(SchemaConstantsGenerated.NS_COMMON, sortParam.getProperty()));
}
return Collections.singletonList(getPrismContext().queryFactory().createOrdering(ordering, order));
} else {
return Collections.emptyList();
}
}
@Override
public Class<OperationExecutionType> getType() {
return OperationExecutionType.class;
}
};
BoxedTablePanel<?> table = new BoxedTablePanel<>(ID_TASK_ERRORS, provider, initColumnsNew());
table.setOutputMarkupId(true);
add(table);
}
use of com.evolveum.midpoint.prism.query.OrderDirection in project midpoint by Evolveum.
the class AuditLogViewerPanel method initLayout.
private void initLayout() {
ContainerableListPanel<AuditEventRecordType, SelectableBean<AuditEventRecordType>> auditLogViewerTable = new ContainerableListPanel<>(ID_AUDIT_LOG_VIEWER_TABLE, AuditEventRecordType.class) {
@Override
protected List<IColumn<SelectableBean<AuditEventRecordType>, String>> createDefaultColumns() {
return AuditLogViewerPanel.this.createColumns();
}
@Override
protected List<InlineMenuItem> createInlineMenu() {
return null;
}
@Override
protected IColumn<SelectableBean<AuditEventRecordType>, String> createNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ItemPath itemPath, ExpressionType expression) {
return AuditLogViewerPanel.this.createNameColumn();
}
@Override
protected IColumn<SelectableBean<AuditEventRecordType>, String> createCheckboxColumn() {
return null;
}
@Override
protected IColumn<SelectableBean<AuditEventRecordType>, String> createIconColumn() {
return null;
}
@Override
protected Search createSearch(Class<AuditEventRecordType> type) {
// TODO: use storage?
AuditLogStorage storage = (AuditLogStorage) getPageStorage();
Search search = SearchFactory.createContainerSearch(new ContainerTypeSearchItem(new SearchValue(type, "")), AuditEventRecordType.F_TIMESTAMP, getPageBase(), true);
DateSearchItem timestampItem = (DateSearchItem) search.findPropertySearchItem(AuditEventRecordType.F_TIMESTAMP);
if (timestampItem != null && timestampItem.getFromDate() == null && timestampItem.getToDate() == null && !isCollectionViewPanelForWidget()) {
Date todayDate = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
timestampItem.setFromDate(MiscUtil.asXMLGregorianCalendar(todayDate));
}
return search;
}
@Override
protected UserProfileStorage.TableId getTableId() {
return UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER;
}
@Override
protected String getStorageKey() {
String collectionNameValue = null;
if (isCollectionViewPanelForCompiledView()) {
StringValue collectionName = getCollectionNameParameterValue();
collectionNameValue = collectionName != null ? collectionName.toString() : "";
}
return getAuditStorageKey(collectionNameValue);
}
@Override
protected ISelectableDataProvider createProvider() {
PageStorage pageStorage = getPageStorage();
SelectableBeanContainerDataProvider<AuditEventRecordType> provider = new SelectableBeanContainerDataProvider<AuditEventRecordType>(AuditLogViewerPanel.this, getSearchModel(), null, false) {
@Override
protected PageStorage getPageStorage() {
return pageStorage;
}
@Override
protected Integer countObjects(Class<? extends AuditEventRecordType> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> currentOptions, Task task, OperationResult result) throws CommonException {
return getPageBase().getModelAuditService().countObjects(query, currentOptions, task, result);
}
@Override
protected List<AuditEventRecordType> searchObjects(Class<? extends AuditEventRecordType> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws CommonException {
return getPageBase().getModelAuditService().searchObjects(query, options, task, result);
}
@NotNull
@Override
protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
if (sortParam != null && sortParam.getProperty() != null) {
OrderDirection order = sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING;
return Collections.singletonList(getPrismContext().queryFactory().createOrdering(ItemPath.create(new QName(AuditEventRecordType.COMPLEX_TYPE.getNamespaceURI(), sortParam.getProperty())), order));
} else {
return Collections.emptyList();
}
}
@Override
protected ObjectQuery getCustomizeContentQuery() {
return AuditLogViewerPanel.this.getCustomizeContentQuery();
}
};
provider.setSort(AuditEventRecordType.F_TIMESTAMP.getLocalPart(), SortOrder.DESCENDING);
return provider;
}
@Override
protected AuditEventRecordType getRowRealValue(SelectableBean<AuditEventRecordType> rowModelObject) {
if (rowModelObject == null) {
return null;
}
return rowModelObject.getValue();
}
@Override
protected List<Component> createToolbarButtonsList(String idButton) {
List<Component> buttonsList = new ArrayList<>();
CsvDownloadButtonPanel exportDataLink = new CsvDownloadButtonPanel(idButton) {
private static final long serialVersionUID = 1L;
@Override
protected String getFilename() {
return "AuditLogViewer_" + createStringResource("MainObjectListPanel.exportFileName").getString();
}
@Override
protected DataTable<?, ?> getDataTable() {
return getTable().getDataTable();
}
};
exportDataLink.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_CSV_EXPORT_ACTION_URI);
}
});
buttonsList.add(exportDataLink);
AjaxCompositedIconButton createReport = new AjaxCompositedIconButton(idButton, WebComponentUtil.createCreateReportIcon(), getPageBase().createStringResource("MainObjectListPanel.createReport")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
createReportPerformed(target);
}
};
createReport.add(AttributeAppender.append("class", "btn btn-default btn-sm btn-margin-right"));
buttonsList.add(createReport);
return buttonsList;
}
};
auditLogViewerTable.setOutputMarkupId(true);
add(auditLogViewerTable);
}
use of com.evolveum.midpoint.prism.query.OrderDirection in project midpoint by Evolveum.
the class ReportObjectsListPanel method createProvider.
@Override
protected ISelectableDataProvider<C, SelectableBean<C>> createProvider() {
SelectableBeanContainerDataProvider<C> provider = new SelectableBeanContainerDataProvider<>(this, getSearchModel(), null, false) {
@Override
public List<SelectableBean<C>> createDataObjectWrappers(Class<? extends C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Collection<SelectorOptions<GetOperationOptions>> defaultOptions = DefaultColumnUtils.createOption(getObjectCollectionView().getTargetClass(getPrismContext()), getSchemaService());
QName qNameType = WebComponentUtil.containerClassToQName(getPrismContext(), type);
VariablesMap variables = new VariablesMap();
if (getSearchModel().getObject() != null) {
variables.putAll(getSearchModel().getObject().getFilterVariables(getVariables(), getPageBase()));
processReferenceVariables(variables);
}
List<C> list = (List<C>) getModelInteractionService().searchObjectsFromCollection(getReport().getObjectCollection().getCollection(), qNameType, defaultOptions, query.getPaging(), variables, task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query {} resulted in {} objects", type.getSimpleName(), list.size());
}
List<SelectableBean<C>> data = new ArrayList<SelectableBean<C>>();
for (C object : list) {
data.add(createDataObjectWrapper(object));
}
return data;
}
@Override
protected Integer countObjects(Class<? extends C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> currentOptions, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Collection<SelectorOptions<GetOperationOptions>> defaultOptions = DefaultColumnUtils.createOption(getObjectCollectionView().getTargetClass(getPrismContext()), getSchemaService());
QName qNameType = WebComponentUtil.containerClassToQName(getPrismContext(), type);
VariablesMap variables = new VariablesMap();
if (getSearchModel().getObject() != null) {
variables.putAll(getSearchModel().getObject().getFilterVariables(getVariables(), getPageBase()));
processReferenceVariables(variables);
}
return getModelInteractionService().countObjectsFromCollection(getReport().getObjectCollection().getCollection(), qNameType, defaultOptions, null, variables, task, result);
}
@Override
protected boolean isUseObjectCounting() {
return !isDisableCounting();
}
@Override
public boolean isOrderingDisabled() {
return isDisableSorting();
}
@Override
public ObjectQuery getQuery() {
// fake query because of we need paging in method createDataObjectWrappers
return getPrismContext().queryFor(ObjectType.class).build();
}
@Override
@NotNull
protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam) {
if (AuditEventRecordType.class.equals(getDefaultType()) && sortParam != null && sortParam.getProperty() != null) {
OrderDirection order = sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING;
return Collections.singletonList(getPrismContext().queryFactory().createOrdering(ItemPath.create(new QName(AuditEventRecordType.COMPLEX_TYPE.getNamespaceURI(), sortParam.getProperty())), order));
}
return super.createObjectOrderings(sortParam);
}
};
if (provider.getSort() == null && hasView()) {
if (ObjectType.class.isAssignableFrom(getDefaultType())) {
provider.setSort("name", SortOrder.ASCENDING);
} else if (AuditEventRecordType.class.isAssignableFrom(getDefaultType())) {
provider.setSort("timestamp", SortOrder.ASCENDING);
}
}
return provider;
}
Aggregations