Search in sources :

Example 56 with PrismPropertyDefinition

use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.

the class MidPointSchemaDefinitionFactory method getAnnotationReference.

private ResourceAttributeDefinition getAnnotationReference(XSAnnotation annotation, QName qname, ObjectClassComplexTypeDefinition objectClass) throws SchemaException {
    Element element = SchemaProcessorUtil.getAnnotationElement(annotation, qname);
    if (element != null) {
        String reference = element.getTextContent();
        if (reference == null || reference.isEmpty()) {
            // Compatibility
            reference = element.getAttribute("ref");
        }
        if (reference != null && !reference.isEmpty()) {
            QName referenceItemName = DOMUtil.resolveQName(element, reference);
            PrismPropertyDefinition definition = objectClass.findPropertyDefinition(referenceItemName);
            if (definition == null) {
                throw new SchemaException("The annotation " + qname + " in " + objectClass + " is pointing to " + referenceItemName + " which does not exist");
            }
            if (definition instanceof ResourceAttributeDefinition) {
                return (ResourceAttributeDefinition) definition;
            } else {
                throw new SchemaException("The annotation " + qname + " in " + objectClass + " is pointing to " + referenceItemName + " which is not an attribute, it is " + definition);
            }
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element)

Example 57 with PrismPropertyDefinition

use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.

the class FocusProjectionsTabPanel method createShadowMenu.

private List<InlineMenuItem> createShadowMenu() {
    List<InlineMenuItem> items = new ArrayList<InlineMenuItem>();
    PrismObjectDefinition def = getObjectWrapper().getObject().getDefinition();
    PrismReferenceDefinition ref = def.findReferenceDefinition(UserType.F_LINK_REF);
    InlineMenuItem item;
    if (ref.canRead() && ref.canAdd()) {
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.addShadow"), new InlineMenuItemAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                List<QName> supportedTypes = new ArrayList<>(1);
                supportedTypes.add(ResourceType.COMPLEX_TYPE);
                PageBase pageBase = FocusProjectionsTabPanel.this.getPageBase();
                ObjectBrowserPanel<ResourceType> resourceSelectionPanel = new ObjectBrowserPanel<ResourceType>(pageBase.getMainPopupBodyId(), ResourceType.class, supportedTypes, true, pageBase) {

                    @Override
                    protected void addPerformed(AjaxRequestTarget target, QName type, List<ResourceType> selected) {
                        // TODO Auto-generated method stub
                        FocusProjectionsTabPanel.this.addSelectedAccountPerformed(target, selected);
                    }
                };
                resourceSelectionPanel.setOutputMarkupId(true);
                pageBase.showMainPopup(resourceSelectionPanel, target);
            }
        });
        items.add(item);
        items.add(new InlineMenuItem());
    }
    PrismPropertyDefinition prop = def.findPropertyDefinition(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
    if (prop.canRead() && prop.canModify()) {
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.enable"), new InlineMenuItemAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                updateShadowActivation(target, getSelectedProjections(projectionModel), true);
            }
        });
        items.add(item);
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.disable"), new InlineMenuItemAction() {

            /**
						 * 
						 */
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                updateShadowActivation(target, getSelectedProjections(projectionModel), false);
            }
        });
        items.add(item);
    }
    if (ref.canRead() && ref.canAdd()) {
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.unlink"), new InlineMenuItemAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                unlinkProjectionPerformed(target, projectionModel, getSelectedProjections(projectionModel), ID_SHADOWS);
            }
        });
        items.add(item);
    }
    prop = def.findPropertyDefinition(SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
    if (prop.canRead() && prop.canModify()) {
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.unlock"), new InlineMenuItemAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                unlockShadowPerformed(target, projectionModel, getSelectedProjections(projectionModel));
            }
        });
        items.add(item);
    }
    prop = def.findPropertyDefinition(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
    if (prop.canRead() && prop.canModify()) {
        items.add(new InlineMenuItem());
        item = new InlineMenuItem(createStringResource("pageAdminFocus.button.delete"), new InlineMenuItemAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                deleteProjectionPerformed(target, projectionModel);
            }
        });
        items.add(item);
    }
    return items;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) List(java.util.List) ArrayList(java.util.ArrayList)

Example 58 with PrismPropertyDefinition

use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.

the class AbstractDummyTest method checkConsistency.

