Skip to content

Commit

Permalink
OpResult and OperationResultPanel improvements (MID-6266)
Browse files Browse the repository at this point in the history
- create xml model instead of pre-parsed string
- do it only for top level
  • Loading branch information
katkav committed May 25, 2020
1 parent b0b3cc0 commit 767b71b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.gui.api.component.result;

import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Visitable;
Expand All @@ -27,6 +28,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.Validate;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;

Expand Down Expand Up @@ -59,7 +61,7 @@ public class OpResult implements Serializable, Visitable {
private List<OpResult> subresults;
private OpResult parent;
private int count;
private String xml;
private IModel<String> xml;
private LocalizableMessage userFriendlyMessage;

// we assume there is at most one background task created (TODO revisit this assumption)
Expand Down Expand Up @@ -165,17 +167,29 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {
opResult.caseOid = caseOid;
}

if (opResult.parent == null) {
opResult.xml = createXmlModel(result, page);
}
return opResult;
}

private static IModel<String> createXmlModel(OperationResult result, PageBase page) {
try {
OperationResultType resultType = result.createOperationResultType();
ObjectFactory of = new ObjectFactory();
opResult.xml = page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType));
} catch (SchemaException | RuntimeException ex) {
return new ReadOnlyModel<String>(() -> {
try {
return page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType));
} catch (SchemaException e) {
throw new TunnelException(e);
}
});
} catch (RuntimeException ex) {
String m = "Can't create xml: " + ex;
// error(m);
opResult.xml = "<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>";
return Model.of("<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>");
// throw ex;
}
return opResult;
}

// This method should be called along with getOpResult for root operationResult. However, it might take some time,
Expand Down Expand Up @@ -301,8 +315,12 @@ public int getCount() {
return count;
}

public boolean isParent() {
return parent == null;
}

public String getXml() {
return xml;
return xml.getObject();
}

public String getBackgroundTaskOid() {
Expand Down
Expand Up @@ -15,6 +15,8 @@
import java.util.List;
import java.util.Locale;

import com.evolveum.midpoint.web.component.util.VisibleBehaviour;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
Expand Down Expand Up @@ -258,6 +260,7 @@ public File getObject() {
}

});
downloadXml.add(new VisibleBehaviour(() -> getModelObject().isParent()));
downloadXml.setDeleteAfterDownload(true);
box.add(downloadXml);
}
Expand Down

0 comments on commit 767b71b

Please sign in to comment.