Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/mini-full-o…
Browse files Browse the repository at this point in the history
…bjects
  • Loading branch information
tonydamage committed Nov 15, 2023
2 parents 23d3242 + e1f299d commit 5b285b9
Show file tree
Hide file tree
Showing 115 changed files with 5,273 additions and 4,031 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.evolveum.midpoint.schema;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -40,7 +41,8 @@
* @author semancik
*/
public class GetOperationOptions extends AbstractOptions implements Serializable, Cloneable, ShortDumpable {
private static final long serialVersionUID = 1L;

@Serial private static final long serialVersionUID = 1L;

public static final GetOperationOptions EMPTY = new GetOperationOptions();

Expand Down Expand Up @@ -778,6 +780,11 @@ public static boolean isMaxStaleness(GetOperationOptions options) {
return GetOperationOptions.getStaleness(options) == Long.MAX_VALUE;
}

public static Collection<SelectorOptions<GetOperationOptions>> zeroStalenessOptions() {
return SelectorOptions.createCollection(
GetOperationOptions.createStaleness(0L));
}

public Boolean getForceRefresh() {
return forceRefresh;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ default ResourceAssociationDefinition findAssociationDefinitionRequired(QName na
.collect(Collectors.toCollection(HashSet::new));
}

/**
* Returns all attributes that are used as targets for object-to-subject associations, i.e., attributes whose values
* are referenced from the entitlements. For example, the group (an entitlement) may list its members by their `uid`
* attribute. This method returns `uid` in such a case.
*
* The goal is to making sure such attributes are always cached, regardless of whether they are formally defined
* as identifiers.
*/
default @NotNull Collection<? extends QName> getAssociationValueAttributes() {
return getAssociationDefinitions().stream()
.filter(assocDef -> assocDef.getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT)
.filter(assocDef -> assocDef.isObjectToSubject())
.map(associationDef -> associationDef.getDefinitionBean().getValueAttribute())
.filter(Objects::nonNull) // just for sure
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ default <AD extends ResourceAttributeDefinition<?>> Collection<AD> getAttributeD
return getAttributeDefinitions().stream()
.filter(def -> type.isAssignableFrom(def.getClass()))
.map(def -> (AD) def)
.collect(Collectors.toUnmodifiableList());
.toList();
}

/**
Expand Down Expand Up @@ -142,13 +142,6 @@ default boolean containsAttributeDefinition(@NotNull QName attributeName) {
return findAttributeDefinition(attributeName) != null;
}

default Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() {
return getAttributeDefinitions().stream()
.filter(attrDef -> attrDef.getOutboundMappingBean() != null)
.map(ItemDefinition::getItemName)
.collect(Collectors.toCollection(HashSet::new));
}

default Collection<? extends QName> getNamesOfAttributesWithInboundExpressions() {
return getAttributeDefinitions().stream()
.filter(attrDef -> !attrDef.getInboundMappingBeans().isEmpty())
Expand Down Expand Up @@ -178,4 +171,14 @@ default Collection<? extends QName> getNamesOfAttributesWithInboundExpressions()
attribute.setIncomplete(property.isIncomplete());
return attribute;
}

@SuppressWarnings("unchecked")
default <T> @NotNull ResourceAttribute<T> instantiateAttribute(@NotNull QName attrName, @NotNull T... realValues)
throws SchemaException {
//noinspection unchecked
var attrDef = (ResourceAttributeDefinition<T>) findAttributeDefinitionRequired(attrName);
var attr = attrDef.instantiate();
attr.addRealValues(realValues);
return attr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ void setAssociationTarget(ResourceObjectTypeDefinition associationTarget) {
() -> "No association direction provided in association definition: " + this);
}

public boolean isObjectToSubject() {
return getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT;
}

public boolean isSubjectToObject() {
return getDirection() == ResourceObjectAssociationDirectionType.SUBJECT_TO_OBJECT;
}

public @NotNull Collection<String> getIntents() {
return definitionBean.getIntent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
package com.evolveum.midpoint.schema.processor;

import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.util.exception.SchemaException;

import org.jetbrains.annotations.NotNull;

/**
/**
Expand Down Expand Up @@ -52,6 +55,14 @@ default String getNativeAttributeName() {
return definition != null ? definition.getNativeAttributeName() : null;
}

/** Returns self to be usable in chained calls. */
default @NotNull ResourceAttribute<T> forceDefinitionFrom(ResourceObjectDefinition objectDefinition) throws SchemaException {
var attrDef = objectDefinition.findAttributeDefinitionRequired(getElementName());
//noinspection unchecked
applyDefinition((ResourceAttributeDefinition<T>) attrDef, true);
return this;
}

@Override
ResourceAttribute<T> clone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,7 @@ static ResourceAttributeContainerImpl createEmptyContainer(QName elementName,
*
* @return set of identifier properties
*/
Collection<ResourceAttribute<?>> getPrimaryIdentifiers();

/**
* TODO review docs
*
* Returns a (single) secondary identifier.
*
* This method returns a property that acts as an secondary identifier for
* the resource object. Secondary identifiers are used to confirm primary
* identification of resource object.
*
* Returns null if no secondary identifier is defined.
*
* Resource objects may have multiple (composite) identifiers, but this
* method assumes that there is only a single identifier. The method will
* throw exception if that assumption is not satisfied.
*
* @return secondary identifier property
* @throws IllegalStateException
* if resource object has multiple secondary identifiers
*/
<T> PrismProperty<T> getSecondaryIdentifier();
@NotNull Collection<ResourceAttribute<?>> getPrimaryIdentifiers();

/**
* TODO review docs
Expand All @@ -165,9 +144,9 @@ static ResourceAttributeContainerImpl createEmptyContainer(QName elementName,
*
* @return set of secondary identifier properties
*/
Collection<ResourceAttribute<?>> getSecondaryIdentifiers();
@NotNull Collection<ResourceAttribute<?>> getSecondaryIdentifiers();

Collection<ResourceAttribute<?>> getAllIdentifiers();
@NotNull Collection<ResourceAttribute<?>> getAllIdentifiers();

@NotNull
Collection<ResourceAttribute<?>> extractAttributesByDefinitions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public ResourceAttributeDefinition<?> getNamingAttribute() {
return getComplexTypeDefinition().getNamingAttribute();
}

public void setNamingAttribute(ResourceAttributeDefinition<?> namingAttribute) {
// We can afford to delegate a set here as we know that there is one-to-one correspondence between
// object class definition and attribute container
((ResourceObjectClassDefinitionImpl) getComplexTypeDefinition()).setNamingAttributeName(namingAttribute.getItemName());
}

public void setNamingAttribute(QName namingAttribute) {
((ResourceObjectClassDefinitionImpl) getComplexTypeDefinition()).setNamingAttributeName(namingAttribute);
}
// public void setNamingAttribute(ResourceAttributeDefinition<?> namingAttribute) {
// // We can afford to delegate a set here as we know that there is one-to-one correspondence between
// // object class definition and attribute container
// ((ResourceObjectClassDefinitionImpl) getComplexTypeDefinition()).setNamingAttributeName(namingAttribute.getItemName());
// }

// public void setNamingAttribute(QName namingAttribute) {
// ((ResourceObjectClassDefinitionImpl) getComplexTypeDefinition()).setNamingAttributeName(namingAttribute);
// }

@Override
public String getNativeObjectClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -99,29 +98,17 @@ public PrismProperty<?> getPrimaryIdentifier() {
}

@Override
public Collection<ResourceAttribute<?>> getPrimaryIdentifiers() {
public @NotNull Collection<ResourceAttribute<?>> getPrimaryIdentifiers() {
return extractAttributesByDefinitions(getDefinition().getPrimaryIdentifiers());
}

@Override
public <T> PrismProperty<T> getSecondaryIdentifier() {
Collection<ResourceAttribute<?>> secondaryIdentifiers = getSecondaryIdentifiers();
if (secondaryIdentifiers.size() > 1){
throw new IllegalStateException("Resource object has more than one identifier.");
}
for (PrismProperty<?> p : secondaryIdentifiers){
return (PrismProperty<T>) p;
}
return null;
}

@Override
public Collection<ResourceAttribute<?>> getSecondaryIdentifiers() {
public @NotNull Collection<ResourceAttribute<?>> getSecondaryIdentifiers() {
return extractAttributesByDefinitions(getDefinition().getSecondaryIdentifiers());
}

@Override
public Collection<ResourceAttribute<?>> getAllIdentifiers() {
public @NotNull Collection<ResourceAttribute<?>> getAllIdentifiers() {
return extractAttributesByDefinitions(getDefinition().getAllIdentifiers());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.match.MatchingRule;
import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.midpoint.schema.TaskExecutionMode;
import com.evolveum.midpoint.schema.util.SimulationUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -336,4 +339,9 @@ default boolean hasOutboundMapping() {
default boolean isVisible(@NotNull TaskExecutionMode taskExecutionMode) {
return SimulationUtil.isVisible(getLifecycleState(), taskExecutionMode);
}

default @NotNull MatchingRule<T> getMatchingRule() throws SchemaException {
return SchemaService.get().matchingRuleRegistry()
.getMatchingRule(getMatchingRuleQName(), getTypeName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.exception.SchemaException;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -201,7 +203,8 @@ static ResourceObjectTypeDefinition findDefaultObjectTypeDefinitionForObjectClas
* See {@link ResourceSchema#findDefinitionForShadow(ShadowType)} for the description.
*/
static @Nullable ResourceObjectDefinition findDefinitionForShadow(
@NotNull ResourceSchema schema, @NotNull ShadowType shadow, @NotNull Collection<QName> additionalAuxObjectClassNames) {
@NotNull ResourceSchema schema, @NotNull ShadowType shadow, @NotNull Collection<QName> additionalAuxObjectClassNames)
throws SchemaException {
ResourceObjectDefinition structuralDefinition = findStructuralDefinitionForShadow(schema, shadow);
if (structuralDefinition != null) {
return addAuxiliaryObjectClasses(
Expand Down

0 comments on commit 5b285b9

Please sign in to comment.