Search in sources :

Example 1 with SimpleAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto in project midpoint by Evolveum.

the class PageSelfDashboard method initMyAccounts.

private void initMyAccounts() {
    AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<Object, List<SimpleAccountDto>>(ID_ACCOUNTS, createStringResource("PageDashboard.accounts"), GuiStyleConstants.CLASS_SHADOW_ICON_ACCOUNT, GuiStyleConstants.CLASS_OBJECT_SHADOW_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>> createCallable(Authentication auth, IModel<Object> callableParameterModel) {
            return new SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>>(getSecurityEnforcer(), auth) {

                @Override
                public AccountCallableResult<List<SimpleAccountDto>> callWithContextPrepared() throws Exception {
                    return loadAccounts();
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new MyAccountsPanel(markupId, new PropertyModel<List<SimpleAccountDto>>(getModel(), CallableResult.F_VALUE));
        }

        @Override
        protected void onPostSuccess(AjaxRequestTarget target) {
            showFetchResult();
            super.onPostSuccess(target);
        }

        @Override
        protected void onUpdateError(AjaxRequestTarget target, Exception ex) {
            showFetchResult();
            super.onUpdateError(target, ex);
        }

        private void showFetchResult() {
            AccountCallableResult<List<SimpleAccountDto>> result = (AccountCallableResult<List<SimpleAccountDto>>) getModel().getObject();
            PageBase page = (PageBase) getPage();
            for (OperationResult res : result.getFetchResults()) {
                if (!WebComponentUtil.isSuccessOrHandledError(res)) {
                    page.showResult(res);
                }
            }
        }
    };
    accounts.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_ACCOUNTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(accounts);
}
Also used : IModel(org.apache.wicket.model.IModel) SimpleAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) MyAccountsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyAccountsPanel) Authentication(org.springframework.security.core.Authentication) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)

Example 2 with SimpleAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto in project midpoint by Evolveum.

the class PageSelfDashboard method initMyAccounts.

private void initMyAccounts(Session session) {
    AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<>(ID_ACCOUNTS, createStringResource("PageDashboard.accounts"), GuiStyleConstants.CLASS_SHADOW_ICON_ACCOUNT, GuiStyleConstants.CLASS_OBJECT_SHADOW_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>> createCallable(Authentication auth, IModel<Object> callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public AccountCallableResult<List<SimpleAccountDto>> callWithContextPrepared() {
                    // TODO is this correct? [med]
                    setupContext(application, session);
                    return loadAccounts();
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new MyAccountsPanel(markupId, new PropertyModel<>(getModel(), CallableResult.F_VALUE));
        }

        @Override
        protected void onPostSuccess(AjaxRequestTarget target) {
            showFetchResult();
            super.onPostSuccess(target);
        }

        @Override
        protected void onUpdateError(AjaxRequestTarget target, Exception ex) {
            showFetchResult();
            super.onUpdateError(target, ex);
        }

        private void showFetchResult() {
            AccountCallableResult<List<SimpleAccountDto>> result = (AccountCallableResult<List<SimpleAccountDto>>) getModel().getObject();
            PageBase page = (PageBase) getPage();
            for (OperationResult res : result.getFetchResults()) {
                if (!WebComponentUtil.isSuccessOrHandledError(res)) {
                    page.showResult(res);
                }
            }
        }
    };
    accounts.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_ACCOUNTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(accounts);
}
Also used : IModel(org.apache.wicket.model.IModel) SimpleAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) MyAccountsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyAccountsPanel) Authentication(org.springframework.security.core.Authentication) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collections.emptyList(java.util.Collections.emptyList) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)

Example 3 with SimpleAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto in project midpoint by Evolveum.

the class PageSelfDashboard method loadAccounts.

private AccountCallableResult<List<SimpleAccountDto>> loadAccounts() {
    LOGGER.debug("Loading accounts.");
    AccountCallableResult callableResult = new AccountCallableResult();
    List<SimpleAccountDto> list = new ArrayList<>();
    callableResult.setValue(list);
    FocusType focus = AuthUtil.getPrincipalUser().getFocus();
    Task task = createSimpleTask(OPERATION_LOAD_ACCOUNTS);
    OperationResult result = task.getResult();
    callableResult.setResult(result);
    Collection<SelectorOptions<GetOperationOptions>> options = getOperationOptionsBuilder().root().resolveNames().noFetch().item(ShadowType.F_RESOURCE_REF).resolve().noFetch().build();
    List<ObjectReferenceType> references = focus.getLinkRef();
    for (ObjectReferenceType reference : references) {
        PrismObject<ShadowType> account = WebModelServiceUtils.loadObject(ShadowType.class, reference.getOid(), options, this, task, result);
        if (account == null) {
            continue;
        }
        ShadowType accountType = account.asObjectable();
        OperationResultType fetchResult = accountType.getFetchResult();
        if (fetchResult != null) {
            callableResult.getFetchResults().add(OperationResult.createOperationResult(fetchResult));
        }
        String resourceName = WebComponentUtil.getName(accountType.getResourceRef());
        list.add(new SimpleAccountDto(WebComponentUtil.getOrigStringFromPoly(accountType.getName()), resourceName));
    }
    result.recordSuccessIfUnknown();
    result.recomputeStatus();
    LOGGER.debug("Finished accounts loading.");
    return callableResult;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SimpleAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 AccountCallableResult (com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)3 SimpleAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto)3 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)2 CallableResult (com.evolveum.midpoint.web.component.util.CallableResult)2 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 AsyncDashboardPanel (com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel)2 MyAccountsPanel (com.evolveum.midpoint.web.page.admin.home.component.MyAccountsPanel)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 IModel (org.apache.wicket.model.IModel)2 Authentication (org.springframework.security.core.Authentication)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 Task (com.evolveum.midpoint.task.api.Task)1 Collections.emptyList (java.util.Collections.emptyList)1