protected void checkConsistency(PrismObject<? extends ShadowType> object) throws SchemaException {
    OperationResult result = new OperationResult(TestDummyNegative.class.getName() + ".checkConsistency");
    PrismPropertyDefinition itemDef = ShadowUtil.getAttributesContainer(object).getDefinition().findAttributeDefinition(SchemaConstants.ICFS_NAME);
    LOGGER.info("item definition: {}", itemDef.debugDump());
    //TODO: matching rule
    ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(itemDef, ShadowType.F_ATTRIBUTES, itemDef.getName()).eq(getWillRepoIcfName()).build();
    System.out.println("Looking for shadows of \"" + getWillRepoIcfName() + "\" with filter " + query.debugDump());
    display("Looking for shadows of \"" + getWillRepoIcfName() + "\" with filter " + query.debugDump());
    List<PrismObject<ShadowType>> objects = repositoryService.searchObjects(ShadowType.class, query, null, result);
    assertEquals("Wrong number of repo shadows for ICF NAME \"" + getWillRepoIcfName() + "\"", 1, objects.size());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 59 with PrismPropertyDefinition

use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.

the class ShadowManager method createSearchShadowQuery.

private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, PrismContext prismContext, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceShadow);
    PrismProperty identifier = attributesContainer.getPrimaryIdentifier();
    Collection<PrismPropertyValue<Object>> idValues = identifier.getValues();
    // Only one value is supported for an identifier
    if (idValues.size() > 1) {
        // TODO: This should probably be switched to checked exception later
        throw new IllegalArgumentException("More than one identifier value is not supported");
    }
    if (idValues.size() < 1) {
        // TODO: This should probably be switched to checked exception later
        throw new IllegalArgumentException("The identifier has no value");
    }
    // We have all the data, we can construct the filter now
    try {
        // TODO TODO TODO TODO: set matching rule instead of null
        PrismPropertyDefinition def = identifier.getDefinition();
        return QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getName()).eq(getNormalizedValue(identifier, ctx.getObjectClassDefinition())).and().item(ShadowType.F_OBJECT_CLASS).eq(resourceShadow.getPropertyRealValue(ShadowType.F_OBJECT_CLASS, QName.class)).and().item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
    } catch (SchemaException e) {
        throw new SchemaException("Schema error while creating search filter: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 60 with PrismPropertyDefinition

use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test021Configuration.

@Test
public void test021Configuration() throws Exception {
    final String TEST_NAME = "test021Configuration";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
    // WHEN
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    resourceType = resource.asObjectable();
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    // There may be one parse. Previous test have changed the resource version
    // Schema for this version will not be re-parsed until getObject is tried
    assertResourceSchemaParseCountIncrement(1);
    assertResourceCacheMissesIncrement(1);
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container", configurationContainer);
    PrismContainerDefinition confContDef = configurationContainer.getDefinition();
    assertNotNull("No configuration container definition", confContDef);
    PrismContainer confingurationPropertiesContainer = configurationContainer.findContainer(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
    assertNotNull("No configuration properties container", confingurationPropertiesContainer);
    PrismContainerDefinition confPropsDef = confingurationPropertiesContainer.getDefinition();
    assertNotNull("No configuration properties container definition", confPropsDef);
    List<PrismProperty<?>> configurationProperties = confingurationPropertiesContainer.getValue().getItems();
    assertFalse("No configuration properties", configurationProperties.isEmpty());
    for (PrismProperty<?> confProp : configurationProperties) {
        PrismPropertyDefinition confPropDef = confProp.getDefinition();
        assertNotNull("No definition for configuration property " + confProp, confPropDef);
        assertFalse("Configuration property " + confProp + " is raw", confProp.isRaw());
        assertConfigurationProperty(confProp);
    }
    // The useless configuration variables should be reflected to the resource now
    assertEquals("Wrong useless string", "Shiver me timbers!", dummyResource.getUselessString());
    assertEquals("Wrong guarded useless string", "Dead men tell no tales", dummyResource.getUselessGuardedString());
    resource.checkConsistence();
    rememberSchemaMetadata(resource);
    rememberConnectorInstance(resource);
    assertSteadyResource();
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Aggregations

PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)134 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)93 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)82 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)62 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 Test (org.testng.annotations.Test)60 PrismObject (com.evolveum.midpoint.prism.PrismObject)24 QName (javax.xml.namespace.QName)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)19 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 Task (com.evolveum.midpoint.task.api.Task)12 ArrayList (java.util.ArrayList)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)8 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)7 File (java.io.File)7