Skip to content

Commit

Permalink
fix for report column of ObjectType (MID-7514)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Jan 17, 2022
1 parent cca537b commit 69cedb3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,32 +718,34 @@ private String getStringValue(Object object, PrismObject<LookupTableType> lookup
if (lookupTable == null) {
if (prismPropertyValue.getValue() == null) {
return "";
}
if (isPolyString(prismPropertyValue.getTypeName())) {
} else if (isPolyString(prismPropertyValue.getTypeName())) {
return WebComponentUtil.getTranslatedPolyString((PolyString) prismPropertyValue.getValue());
} else if (prismPropertyValue.getValue() instanceof Enum) {
object = prismPropertyValue.getValue();
} else if (prismPropertyValue.getValue() instanceof ObjectType) {
object = prismPropertyValue.getValue();
} else {
return String.valueOf(prismPropertyValue.getValue());
}
if (prismPropertyValue.getValue() instanceof Enum) {
return getPageBase().createStringResource((Enum)prismPropertyValue.getValue()).getString();
}
return String.valueOf(prismPropertyValue.getValue());
}
} else {

String lookupTableKey = prismPropertyValue.getValue().toString();
LookupTableType lookupTableObject = lookupTable.asObjectable();
String rowLabel = "";
for (LookupTableRowType lookupTableRow : lookupTableObject.getRow()) {
if (lookupTableRow.getKey().equals(lookupTableKey)) {
return lookupTableRow.getLabel() != null ? lookupTableRow.getLabel().getOrig() : lookupTableRow.getValue();
String lookupTableKey = prismPropertyValue.getValue().toString();
LookupTableType lookupTableObject = lookupTable.asObjectable();
String rowLabel = "";
for (LookupTableRowType lookupTableRow : lookupTableObject.getRow()) {
if (lookupTableRow.getKey().equals(lookupTableKey)) {
return lookupTableRow.getLabel() != null ? lookupTableRow.getLabel().getOrig() : lookupTableRow.getValue();
}
}
return rowLabel;
}
return rowLabel;
}

if (object instanceof Enum) {
return getPageBase().createStringResource((Enum)object).getString();
}
if (object instanceof ObjectType){
return WebComponentUtil.getDisplayName(((ObjectType)object).asPrismObject());
return getStringValueForObject((ObjectType)object);
}
if (object instanceof PrismObject){
return WebComponentUtil.getDisplayName((PrismObject) object);
Expand All @@ -760,6 +762,10 @@ private String getStringValue(Object object, PrismObject<LookupTableType> lookup
return object.toString();
}

protected String getStringValueForObject(ObjectType object) {
return WebComponentUtil.getDisplayName(object.asPrismObject());
}

private boolean isPolyString(QName typeName) {
return QNameUtil.match(typeName, PolyStringType.COMPLEX_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ private void initView() {
} catch (Exception e) {
LOGGER.debug("Couldn't create compiled view for report " + getReport(), e);
}
if (checkViewAfterInicialize()) {
if (checkViewAfterInitialize()) {
checkView();
}
}

protected boolean checkViewAfterInicialize() {
protected boolean checkViewAfterInitialize() {
return false;
}

Expand Down Expand Up @@ -333,4 +333,9 @@ public void resetTable(AjaxRequestTarget target) {
initView();
super.resetTable(target);
}

@Override
protected String getStringValueForObject(ObjectType object) {
return super.getStringValueForObject(object) + " (" + object.getOid() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public Component getFeedbackPanel() {
}

@Override
protected boolean checkViewAfterInicialize() {
protected boolean checkViewAfterInitialize() {
if (checkViewAfterInitialize) {
return true;
}
return super.checkViewAfterInicialize();
return super.checkViewAfterInitialize();
}
};
table.setOutputMarkupId(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.certification.api.OutcomeUtils;
import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.*;
Expand All @@ -30,10 +31,12 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.report.impl.controller.*;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -64,6 +67,7 @@
import java.util.stream.Collectors;

import org.apache.commons.lang.WordUtils;
import org.springframework.boot.web.servlet.server.Session;

/**
* Utility methods for report. Mostly pretty print functions. Do not use any
Expand Down Expand Up @@ -271,6 +275,26 @@ public static String prettyPrintForReport(ObjectReferenceType prv, boolean showT
return sb.toString();
}

public static String prettyPrintForReport(ObjectType object, LocalizationService localizationService) {
if (object == null) {
return "";
}
String name = PolyString.getOrig(object.getName());

PolyStringType displayName = ObjectTypeUtil.getDisplayName(object);
if (displayName != null) {
if (localizationService != null) {
String translatedValue = localizationService.translate(PolyString.toPolyString(displayName), Locale.getDefault(), true);
if (StringUtils.isNotEmpty(translatedValue)) {
name = translatedValue;
}
} else {
name = PolyString.getOrig(ObjectTypeUtil.getDisplayName(object));
}
}
return name + " (" + object.getOid() + ")";
}

public static String prettyPrintUsersForReport(List<ObjectReferenceType> userRefList) {
StringBuilder sb = new StringBuilder();
boolean first = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,15 @@ private String prettyPrintValue(PrismValue value) {
LOGGER.error("Couldn't convert delta from ObjectDeltaOperationType to ObjectDeltaOperation {}", realValue);
return "";
}
} if (realValue instanceof ObjectType) {
return ReportUtils.prettyPrintForReport((ObjectType) realValue, reportService.getLocalizationService());
} else {
return ReportUtils.prettyPrintForReport(realValue);
}
} else if (value instanceof PrismReferenceValue) {
return getObjectNameFromRef(value.getRealValue());
} if (value instanceof ObjectType) {
return ReportUtils.prettyPrintForReport((ObjectType) value, reportService.getLocalizationService());
} else {
return ReportUtils.prettyPrintForReport(value);
}
Expand Down

0 comments on commit 69cedb3

Please sign in to comment.