Search in sources :

Example 36 with ItemName

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;
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 37 with ItemName

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());
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName) Test(org.testng.annotations.Test) AbstractUnitTest(com.evolveum.midpoint.tools.testng.AbstractUnitTest)

Example 38 with ItemName

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));
    }
}
Also used : PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) ItemName(com.evolveum.midpoint.prism.path.ItemName) SortableDataProvider(org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam)

Example 39 with ItemName

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);
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 40 with ItemName

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);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3