use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class DomLexicalWriter method serializePrimitiveElementOrAttribute.
private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement, QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
QName typeQName = xprim.getTypeQName();
// TODO we should probably set typeQName when parsing the value...
if (typeQName == null && xprim.isParsed()) {
Object v = xprim.getValue();
if (v != null) {
typeQName = XsdTypeMapper.toXsdType(v.getClass());
}
}
if (typeQName == null) {
// this means that either xprim is unparsed or it is empty
if (com.evolveum.midpoint.prism.PrismContextImpl.isAllowSchemalessSerialization()) {
// We cannot correctly serialize without a type. But this is needed
// sometimes. So just default to string
String stringValue = xprim.getStringValue();
if (stringValue != null) {
if (asAttribute) {
DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), stringValue);
DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
} else {
Element element;
try {
element = createElement(elementOrAttributeName, parentElement);
appendCommentIfPresent(element, xprim);
} catch (DOMException e) {
throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
}
parentElement.appendChild(element);
DOMUtil.setElementTextContent(element, stringValue);
DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
}
}
return;
} else {
throw new IllegalStateException("No type for primitive element " + elementOrAttributeName + ", cannot serialize (schemaless serialization is disabled)");
}
}
if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
}
Element element = null;
if (ItemPathType.COMPLEX_TYPE.equals(typeQName)) {
//ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue()); // TODO fix this hack
ItemPathType itemPathType = (ItemPathType) xprim.getValue();
if (itemPathType != null) {
if (asAttribute) {
throw new UnsupportedOperationException("Serializing ItemPath as an attribute is not supported yet");
}
XPathHolder holder = new XPathHolder(itemPathType.getItemPath());
element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
parentElement.appendChild(element);
}
} else {
if (!asAttribute) {
try {
element = createElement(elementOrAttributeName, parentElement);
} catch (DOMException e) {
throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
}
appendCommentIfPresent(element, xprim);
parentElement.appendChild(element);
}
if (DOMUtil.XSD_QNAME.equals(typeQName)) {
QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
value = setQNamePrefixExplicitIfNeeded(value);
if (asAttribute) {
try {
DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
} catch (DOMException e) {
throw new DOMException(e.code, e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart() + " in element " + DOMUtil.getQName(parentElement) + " to QName value " + value);
}
} else {
DOMUtil.setQNameValue(element, value);
}
} else {
// not ItemType nor QName
String value = xprim.getGuessedFormattedValue();
if (asAttribute) {
DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
} else {
DOMUtil.setElementTextContent(element, value);
}
}
}
if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class FullTextSearchConfigurationUtil method getFullTextSearchItemPaths.
@NotNull
public static Set<ItemPath> getFullTextSearchItemPaths(@NotNull FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) {
List<QName> types = ObjectTypes.getObjectType(clazz).thisAndSupertypes().stream().map(ot -> ot.getTypeQName()).collect(Collectors.toList());
Set<ItemPath> paths = new HashSet<>();
for (FullTextSearchIndexedItemsConfigurationType indexed : config.getIndexed()) {
if (isApplicable(indexed, types)) {
for (ItemPathType itemPathType : indexed.getItem()) {
ItemPath path = itemPathType.getItemPath();
if (!ItemPath.isNullOrEmpty(path) && !ItemPath.containsEquivalent(paths, path)) {
paths.add(path);
}
}
}
}
return paths;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class MiscSchemaUtil method selectorToSelectorType.
private static OptionObjectSelectorType selectorToSelectorType(ObjectSelector selector) {
if (selector == null) {
return null;
}
OptionObjectSelectorType selectorType = new OptionObjectSelectorType();
selectorType.setPath(new ItemPathType(selector.getPath()));
return selectorType;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.
private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ExpressionType expressionType = populateItem.getExpression();
if (expressionType == null) {
LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
VariableBindingDefinitionType targetType = populateItem.getTarget();
if (targetType == null) {
LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
ItemPathType itemPathType = targetType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in target definition in " + contextDescription);
}
ItemPath targetPath = itemPathType.getItemPath();
ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
if (propOutputDefinition == null) {
throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
}
String expressionDesc = "expression in assignment expression in " + contextDescription;
ExpressionFactory expressionFactory = params.getExpressionFactory();
Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
context.setExpressionFactory(expressionFactory);
context.setStringPolicyResolver(params.getStringPolicyResolver());
context.setDefaultTargetContext(params.getDefaultTargetContext());
context.setSkipEvaluationMinus(true);
context.setSkipEvaluationPlus(false);
PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
LOGGER.trace("output triple: {}", outputTriple.debugDump());
Collection<IV> pvalues = outputTriple.getNonNegativeValues();
// Maybe not really clean but it works. TODO: refactor later
NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
if (first.isVariable()) {
targetPath = targetPath.rest();
}
ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
return itemDelta;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class Mapping method parseTimeSource.
private XMLGregorianCalendar parseTimeSource(VariableBindingDefinitionType sourceType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
ItemPathType itemPathType = sourceType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in source definition in " + getMappingContextDescription());
}
ItemPath path = itemPathType.getItemPath();
if (path.isEmpty()) {
throw new SchemaException("Empty source path in " + getMappingContextDescription());
}
Object sourceObject = ExpressionUtil.resolvePath(path, variables, sourceContext, objectResolver, "reference time definition in " + getMappingContextDescription(), task, result);
if (sourceObject == null) {
return null;
}
PrismProperty<XMLGregorianCalendar> timeProperty;
if (sourceObject instanceof ItemDeltaItem<?, ?>) {
timeProperty = (PrismProperty<XMLGregorianCalendar>) ((ItemDeltaItem<?, ?>) sourceObject).getItemNew();
} else if (sourceObject instanceof Item<?, ?>) {
timeProperty = (PrismProperty<XMLGregorianCalendar>) sourceObject;
} else {
throw new IllegalStateException("Unknown resolve result " + sourceObject);
}
if (timeProperty == null) {
return null;
}
return timeProperty.getRealValue();
}
Aggregations