Skip to content

Commit

Permalink
Re-implement hiding task link in role wizard
Browse files Browse the repository at this point in the history
The hiding of "(task link)" when assigning members in role wizard was
left out when doing the migration to "clockwork task processing". Now
it is back; with additional improvement of keeping the operation name
"as is", with adding the text "(running in background)".
  • Loading branch information
mederly committed Jun 22, 2023
1 parent f184bda commit 56853bb
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
package com.evolveum.midpoint.gui.api.component;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.result.OpResult;
import com.evolveum.midpoint.gui.api.component.tabs.CountablePanelTab;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon;
Expand All @@ -18,7 +18,6 @@
import com.evolveum.midpoint.gui.impl.component.search.Search;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.AbstractRoleSearchItemWrapper;
import com.evolveum.midpoint.gui.impl.page.admin.abstractrole.component.MemberOperationsTaskCreator;
import com.evolveum.midpoint.gui.impl.page.admin.abstractrole.component.TaskAwareExecutor;
import com.evolveum.midpoint.model.api.AssignmentCandidatesSpecification;
import com.evolveum.midpoint.model.api.AssignmentObjectRelation;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
Expand Down Expand Up @@ -130,12 +129,21 @@ public void onClick(AjaxRequestTarget target) {
if (selectedObjects == null || selectedObjects.size() == 0) {
continue;
}
executeAssignMemberOperation(

var pageBase = getPageBase();
var taskCreator = new MemberOperationsTaskCreator.Assign(
memberPanel.getAbstractRoleTypeObject(),
memberPanel.getObjectType().getTypeQName(), createInOidQuery(selectedObjects),
memberPanel.getRelationValue(),
target,
getPageBase());
memberPanel.getObjectType().getTypeQName(),
createInOidQuery(selectedObjects),
pageBase,
memberPanel.getRelationValue());

pageBase.taskAwareExecutor(target, taskCreator.getOperationName())
.withOpResultOptions(OpResult.Options.create()
.withHideTaskLinks(shouldHideTaskLink()))
.withCustomFeedbackPanel(getFeedbackPanel())
.run(taskCreator::createAndSubmitTask);

if (memberPanel.getObjectType().equals(ObjectTypes.ORG)) {
orgPanelProcessed = true;
}
Expand Down Expand Up @@ -417,14 +425,9 @@ private boolean isAddButtonEnabled() {
return false;
}

/** Returns task OID */
protected String executeAssignMemberOperation(
@NotNull AbstractRoleType targetObject, @NotNull QName memberType, @NotNull ObjectQuery memberQuery,
@NotNull QName relation, @NotNull AjaxRequestTarget target, @NotNull PageBase pageBase) {

var taskCreator = new MemberOperationsTaskCreator.Assign(targetObject, memberType, memberQuery, pageBase, relation);
return pageBase.taskAwareExecutor(target, taskCreator.getOperationName())
.run(taskCreator::createAndSubmitTask);
/** Should the "show task" link be hidden? This feature is used in wizards to avoid complexity for users. */
protected boolean shouldHideTaskLink() {
return false;
}

private IModel<List<CompositedIconButtonDto>> createAssignButtonDescriptionModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.wicket.model.Model;

import com.evolveum.midpoint.gui.api.page.PageAdminLTE;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Visitable;
import com.evolveum.midpoint.prism.Visitor;
Expand Down Expand Up @@ -175,15 +174,19 @@ private static IModel<String> createXmlModel(OperationResult result, PageAdminLT

// This method should be called along with getOpResult for root operationResult. However, it might take some time,
// and there might be situations in which it is not required -- so we opted for calling it explicitly.
public void determineObjectsVisibility(PageAdminLTE pageBase) {
determineBackgroundTaskVisibility(pageBase);
public void determineObjectsVisibility(PageAdminLTE pageBase, Options options) {
determineBackgroundTaskVisibility(pageBase, options.hideTaskLinks());
determineCaseVisibility(pageBase);
}

private void determineBackgroundTaskVisibility(PageAdminLTE pageBase) {
private void determineBackgroundTaskVisibility(PageAdminLTE pageBase, boolean explicitlyHidden) {
if (backgroundTaskOid == null) {
return;
}
if (explicitlyHidden) {
backgroundTaskVisible = false;
return;
}
try {
if (pageBase.isAuthorized(AuthorizationConstants.AUTZ_ALL_URL)) {
backgroundTaskVisible = true;
Expand Down Expand Up @@ -212,7 +215,6 @@ private void determineCaseVisibility(PageAdminLTE pageBase) {
caseVisible = false;
return;
}

if (caseOid == null) {
return;
}
Expand Down Expand Up @@ -312,14 +314,14 @@ public String getBackgroundTaskOid() {
return backgroundTaskOid;
}

public boolean isBackgroundTaskVisible() {
boolean isBackgroundTaskVisible() {
if (backgroundTaskVisible != null) {
return backgroundTaskVisible;
}
if (parent != null) {
return parent.isBackgroundTaskVisible();
}
return true; // at least as for now
return true; // at least as for now
}

public String getCaseOid() {
Expand All @@ -333,7 +335,7 @@ public boolean isCaseVisible() {
if (parent != null) {
return parent.isCaseVisible();
}
return true; // at least as for now
return true; // at least as for now
}

@Override
Expand All @@ -358,4 +360,29 @@ public void setShowMoreAll(final boolean show) {

accept(visitor);
}

/** Options for showing {@link OpResult} objects. */
public record Options (boolean hideSuccess,
boolean hideInProgress,
boolean hideTaskLinks) {

public static Options create() {
return new Options(false, false, false);
}

/** `SUCCESS` messages are hidden. */
public Options withHideSuccess(boolean value) {
return new Options(value, hideInProgress, hideTaskLinks);
}

/** `IN_PROGRESS` messages are hidden. */
public Options withHideInProgress(boolean value) {
return new Options(hideSuccess, value, hideTaskLinks);
}

/** Information about background tasks is not clickable. TODO better name? */
public Options withHideTaskLinks(boolean value) {
return new Options(hideSuccess, hideInProgress, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
<h3 class="card-title mw-100" style="word-break: break-all" wicket:id="message">
<i class="mr-2 fa" wicket:id="iconType"></i>
<span wicket:id="messageLabel"/>
<a class="text-sm" wicket:id="backgroundTask">
<a class="text-sm" wicket:id="backgroundTaskLink">
<wicket:message key="OperationResultPanel.showTask"/>
</a>
<span class="text-sm" wicket:id="backgroundTaskExists"></span>
<a class="text-sm" wicket:id="case">
<wicket:message key="OperationResultPanel.showCase"/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class OperationResultPanel extends BasePanel<OpResult> implements Popupab
private static final String ID_MESSAGE = "message";
private static final String ID_MESSAGE_LABEL = "messageLabel";
private static final String ID_PARAMS = "params";
private static final String ID_BACKGROUND_TASK = "backgroundTask";
private static final String ID_BACKGROUND_TASK_LINK = "backgroundTaskLink";
private static final String ID_BACKGROUND_TASK_EXISTS = "backgroundTaskExists";
private static final String ID_CASE = "case";
private static final String ID_SHOW_ALL = "showAll";
private static final String ID_HIDE_ALL = "hideAll";
Expand Down Expand Up @@ -126,7 +127,7 @@ public String getObject() {

box.add(message);

AjaxLink<String> backgroundTask = new AjaxLink<>(ID_BACKGROUND_TASK) {
AjaxLink<String> backgroundTaskLink = new AjaxLink<>(ID_BACKGROUND_TASK_LINK) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -140,8 +141,18 @@ public void onClick(AjaxRequestTarget target) {
WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false);
}
};
backgroundTask.add(new VisibleBehaviour(() -> getModelObject().getBackgroundTaskOid() != null && getModelObject().isBackgroundTaskVisible()));
message.add(backgroundTask);
backgroundTaskLink.add(new VisibleBehaviour(
() -> getModelObject().getBackgroundTaskOid() != null
&& getModelObject().isBackgroundTaskVisible()));
message.add(backgroundTaskLink);

Label backgroundTaskExists = new Label(
ID_BACKGROUND_TASK_EXISTS,
createStringResource("OperationResultPanel.taskExists"));
backgroundTaskExists.add(new VisibleBehaviour(
() -> getModelObject().getBackgroundTaskOid() != null
&& !getModelObject().isBackgroundTaskVisible()));
message.add(backgroundTaskExists);

AjaxLink<String> aCase = new AjaxLink<>(ID_CASE) {
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.evolveum.midpoint.repo.common.ObjectOperationPolicyHelper;

import com.evolveum.midpoint.schema.result.OperationResultStatus;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -854,41 +856,38 @@ public OpResult showResult(OperationResult result) {
}

public OpResult showResult(OperationResult result, String errorMessageKey, boolean showSuccess) {
return showResult(result, errorMessageKey,
OpResult.Options.create()
.withHideSuccess(!showSuccess));
}

// FIXME why the `errorMessageKey` is not used?
public OpResult showResult(OperationResult result, String errorMessageKey, @NotNull OpResult.Options options) {
Validate.notNull(result, "Operation result must not be null.");
Validate.notNull(result.getStatus(), "Operation result status must not be null.");

OperationResult scriptResult = executeResultScriptHook(result);
if (scriptResult == null) {
OperationResult processedResult = executeResultScriptHook(result);
if (processedResult == null) {
return null;
}

result = scriptResult;
OpResult opResult = OpResult.getOpResult((PageAdminLTE) getPage(), processedResult);

OpResult opResult = OpResult.getOpResult((PageAdminLTE) getPage(), result);
opResult.determineObjectsVisibility(this);
switch (opResult.getStatus()) {
case FATAL_ERROR:
case PARTIAL_ERROR:
getSession().error(opResult);

break;
case IN_PROGRESS:
case NOT_APPLICABLE:
getSession().info(opResult);
break;
case SUCCESS:
if (!showSuccess) {
break;
}
getSession().success(opResult);

break;
case UNKNOWN:
case WARNING:
default:
getSession().warn(opResult);
// Checking these options here to eliminate the rest of processing (visibility determination etc.) if not needed
if (opResult.getStatus() == OperationResultStatus.SUCCESS && options.hideSuccess()
|| opResult.getStatus() == OperationResultStatus.IN_PROGRESS && options.hideInProgress()) {
return opResult;
}

opResult.determineObjectsVisibility(this, options);

switch (opResult.getStatus()) {
case FATAL_ERROR, PARTIAL_ERROR -> getSession().error(opResult);
case IN_PROGRESS, NOT_APPLICABLE -> getSession().info(opResult);
case SUCCESS -> getSession().success(opResult);
default -> getSession().warn(opResult); // includes unknown and warning
}

return opResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.ChooseMemberPopup;
import com.evolveum.midpoint.gui.api.component.MainObjectListPanel;
import com.evolveum.midpoint.gui.api.component.result.OpResult;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil;
Expand Down Expand Up @@ -65,7 +64,6 @@
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -528,45 +526,36 @@ protected boolean isOrgTreeVisible() {
}

@Override
protected String executeAssignMemberOperation(
@NotNull AbstractRoleType targetObject, @NotNull QName memberType, @NotNull ObjectQuery memberQuery, @NotNull QName relation,
@NotNull AjaxRequestTarget target, @NotNull PageBase pageBase) {
var taskOid = super.executeAssignMemberOperation(targetObject, memberType, memberQuery, relation, target, pageBase);
// FIXME ... deal with this: processTaskAfterOperation(task, target);
return taskOid;
protected QName getRelationIfIsStable() {
return stableRelation;
}

@Override
protected QName getRelationIfIsStable() {
return stableRelation;
protected boolean shouldHideTaskLink() {
return AbstractRoleMemberPanel.this.shouldHideTaskLink();
}

@Override
public Component getFeedbackPanel() {
return AbstractRoleMemberPanel.this.getFeedback();
}
};
browser.setOutputMarkupId(true);
return browser;
}

/** FIXME implement somehow for the new task submission style */
protected void processTaskAfterOperation(Task task, AjaxRequestTarget target) {
}

protected void showMessageWithoutLinkForTask(Task task, AjaxRequestTarget target) {
getSession().getFeedbackMessages().clear(message -> message.getMessage() instanceof OpResult
&& OperationResultStatus.IN_PROGRESS.equals(((OpResult) message.getMessage()).getStatus()));

if (!task.getResult().isInProgress()) {
getPageBase().showResult(task.getResult());
} else {
getPageBase().info(createStringResource(
"AbstractRoleMemberPanel.message.info.created.task",
task.getResult().getOperation())
.getString());
// OperationResult showedResult = new OperationResult(task.getResult().getOperation());
// showedResult.setStatus(task.getResult().getStatus());
// getPageBase().showResult(showedResult);
}

refreshTable(target);
target.add(getFeedback());
/**
* Should the "show task" link be hidden for tasks submitted from this panel?
* This feature is used in wizards to avoid complexity for users.
*
* TODO originally, the role wizard showed "AbstractRoleMemberPanel.message.info.created.task"
* ("Task "{0}" has been created in the background") when there was a background task started.
* I originally planned to do so for any tasks. But is that really better than simply showing
* the original operation name with a blue color indicating "in progress" state and a text note
* "(running in background)"?
*/
protected boolean shouldHideTaskLink() {
return false;
}

protected AjaxIconButton createUnassignButton(String buttonId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,9 @@ protected void refreshTable(AjaxRequestTarget target) {
}

@Override
protected void processTaskAfterOperation(Task task, AjaxRequestTarget target) {
showMessageWithoutLinkForTask(task, target);
protected boolean shouldHideTaskLink() {
// This panel is used in wizard (at least I think so), hence we don't want to show task links.
return true;
}

@Override
Expand Down

0 comments on commit 56853bb

Please sign in to comment.