Search in sources :

Example 6 with ObjectOrdering

use of com.evolveum.midpoint.prism.query.ObjectOrdering 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);
}
Also used : AjaxCompositedIconButton(com.evolveum.midpoint.gui.impl.component.AjaxCompositedIconButton) Task(com.evolveum.midpoint.task.api.Task) GuiObjectColumnType(com.evolveum.midpoint.xml.ns._public.common.common_3.GuiObjectColumnType) AuditLogStorage(com.evolveum.midpoint.web.session.AuditLogStorage) ContainerableListPanel(com.evolveum.midpoint.gui.impl.component.ContainerableListPanel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) StringValue(org.apache.wicket.util.string.StringValue) Component(org.apache.wicket.Component) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) PageStorage(com.evolveum.midpoint.web.session.PageStorage) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) ObjectOrdering(com.evolveum.midpoint.prism.query.ObjectOrdering) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) LocalDate(java.time.LocalDate) CsvDownloadButtonPanel(com.evolveum.midpoint.gui.api.component.button.CsvDownloadButtonPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) SelectableBeanContainerDataProvider(com.evolveum.midpoint.web.component.data.SelectableBeanContainerDataProvider) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with ObjectOrdering

use of com.evolveum.midpoint.prism.query.ObjectOrdering 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;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectOrdering(com.evolveum.midpoint.prism.query.ObjectOrdering) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) SelectableBeanContainerDataProvider(com.evolveum.midpoint.web.component.data.SelectableBeanContainerDataProvider) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection)

Example 8 with ObjectOrdering

use of com.evolveum.midpoint.prism.query.ObjectOrdering in project midpoint by Evolveum.

the class TaskErrorsPanel method initLayoutOld.

private void initLayoutOld() {
    SelectableBeanObjectDataProvider<? extends ObjectType> provider = new SelectableBeanObjectDataProvider<>(this, null) {

        @Override
        protected String getDefaultSortParam() {
            return TaskErrorSelectableBeanImplOld.F_ERROR_TIMESTAMP;
        }

        @Override
        protected SortOrder getDefaultSortOrder() {
            return SortOrder.DESCENDING;
        }

        @Override
        public SelectableBean<ObjectType> createDataObjectWrapper(ObjectType obj) {
            return new TaskErrorSelectableBeanImplOld<>(obj, getObjectWrapper().getOid());
        }

        @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(TaskErrorSelectableBeanImplOld.F_ERROR_TIMESTAMP)) {
                    ordering = ItemPath.create("operationExecution", "timestamp");
                } else {
                    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<ObjectType> getType() {
            return ObjectType.class;
        }
    };
    BoxedTablePanel<TaskErrorSelectableBeanImplOld<ObjectType>> table = new BoxedTablePanel<>(ID_TASK_ERRORS, provider, initColumnsOld());
    table.setOutputMarkupId(true);
    add(table);
}
Also used : QName(javax.xml.namespace.QName) SelectableBeanObjectDataProvider(com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider) ObjectOrdering(com.evolveum.midpoint.prism.query.ObjectOrdering) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel) TaskErrorSelectableBeanImplOld(com.evolveum.midpoint.web.page.admin.server.dto.TaskErrorSelectableBeanImplOld) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 9 with ObjectOrdering

use of com.evolveum.midpoint.prism.query.ObjectOrdering in project midpoint by Evolveum.

the class TaskErrorsTabPanel method initLayoutOld.

private void initLayoutOld() {
    SelectableBeanObjectDataProvider<? extends ObjectType> provider = new SelectableBeanObjectDataProvider<>(this, null) {

        @Override
        public SelectableBean<ObjectType> createDataObjectWrapper(ObjectType obj) {
            return new TaskErrorSelectableBeanImplOld<>(obj, getModelObject().getOid());
        }

        @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(TaskErrorSelectableBeanImplOld.F_ERROR_TIMESTAMP)) {
                    ordering = ItemPath.create("operationExecution", "timestamp");
                } else {
                    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<ObjectType> getType() {
            return ObjectType.class;
        }
    };
    BoxedTablePanel<TaskErrorSelectableBeanImplOld<ObjectType>> table = new BoxedTablePanel<>(ID_TASK_ERRORS, provider, initColumnsOld());
    table.setOutputMarkupId(true);
    add(table);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) QName(javax.xml.namespace.QName) SelectableBeanObjectDataProvider(com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider) ObjectOrdering(com.evolveum.midpoint.prism.query.ObjectOrdering) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel) TaskErrorSelectableBeanImplOld(com.evolveum.midpoint.web.page.admin.server.dto.TaskErrorSelectableBeanImplOld) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with ObjectOrdering

use of com.evolveum.midpoint.prism.query.ObjectOrdering in project midpoint by Evolveum.

the class QLookupTableMapping method pagingAndOrdering.

@SuppressWarnings({ "unchecked", "rawtypes" })
private <R> SQLQuery<R> pagingAndOrdering(SQLQuery<R> query, RelationalValueSearchQuery queryDef, QLookupTableRowMapping rowMapping, QLookupTableRow alias) throws QueryException {
    if (queryDef != null && queryDef.getPaging() != null) {
        var paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            query = query.offset(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            query = query.limit(paging.getMaxSize());
        }
        for (ObjectOrdering ordering : paging.getOrderingInstructions()) {
            Order direction = ordering.getDirection() == OrderDirection.DESCENDING ? Order.DESC : Order.ASC;
            var mapper = rowMapping.itemMapper(ordering.getOrderBy().firstToQName());
            Expression path = mapper.primaryPath(alias, null);
            if (ItemPath.equivalent(LookupTableRowType.F_LABEL, ordering.getOrderBy())) {
                // old repository uses normalized form for ordering
                path = alias.labelNorm;
            }
            query.orderBy(new OrderSpecifier<>(direction, path));
        }
    }
    return query;
}
Also used : Order(com.querydsl.core.types.Order) Expression(com.querydsl.core.types.Expression) BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) ObjectOrdering(com.evolveum.midpoint.prism.query.ObjectOrdering)

Aggregations

ObjectOrdering (com.evolveum.midpoint.prism.query.ObjectOrdering)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 QName (javax.xml.namespace.QName)7 OrderDirection (com.evolveum.midpoint.prism.query.OrderDirection)6 SortParam (org.apache.wicket.extensions.markup.html.repeater.util.SortParam)6 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)4 SelectableBeanContainerDataProvider (com.evolveum.midpoint.web.component.data.SelectableBeanContainerDataProvider)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 SelectableBeanObjectDataProvider (com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider)2 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)2 TaskErrorSelectableBeanImpl (com.evolveum.midpoint.web.page.admin.server.dto.TaskErrorSelectableBeanImpl)2 TaskErrorSelectableBeanImplOld (com.evolveum.midpoint.web.page.admin.server.dto.TaskErrorSelectableBeanImplOld)2 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 CsvDownloadButtonPanel (com.evolveum.midpoint.gui.api.component.button.CsvDownloadButtonPanel)1 WebComponentUtil.safeLongToInteger (com.evolveum.midpoint.gui.api.util.WebComponentUtil.safeLongToInteger)1