Skip to content

Commit

Permalink
My requests panel is added to user dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 5, 2015
1 parent 4d764a9 commit 6de46d5
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 9 deletions.
Expand Up @@ -28,11 +28,11 @@
<div wicket:id="workItemsPanel"/>
</div>
</div>
<!--<div class="row">-->
<!--<div class="col-md-12">-->
<!--<div wicket:id="requestPanel"/>-->
<!--</div>-->
<!--</div>-->
<div class="row">
<div class="col-md-12">
<div wicket:id="requestPanel"/>
</div>
</div>
</wicket:extend>
</body>
</html>
Expand Up @@ -7,6 +7,7 @@
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -20,13 +21,16 @@
import com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel;
import com.evolveum.midpoint.web.page.admin.home.component.DashboardColor;
import com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult;
import com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto;
import com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto;
import com.evolveum.midpoint.web.page.self.component.LinksPanel;
import com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel;
import com.evolveum.midpoint.web.page.self.component.MyRequestsPanel;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns.model.workflow.process_instance_state_3.ProcessInstanceState;
import org.apache.commons.lang.Validate;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand Down Expand Up @@ -58,7 +62,9 @@ public class PageSelfDashboard extends PageSelf {
private static final String ID_REQUESTS_PANEL = "requestPanel";
private static final String DOT_CLASS = PageSelfDashboard.class.getName() + ".";
private static final String OPERATION_LOAD_WORK_ITEMS = DOT_CLASS + "loadWorkItems";
private static final String OPERATION_LOAD_REQUESTS = DOT_CLASS + "loadRequests";
private static final int MAX_WORK_ITEMS = 1000;
private static final int MAX_REQUESTS = 1000;
private final Model<PrismObject<UserType>> principalModel = new Model<PrismObject<UserType>>();
private static final String OPERATION_LOAD_USER = DOT_CLASS + "loadUser";
private static final String TASK_GET_SYSTEM_CONFIG = DOT_CLASS + "getSystemConfiguration";
Expand Down Expand Up @@ -133,6 +139,38 @@ public boolean isVisible() {
});
add(workItemsPanel);

AsyncDashboardPanel<Object, List<ProcessInstanceDto>> myRequestsPanel =
new AsyncDashboardPanel<Object, List<ProcessInstanceDto>>(ID_REQUESTS_PANEL, createStringResource("PageSelfDashboard.myRequests"),
"fa fa-fw fa-pencil-square-o", DashboardColor.GREEN) {

@Override
protected SecurityContextAwareCallable<CallableResult<List<ProcessInstanceDto>>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<ProcessInstanceDto>>>(
getSecurityEnforcer(), auth) {

@Override
public CallableResult<List<ProcessInstanceDto>> callWithContextPrepared() throws Exception {
return loadMyRequests();
}
};
}

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

myRequestsPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getWorkflowManager().isEnabled();
}
});
add(myRequestsPanel);

}

