/** * Always returns collection, even for single-valued results. */ public static <X> Collection<X> getPropertyStaticRealValues(ExpressionType expressionType, PrismPropertyDefinition outputDefinition, String contextDescription, PrismContext prismContext) throws SchemaException { PrismProperty<X> output = getPropertyStatic(expressionType, outputDefinition, contextDescription, prismContext); return output.getRealValues(); }
public String determineLdapSingleAttributeValue(Collection<String> dns, String attributeName, PrismProperty attribute) throws NamingException { return determineLdapSingleAttributeValue(dns, attributeName, attribute.getRealValues()); }
private static String getMultiStringAttributeValueAsSingle(PrismObject<ShadowType> shadow, QName attrName) { PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null) { return null; } PrismProperty<String> attribute = attributesContainer.findProperty(ItemName.fromQName(attrName)); if (attribute == null) { return null; } Collection<String> realValues = attribute.getRealValues(); if (realValues == null || realValues.isEmpty()) { return null; } if (realValues.size() > 1) { throw new IllegalStateException("More than one value in attribute "+attrName); } return realValues.iterator().next(); }
public static boolean compareCollectionRealValues(Collection<? extends PrismProperty> col1, Collection<? extends PrismProperty> col2) { return MiscUtil.unorderedCollectionEquals(col1, col2, (p1, p2) -> { if (!p1.getElementName().equals(p2.getElementName())) { return false; } Collection p1RealVals = p1.getRealValues(); Collection p2RealVals = p2.getRealValues(); return MiscUtil.unorderedCollectionEquals(p1RealVals, p2RealVals); }); } }
public static <T> Collection<T> getAttributeValues(PrismObject<? extends ShadowType> shadow, QName name) { if (shadow == null) { throw new IllegalArgumentException("No shadow"); } PrismContainer<?> attrCont = shadow.findContainer(ShadowType.F_ATTRIBUTES); if (attrCont == null) { return null; } PrismProperty<T> attrProp = attrCont.findProperty(ItemName.fromQName(name)); if (attrProp == null) { return null; } return attrProp.getRealValues(); }
Collection<?> anyElementList = property.getRealValues(); T requestedTypeInstance; try {
private <X> PrismProperty<X> resolveStructuredPropertyItem(PrismProperty<Structured> sourceProperty, ItemPath resolvePath, PrismPropertyDefinition outputDefinition) { if (sourceProperty == null) { return null; } PrismProperty<X> outputProperty = outputDefinition.instantiate(); for (Structured sourceRealValue: sourceProperty.getRealValues()) { X outputRealValue = (X) sourceRealValue.resolve(resolvePath); outputProperty.addRealValue(outputRealValue); } return outputProperty; }
public boolean hasRealValue(PrismProperty<T> property, PrismPropertyValue<T> pValue) { for (T existingRealValue: property.getRealValues()) { try { if (matchingRule.match(existingRealValue, pValue.getValue())) { // LOGGER.trace("MATCH: {} ({}) <-> {} ({}) (rule: {})", new Object[]{ // existingRealValue, existingRealValue.getClass(), pValue.getValue(), pValue.getValue().getClass(), matchingRule}); return true; } // LOGGER.trace("NO match: {} ({}) <-> {} ({}) (rule: {})", new Object[]{ // existingRealValue, existingRealValue.getClass(), pValue.getValue(), pValue.getValue().getClass(), matchingRule}); } catch (SchemaException e) { // At least one of the values is invalid. But we do not want to throw exception from // a comparison operation. That will make the system very fragile. Let's fall back to // ordinary equality mechanism instead. if (existingRealValue.equals(pValue.getValue())) { return true; } } } return false; }
private boolean isMatching(String newPassword, PrismProperty<Object> objectProperty) { for (Object objectRealValue: objectProperty.getRealValues()) { if (objectRealValue instanceof String) { if (newPassword.equals(objectRealValue)) { return true; } } else if (objectRealValue instanceof ProtectedStringType) { ProtectedStringType newPasswordPs = new ProtectedStringType(); newPasswordPs.setClearValue(newPassword); try { if (protector.compare(newPasswordPs, (ProtectedStringType)objectRealValue)) { return true; } } catch (SchemaException | EncryptionException e) { throw new SystemException(e); } } else { if (newPassword.equals(objectRealValue.toString())) { return true; } } } return false; }
private Object findSyncTokenObject(Task syncCycle) { Object token = null; PrismProperty<?> tokenProperty = syncCycle.getExtension().findProperty(SchemaConstants.SYNC_TOKEN); if (tokenProperty != null) { Collection<?> values = tokenProperty.getRealValues(); if (values.size() > 1) { throw new IllegalStateException("Too must values in token "+tokenProperty); } token = values.iterator().next(); } return token; }
public static <T> Collection<T> getExtensionPropertyValues(ObjectType objectType, QName propertyQname) { PrismObject<? extends ObjectType> object = objectType.asPrismObject(); PrismContainer<Containerable> extensionContainer = object.findContainer(ObjectType.F_EXTENSION); if (extensionContainer == null) { return null; } PrismProperty<T> property = extensionContainer.findProperty(ItemName.fromQName(propertyQname)); if (property == null) { return null; } return property.getRealValues(); }
/** * Returns either Object (if result is supposed to be single-value) or Collection<X> (if result is supposed to be multi-value) */ public static Object getStaticOutput(ExpressionType expressionType, PrismPropertyDefinition outputDefinition, String contextDescription, ExpressionReturnMultiplicityType preferredMultiplicity, PrismContext prismContext) throws SchemaException { PrismProperty<?> output = getPropertyStatic(expressionType, outputDefinition, contextDescription, prismContext); ExpressionReturnMultiplicityType multiplicity = preferredMultiplicity; if (expressionType.getReturnMultiplicity() != null) { multiplicity = expressionType.getReturnMultiplicity(); } else if (output != null && output.size() > 1) { multiplicity = ExpressionReturnMultiplicityType.MULTI; } if (output == null) { switch (multiplicity) { case MULTI: return new ArrayList<>(0); case SINGLE: return null; default: throw new IllegalStateException("Unknown return type "+multiplicity); } } else { Collection<?> realValues = output.getRealValues(); switch (multiplicity) { case MULTI: return realValues; case SINGLE: return MiscUtil.extractSingleton(realValues); default: throw new IllegalStateException("Unknown return type "+multiplicity); } } }
protected void assertPolyStringPropertyMulti(QName propName, String... expectedOrigs) { PrismProperty<PolyString> prop = getObject().findProperty(ItemName.fromQName(propName)); assertNotNull("No "+propName.getLocalPart()+" in "+desc(), prop); PrismAsserts.assertEqualsPolyStringMulti("Wrong "+propName.getLocalPart()+" in "+desc(), prop.getRealValues(), expectedOrigs); }
Collection realValues = simulatedActivationProperty.getRealValues(); if (realValues.isEmpty()) {
private <O extends ObjectType,T> void checkObjectProperty(PrismObject<O> object, QName propQName, OperationResult parentResult, T... expectedValues) { String propName = propQName.getLocalPart(); OperationResult result = parentResult.createSubresult(parentResult.getOperation() + ".checkObjectProperty." + propName); PrismProperty<T> prop = object.findProperty(ItemName.fromQName(propQName)); Collection<T> actualValues = prop.getRealValues(); result.addArbitraryObjectCollectionAsParam("actualValues", actualValues); assertMultivalue("User, property '"+propName+"'", expectedValues, actualValues, result); result.recordSuccessIfUnknown(); }
private <O extends ObjectType> void checkObjectPropertyPolyString(PrismObject<O> object, QName propQName, OperationResult parentResult, String... expectedValues) { String propName = propQName.getLocalPart(); OperationResult result = parentResult.createSubresult(parentResult.getOperation() + "." + propName); PrismProperty<PolyString> prop = object.findProperty(ItemName.fromQName(propQName)); Collection<PolyString> actualValues = prop.getRealValues(); result.addArbitraryObjectCollectionAsParam("actualValues", actualValues); assertMultivaluePolyString("User, property '"+propName+"'", expectedValues, actualValues, result); result.recordSuccessIfUnknown(); }
Collection<T> realValues = simulatedActivationProperty.getRealValues(); if (realValues.isEmpty()) {
throw new IllegalArgumentException("No deltas to execute"); } else { deltas = deltaProperty.getRealValues(); deltas = deltasProperty.getRealValues();
private <O extends ObjectType, T> void checkUserProperty(PrismObject<O> object, QName propQName, OperationResult parentResult, T... expectedValues) { String propName = propQName.getLocalPart(); OperationResult result = parentResult.createSubresult(parentResult.getOperation() + "." + propName); PrismProperty<T> prop = object.findProperty(ItemName.fromQName(propQName)); Collection<T> actualValues = prop.getRealValues(); result.addArbitraryObjectCollectionAsParam("actualValues", actualValues); assertMultivalue("User, property '" + propName + "'", expectedValues, actualValues, result); result.recordSuccessIfUnknown(); }
private <O extends ObjectType> void checkUserPropertyPolyString(PrismObject<O> object, QName propQName, OperationResult parentResult, String... expectedValues) { String propName = propQName.getLocalPart(); OperationResult result = parentResult.createSubresult(parentResult.getOperation() + "." + propName); PrismProperty<PolyString> prop = object.findProperty(ItemName.fromQName(propQName)); Collection<PolyString> actualValues = prop.getRealValues(); result.addArbitraryObjectCollectionAsParam("actualValues", actualValues); assertMultivaluePolyString("User, property '" + propName + "'", expectedValues, actualValues, result); result.recordSuccessIfUnknown(); }