public Collection<QName> getPropertyNames() { Collection<QName> names = new HashSet<>(); for (PrismProperty<?> prop: getProperties()) { names.add(prop.getElementName()); } return names; }
public static <T> void assertPropertyValueDesc(PrismProperty<T> property, MatchingRule<T> matchingRule, String contextDescrition, T... expectedPropValues) throws SchemaException { Collection<PrismPropertyValue<T>> pvals = property.getValues(); QName propQName = property.getElementName(); assert pvals != null && !pvals.isEmpty() : "Empty property "+propQName; assertSet("property "+propQName + (contextDescrition == null ? "" : " in " + contextDescrition), "value", matchingRule, pvals, expectedPropValues); }
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 <T> T getResourceIcfConfigurationPropertyValue(ResourceType resource, String propertyLocalPart) throws SchemaException { if (propertyLocalPart == null) { return null; } PrismContainer<?> configurationProperties = getIcfConfigurationProperties(resource); if (configurationProperties == null) { return null; } for (PrismProperty<?> property : configurationProperties.getValue().getProperties()) { if (propertyLocalPart.equals(property.getElementName().getLocalPart())) { return (T) property.getAnyRealValue(); } } return null; }
private void transformConnectorTimeoutsConfiguration(APIConfiguration apiConfig, PrismContainer<?> connectorTimeoutsContainer) throws SchemaException { if (connectorTimeoutsContainer == null || connectorTimeoutsContainer.getValue() == null) { return; } for (PrismProperty prismProperty : connectorTimeoutsContainer.getValue().getProperties()) { QName propertQName = prismProperty.getElementName(); if (SchemaConstants.NS_ICF_CONFIGURATION.equals(propertQName.getNamespaceURI())) { String opName = propertQName.getLocalPart(); Class<? extends APIOperation> apiOpClass = ConnectorFactoryConnIdImpl.resolveApiOpClass(opName); if (apiOpClass != null) { apiConfig.setTimeout(apiOpClass, parseInt(prismProperty)); } else { throw new SchemaException("Unknown operation name " + opName + " in " + ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME); } } } }
private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException { BeanWrapper connectorBean = new BeanWrapperImpl(this); PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class); if (connectorConfigurationProp == null) { return; } Class<?> configurationClass = connectorConfigurationProp.getPropertyType(); Object configurationObject; try { configurationObject = configurationClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new ConfigurationException("Cannot instantiate configuration "+configurationClass); } BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject); for (Item<?, ?> configurationItem: configurationContainer.getItems()) { if (! (configurationItem instanceof PrismProperty<?>)) { throw new ConfigurationException("Only properties are supported for now"); } PrismProperty<?> configurationProperty = (PrismProperty<?>)configurationItem; Object realValue = configurationProperty.getRealValue(); configurationClassBean.setPropertyValue(configurationProperty.getElementName().getLocalPart(), realValue); } connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject); } }
@Override public void deleteExtensionProperty(PrismProperty<?> property) throws SchemaException { processModificationBatched(deleteExtensionPropertyAndPrepareDelta(property.getElementName(), property.getDefinition(), PrismValueCollectionsUtil.cloneCollection(property.getValues()))); }
@Override public void setExtensionProperty(PrismProperty<?> property) throws SchemaException { processModificationBatched(setExtensionPropertyAndPrepareDelta(property.getElementName(), property.getDefinition(), PrismValueCollectionsUtil.cloneCollection(property.getValues()))); }
@Override public void addExtensionProperty(PrismProperty<?> property) throws SchemaException { processModificationBatched(addExtensionPropertyAndPrepareDelta(property.getElementName(), property.getDefinition(), PrismValueCollectionsUtil.cloneCollection(property.getValues()))); }
private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException { RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName()); QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName(); MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName()); List<PrismPropertyValue<T>> normalized = new ArrayList<>(); for (PrismPropertyValue<T> origPValue : attr.getValues()){ T normalizedValue = matchingRule.normalize(origPValue.getValue()); PrismPropertyValue<T> normalizedPValue = origPValue.clone(); normalizedPValue.setValue(normalizedValue); normalized.add(normalizedPValue); } return normalized; }
@Override public void setExtensionPropertyImmediate(PrismProperty<?> property, OperationResult parentResult) throws ObjectNotFoundException, SchemaException { try { processModificationNow(setExtensionPropertyAndPrepareDelta(property.getElementName(), property.getDefinition(), PrismValueCollectionsUtil.cloneCollection(property.getValues())), parentResult); } catch (ObjectAlreadyExistsException ex) { throw new SystemException(ex); } }
public ShadowAttributesAsserter<R> assertAttributes(QName... expectedAttributes) { for (QName expectedAttribute: expectedAttributes) { PrismProperty<Object> attr = getAttributes().findProperty(ItemName.fromQName(expectedAttribute)); if (attr == null) { fail("Expected attribute "+expectedAttribute+" in "+desc()+" but there was none. Attributes present: "+presentAttributeNames()); } } for (PrismProperty<?> existingAttr : getAttributes().getProperties()) { if (!QNameUtil.contains(expectedAttributes, existingAttr.getElementName())) { fail("Unexpected attribute "+existingAttr.getElementName()+" in "+desc()+". Expected attributes: "+QNameUtil.prettyPrint(expectedAttributes)); } } return this; }
QName propertyQName = prismProperty.getElementName(); if (propertyQName.getNamespaceURI().equals(SchemaConstants.NS_ICF_CONFIGURATION)) { String subelementName = propertyQName.getLocalPart();
rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName()); if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) { continue; if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) { continue; rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
Collection primaryIdentifiers = new ArrayList<>(); for (PrismProperty property: attributesContainer.getValue().getProperties()) { if (ocDef.isPrimaryIdentifier(property.getElementName())) { RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName()); if (attrDef == null) { throw new IllegalStateException("No definition for attribute " + property);
public ConstraintsCheckingResult check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { constraintsCheckingResult = new ConstraintsCheckingResult(); constraintsCheckingResult.setSatisfiesConstraints(true); PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null) { // No attributes no constraint violations LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness."); return constraintsCheckingResult; } RefinedObjectClassDefinition objectClassDefinition = provisioningContext.getObjectClassDefinition(); Collection<? extends ResourceAttributeDefinition> uniqueAttributeDefs = MiscUtil.unionExtends(objectClassDefinition.getPrimaryIdentifiers(), objectClassDefinition.getSecondaryIdentifiers()); LOGGER.trace("Checking uniquenss of attributes: {}", uniqueAttributeDefs); for (ResourceAttributeDefinition attrDef: uniqueAttributeDefs) { PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getName()); LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef); if (attr == null) { continue; } constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName()); boolean unique = checkAttributeUniqueness(attr, objectClassDefinition, provisioningContext.getResource(), shadowOid, task, result); if (!unique) { LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, provisioningContext.getShadowCoordinates()); constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName()); constraintsCheckingResult.setSatisfiesConstraints(false); } } constraintsCheckingResult.setMessages(messageBuilder.toString()); return constraintsCheckingResult; }
protected PrismObject<ShadowType> repoAddShadowFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, EncryptionException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".repoAddShadowFromFile"); result.addParam("file", file.getPath()); LOGGER.debug("addShadowFromFile: {}", file); PrismObject<ShadowType> object = prismContext.parseObject(file); PrismContainer<Containerable> attrCont = object.findContainer(ShadowType.F_ATTRIBUTES); for (PrismProperty<?> attr: attrCont.getValue().getProperties()) { if (attr.getDefinition() == null) { ResourceAttributeDefinition<String> attrDef = ObjectFactory.createResourceAttributeDefinition(attr.getElementName(), DOMUtil.XSD_STRING, prismContext); attr.setDefinition((PrismPropertyDefinition) attrDef); } } addBasicMetadata(object); LOGGER.trace("Adding object:\n{}", object.debugDump()); repoAddObject(object, "from file "+file, result); result.recordSuccess(); return object; }
static ResourceAttributeContainer convertFromContainer(PrismContainer<?> origAttrContainer, ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException { if (origAttrContainer == null || origAttrContainer.getValue() == null) { return null; } QName elementName = origAttrContainer.getElementName(); ResourceAttributeContainer attributesContainer = createEmptyContainer(elementName, objectClassDefinition); for (Item item: origAttrContainer.getValue().getItems()) { if (item instanceof PrismProperty) { PrismProperty<?> property = (PrismProperty)item; QName attributeName = property.getElementName(); ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName); if (attributeDefinition == null) { throw new SchemaException("No definition for attribute "+attributeName+" in object class "+objectClassDefinition); } ResourceAttribute attribute = new ResourceAttributeImpl(attributeName, attributeDefinition , property.getPrismContext()); for(PrismPropertyValue pval: property.getValues()) { attribute.add(pval.clone()); } attributesContainer.add(attribute); attribute.applyDefinition(attributeDefinition); } else { throw new SchemaException("Cannot process item of type "+item.getClass().getSimpleName()+", attributes can only be properties"); } } return attributesContainer; }
@Override protected <T> void assertConfigurationProperty(PrismProperty<T> confProp) { T val = confProp.getRealValue(); switch (confProp.getElementName().getLocalPart()) { case "instanceId": assertEquals("Wrong value for "+confProp, "", val); break; case "uselessString": assertEquals("Wrong value for "+confProp, "Shiver me timbers!", val); assertExpression(confProp, "value"); break; default: break; } }
public static ItemDelta<?, ?> createExtensionDelta(PrismPropertyDefinition definition, Object realValue, PrismContext prismContext) { PrismProperty<Object> property = (PrismProperty<Object>) definition.instantiate(); property.setRealValue(realValue); return prismContext.deltaFactory().property() .createModificationReplaceProperty(ItemPath.create(TaskType.F_EXTENSION, property.getElementName()), definition, realValue); }