Skip to content

Commit

Permalink
fix for MID-4458 AdminGuiConfiguration - Custom columns (extension at…
Browse files Browse the repository at this point in the history
…tributes)
  • Loading branch information
KaterynaHonchar committed Feb 21, 2018
1 parent a60a5ed commit 2306e22
Showing 1 changed file with 43 additions and 2 deletions.
Expand Up @@ -17,8 +17,11 @@

import java.util.*;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -29,6 +32,7 @@
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
Expand Down Expand Up @@ -260,9 +264,46 @@ protected List<IColumn<SelectableBean<O>, String>> getCustomColumnsTransformed(L
Model.of(customColumn.getDisplay().getLabel()) : createStringResource(getItemDisplayName(customColumn)),
customColumn.getPath().toString());
} else {
column = new PropertyColumn(customColumn.getDisplay() != null && customColumn.getDisplay().getLabel() != null ?
column = new PropertyColumn<SelectableBean<O>, String>(customColumn.getDisplay() != null && customColumn.getDisplay().getLabel() != null ?
Model.of(customColumn.getDisplay().getLabel()) : createStringResource(getItemDisplayName(customColumn)), null,
SelectableBean.F_VALUE + "." + customColumn.getPath());
SelectableBean.F_VALUE + "." + customColumn.getPath().toString().replaceAll("/", ".")){
private static final long serialVersionUID = 1L;

@Override
public IModel<?> getDataModel(IModel<SelectableBean<O>> rowModel) {
ItemPathType itemPathType = customColumn.getPath();
if (itemPathType != null
&& itemPathType.getItemPath() != null) {
if (itemPathType.getItemPath().toString().contains(ObjectType.F_EXTENSION.getLocalPart() + "/")) {

O rowModelObject = rowModel.getObject().getValue();
if (rowModelObject.getExtension() != null) {
ExtensionType extensionType = rowModelObject.getExtension();
Item item = extensionType.asPrismContainerValue().findItem(itemPathType.getItemPath().lastNamed().getName());
if (item != null && item.getValues() != null) {
StringBuilder sb = new StringBuilder();
item.getValues().forEach(itemValue -> {
if (StringUtils.isNotEmpty(sb.toString())) {
sb.append(", ");
}
if (itemValue instanceof PrismPropertyValue) {
sb.append(((PrismPropertyValue) itemValue).getValue().toString());
} else {
sb.append(itemValue.toString() + " ");
}
});
return Model.of(sb.toString());
}
}
} else {
return super.getDataModel(rowModel);
}
}
return Model.of("");

}

};
}
columns.add(column);
}
Expand Down

0 comments on commit 2306e22

Please sign in to comment.