Search in sources :

Example 1 with AccountCallableResult

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

the class PageSelfDashboard method loadWorkItems.

private CallableResult<List<WorkItemDto>> loadWorkItems() {
    LOGGER.debug("Loading work items.");
    AccountCallableResult callableResult = new AccountCallableResult();
    List<WorkItemDto> list = new ArrayList<>();
    callableResult.setValue(list);
    if (!getWorkflowManager().isEnabled()) {
        return callableResult;
    }
    PrismObject<UserType> user = principalModel.getObject();
    if (user == null) {
        return callableResult;
    }
    Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEMS);
    OperationResult result = task.getResult();
    callableResult.setResult(result);
    try {
        ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()).item(WorkItemType.F_ASSIGNEE_REF).ref(user.getOid()).desc(F_CREATE_TIMESTAMP).build();
        Collection<SelectorOptions<GetOperationOptions>> options = GetOperationOptions.resolveItemsNamed(new ItemPath(T_PARENT, WfContextType.F_OBJECT_REF), new ItemPath(T_PARENT, WfContextType.F_TARGET_REF));
        List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result);
        for (WorkItemType workItem : workItems) {
            list.add(new WorkItemDto(workItem));
        }
    } catch (Exception e) {
        result.recordFatalError("Couldn't get list of work items.", e);
    }
    result.recordSuccessIfUnknown();
    result.recomputeStatus();
    LOGGER.debug("Finished work items loading.");
    return callableResult;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with AccountCallableResult

use of com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult 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 3 with AccountCallableResult

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

the class PageSelfDashboard method loadMyRequests.

private CallableResult<List<ProcessInstanceDto>> loadMyRequests() {
    LOGGER.debug("Loading requests.");
    AccountCallableResult<List<ProcessInstanceDto>> callableResult = new AccountCallableResult<>();
    List<ProcessInstanceDto> list = new ArrayList<ProcessInstanceDto>();
    callableResult.setValue(list);
    if (!getWorkflowManager().isEnabled()) {
        return callableResult;
    }
    ProcessInstanceDtoProvider provider = new ProcessInstanceDtoProvider(this, true, false);
    provider.iterator(0, Integer.MAX_VALUE);
    callableResult.setValue(provider.getAvailableData());
    LOGGER.debug("Finished requests loading.");
    return callableResult;
}
Also used : ProcessInstanceDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) ProcessInstanceDtoProvider(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider)

Example 4 with AccountCallableResult

use of com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult 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 5 with AccountCallableResult

use of com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult 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

AccountCallableResult (com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 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 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 Task (com.evolveum.midpoint.task.api.Task)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 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ProcessInstanceDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto)1 ProcessInstanceDtoProvider (com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider)1 WorkItemDto (com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto)1