public static <T> Set<T> getRealValuesOfCollection(Collection<? extends PrismValue> collection) { Set<T> retval = new HashSet<>(collection.size()); for (PrismValue value : collection) { retval.add(value.getRealValue()); } return retval; }
private static Collection<?> unwrapPrismValues(Collection<?> prismValues) { Collection<Object> rv = new ArrayList<>(prismValues.size()); for (Object value : prismValues) { if (value instanceof PrismValue) { rv.add(((PrismValue) value).getRealValue()); } else { rv.add(value); } } return rv; }
@Nullable @Override public Object getRealValue() { V value = getValue(); return value != null ? value.getRealValue() : null; }
public String guessFormattedValue() throws SchemaException { if (parsed != null) { return parsed.getRealValue().toString(); // todo reconsider this } else if (xnode instanceof PrimitiveXNode) { return ((PrimitiveXNode) xnode).getGuessedFormattedValue(); } else { return null; } } }
private String dumpValueCombination(Collection<? extends PrismValue> pvalues, List<SourceTriple<?, ?>> sourceTriples) { StringBuilder sb = new StringBuilder(); Iterator<SourceTriple<PrismValue,?>> sourceTriplesIterator = (Iterator)sourceTriples.iterator(); for (PrismValue pval: pvalues) { SourceTriple<PrismValue,?> sourceTriple = sourceTriplesIterator.next(); sb.append(sourceTriple.getName().getLocalPart()).append('='); sb.append(pval==null?null:(Object)pval.getRealValue()); if (sourceTriplesIterator.hasNext()) { sb.append(", "); } } return sb.toString(); }
public <IV extends PrismValue> boolean contains(IV pval) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException { return evalCondition(pval.getRealValue()); }
private <V extends PrismValue> boolean hasNoOrHashedValuesOnly(Collection<V> set) { if (set == null) { return true; } for (V pval: set) { Object val = pval.getRealValue(); if (val instanceof ProtectedStringType) { if (!((ProtectedStringType)val).isHashed()) { return false; } } else { return false; } } return true; }
public <T> T getParsedRealValue(@NotNull Class<T> clazz) throws SchemaException { if (parsed != null) { if (clazz.isAssignableFrom(parsed.getRealValue().getClass())) { return (T) parsed.getRealValue(); } else { throw new IllegalArgumentException("Parsed value ("+parsed.getClass()+") is not assignable to "+clazz); } } else if (xnode != null) { return prismContext.parserFor(xnode.toRootXNode()).parseRealValue(clazz); } else { return null; } }
@Override public void shortDump(StringBuilder sb) { if (xnode != null) { sb.append("(raw"); sb.append("):").append(xnode); } else if (parsed != null) { if (parsed instanceof ShortDumpable) { ((ShortDumpable)parsed).shortDump(sb); } else { Object realValue = parsed.getRealValue(); if (realValue == null) { sb.append("null"); } else if (realValue instanceof ShortDumpable) { ((ShortDumpable)realValue).shortDump(sb); } else { sb.append(realValue.toString()); } } } }
@SuppressWarnings("unchecked") private Comparable<Object> getComparable(Object o) { if (o instanceof Item) { Item item = (Item) o; if (item.getValues().size() > 1) { throw new IllegalStateException("Couldn't compare multivalued items"); } else if (item.getValues().size() == 1) { o = item.getValues().get(0); } else { return null; } } if (o instanceof PrismValue) { o = ((PrismValue) o).getRealValue(); } if (o instanceof Comparable) { return (Comparable<Object>) o; } if (o instanceof XMLGregorianCalendar) { return (Comparable) XmlTypeConverter.toDate((XMLGregorianCalendar) o); } return null; }
public static Map<String, Serializable> fromParamsType(ParamsType paramsType, PrismContext prismContext) throws SchemaException { if (paramsType != null) { Map<String, Serializable> params = new HashMap<>(); for (EntryType entry : paramsType.getEntry()) { Serializable realValue; if (entry.getEntryValue() != null) { Serializable value = (Serializable) entry.getEntryValue().getValue(); if (value instanceof RawType) { RawType raw = (RawType) value; if (raw.isParsed()) { realValue = raw.getAlreadyParsedValue().getRealValue(); } else { realValue = raw.guessFormattedValue(); } } else { realValue = value; } } else { realValue = null; } params.put(entry.getKey(), realValue); } return params; } return null; }
public <V,ID extends ItemDefinition> V getParsedRealValue(ID itemDefinition, ItemPath itemPath) throws SchemaException { if (parsed == null && xnode != null) { if (itemDefinition == null) { return prismContext.parserFor(xnode.toRootXNode()).parseRealValue(); // TODO what will be the result without definition? } else { getParsedValue(itemDefinition, itemPath.lastName()); } } if (parsed != null) { return parsed.getRealValue(); } return null; }
@Override public T getValue() { if (actualValue != null) { return actualValue; } if (valueForStorageWhenNotEncoded != null) { actualValue = valueForStorageWhenNotEncoded; return actualValue; } if (valueForStorageWhenEncoded != null) { if (prismContext == null) { throw new IllegalStateException("PrismContext not set for SerializationSafeContainer holding " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH)); } if (encodingScheme == EncodingScheme.PRISM) { try { PrismValue prismValue = prismContext.parserFor(valueForStorageWhenEncoded).xml().parseItemValue(); actualValue = prismValue != null ? prismValue.getRealValue() : null; } catch (SchemaException e) { throw new SystemException("Couldn't deserialize value from JAXB: " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH), e); } return actualValue; } else { throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme); } } return null; }
RFocusPhoto photo = prismEntityMapper.map(value.getRealValue(), RFocusPhoto.class, context);
public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) throws JAXBException, SchemaException { boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults()); PipelineDataType rv = new PipelineDataType(); if (output != null) { for (PipelineItem item: output) { PipelineItemType itemType = new PipelineItemType(); PrismValue value = item.getValue(); if (value instanceof PrismReferenceValue) { // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName) ObjectReferenceType ort = new ObjectReferenceType(); ort.setupReferenceValue((PrismReferenceValue) value); itemType.setValue(ort); } else { itemType.setValue(value.getRealValue()); // TODO - ok? } if (!hideResults) { itemType.setResult(item.getResult().createOperationResultType()); } rv.getItem().add(itemType); } } return rv; }
private void handleBasicOrEmbedded(Object bean, ItemDelta delta, Attribute attribute) { Class outputType = getRealOutputType(attribute); PrismValue anyPrismValue = delta.getAnyValue(); Object value; if (delta.isDelete() || (delta.isReplace() && (anyPrismValue == null || anyPrismValue.isEmpty()))) { value = null; } else { value = anyPrismValue.getRealValue(); } value = prismEntityMapper.map(value, outputType); try { PropertyUtils.setSimpleProperty(bean, attribute.getName(), value); } catch (Exception ex) { throw new SystemException("Couldn't set simple property for '" + attribute.getName() + "'", ex); } }
@SuppressWarnings("unchecked") private <T> T doParseRealValue(Class<T> clazz, RootXNodeImpl root) throws IOException, SchemaException { if (clazz == null) { ItemInfo info = ItemInfo.determine(itemDefinition, root.getRootElementName(), itemName, null, root.getTypeQName(), typeName, null, ItemDefinition.class, context, prismContext.getSchemaRegistry()); if (info.getItemDefinition() instanceof PrismContainerDefinition) { clazz = ((PrismContainerDefinition) info.getItemDefinition()).getCompileTimeClass(); } if (clazz == null && info.getTypeName() != null) { clazz = (Class) prismContext.getSchemaRegistry().determineClassForType(info.getTypeName()); } } // although bean unmarshaller can process containerables as well, prism unmarshaller is better at it if (clazz != null && !Containerable.class.isAssignableFrom(clazz) && getBeanUnmarshaller().canProcess(clazz)) { return getBeanUnmarshaller().unmarshal(root, clazz, context); } else if (clazz != null && Objectable.class.isAssignableFrom(clazz)) { // we need to NOT strip off OID PrismObject object = (PrismObject) doParseItem(root, clazz); return (T) object.asObjectable(); } else { PrismValue prismValue = doParseItemValue(root, clazz); if (prismValue == null) { return null; } else { return prismValue.getRealValue(); } } }
/** * Extracts a "real value" from RawType object without expecting any specific type beforehand. * If no explicit type is present, assumes xsd:string (and fails if the content is structured). */ public Object getValue() throws SchemaException { if (parsed != null) { return parsed.getRealValue(); } if (xnode == null) { return null; } if (xnode.getTypeQName() != null) { TypeDefinition typeDefinition = prismContext.getSchemaRegistry().findTypeDefinitionByType(xnode.getTypeQName()); if (typeDefinition != null && typeDefinition.getCompileTimeClass() != null) { return getParsedRealValue(typeDefinition.getCompileTimeClass()); } Class<?> javaClass = XsdTypeMapper.getXsdToJavaMapping(xnode.getTypeQName()); if (javaClass != null) { return getParsedRealValue(javaClass); } } // unknown or null type -- try parsing as string if (!(xnode instanceof PrimitiveXNode<?>)) { throw new SchemaException("Trying to parse non-primitive XNode as type '" + xnode.getTypeQName() + "'"); } else { return ((PrimitiveXNode) xnode).getStringValue(); } }
@Test public void test550UseVariables() throws Exception { final String TEST_NAME = "test550UseVariables"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(DOT_CLASS + TEST_NAME); OperationResult result = task.getResult(); ExecuteScriptType executeScript = parseRealValue(USE_VARIABLES_FILE); PrismContainer<Containerable> taskExtension = task.getTaskPrismObject().findOrCreateContainer(TaskType.F_EXTENSION); taskExtension .findOrCreateProperty(USER_NAME_TASK_EXTENSION_PROPERTY) .addRealValue("user1"); taskExtension .findOrCreateProperty(STUDY_GROUP_TASK_EXTENSION_PROPERTY) .addRealValues("group1", "group2", "group3"); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(executeScript, emptyMap(), false, task, result); // THEN dumpOutput(output, result); result.computeStatus(); PipelineData data = output.getFinalOutput(); assertEquals("Unexpected # of items in output", 1, data.getData().size()); String returned = data.getData().get(0).getValue().getRealValue(); assertEquals("Wrong returned status", "ok", returned); }
@Test public void testShadowKindTypeQuery() throws Exception { displayTestTitle("testShadowKindTypeQuery"); SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE); ObjectQuery query; try { ObjectFilter kindFilter = getPrismContext().queryFor(ShadowType.class) .item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT) .buildFilter(); query = getQueryFactory().createQuery(kindFilter); assertNotNull(query); ObjectFilter filter = query.getFilter(); assertTrue("filter is not an instance of type filter", filter instanceof EqualFilter); EqualFilter typeFilter = (EqualFilter) filter; assertEquals(typeFilter.getSingleValue().getRealValue(), ShadowKindType.ACCOUNT); QueryType convertedQueryType = toQueryType(query); toObjectQuery(ShadowType.class, convertedQueryType); displayQueryType(convertedQueryType); } catch (Exception ex) { LOGGER.error("Error while converting query: {}", ex.getMessage(), ex); throw ex; } }