use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class PrismContainerValueWrapperImpl method findItem.
@Override
public <IW extends ItemWrapper> IW findItem(ItemPath path, Class<IW> type) throws SchemaException {
Object first = path.first();
if (!ItemPath.isName(first)) {
throw new IllegalArgumentException("Attempt to lookup item using a non-name path " + path + " in " + this);
}
ItemName subName = ItemPath.toName(first);
ItemPath rest = path.rest();
IW item = findItemByQName(subName);
if (item != null) {
if (rest.isEmpty()) {
if (type.isAssignableFrom(item.getClass())) {
return item;
}
} else {
// Go deeper
if (item instanceof PrismContainerWrapper) {
return ((PrismContainerWrapper<?>) item).findItem(rest, type);
}
}
}
return null;
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestRefinedSchema method test140ParseFromResourcePosix.
@Test
public void test140ParseFromResourcePosix() throws Exception {
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_POSIX_FILE);
ResourceType resourceType = resource.asObjectable();
// WHEN
when();
ResourceSchema rSchema = ResourceSchemaFactory.parseCompleteSchema(resourceType);
// THEN
when();
assertNotNull("Refined schema is null", rSchema);
System.out.println("Refined schema");
System.out.println(rSchema.debugDump());
assertFalse("No account definitions", rSchema.getObjectTypeDefinitions(ShadowKindType.ACCOUNT).isEmpty());
// ### default account objectType
ResourceObjectTypeDefinition rAccountDef = rSchema.findObjectTypeDefinitionRequired(ShadowKindType.ACCOUNT, null);
assertTrue(rAccountDef.isDefaultForKind());
Collection<? extends ResourceAttributeDefinition<?>> rAccountAttrs = rAccountDef.getAttributeDefinitions();
assertFalse(rAccountAttrs.isEmpty());
assertAttributeDef(rAccountAttrs, new QName(MidPointConstants.NS_RI, "dn"), DOMUtil.XSD_STRING, 1, 1, "Distinguished Name", 110, true, false, // Access: create, read, update
true, // Access: create, read, update
true, // Access: create, read, update
true, LayerType.SCHEMA, LayerType.PRESENTATION);
assertAttributeDef(rAccountAttrs, new QName(MidPointConstants.NS_RI, "entryUUID"), DOMUtil.XSD_STRING, 0, 1, "entryUUID", 100, false, false, // Access: create, read, update
false, // Access: create, read, update
true, // Access: create, read, update
false, LayerType.SCHEMA, LayerType.PRESENTATION);
assertAttributeDef(rAccountAttrs, new QName(MidPointConstants.NS_RI, "cn"), DOMUtil.XSD_STRING, 1, -1, "Common Name", 590, true, false, // Access: create, read, update
true, // Access: create, read, update
true, // Access: create, read, update
true, LayerType.SCHEMA, LayerType.PRESENTATION);
assertAttributeDef(rAccountAttrs, new QName(MidPointConstants.NS_RI, "uid"), DOMUtil.XSD_STRING, 0, -1, "Login Name", 300, true, false, // Access: create, read, update
true, // Access: create, read, update
true, // Access: create, read, update
true, LayerType.SCHEMA, LayerType.PRESENTATION);
assertAttributeDef(rAccountAttrs, new QName(MidPointConstants.NS_RI, "employeeNumber"), DOMUtil.XSD_STRING, 0, 1, "employeeNumber", 140, false, false, // Access: create, read, update
true, // Access: create, read, update
true, // Access: create, read, update
true, LayerType.SCHEMA, LayerType.PRESENTATION);
System.out.println("Refined account definitionn:");
System.out.println(rAccountDef.debugDump());
assertEquals("Wrong kind", ShadowKindType.ACCOUNT, rAccountDef.getKind());
Collection<? extends ResourceAttributeDefinition<?>> accAttrsDef = rAccountDef.getAttributeDefinitions();
assertNotNull("Null attributeDefinitions", accAttrsDef);
assertFalse("Empty attributeDefinitions", accAttrsDef.isEmpty());
assertEquals("Unexpected number of attributeDefinitions", 53, accAttrsDef.size());
ResourceAttributeDefinition<?> disabledAttribute = rAccountDef.findAttributeDefinition("ds-pwp-account-disabled");
assertNotNull("No ds-pwp-account-disabled attribute", disabledAttribute);
assertTrue("ds-pwp-account-disabled not ignored", disabledAttribute.isIgnored());
ResourceAttributeDefinition<?> displayNameAttributeDef = rAccountDef.getDisplayNameAttribute();
assertNotNull("No account displayNameAttribute", displayNameAttributeDef);
assertEquals("Wrong account displayNameAttribute", new QName(MidPointConstants.NS_RI, "dn"), displayNameAttributeDef.getItemName());
// This is compatibility with PrismContainerDefinition, it should work well
Collection<? extends ItemDefinition> propertyDefinitions = rAccountDef.getDefinitions();
assertNotNull("Null propertyDefinitions", propertyDefinitions);
assertFalse("Empty propertyDefinitions", propertyDefinitions.isEmpty());
assertEquals("Unexpected number of propertyDefinitions", 53, propertyDefinitions.size());
assertFalse("No entitlement definitions", rSchema.getObjectTypeDefinitions(ShadowKindType.ENTITLEMENT).isEmpty());
ResourceObjectTypeDefinition rEntDef = rSchema.findObjectTypeDefinitionRequired(ShadowKindType.ENTITLEMENT, null);
rSchema.findObjectTypeDefinitionRequired(ShadowKindType.ENTITLEMENT, ENTITLEMENT_LDAP_GROUP_INTENT);
assertEquals("Wrong kind", ShadowKindType.ENTITLEMENT, rEntDef.getKind());
Collection<? extends ResourceAttributeDefinition<?>> entAttrDefs = rEntDef.getAttributeDefinitions();
assertNotNull("Null attributeDefinitions", entAttrDefs);
assertFalse("Empty attributeDefinitions", entAttrDefs.isEmpty());
assertEquals("Unexpected number of attributeDefinitions", 12, entAttrDefs.size());
ResourceAttributeDefinition<?> entDisplayNameAttributeDef = rEntDef.getDisplayNameAttribute();
assertNotNull("No entitlement displayNameAttribute", entDisplayNameAttributeDef);
assertEquals("Wrong entitlement displayNameAttribute", new QName(MidPointConstants.NS_RI, "dn"), entDisplayNameAttributeDef.getItemName());
assertEquals("Unexpected number of entitlement associations", 1, rAccountDef.getAssociationDefinitions().size());
ResourceAttributeContainerDefinition resAttrContainerDef = rAccountDef.toResourceAttributeContainerDefinition();
assertNotNull("No ResourceAttributeContainerDefinition", resAttrContainerDef);
System.out.println("\nResourceAttributeContainerDefinition");
System.out.println(resAttrContainerDef.debugDump());
ResourceObjectDefinition rComplexTypeDefinition = resAttrContainerDef.getComplexTypeDefinition();
System.out.println("\nResourceAttributeContainerDefinition ComplexTypeDefinition");
System.out.println(rComplexTypeDefinition.debugDump());
ResourceAttributeDefinition<?> riUidAttrDef = resAttrContainerDef.findAttributeDefinition(new ItemName(MidPointConstants.NS_RI, "uid"));
assertNotNull("No ri:uid def in ResourceAttributeContainerDefinition", riUidAttrDef);
System.out.println("\nri:uid def " + riUidAttrDef.getClass());
System.out.println(riUidAttrDef.debugDump());
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ContainerableListPanel method setDefaultSorting.
protected void setDefaultSorting(ISelectableDataProvider<C, PO> provider) {
if (provider instanceof SortableDataProvider && isCollectionViewPanel() && getObjectCollectionView().getPaging() != null && getObjectCollectionView().getPaging().getOrderBy() != null) {
PagingType paging = getObjectCollectionView().getPaging();
boolean ascending = !OrderDirectionType.DESCENDING.equals(paging.getOrderDirection());
ItemPath orderBy = paging.getOrderBy().getItemPath();
ItemName name = orderBy.lastName();
if (name == null) {
return;
}
((SortableDataProvider) provider).setSort(new SortParam(name.getLocalPart(), ascending));
}
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ItemWrapperFactoryImpl method createWrapper.
@SuppressWarnings("unchecked")
@Override
public IW createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
ItemName name = def.getItemName();
I childItem = (I) parent.getNewValue().findItem(name);
ItemStatus status = getStatus(childItem);
if (skipCreateWrapper(def, status, context, childItem == null || CollectionUtils.isEmpty(childItem.getValues()))) {
LOGGER.trace("Skipping creating wrapper for non-existent item. It is not supported for {}", def);
return null;
}
if (childItem == null) {
childItem = (I) parent.getNewValue().findOrCreateItem(name);
}
return createWrapper(parent, childItem, status, context);
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class MatchingUtil method putIntoFocus.
private static void putIntoFocus(FocusType preFocus, Item<?, ?> attributeItem) throws SchemaException {
LOGGER.debug("Converting {}", attributeItem);
if (!(attributeItem instanceof PrismProperty<?>)) {
LOGGER.trace("Not a property: {}", attributeItem);
return;
}
PrismProperty<?> attribute = (PrismProperty<?>) attributeItem;
PrismObject<? extends FocusType> preFocusObject = preFocus.asPrismObject();
PrismObjectDefinition<? extends FocusType> def = Objects.requireNonNull(preFocusObject.getDefinition(), () -> "no definition for pre-focus: " + preFocus);
String localName = attribute.getElementName().getLocalPart();
ItemName directPath = new ItemName("", localName);
PrismPropertyDefinition<?> directDef = def.findPropertyDefinition(directPath);
if (directDef != null && isCompatible(attribute, directDef)) {
if (preFocusObject.findItem(directPath) == null) {
preFocusObject.add(createPropertyClone(attribute, directDef));
}
return;
}
ItemPath extensionPath = ItemPath.create(ObjectType.F_EXTENSION, directPath);
PrismPropertyDefinition<Object> extensionDef = def.findPropertyDefinition(extensionPath);
if (extensionDef != null && isCompatible(attribute, extensionDef)) {
if (preFocusObject.findItem(extensionPath) == null) {
preFocusObject.getOrCreateExtension().getValue().add(createPropertyClone(attribute, extensionDef));
}
return;
}
LOGGER.trace("{} has no definition in focus", localName);
}
Aggregations