Skip to content

Commit

Permalink
adding 'show case' to result panel (MID-5425)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 2, 2019
1 parent 0d49aea commit ed9ec58
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
Expand Up @@ -29,6 +29,7 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;

Expand All @@ -55,6 +56,7 @@ public class OpResult implements Serializable, Visitable {
private static final Trace LOGGER = TraceManager.getTrace(OpResult.class);

private static final String OPERATION_CHECK_TASK_VISIBILITY = OpResult.class.getName() + ".checkTaskVisibility";
private static final String OPERATION_CHECK_CASE_VISIBILITY = OpResult.class.getName() + ".checkCaseVisibility";

private OperationResultStatus status;
private String operation;
Expand All @@ -72,7 +74,10 @@ public class OpResult implements Serializable, Visitable {
// we assume there is at most one background task created (TODO revisit this assumption)
private String backgroundTaskOid;
private Boolean backgroundTaskVisible; // available on root opResult only


private String caseOid;
private Boolean caseVisible;

private boolean showMore;
private boolean showError;

Expand Down Expand Up @@ -163,6 +168,11 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {
if (result.getBackgroundTaskOid() != null) {
opResult.backgroundTaskOid = result.getBackgroundTaskOid();
}

String caseOid = OperationResult.referenceToCaseOid(result.findAsynchronousOperationReference());
if(caseOid != null) {
opResult.caseOid = caseOid;
}

try {
OperationResultType resultType = result.createOperationResultType();
Expand All @@ -179,7 +189,12 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {

// 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 determineBackgroundTaskVisibility(PageBase pageBase) {
public void determineObjectsVisibility(PageBase pageBase) {
determineBackgroundTaskVisibility(pageBase);
determineCaseVisibility(pageBase);
}

private void determineBackgroundTaskVisibility(PageBase pageBase) {
if (backgroundTaskOid == null) {
return;
}
Expand All @@ -203,6 +218,31 @@ public void determineBackgroundTaskVisibility(PageBase pageBase) {
backgroundTaskVisible = false;
}
}

private void determineCaseVisibility(PageBase pageBase) {
if (caseOid == null) {
return;
}
try {
if (pageBase.isAuthorized(AuthorizationConstants.AUTZ_ALL_URL)) {
caseVisible = true;
return;
}
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
caseVisible = false;
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't determine case visibility", e);
return;
}

Task task = pageBase.createSimpleTask(OPERATION_CHECK_CASE_VISIBILITY);
try {
pageBase.getModelService().getObject(CaseType.class, caseOid, null, task, task.getResult());
caseVisible = true;
} catch (ObjectNotFoundException|SchemaException|SecurityViolationException|CommunicationException|ConfigurationException|ExpressionEvaluationException e) {
LOGGER.debug("Case {} is not visible by the current user: {}: {}", caseOid, e.getClass(), e.getMessage());
caseVisible = false;
}
}

public boolean isShowMore() {
return showMore;
Expand Down Expand Up @@ -282,6 +322,20 @@ public boolean isBackgroundTaskVisible() {
}
return true; // at least as for now
}

public String getCaseOid() {
return caseOid;
}

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

@Override
public void accept(Visitor visitor) {
Expand Down
Expand Up @@ -24,6 +24,9 @@
</a>
<a class="box-title" wicket:id="backgroundTask">
<wicket:message key="OperationResultPanel.showTask"/>
</a>
<a class="box-title" wicket:id="case">
<wicket:message key="OperationResultPanel.showCase"/>
</a>
<div class="box-tools pull-right">
<a wicket:id="showAll" class="btn btn-box-tool">
Expand Down
Expand Up @@ -69,6 +69,7 @@ public class OperationResultPanel extends BasePanel<OpResult> implements Popupab
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_CASE = "case";
private static final String ID_SHOW_ALL = "showAll";
private static final String ID_HIDE_ALL = "hideAll";
private static final String ID_ERROR_STACK_TRACE = "errorStackTrace";
Expand Down Expand Up @@ -173,6 +174,31 @@ public boolean isVisible() {
}
});
box.add(backgroundTask);

AjaxLink<String> aCase = new AjaxLink<String>(ID_CASE) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
final OpResult opResult = OperationResultPanel.this.getModelObject();
String oid = opResult.getCaseOid();
if (oid == null || !opResult.isCaseVisible()) {
return; // just for safety
}
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.CASE);
WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false);
}
};
aCase.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return getModelObject().getCaseOid() != null
&& getModelObject().isCaseVisible();
}
});
box.add(aCase);

AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -1374,7 +1374,7 @@ public OpResult showResult(OperationResult result, String errorMessageKey, boole
result = scriptResult;

OpResult opResult = OpResult.getOpResult((PageBase) getPage(), result);
opResult.determineBackgroundTaskVisibility(this);
opResult.determineObjectsVisibility(this);
switch (opResult.getStatus()) {
case FATAL_ERROR:
case PARTIAL_ERROR:
Expand Down

0 comments on commit ed9ec58

Please sign in to comment.