Skip to content

Commit

Permalink
Fixing process instances on dashboard page.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 23, 2016
1 parent 80a9143 commit 0f7fd62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 47 deletions.
Expand Up @@ -126,20 +126,6 @@ private TablePanel getTable() {
return (TablePanel) get("mainForm:processInstancesTable");
}

// private List<ProcessInstanceDto> getSelectedItems() {
// DataTable table = getTable().getDataTable();
// ProcessInstanceDtoProvider provider = (ProcessInstanceDtoProvider) table.getDataProvider();
//
// List<ProcessInstanceDto> selected = new ArrayList<ProcessInstanceDto>();
// for (ProcessInstanceDto row : provider.getAvailableData()) {
// if (row.isSelected()) {
// selected.add(row);
// }
// }
//
// return selected;
// }

private boolean isSomeItemSelected(List<ProcessInstanceDto> instances, AjaxRequestTarget target) {
if (!instances.isEmpty()) {
return true;
Expand Down
Expand Up @@ -41,6 +41,7 @@
import com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult;
import com.evolveum.midpoint.web.page.admin.workflow.WorkflowRequestsPanel;
import com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto;
import com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider;
import com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto;
import com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel;
import com.evolveum.midpoint.web.page.self.component.LinksPanel;
Expand All @@ -50,7 +51,9 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType;
import org.apache.commons.lang.Validate;
import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
Expand Down Expand Up @@ -96,6 +99,8 @@ public PageSelfDashboard() {
initLayout();
}

private transient Application application;

@Override
protected void createBreadcrumb() {
super.createBreadcrumb();
Expand Down Expand Up @@ -131,7 +136,7 @@ public void detach() {
});
add(linksPanel);

final PrismContext prismContext = getPrismContext();
application = getApplication();

AsyncDashboardPanel<Object, List<WorkItemDto>> workItemsPanel =
new AsyncDashboardPanel<Object, List<WorkItemDto>>(ID_WORK_ITEMS_PANEL, createStringResource("PageSelfDashboard.workItems"),
Expand All @@ -146,7 +151,10 @@ protected SecurityContextAwareCallable<CallableResult<List<WorkItemDto>>> create

@Override
public CallableResult<List<WorkItemDto>> callWithContextPrepared() throws Exception {
return loadWorkItems(prismContext);
if (!Application.exists()) {
ThreadContext.setApplication(application);
}
return loadWorkItems();
}
};
}
Expand Down Expand Up @@ -179,7 +187,10 @@ protected SecurityContextAwareCallable<CallableResult<List<ProcessInstanceDto>>>

@Override
public CallableResult<List<ProcessInstanceDto>> callWithContextPrepared() throws Exception {
return loadMyRequests(prismContext);
if (!Application.exists()) {
ThreadContext.setApplication(application);
}
return loadMyRequests();
}
};
}
Expand All @@ -201,7 +212,7 @@ public boolean isVisible() {

}

private CallableResult<List<WorkItemDto>> loadWorkItems(PrismContext prismContext) {
private CallableResult<List<WorkItemDto>> loadWorkItems() {

LOGGER.debug("Loading work items.");

Expand All @@ -223,7 +234,7 @@ private CallableResult<List<WorkItemDto>> loadWorkItems(PrismContext prismContex
callableResult.setResult(result);

try {
ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, prismContext)
ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext())
.item(WorkItemType.F_ASSIGNEE_REF).ref(user.getOid())
.desc(F_WORK_ITEM_CREATED_TIMESTAMP)
.build();
Expand All @@ -243,44 +254,21 @@ private CallableResult<List<WorkItemDto>> loadWorkItems(PrismContext prismContex
return callableResult;
}

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

LOGGER.debug("Loading requests.");

AccountCallableResult callableResult = new AccountCallableResult();
AccountCallableResult<List<ProcessInstanceDto>> 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;
}

Task opTask = createSimpleTask(OPERATION_LOAD_REQUESTS);
OperationResult result = opTask.getResult();
callableResult.setResult(result);

try {
ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext)
.item(F_WORKFLOW_CONTEXT, F_REQUESTER_REF).ref(user.getOid())
.and().not().item(F_WORKFLOW_CONTEXT, F_PROCESS_INSTANCE_ID).isNull()
.desc(F_WORKFLOW_CONTEXT, F_START_TIMESTAMP)
.build();

List<PrismObject<TaskType>> tasks = getModelService().searchObjects(TaskType.class, query, null, opTask, result);
for (PrismObject<TaskType> task : tasks) {
list.add(new ProcessInstanceDto(task.asObjectable()));
}
} catch (Exception e) {
result.recordFatalError("Couldn't get list of work items.", e);
}

result.recordSuccessIfUnknown();
result.recomputeStatus();
ProcessInstanceDtoProvider provider = new ProcessInstanceDtoProvider(this, true, false);
provider.iterator(0, Integer.MAX_VALUE);
callableResult.setValue(provider.getAvailableData());

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

Expand Down

0 comments on commit 0f7fd62

Please sign in to comment.