Search in sources :

Example 6 with TreeSelectableBean

use of com.evolveum.midpoint.web.component.util.TreeSelectableBean in project midpoint by Evolveum.

the class OrgTreeProvider method createObjectWrapper.

private TreeSelectableBean<OrgType> createObjectWrapper(TreeSelectableBean<OrgType> parent, PrismObject<OrgType> unit) {
    if (unit == null) {
        return null;
    }
    // todo relation [lazyman]
    OrgType org = unit.asObjectable();
    if (parent != null) {
        org.getParentOrgRef().clear();
        ObjectReferenceType parentOrgRef = new ObjectReferenceType();
        parentOrgRef.asReferenceValue().setObject(parent.getValue().asPrismObject());
        org.getParentOrgRef().add(parentOrgRef);
    }
    TreeSelectableBean<OrgType> orgDto = new TreeSelectableBean<>(org);
    return orgDto;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean)

Example 7 with TreeSelectableBean

use of com.evolveum.midpoint.web.component.util.TreeSelectableBean in project midpoint by Evolveum.

the class OrgTreeProvider method getChildren.

@Override
public Iterator<? extends TreeSelectableBean<OrgType>> getChildren(TreeSelectableBean<OrgType> node) {
    LOGGER.debug("Getting children for {}", node.getValue());
    String nodeOid = node.getValue().getOid();
    List<TreeSelectableBean<OrgType>> children;
    long currentTime = System.currentTimeMillis();
    if (currentTime > lastFetchOperation + EXPIRATION_AFTER_LAST_FETCH_OPERATION) {
        childrenCache.clear();
    }
    if (childrenCache.containsKey(nodeOid)) {
        LOGGER.debug("Using cached children for {}", node.getValue());
        children = childrenCache.get(nodeOid);
    } else {
        LOGGER.debug("Loading fresh children for {}", node.getValue());
        OperationResult result = new OperationResult(LOAD_ORG_UNITS);
        try {
            ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
            ObjectFilter customFilter = getCustomFilter();
            if (customFilter != null) {
                query.addFilter(customFilter);
            }
            Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
            ObjectPaging paging = createPaging(node);
            query.setPaging(paging);
            List<PrismObject<OrgType>> orgs = getModelService().searchObjects(OrgType.class, query, null, task, result);
            LOGGER.debug("Found {} sub-orgs.", orgs.size());
            children = new ArrayList<>();
            for (PrismObject<OrgType> org : orgs) {
                children.add(createObjectWrapper(node, org));
            }
            childrenCache.put(nodeOid, children);
        } catch (CommonException | RuntimeException ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
            result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
            children = new ArrayList<>();
        } finally {
            result.computeStatus();
        }
        if (WebComponentUtil.showResultInPage(result)) {
            getPageBase().showResult(result);
            throw new RestartResponseException(PageOrgTree.class);
        }
        children.forEach(orgUnit -> {
            getAvailableData().putIfAbsent(orgUnit.getValue().getOid(), orgUnit);
        });
    }
    LOGGER.debug("Finished getting children.");
    lastFetchOperation = System.currentTimeMillis();
    return children.iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) RestartResponseException(org.apache.wicket.RestartResponseException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 8 with TreeSelectableBean

use of com.evolveum.midpoint.web.component.util.TreeSelectableBean in project midpoint by Evolveum.

the class RoleCatalogTabPanel method initLeftSidePanel.

@Override
protected void initLeftSidePanel() {
    if (StringUtils.isEmpty(getRoleCatalogStorage().getSelectedOid())) {
        getRoleCatalogStorage().setSelectedOid(roleCatalogOid);
    }
    WebMarkupContainer treePanelContainer = new WebMarkupContainer(ID_TREE_PANEL_CONTAINER);
    treePanelContainer.setOutputMarkupId(true);
    add(treePanelContainer);
    OrgTreePanel treePanel = new OrgTreePanel(ID_TREE_PANEL, Model.of(roleCatalogOid), false, getPageBase(), "AssignmentShoppingCartPanel.treeTitle") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void selectTreeItemPerformed(TreeSelectableBean<OrgType> selected, AjaxRequestTarget target) {
            setSelected(selected);
            refreshContentPannels();
            RoleCatalogTabPanel.this.selectTreeItemPerformed(selected, target);
        }

        protected List<InlineMenuItem> createTreeMenu() {
            return new ArrayList<>();
        }

        @Override
        protected List<InlineMenuItem> createTreeChildrenMenu(TreeSelectableBean<OrgType> org) {
            return new ArrayList<>();
        }

        @Override
        public OrgTreeStateStorage getOrgTreeStateStorage() {
            return getRoleCatalogStorage();
        }
    };
    treePanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isRootOrgExists();
        }
    });
    treePanel.setOutputMarkupId(true);
    treePanelContainer.add(treePanel);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) OrgTreePanel(com.evolveum.midpoint.web.page.admin.orgs.OrgTreePanel) ArrayList(java.util.ArrayList) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

TreeSelectableBean (com.evolveum.midpoint.web.component.util.TreeSelectableBean)8 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 OrgTreePanel (com.evolveum.midpoint.web.page.admin.orgs.OrgTreePanel)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 IModel (org.apache.wicket.model.IModel)2 DropdownButtonDto (com.evolveum.midpoint.gui.api.component.button.DropdownButtonDto)1 DropdownButtonPanel (com.evolveum.midpoint.gui.api.component.button.DropdownButtonPanel)1 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 MidpointNestedTree (com.evolveum.midpoint.web.page.admin.orgs.MidpointNestedTree)1 OrgTreeProvider (com.evolveum.midpoint.web.page.admin.users.component.OrgTreeProvider)1