Search in sources :

Example 11 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ShadowManager method updateShadow.

@SuppressWarnings("unchecked")
public Collection<ItemDelta> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, Collection<? extends ItemDelta> aprioriDeltas, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, resourceShadow.getOid(), null, result);
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    Collection<ItemDelta> repoShadowChanges = new ArrayList<ItemDelta>();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    for (RefinedAttributeDefinition attrDef : objectClassDefinition.getAttributeDefinitions()) {
        if (ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrDef.getName(), cachingStrategy)) {
            ResourceAttribute<Object> resourceAttr = ShadowUtil.getAttribute(resourceShadow, attrDef.getName());
            PrismProperty<Object> repoAttr = repoShadow.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
            PropertyDelta attrDelta;
            if (repoAttr == null && repoAttr == null) {
                continue;
            }
            if (repoAttr == null) {
                attrDelta = attrDef.createEmptyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
                attrDelta.setValuesToReplace(PrismValue.cloneCollection(resourceAttr.getValues()));
            } else {
                attrDelta = repoAttr.diff(resourceAttr);
            //					LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", repoAttr==null?null:repoAttr.debugDump(1), resourceAttr==null?null:resourceAttr.debugDump(1), attrDelta==null?null:attrDelta.debugDump(1));
            }
            if (attrDelta != null && !attrDelta.isEmpty()) {
                normalizeDelta(attrDelta, attrDef);
                repoShadowChanges.add(attrDelta);
            }
        }
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Updating repo shadow {}:\n{}", resourceShadow.getOid(), DebugUtil.debugDump(repoShadowChanges));
    }
    try {
        repositoryService.modifyObject(ShadowType.class, resourceShadow.getOid(), repoShadowChanges, result);
    } catch (ObjectAlreadyExistsException e) {
        // We are not renaming the object here. This should not happen.
        throw new SystemException(e.getMessage(), e);
    }
    return repoShadowChanges;
}
Also used : ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SystemException(com.evolveum.midpoint.util.exception.SystemException) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ShadowManager method processQueryMatchingRuleFilter.

private <T> void processQueryMatchingRuleFilter(ObjectFilter filter, RefinedObjectClassDefinition objectClassDef) throws SchemaException {
    if (!(filter instanceof EqualFilter)) {
        return;
    }
    EqualFilter<T> eqFilter = (EqualFilter) filter;
    ItemPath parentPath = eqFilter.getParentPath();
    if (parentPath == null || !parentPath.equivalent(SchemaConstants.PATH_ATTRIBUTES)) {
        return;
    }
    QName attrName = eqFilter.getElementName();
    RefinedAttributeDefinition rAttrDef = objectClassDef.findAttributeDefinition(attrName);
    if (rAttrDef == null) {
        throw new SchemaException("Unknown attribute " + attrName + " in filter " + filter);
    }
    QName matchingRuleQName = rAttrDef.getMatchingRuleQName();
    if (matchingRuleQName == null) {
        return;
    }
    Class<?> valueClass = null;
    MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName());
    List<PrismValue> newValues = new ArrayList<PrismValue>();
    if (eqFilter.getValues() != null) {
        for (PrismPropertyValue<T> ppval : eqFilter.getValues()) {
            T normalizedRealValue = matchingRule.normalize(ppval.getValue());
            PrismPropertyValue<T> newPPval = ppval.clone();
            newPPval.setValue(normalizedRealValue);
            newValues.add(newPPval);
            if (normalizedRealValue != null) {
                valueClass = normalizedRealValue.getClass();
            }
        }
        eqFilter.getValues().clear();
        eqFilter.getValues().addAll((Collection) newValues);
        LOGGER.trace("Replacing values for attribute {} in search filter with normalized values because there is a matching rule, normalized values: {}", attrName, newValues);
    }
    if (eqFilter.getMatchingRule() == null) {
        QName supportedMatchingRule = valueClass != null ? repositoryService.getApproximateSupportedMatchingRule(valueClass, matchingRuleQName) : matchingRuleQName;
        eqFilter.setMatchingRule(supportedMatchingRule);
        LOGGER.trace("Setting matching rule to {} (supported by repo as a replacement for {} to search for {})", supportedMatchingRule, matchingRuleQName, valueClass);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PrismValue(com.evolveum.midpoint.prism.PrismValue) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class TestSanityLegacy method getNormalizedAttributeValue.

public static String getNormalizedAttributeValue(ShadowType repoShadow, RefinedObjectClassDefinition objClassDef, QName name) {
    String value = getAttributeValue(repoShadow, name);
    RefinedAttributeDefinition attrDef = objClassDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
    if (attrDef.getMatchingRuleQName() != null && attrDef.getMatchingRuleQName().equals(StringIgnoreCaseMatchingRule.NAME)) {
        return value.toLowerCase();
    }
    return value;
}
Also used : RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)

