Search in sources :

Example 41 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestRefinedSchema method assertAccountObjectDefinition.

private void assertAccountObjectDefinition(ResourceObjectDefinition accountDef, LayerType sourceLayer, LayerType validationLayer) {
    assertRObjectClassDef(accountDef, sourceLayer, validationLayer);
    System.out.println("Refined account definition:");
    System.out.println(accountDef.debugDump());
    if (accountDef instanceof ResourceObjectTypeDefinition) {
        assertEquals("Wrong kind", ShadowKindType.ACCOUNT, ((ResourceObjectTypeDefinition) accountDef).getKind());
    }
    Collection<? extends ResourceAttributeDefinition<?>> accAttrsDef = accountDef.getAttributeDefinitions();
    assertNotNull("Null attributeDefinitions", accAttrsDef);
    assertFalse("Empty attributeDefinitions", accAttrsDef.isEmpty());
    assertEquals("Unexpected number of attributeDefinitions", 55, accAttrsDef.size());
    ResourceAttributeDefinition<?> disabledAttribute = accountDef.findAttributeDefinition("ds-pwp-account-disabled");
    assertNotNull("No ds-pwp-account-disabled attribute", disabledAttribute);
    assertTrue("ds-pwp-account-disabled not ignored", disabledAttribute.isIgnored());
    ResourceAttributeDefinition<?> displayNameAttributeDef = accountDef.getDisplayNameAttribute();
    assertNotNull("No account displayNameAttribute", displayNameAttributeDef);
    assertEquals("Wrong account displayNameAttribute", new QName(MidPointConstants.NS_RI, "uid"), displayNameAttributeDef.getItemName());
    // This is compatibility with PrismContainerDefinition, it should work well
    Collection<? extends ItemDefinition<?>> propertyDefinitions = accountDef.getDefinitions();
    assertNotNull("Null propertyDefinitions", propertyDefinitions);
    assertFalse("Empty propertyDefinitions", propertyDefinitions.isEmpty());
    assertEquals("Unexpected number of propertyDefinitions", 55, propertyDefinitions.size());
    ResourceAttributeContainerDefinition resAttrContainerDef = accountDef.toResourceAttributeContainerDefinition();
    assertNotNull("No ResourceAttributeContainerDefinition", resAttrContainerDef);
    System.out.println("\nResourceAttributeContainerDefinition (" + sourceLayer + ")");
    System.out.println(resAttrContainerDef.debugDump());
    ResourceObjectDefinition rComplexTypeDefinition = resAttrContainerDef.getComplexTypeDefinition();
    System.out.println("\nResourceAttributeContainerDefinition ComplexTypeDefinition (" + sourceLayer + ")");
    System.out.println(rComplexTypeDefinition.debugDump());
    if (accountDef instanceof ResourceObjectTypeDefinition) {
        assertRefinedToLayer(rComplexTypeDefinition, sourceLayer);
    }
    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() + " (" + sourceLayer + ")");
    System.out.println(riUidAttrDef.debugDump());
    if (accountDef instanceof ResourceObjectTypeDefinition) {
        assertRefinedToLayer(riUidAttrDef, sourceLayer);
        if (validationLayer == LayerType.PRESENTATION) {
            assertFalse("Can update " + riUidAttrDef + " from ResourceAttributeContainerDefinition (" + sourceLayer + ")", riUidAttrDef.canModify());
        } else {
            assertTrue("Cannot update " + riUidAttrDef + " from ResourceAttributeContainerDefinition (" + sourceLayer + ")", riUidAttrDef.canModify());
        }
        Collection<? extends ResourceAttributeDefinition<?>> definitionsFromResAttrContainerDef = resAttrContainerDef.getDefinitions();
        for (ResourceAttributeDefinition<?> definitionFromResAttrContainerDef : definitionsFromResAttrContainerDef) {
            assertRefinedToLayer(definitionFromResAttrContainerDef, sourceLayer);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 42 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class BasicValidatorTest method resource1Valid.

@Test
public void resource1Valid() throws Exception {
    OperationResult result = createOperationResult();
    EventHandler<Objectable> handler = new EventHandler<>() {

        @Override
        public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
            return EventResult.cont();
        }

        @Override
        public EventResult postMarshall(Objectable object, Element objectElement, OperationResult objectResult) {
            PrismObject<?> prismObject = object.asPrismObject();
            displayDumpable("Validating resource:", prismObject);
            prismObject.checkConsistence();
            PrismContainer<?> extensionContainer = prismObject.getExtension();
            PrismProperty<Integer> menProp = extensionContainer.findProperty(new ItemName("http://myself.me/schemas/whatever", "menOnChest"));
            assertNotNull("No men on a dead man chest!", menProp);
            assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
            PrismPropertyDefinition<?> menPropDef = menProp.getDefinition();
            assertNotNull("Men on a dead man chest NOT defined", menPropDef);
            assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
            assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
            return EventResult.cont();
        }

        @Override
        public void handleGlobalError(OperationResult currentResult) {
        /* nothing */
        }
    };
    validateFile("resource-1-valid.xml", handler, result);
    AssertJUnit.assertTrue(result.isSuccess());
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) ItemName(com.evolveum.midpoint.prism.path.ItemName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractUnitTest(com.evolveum.midpoint.tools.testng.AbstractUnitTest)

Example 43 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ResourceAttributeRefPanelFactory method getChoicesList.

private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
    PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
    // attribute/ref
    if (wrapper == null) {
        return Collections.emptyList();
    }
    // attribute value
    if (wrapper.getParent() == null) {
        return Collections.emptyList();
    }
    // attribute
    ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
    if (attributeWrapper == null) {
        return Collections.emptyList();
    }
    PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
    if (itemWrapper == null) {
        return Collections.emptyList();
    }
    if (!(itemWrapper instanceof ConstructionValueWrapper)) {
        return Collections.emptyList();
    }
    ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
    try {
        ResourceSchema schema = constructionWrapper.getRefinedSchema();
        if (schema == null) {
            return new ArrayList<>();
        }
        ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
        if (rOcd == null) {
            return Collections.emptyList();
        }
        if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
            Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
            return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
        }
        Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
        return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
    } catch (SchemaException e) {
        LOGGER.warn("Cannot get resource attribute definitions");
    }
    return Collections.emptyList();
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ArrayList(java.util.ArrayList) PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) IModel(org.apache.wicket.model.IModel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Serializable(java.io.Serializable) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) List(java.util.List) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) PostConstruct(javax.annotation.PostConstruct) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 44 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ChildOfReportParamWrapperFactory method createWrapper.

