@NotNull public ItemName getName() { return attributeDefinition.getName(); }
public QName convertAttributeNameToQName(String icfAttrName, ResourceAttributeDefinition attrDef) { if (specialAttributeMapIcf.containsKey(icfAttrName)) { if (icfAttrName.equals(attrDef.getFrameworkAttributeName())) { return attrDef.getName(); } // fallback, compatibility return specialAttributeMapIcf.get(icfAttrName); } return attrDef.getName(); }
protected RefinedAttributeDefinitionImpl(ResourceAttributeDefinition<T> attrDef, PrismContext prismContext) { super(attrDef.getName(), attrDef.getTypeName(), prismContext); this.attributeDefinition = attrDef; }
/** * Returns true if the attribute with a given name is among primary identifiers. * Matching is done using namespace-approximate method (testing only local part if * no namespace is provided), so beware of incidental matching (e.g. ri:uid vs icfs:uid). */ default boolean isPrimaryIdentifier(QName attrName) { return getPrimaryIdentifiers().stream() .anyMatch(idDef -> QNameUtil.match(idDef.getName(), attrName)); }
/** * Returns true if the attribute with a given name is among secondary identifiers. * Matching is done using namespace-approximate method (testing only local part if * no namespace is provided), so beware of incidental matching (e.g. ri:uid vs icfs:uid). */ default boolean isSecondaryIdentifier(QName attrName) { return getSecondaryIdentifiers().stream() .anyMatch(idDef -> QNameUtil.match(idDef.getName(), attrName)); }
public String convertAttributeNameToConnId(ResourceAttributeDefinition<?> attrDef) throws SchemaException { if (attrDef.getFrameworkAttributeName() != null) { return attrDef.getFrameworkAttributeName(); } QName attrQName = attrDef.getName(); if (specialAttributeMapMp.containsKey(attrQName)) { return specialAttributeMapMp.get(attrQName); } if (!attrQName.getNamespaceURI().equals(resourceSchemaNamespace)) { throw new SchemaException("No mapping from QName " + attrQName + " to an ICF attribute in resource schema namespace: " + resourceSchemaNamespace); } return attrQName.getLocalPart(); }
public QName convertAttributeNameToQName(String icfAttrName, ObjectClassComplexTypeDefinition ocDef) { if (specialAttributeMapIcf.containsKey(icfAttrName)) { for (ResourceAttributeDefinition attributeDefinition: ocDef.getAttributeDefinitions()) { if (icfAttrName.equals(attributeDefinition.getFrameworkAttributeName())) { return attributeDefinition.getName(); } } // fallback, compatibility return specialAttributeMapIcf.get(icfAttrName); } QName attrXsdName = new QName(resourceSchemaNamespace, QNameUtil.escapeElementName(icfAttrName), MidPointConstants.PREFIX_NS_RI); return attrXsdName; }
@Override public Collection<ResourceAttribute<?>> extractAttributesByDefinitions( Collection<? extends ResourceAttributeDefinition> definitions) { Collection<ResourceAttribute<?>> attributes = new ArrayList<>(definitions.size()); for (ResourceAttributeDefinition attrDef : definitions) { for (ResourceAttribute<?> property : getAttributes()){ if (attrDef.getName().equals(property.getElementName())){ property.setDefinition(attrDef); attributes.add(property); } } } return attributes; }
protected String desc() { return descWithDetails("resource attribute definition " + PrettyPrinter.prettyPrint(getDefinition().getName())); }
protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType); ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass()); ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next(); PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName()); assertNotNull("No secondary identifier ("+idSecDef.getName()+") attribute in shadow for "+expectedIdentifier, idProp); if (nameMatchingRule == null) { assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, expectedIdentifier, idProp.getRealValue()); } else { PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue()); } }
protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType); ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass()); ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next(); PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName()); assertNotNull("No secondary identifier ("+idSecDef.getName()+") attribute in shadow for "+expectedIdentifier, idProp); if (nameMatchingRule == null) { assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, expectedIdentifier, idProp.getRealValue()); } else { PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for "+expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue()); } }
private void assertRefinedToLayer(ResourceAttributeDefinition attrDef, LayerType expectedLayer) { if (expectedLayer == null) { // This is OK, it may not be layer-bound. return; } if (!(attrDef instanceof LayerRefinedAttributeDefinition)) { AssertJUnit.fail("Expected that definition of attribute "+attrDef.getName()+" in layer "+expectedLayer +" will be LayerRefinedAttributeDefinition, but it is "+attrDef.getClass()+": "+attrDef); } assertEquals("Wrong layer in "+attrDef, expectedLayer, ((LayerRefinedAttributeDefinition)attrDef).getLayer()); }
private PropertyDelta<String> createNameDelta(Name name, ResourceAttributeDefinition nameDefinition) { PropertyDelta<String> uidDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, nameDefinition.getName()), nameDefinition); uidDelta.setRealValuesToReplace(name.getNameValue()); return uidDelta; }
protected ObjectQuery createShadowQuerySecondaryIdentifier(ObjectClassComplexTypeDefinition rAccount, String identifier, PrismObject<ResourceType> resource) throws SchemaException { Collection<? extends ResourceAttributeDefinition> identifierDefs = rAccount.getSecondaryIdentifiers(); assert identifierDefs.size() == 1 : "Unexpected identifier set in "+resource+" refined schema: "+identifierDefs; ResourceAttributeDefinition identifierDef = identifierDefs.iterator().next(); //TODO: set matching rule instead of null return prismContext.queryFor(ShadowType.class) .itemWithDef(identifierDef, ShadowType.F_ATTRIBUTES, identifierDef.getName()).eq(identifier) .and().item(ShadowType.F_OBJECT_CLASS).eq(rAccount.getTypeName()) .and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid()) .build(); }
private PropertyDelta<String> createUidDelta(Uid uid, ResourceAttributeDefinition uidDefinition) { PropertyDelta<String> uidDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, uidDefinition.getName()), uidDefinition); uidDelta.setRealValuesToReplace(uid.getUidValue()); return uidDelta; }
protected ObjectQuery createAccountShadowQuery(String identifier, PrismObject<ResourceType> resource) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); RefinedObjectClassDefinition rAccount = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); Collection<? extends ResourceAttributeDefinition> identifierDefs = rAccount.getPrimaryIdentifiers(); assert identifierDefs.size() == 1 : "Unexpected identifier set in "+resource+" refined schema: "+identifierDefs; ResourceAttributeDefinition identifierDef = identifierDefs.iterator().next(); //TODO: set matching rule instead of null return prismContext.queryFor(ShadowType.class) .itemWithDef(identifierDef, ShadowType.F_ATTRIBUTES, identifierDef.getName()).eq(identifier) .and().item(ShadowType.F_OBJECT_CLASS).eq(rAccount.getObjectClassDefinition().getTypeName()) .and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid()) .build(); }
protected ObjectQuery createAccountShadowQuery(String username, PrismObject<ResourceType> resource) throws SchemaException { RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); RefinedObjectClassDefinition rAccount = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); Collection<? extends ResourceAttributeDefinition> identifierDefs = rAccount.getPrimaryIdentifiers(); assert identifierDefs.size() == 1 : "Unexpected identifier set in "+resource+" refined schema: "+identifierDefs; ResourceAttributeDefinition identifierDef = identifierDefs.iterator().next(); //TODO: set matching rule instead of null return prismContext.queryFor(ShadowType.class) .itemWithDef(identifierDef, ShadowType.F_ATTRIBUTES, identifierDef.getName()).eq(username) .and().item(ShadowType.F_OBJECT_CLASS).eq(rAccount.getObjectClassDefinition().getTypeName()) .and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid()) .build(); }
protected ObjectQuery createShadowQueryByAttribute(ObjectClassComplexTypeDefinition rAccount, String attributeName, String attributeValue, PrismObject<ResourceType> resource) throws SchemaException { ResourceAttributeDefinition<Object> attrDef = rAccount.findAttributeDefinition(attributeName); return prismContext.queryFor(ShadowType.class) .itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attributeValue) .and().item(ShadowType.F_OBJECT_CLASS).eq(rAccount.getTypeName()) .and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid()) .build(); }
protected <T> void testSeachIterativeAlternativeAttrFilter(final String TEST_NAME, QName attr1QName, T attr1Val, QName attr2QName, T attr2Val, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME); ResourceAttributeDefinition<T> attr1Def = objectClassDef.findAttributeDefinition(attr1QName); ResourceAttributeDefinition<T> attr2Def = objectClassDef.findAttributeDefinition(attr2QName); ObjectFilter filter = prismContext.queryFor(ShadowType.class) .itemWithDef(attr1Def, ShadowType.F_ATTRIBUTES, attr1Def.getName()).eq(attr1Val) .or().itemWithDef(attr2Def, ShadowType.F_ATTRIBUTES, attr2Def.getName()).eq(attr2Val) .buildFilter(); testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, false, true, expectedAccountNames); }
protected <T> void testSeachIterativeSingleAttrFilter(final String TEST_NAME, QName attrQName, T attrVal, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME); ResourceAttributeDefinition<T> attrDef = objectClassDef.findAttributeDefinition(attrQName); ObjectFilter filter = prismContext.queryFor(ShadowType.class) .itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attrVal) .buildFilter(); testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, true, false, expectedAccountNames); }