Example 14 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class TestSanity method getNormalizedAttributeValue.

public static String getNormalizedAttributeValue(ShadowType repoShadow, RefinedObjectClassDefinition objClassDef, QName name) {
    String value = getAttributeValue(repoShadow, name);
    RefinedAttributeDefinition idDef = objClassDef.getPrimaryIdentifiers().iterator().next();
    if (idDef.getMatchingRuleQName() != null && idDef.getMatchingRuleQName().equals(StringIgnoreCaseMatchingRule.NAME)) {
        return value.toLowerCase();
    }
    return value;
}
Also used : RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)

Example 15 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class DummyResourceContoller method assertRefinedSchemaSanity.

public void assertRefinedSchemaSanity(RefinedResourceSchema refinedSchema) {
    RefinedObjectClassDefinition accountDef = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("Account definition is missing", accountDef);
    assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
    assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
    assertNotNull("Null secondary identifiers in account", accountDef.getSecondaryIdentifiers());
    assertFalse("Empty secondary identifiers in account", accountDef.getSecondaryIdentifiers().isEmpty());
    assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
    assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getNativeObjectClass()));
    RefinedAttributeDefinition uidDef = accountDef.findAttributeDefinition(SchemaTestConstants.ICFS_UID);
    assertEquals(1, uidDef.getMaxOccurs());
    assertEquals(0, uidDef.getMinOccurs());
    assertFalse("No UID display name", StringUtils.isBlank(uidDef.getDisplayName()));
    assertFalse("UID has create", uidDef.canAdd());
    assertFalse("UID has update", uidDef.canModify());
    assertTrue("No UID read", uidDef.canRead());
    assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(uidDef));
    RefinedAttributeDefinition nameDef = accountDef.findAttributeDefinition(SchemaTestConstants.ICFS_NAME);
    assertEquals(1, nameDef.getMaxOccurs());
    assertEquals(1, nameDef.getMinOccurs());
    assertFalse("No NAME displayName", StringUtils.isBlank(nameDef.getDisplayName()));
    assertTrue("No NAME create", nameDef.canAdd());
    assertTrue("No NAME update", nameDef.canModify());
    assertTrue("No NAME read", nameDef.canRead());
    assertTrue("NAME definition not in identifiers", accountDef.getSecondaryIdentifiers().contains(nameDef));
    RefinedAttributeDefinition fullnameDef = accountDef.findAttributeDefinition(DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME);
    assertNotNull("No definition for fullname", fullnameDef);
    assertEquals(1, fullnameDef.getMaxOccurs());
    assertEquals(1, fullnameDef.getMinOccurs());
    assertTrue("No fullname create", fullnameDef.canAdd());
    assertTrue("No fullname update", fullnameDef.canModify());
    assertTrue("No fullname read", fullnameDef.canRead());
    assertNull("The _PASSSWORD_ attribute sneaked into schema", accountDef.findAttributeDefinition(new QName(SchemaTestConstants.NS_ICFS, "password")));
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) QName(javax.xml.namespace.QName) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)

Aggregations

RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)28 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)12 QName (javax.xml.namespace.QName)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 PropertyLimitations (com.evolveum.midpoint.common.refinery.PropertyLimitations)4 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)4 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 PropertyAccessType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType)3 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2