@Override
public PrismReferenceWrapper<R> createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
    ItemName name = def.getItemName();
    Item<PrismValue, ItemDefinition> childItem = parent.getNewValue().findItem(name);
    if ((skipCreateWrapper(def, ItemStatus.NOT_CHANGED, context, childItem == null || CollectionUtils.isEmpty(childItem.getValues()))) || !(childItem.getRealValue() instanceof RawType)) {
        LOGGER.trace("Skipping creating wrapper for non-existent item. It is not supported for {}", def);
        if (parent != null && parent.getNewValue() != null) {
            parent.getNewValue().remove(childItem);
        }
        return null;
    }
    if (childItem == null) {
        childItem = parent.getNewValue().findOrCreateItem(name);
    }
    PrismReference newItem = (PrismReference) def.instantiate();
    ObjectReferenceType parsedRealValue = ((RawType) childItem.getRealValue()).getParsedRealValue(ObjectReferenceType.class);
    newItem.add(parsedRealValue.asReferenceValue());
    PrismReferenceWrapper<R> itemWrapper = createWrapperInternal(parent, newItem, ItemStatus.NOT_CHANGED, context);
    itemWrapper.setMetadata(context.isMetadata());
    itemWrapper.setProcessProvenanceMetadata(context.isProcessMetadataFor(itemWrapper.getPath()));
    registerWrapperPanel(itemWrapper);
    List<PrismReferenceValueWrapperImpl<R>> valueWrappers = createValuesWrapper(itemWrapper, newItem, context);
    itemWrapper.getValues().addAll(valueWrappers);
    itemWrapper.setShowEmpty(context.isShowEmpty(), false);
    setupWrapper(itemWrapper);
    return itemWrapper;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValueWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismReferenceValueWrapperImpl) ItemName(com.evolveum.midpoint.prism.path.ItemName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 45 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ConstructionAssociationPanel method addNewShadowRefValuePerformed.

private void addNewShadowRefValuePerformed(AjaxRequestTarget target, ResourceAssociationDefinition def) {
    ObjectFilter filter = WebComponentUtil.createAssociationShadowRefFilter(def, getPageBase().getPrismContext(), resourceModel.getObject().getOid());
    ObjectBrowserPanel<ShadowType> objectBrowserPanel = new ObjectBrowserPanel<ShadowType>(getPageBase().getMainPopupBodyId(), ShadowType.class, Collections.singletonList(ShadowType.COMPLEX_TYPE), false, getPageBase(), filter) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSelectPerformed(AjaxRequestTarget target, ShadowType object) {
            getPageBase().hideMainPopup(target);
            try {
                PrismContainerWrapper<ConstructionType> constructionContainerWrapper = ConstructionAssociationPanel.this.getModelObject();
                PrismContainerWrapper<ResourceObjectAssociationType> associationWrapper = constructionContainerWrapper.findContainer(ConstructionType.F_ASSOCIATION);
                List<PrismContainerValue<ResourceObjectAssociationType>> associationValueList = associationWrapper.getItem().getValues();
                PrismContainerValue<ResourceObjectAssociationType> associationValue;
                if (CollectionUtils.isEmpty(associationValueList)) {
                    associationValue = associationWrapper.getItem().createNewValue();
                } else {
                    associationValue = associationValueList.get(0);
                }
                ItemName associationRefPath = def.getName();
                associationValue.asContainerable().setRef(new ItemPathType(associationRefPath));
                ExpressionType newAssociationExpression = associationValue.asContainerable().beginOutbound().beginExpression();
                ExpressionUtil.addShadowRefEvaluatorValue(newAssociationExpression, object.getOid(), getPageBase().getPrismContext());
            } catch (SchemaException ex) {
                LOGGER.error("Couldn't find association container: {}", ex.getLocalizedMessage());
            }
            target.add(ConstructionAssociationPanel.this);
        }
    };
    getPageBase().showMainPopup(objectBrowserPanel, target);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) ItemName(com.evolveum.midpoint.prism.path.ItemName)

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