use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowDeltaComputer method processAttributes.
private void processAttributes(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, PrismObject<ShadowType> resourceObject, ObjectDelta<ShadowType> resourceObjectDelta, CachingStategyType cachingStrategy, Collection<QName> incompleteCacheableAttributes, ObjectDelta<ShadowType> computedShadowDelta) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException {
PrismContainer<Containerable> resourceObjectAttributes = resourceObject.findContainer(ShadowType.F_ATTRIBUTES);
PrismContainer<Containerable> repoShadowAttributes = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
ResourceObjectDefinition ocDef = ctx.computeCompositeObjectDefinition(resourceObject);
for (Item<?, ?> currentResourceAttrItem : resourceObjectAttributes.getValue().getItems()) {
if (currentResourceAttrItem instanceof PrismProperty<?>) {
// noinspection unchecked
PrismProperty<Object> currentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrItem;
ResourceAttributeDefinition<?> attrDef = ocDef.findAttributeDefinitionRequired(currentResourceAttrProperty.getElementName());
if (ProvisioningUtil.shouldStoreAttributeInShadow(ocDef, attrDef.getItemName(), cachingStrategy)) {
if (!currentResourceAttrItem.isIncomplete()) {
processResourceAttribute(computedShadowDelta, repoShadowAttributes, currentResourceAttrProperty, attrDef);
} else {
incompleteCacheableAttributes.add(attrDef.getItemName());
if (resourceObjectDelta != null) {
LOGGER.trace("Resource attribute {} is incomplete but a delta does exist: we'll update the shadow " + "using the delta", attrDef.getItemName());
} else {
LOGGER.trace("Resource attribute {} is incomplete and object delta is not present: will not update the" + " shadow with its content", attrDef.getItemName());
}
}
} else {
LOGGER.trace("Skipping resource attribute because it's not going to be stored in shadow: {}", attrDef.getItemName());
}
} else {
LOGGER.warn("Skipping resource attribute because it's not a PrismProperty (huh?): {}", currentResourceAttrItem);
}
}
for (Item<?, ?> oldRepoItem : repoShadowAttributes.getValue().getItems()) {
if (oldRepoItem instanceof PrismProperty<?>) {
// noinspection unchecked
PrismProperty<Object> oldRepoAttrProperty = (PrismProperty<Object>) oldRepoItem;
ResourceAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
PrismProperty<Object> currentAttribute = resourceObjectAttributes.findProperty(oldRepoAttrProperty.getElementName());
// note: incomplete attributes with no values are not here: they are found in resourceObjectAttributes container
if (attrDef == null || !ProvisioningUtil.shouldStoreAttributeInShadow(ocDef, attrDef.getItemName(), cachingStrategy) || currentAttribute == null) {
// No definition for this property it should not be there or no current value: remove it from the shadow
PropertyDelta<Object> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete(PrismValueCollectionsUtil.cloneCollection(oldRepoAttrProperty.getValues()));
computedShadowDelta.addModification(oldRepoAttrPropDelta);
}
} else {
LOGGER.warn("Skipping repo shadow attribute because it's not a PrismProperty (huh?): {}", oldRepoItem);
}
}
if (resourceObjectDelta != null && !incompleteCacheableAttributes.isEmpty()) {
LOGGER.trace("Found incomplete cacheable attributes: {} while resource object delta is known. " + "We'll update them using the delta.", incompleteCacheableAttributes);
for (ItemDelta<?, ?> modification : resourceObjectDelta.getModifications()) {
if (modification.getPath().startsWith(ShadowType.F_ATTRIBUTES)) {
if (QNameUtil.contains(incompleteCacheableAttributes, modification.getElementName())) {
LOGGER.trace(" - using: {}", modification);
computedShadowDelta.addModification(modification.clone());
}
}
}
// So we are OK regarding this. We can update caching timestamp.
incompleteCacheableAttributes.clear();
}
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowFinder method createQueryBySelectedIds.
private ObjectQuery createQueryBySelectedIds(ProvisioningContext ctx, Collection<ResourceAttribute<?>> identifiers, boolean primaryIdentifiersOnly) throws SchemaException, ConfigurationException {
boolean identifierFound = false;
S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
ResourceObjectDefinition objectClassDefinition = ctx.getObjectDefinition();
for (PrismProperty<?> identifier : identifiers) {
ResourceAttributeDefinition<?> rAttrDef;
PrismPropertyValue<?> identifierValue = identifier.getValue();
if (objectClassDefinition == null) {
// If there is no specific object class definition then the identifier definition
// must be the same in all object classes and that means that we can use
// definition from any of them.
ResourceObjectTypeDefinition anyDefinition = ctx.getResourceSchema().getObjectTypeDefinitions().iterator().next();
rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName());
if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) {
continue;
}
} else {
if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) {
continue;
}
rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
}
if (rAttrDef == null) {
throw new SchemaException("No definition for " + identifier.getElementName());
}
String normalizedIdentifierValue = (String) helper.getNormalizedAttributeValue(identifierValue, rAttrDef);
// noinspection unchecked
PrismPropertyDefinition<String> def = (PrismPropertyDefinition<String>) identifier.getDefinition();
q = q.itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getItemName()).eq(normalizedIdentifierValue).and();
identifierFound = true;
}
if (!identifierFound) {
throw new SchemaException("Identifiers not found. Cannot create search query by identifier.");
}
if (objectClassDefinition != null) {
q = q.item(ShadowType.F_OBJECT_CLASS).eq(objectClassDefinition.getTypeName()).and();
}
return q.item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowedObjectConstruction method copyAttributes.
private void copyAttributes(OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
resultingShadowedObject.removeContainer(ShadowType.F_ATTRIBUTES);
ResourceAttributeContainer resultAttributes = resourceObjectAttributes.clone();
ResourceObjectDefinition compositeObjectClassDef = computeCompositeObjectClassDefinition();
localBeans.accessChecker.filterGetAttributes(resultAttributes, compositeObjectClassDef, result);
resultingShadowedObject.add(resultAttributes);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.
/**
* Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
if (identifiers == null) {
return null;
}
ResourceObjectDefinition objDef = ctx.getObjectDefinitionRequired();
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, objDef);
PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIds(ctx, secondaryIdentifiers, result);
if (repoShadow == null) {
return null;
}
shadowsFacade.applyDefinition(repoShadow, ctx.getTask(), result);
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
return null;
}
Collection primaryIdentifiers = new ArrayList<>();
for (PrismProperty property : attributesContainer.getValue().getProperties()) {
if (objDef.isPrimaryIdentifier(property.getElementName())) {
ResourceAttributeDefinition<?> attrDef = objDef.findAttributeDefinition(property.getElementName());
if (attrDef == null) {
throw new IllegalStateException("No definition for attribute " + property);
}
ResourceAttribute primaryIdentifier = attrDef.instantiate();
primaryIdentifier.setRealValue(property.getRealValue());
primaryIdentifiers.add(primaryIdentifier);
}
}
LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, objDef);
return primaryIdentifiers;
}
Aggregations