Skip to content

Commit

Permalink
Fixed MID-3799.9: when opening already-closed work item, more user fr…
Browse files Browse the repository at this point in the history
…iendly message is shown.
  • Loading branch information
mederly committed Jun 19, 2017
1 parent 0b72fcf commit cd2e63f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Expand Up @@ -140,7 +140,7 @@ private WorkItemDto loadWorkItemDtoIfNecessary() {
if (workItems.size() > 1) {
throw new SystemException("More than one work item with ID of " + taskId);
} else if (workItems.size() == 0) {
throw new SystemException("No work item with ID of " + taskId);
throw new ObjectNotFoundException("No work item with ID of " + taskId);
}
final WorkItemType workItem = workItems.get(0);

Expand Down Expand Up @@ -172,13 +172,17 @@ private WorkItemDto loadWorkItemDtoIfNecessary() {
workItemDto = new WorkItemDto(workItem, taskType, relatedTasks);
workItemDto.prepareDeltaVisualization("pageWorkItem.delta", getPrismContext(), getModelInteractionService(), task, result);
result.recordSuccessIfUnknown();
} catch (ObjectNotFoundException ex) {
result.recordFatalError(getString("PageWorkItem.couldNotGetWorkItem"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get work item because it does not exist. (It might have been already completed or deleted.)", ex);
} catch (CommonException|RuntimeException ex) {
result.recordFatalError("Couldn't get work item.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get work item.", ex);
}
showResult(result, false);
if (!result.isSuccess()) {
throw getRestartResponseException(PageDashboard.class);
throw redirectBackViaRestartResponseException();
//throw getRestartResponseException(PageDashboard.class);
}
return workItemDto;
}
Expand Down
Expand Up @@ -22,6 +22,8 @@
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
Expand All @@ -32,7 +34,6 @@
import com.evolveum.midpoint.web.page.admin.server.TaskChangesPanel;
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.forgetpassword.PageForgotPassword;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalStageDefinitionType;
Expand All @@ -59,7 +60,7 @@
*/
public class WorkItemPanel extends BasePanel<WorkItemDto> {

//private static final Trace LOGGER = TraceManager.getTrace(WorkItemPanel.class);
private static final Trace LOGGER = TraceManager.getTrace(WorkItemPanel.class);

private static final String ID_PRIMARY_INFO_COLUMN = "primaryInfoColumn";
private static final String ID_ADDITIONAL_INFO_COLUMN = "additionalInfoColumn";
Expand Down Expand Up @@ -212,12 +213,22 @@ public void onClick(AjaxRequestTarget target) {
WebMarkupContainer additionalInformation = new InformationListPanel(ID_ADDITIONAL_INFORMATION,
new PropertyModel<>(getModel(), WorkItemDto.F_ADDITIONAL_INFORMATION));
add(additionalInformation);
WorkItemDto dto = getModelObject();
ApprovalStageDefinitionType level = WfContextUtil.getCurrentStageDefinition(dto.getWorkflowContext());

WebMarkupContainer additionalAttribues = new WebMarkupContainer(ID_ADDITIONAL_ATTRIBUTES);
add(additionalAttribues);
additionalAttribues.add(new VisibleEnableBehaviour() {

WorkItemDto dto = null;
try {
dto = getModelObject();
} catch (Throwable t) {
// We don't want to process the exception in the constructor (e.g. because breadcrumbs are not initialized,
// so we are not able to return to the previous page, etc - see MID-3799.9). But we need to have the object
// here, if at all possible, to include dynamic form. So the hack is: if there's an error, just ignore it here.
// It will repeat when trying to draw the page. And then we will process it correctly.
LOGGER.debug("Ignoring getModelObject exception because we're in constructor. It will occur later and will be correctly processed then.", t);
getSession().getFeedbackMessages().clear();
}
ApprovalStageDefinitionType level = dto != null ? WfContextUtil.getCurrentStageDefinition(dto.getWorkflowContext()) : null;
WebMarkupContainer additionalAttributes = new WebMarkupContainer(ID_ADDITIONAL_ATTRIBUTES);
add(additionalAttributes);
additionalAttributes.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

Expand All @@ -235,9 +246,9 @@ public boolean isVisible() {
Task task = pageBase.createSimpleTask(OPERATION_LOAD_CUSTOM_FORM);
DynamicFormPanel<?> customForm = new DynamicFormPanel<>(ID_CUSTOM_FORM,
focus.asPrismObject(), formOid, mainForm, task, pageBase, false);
additionalAttribues.add(customForm);
additionalAttributes.add(customForm);
} else {
additionalAttribues.add(new Label(ID_CUSTOM_FORM));
additionalAttributes.add(new Label(ID_CUSTOM_FORM));
}

add(new TextArea<>(ID_APPROVER_COMMENT, new PropertyModel<String>(getModel(), WorkItemDto.F_APPROVER_COMMENT)));
Expand Down
Expand Up @@ -3682,3 +3682,4 @@ operation.com.evolveum.midpoint.web.page.admin.reports.PageCreatedReports.delete
operation.com.evolveum.midpoint.report.impl.ReportManagerImpl.deleteReportOutput=Delete report (Report)
operation.com.evolveum.midpoint.web.page.admin.reports.PageCreatedReports.downloadReport=Download report (GUI)
operation..com.evolveum.midpoint.report.impl.ReportManagerImpl.getReportOutputData=Load report (Report)
PageWorkItem.couldNotGetWorkItem=Couldn't get work item. It might have been already completed or deleted.

0 comments on commit cd2e63f

Please sign in to comment.