private CallableResult<List<WorkItemDto>> loadWorkItems() {
Expand Down Expand Up @@ -173,6 +211,55 @@ private CallableResult<List<WorkItemDto>> loadWorkItems() {
return callableResult;
}

private CallableResult<List<ProcessInstanceDto>> loadMyRequests() {

LOGGER.debug("Loading requests.");

AccountCallableResult callableResult = new AccountCallableResult();
List<ProcessInstanceDto> list = new ArrayList<ProcessInstanceDto>();
callableResult.setValue(list);

if (!getWorkflowManager().isEnabled()) {
return callableResult;
}

PrismObject<UserType> user = principalModel.getObject();
if (user == null) {
return callableResult;
}

OperationResult result = new OperationResult(OPERATION_LOAD_REQUESTS);
callableResult.setResult(result);

try {
List<WfProcessInstanceType> processInstanceTypes = getWorkflowService().listProcessInstancesRelatedToUser(user.getOid(),
false, false, false, 0, MAX_REQUESTS, result);
for (WfProcessInstanceType processInstanceType : processInstanceTypes) {
ProcessInstanceState processInstanceState = (ProcessInstanceState) processInstanceType.getState();
Task shadowTask = null;
if (processInstanceState != null) {
String shadowTaskOid = processInstanceState.getShadowTaskOid();
try {
shadowTask = getTaskManager().getTask(shadowTaskOid, result);
} catch (ObjectNotFoundException e) {
// task is already deleted, no problem here
}
}

list.add(new ProcessInstanceDto(processInstanceType, shadowTask));
}
} catch (Exception e) {
result.recordFatalError("Couldn't get list of work items.", e);
}

result.recordSuccessIfUnknown();
result.recomputeStatus();

LOGGER.debug("Finished requests loading.");

return callableResult;
}

private PrismObject<UserType> loadUser() {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
Validate.notNull(principal, "No principal");
Expand Down

This file was deleted.

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2010-2013 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div wicket:id="requestsTable"/>
</wicket:panel>
</html>
@@ -0,0 +1,84 @@
package com.evolveum.midpoint.web.page.self.component;

import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.web.component.data.TablePanel;
import com.evolveum.midpoint.web.component.data.column.LinkColumn;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.page.admin.workflow.PageProcessInstance;
import com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* Created by Kate on 03.10.2015.
*/
public class MyRequestsPanel extends SimplePanel<List<ProcessInstanceDto>> {
private static final String ID_REQUESTS_TABLE = "requestsTable";

public MyRequestsPanel(String id) {
super(id, null);
}

public MyRequestsPanel(String id, IModel<List<ProcessInstanceDto>> model) {
super(id, model);
}

@Override
protected void initLayout() {
List<IColumn<ProcessInstanceDto, String>> columns = new ArrayList<IColumn<ProcessInstanceDto, String>>();
columns.add(new LinkColumn<ProcessInstanceDto>(createStringResource("MyRequestsPanel.waitingFor"), "name") {

@Override
public void onClick(AjaxRequestTarget target, IModel<ProcessInstanceDto> rowModel) {
ProcessInstanceDto piDto = rowModel.getObject();
itemDetailsPerformed(target, false, piDto.getProcessInstance().getProcessInstanceId());
}
});
columns.add(new AbstractColumn<ProcessInstanceDto, String>(createStringResource("MyRequestsPanel.started")) {

@Override
public void populateItem(Item<ICellPopulator<ProcessInstanceDto>> item, String componentId,
final IModel<ProcessInstanceDto> rowModel) {
item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() {

@Override
public Object getObject() {
ProcessInstanceDto pi = rowModel.getObject();
Date started = XmlTypeConverter.toDate(pi.getProcessInstance().getStartTimestamp());
if (started == null) {
return "?";
} else {
// todo i18n
return DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - started.getTime(), true, true) + " ago";
}
}
}));
}
});
ISortableDataProvider provider = new ListDataProvider(this, getModel());
TablePanel accountsTable = new TablePanel<ProcessInstanceDto>(ID_REQUESTS_TABLE, provider, columns);
add(accountsTable);
}

private void itemDetailsPerformed(AjaxRequestTarget target, boolean finished, String pid) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, pid);
parameters.add(PageProcessInstance.PARAM_PROCESS_INSTANCE_FINISHED, finished);
setResponsePage(new PageProcessInstance(parameters, this.getPageBase()));
}
}
Expand Up @@ -2724,4 +2724,10 @@ PageTemplate.user=user
PageTemplate.couldntNavigateBreadcrumb=Couldn't navigate breadcrumb, reason: {0}
SystemInfoPanel.starttime=Start time
SystemInfoPanel.uptime=Uptime
CountToolbar.label.unknownCount=Displaying {0,number,integer} to {1,number,integer}, unknown number of matching results.
CountToolbar.label.unknownCount=Displaying {0,number,integer} to {1,number,integer}, unknown number of matching results.
MyRequestsPanel.started = Started
MyRequestsPanel.waitingFor = Waiting for
MyRequestsPanel.name = Name
PageSelfDashboard.title=Dashboard
PageSelfDashboard.workItems=My work items
PageSelfDashboard.myRequests=My requests

0 comments on commit 6de46d5

Please sign in to comment.