use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ExpressionUtil method getTargetSearchExpPathValue.
public static String getTargetSearchExpPathValue(ExpressionType expression) {
if (expression == null) {
return null;
}
MapXNode filterNodeMap = getAssociationTargetSearchFilterValuesMap(expression);
if (filterNodeMap == null || !filterNodeMap.containsKey(new QName("path"))) {
return null;
}
PrimitiveXNode<ItemPathType> pathValue = (PrimitiveXNode<ItemPathType>) filterNodeMap.get(new QName("path"));
return pathValue != null && pathValue.getValue() != null ? pathValue.getValue().toString() : null;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ValueDisplayUtil method toStringValue.
private static String toStringValue(Object value) {
// todo i18n
String defaultStr = "(a value of type " + value.getClass().getSimpleName() + ")";
if (value instanceof String) {
return (String) value;
} else if (value instanceof PolyString) {
return ((PolyString) value).getOrig();
} else if (value instanceof ProtectedStringType) {
// todo i18n
return "(protected string)";
} else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) {
return value.toString();
} else if (value instanceof XMLGregorianCalendar) {
// todo fix
return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString();
} else if (value instanceof Date) {
// todo fix
return ((Date) value).toLocaleString();
} else if (value instanceof LoginEventType) {
LoginEventType loginEventType = (LoginEventType) value;
if (loginEventType.getTimestamp() != null) {
// todo fix
return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString();
} else {
return "";
}
} else if (value instanceof ScheduleType) {
return SchemaDebugUtil.prettyPrint((ScheduleType) value);
} else if (value instanceof ApprovalSchemaType) {
ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value;
return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)";
} else if (value instanceof ConstructionType) {
ConstructionType ct = (ConstructionType) value;
Object resource = (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null);
return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : "");
} else if (value instanceof Enum) {
return value.toString();
} else if (value instanceof ResourceAttributeDefinitionType) {
ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value;
ItemPathType ref = radt.getRef();
String path;
if (ref != null) {
path = ref.getItemPath().toString();
} else {
path = "(null)";
}
StringBuilder sb = new StringBuilder();
MappingType mappingType = radt.getOutbound();
if (mappingType != null) {
if (mappingType.getExpression() == null) {
sb.append("Empty mapping for ").append(path);
} else {
sb.append(path).append(" = ");
boolean first = true;
for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) {
if (first) {
first = false;
} else {
sb.append(", ");
}
if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
RawType raw = (RawType) evaluator.getValue();
try {
sb.append(raw.extractString("(a complex value)"));
} catch (RuntimeException e) {
sb.append("(an invalid value)");
}
} else {
sb.append("(a complex expression)");
}
}
}
if (mappingType.getStrength() != null) {
sb.append(" (").append(mappingType.getStrength().value()).append(")");
}
} else {
sb.append("Empty mapping for ").append(path);
}
return sb.toString();
} else if (value instanceof QName) {
QName qname = (QName) value;
return qname.getLocalPart();
// if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
// return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")";
// } else {
// return qname.getLocalPart();
// }
} else if (value instanceof Number) {
return String.valueOf(value);
} else if (value instanceof byte[]) {
return "(binary data)";
} else if (value instanceof RawType) {
try {
Object parsedValue = ((RawType) value).getValue();
return toStringValue(parsedValue);
} catch (SchemaException e) {
return PrettyPrinter.prettyPrint(value);
}
} else if (value instanceof ItemPathType) {
ItemPath itemPath = ((ItemPathType) value).getItemPath();
StringBuilder sb = new StringBuilder();
itemPath.getSegments().forEach(segment -> {
if (ItemPath.isName(segment)) {
sb.append(PrettyPrinter.prettyPrint(ItemPath.toName(segment)));
} else if (ItemPath.isVariable(segment)) {
sb.append(PrettyPrinter.prettyPrint(ItemPath.toVariableName(segment)));
} else {
sb.append(segment.toString());
}
sb.append("; ");
});
return sb.toString();
} else if (value instanceof ExpressionType) {
StringBuilder expressionString = new StringBuilder();
if (((ExpressionType) value).getExpressionEvaluator() != null && ((ExpressionType) value).getExpressionEvaluator().size() > 0) {
((ExpressionType) value).getExpressionEvaluator().forEach(evaluator -> {
if (evaluator.getValue() instanceof RawType) {
expressionString.append(PrettyPrinter.prettyPrint(evaluator.getValue()));
expressionString.append("; ");
} else if (evaluator.getValue() instanceof SearchObjectExpressionEvaluatorType) {
SearchObjectExpressionEvaluatorType evaluatorValue = (SearchObjectExpressionEvaluatorType) evaluator.getValue();
if (evaluatorValue.getFilter() != null) {
DebugUtil.debugDumpMapMultiLine(expressionString, evaluatorValue.getFilter().getFilterClauseXNode().toMap(), 0, false, null);
// TODO temporary hack: removing namespace part of the QName
while (expressionString.indexOf("}") >= 0 && expressionString.indexOf("{") >= 0 && expressionString.indexOf("}") - expressionString.indexOf("{") > 0) {
expressionString.replace(expressionString.indexOf("{"), expressionString.indexOf("}") + 1, "");
}
}
} else {
expressionString.append(defaultStr);
}
});
}
return expressionString.toString();
} else {
return defaultStr;
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class SearchFactory method getConfiguredSearchItemDefinitions.
public static List<SearchItemDefinition> getConfiguredSearchItemDefinitions(List<SearchItemDefinition> availableDefinitions, ModelServiceLocator modelServiceLocator, QName type, String collectionViewName, Search.PanelType panelType) {
SearchBoxConfigurationType searchConfig = getSearchBoxConfiguration(modelServiceLocator, type, collectionViewName, panelType);
if (searchConfig == null) {
return null;
}
SearchItemsType configuredSearchItems = searchConfig.getSearchItems();
if (configuredSearchItems == null || CollectionUtils.isEmpty(configuredSearchItems.getSearchItem())) {
return null;
}
List<SearchItemDefinition> configuredSearchItemList = new ArrayList<>();
configuredSearchItems.getSearchItem().forEach(searchItem -> {
for (SearchItemDefinition def : availableDefinitions) {
ItemPathType searchItemPath = new ItemPathType(def.getPath());
if (searchItem.getPath() != null && searchItem.getPath().equivalent(searchItemPath)) {
def.setDisplayName(searchItem.getDisplayName());
configuredSearchItemList.add(def);
return;
}
}
});
configuredSearchItems.getSearchItem().forEach(searchItem -> {
if (searchItem.getFilter() != null || searchItem.getFilterExpression() != null) {
configuredSearchItemList.add(new SearchItemDefinition(searchItem));
return;
}
});
return configuredSearchItemList;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class Search method createFilterForSearchValue.
private ObjectFilter createFilterForSearchValue(PropertySearchItem item, DisplayableValue searchValue, PrismContext ctx) {
ItemDefinition definition = item.getDefinition().getDef();
ItemPath path = item.getPath();
if (definition instanceof PrismReferenceDefinition) {
PrismReferenceValue refValue = ((ObjectReferenceType) searchValue.getValue()).asReferenceValue();
if (refValue.isEmpty()) {
return null;
}
List<QName> supportedTargets = WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) definition).getTargetTypeName());
if (supportedTargets.size() == 1 && QNameUtil.match(supportedTargets.iterator().next(), refValue.getTargetType()) && refValue.getOid() == null && refValue.getObject() == null && refValue.getRelation() == null && refValue.getFilter() == null) {
return null;
}
RefFilter refFilter = (RefFilter) ctx.queryFor(ObjectType.class).item(path, definition).ref(refValue.clone()).buildFilter();
refFilter.setOidNullAsAny(true);
refFilter.setTargetTypeNullAsAny(true);
return refFilter;
}
PrismPropertyDefinition<?> propDef = (PrismPropertyDefinition<?>) definition;
if ((propDef.getAllowedValues() != null && !propDef.getAllowedValues().isEmpty()) || DOMUtil.XSD_BOOLEAN.equals(propDef.getTypeName())) {
// we're looking for enum value, therefore equals filter is ok
// or if it's boolean value
Object value = searchValue.getValue();
return ctx.queryFor(ObjectType.class).item(path, propDef).eq(value).buildFilter();
} else if (DOMUtil.XSD_INT.equals(propDef.getTypeName()) || DOMUtil.XSD_INTEGER.equals(propDef.getTypeName()) || DOMUtil.XSD_LONG.equals(propDef.getTypeName()) || DOMUtil.XSD_SHORT.equals(propDef.getTypeName())) {
String text = (String) searchValue.getValue();
if (!StringUtils.isNumeric(text) && (searchValue instanceof SearchValue)) {
((SearchValue) searchValue).clear();
return null;
}
Object value = Long.parseLong((String) searchValue.getValue());
return ctx.queryFor(ObjectType.class).item(path, propDef).eq(value).buildFilter();
} else if (DOMUtil.XSD_STRING.equals(propDef.getTypeName())) {
String text = (String) searchValue.getValue();
return ctx.queryFor(ObjectType.class).item(path, propDef).contains(text).matchingCaseIgnore().buildFilter();
} else if (DOMUtil.XSD_QNAME.equals(propDef.getTypeName())) {
Object value = searchValue.getValue();
QName qName;
if (value instanceof QName) {
qName = (QName) value;
} else {
qName = new QName((String) value);
}
return ctx.queryFor(ObjectType.class).item(path, propDef).eq(qName).buildFilter();
} else if (DOMUtil.XSD_DATETIME.equals(propDef.getTypeName())) {
if (((DateSearchItem) item).getFromDate() != null && ((DateSearchItem) item).getToDate() != null) {
return ctx.queryFor(ObjectType.class).item(path, propDef).gt(((DateSearchItem) item).getFromDate()).and().item(path, propDef).lt(((DateSearchItem) item).getToDate()).buildFilter();
} else if (((DateSearchItem) item).getFromDate() != null) {
return ctx.queryFor(ObjectType.class).item(path, propDef).gt(((DateSearchItem) item).getFromDate()).buildFilter();
} else if (((DateSearchItem) item).getToDate() != null) {
return ctx.queryFor(ObjectType.class).item(path, propDef).lt(((DateSearchItem) item).getToDate()).buildFilter();
} else {
return null;
}
} else if (SchemaConstants.T_POLY_STRING_TYPE.equals(propDef.getTypeName())) {
// we're looking for string value, therefore substring filter should be used
String text = (String) searchValue.getValue();
return ctx.queryFor(ObjectType.class).item(path, propDef).contains(text).matchingNorm().buildFilter();
} else if (propDef.getValueEnumerationRef() != null) {
String value = (String) searchValue.getValue();
return ctx.queryFor(ObjectType.class).item(path, propDef).contains(value).matchingCaseIgnore().buildFilter();
} else if (QNameUtil.match(ItemPathType.COMPLEX_TYPE, propDef.getTypeName())) {
ItemPathType itemPath = (ItemPathType) searchValue.getValue();
return ctx.queryFor(ObjectType.class).item(path, propDef).eq(itemPath).buildFilter();
}
if (searchValue instanceof SearchValue) {
// ((SearchValue) searchValue).clear();
}
return null;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ItemPathSearchPopupPanel method customizationPopoverForm.
@Override
protected void customizationPopoverForm(MidpointForm popoverForm) {
ItemPathPanel itemPathPanel = new ItemPathPanel(ID_ITEM_PATH, Model.of(new ItemPathDto(itemPathModel.getObject()))) {
@Override
protected void onUpdate(ItemPathDto itemPathDto) {
itemPathModel.setObject(new ItemPathType(itemPathDto.toItemPath()));
}
};
popoverForm.add(itemPathPanel);
}
Aggregations