Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 16, 2021
2 parents 8755b8d + d4f00b3 commit 7730664
Show file tree
Hide file tree
Showing 224 changed files with 6,404 additions and 5,186 deletions.
Expand Up @@ -186,24 +186,21 @@ public void setAbortRequested(boolean value) {
this.abortRequested = value;
}

private void addExpectedStatusItems(List<ProgressReportActivityDto> progressReportActivities, ModelContext modelContext) {
private void addExpectedStatusItems(List<ProgressReportActivityDto> progressReportActivities, ModelContext<?> modelContext) {
if (modelContext.getFocusContext() != null) {
ModelElementContext fc = modelContext.getFocusContext();
ModelElementContext<?> fc = modelContext.getFocusContext();
if (isNotEmpty(fc.getPrimaryDelta()) || isNotEmpty(fc.getSecondaryDelta())) {
ProgressInformation modelStatus = new ProgressInformation(FOCUS_OPERATION, (ProgressInformation.StateType) null);
if (findRelevantStatusItem(progressReportActivities, modelStatus) == null) {
progressReportActivities.add(createStatusItem(modelStatus, modelContext));
}
}
}
if (modelContext.getProjectionContexts() != null) {
Collection<ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
for (ModelProjectionContext mpc : projectionContexts) {
ProgressInformation projectionStatus = new ProgressInformation(RESOURCE_OBJECT_OPERATION,
mpc.getResourceShadowDiscriminator(), (ProgressInformation.StateType) null);
if (findRelevantStatusItem(progressReportActivities, projectionStatus) == null) {
progressReportActivities.add(createStatusItem(projectionStatus, modelContext));
}
for (ModelProjectionContext mpc : modelContext.getProjectionContexts()) {
ProgressInformation projectionStatus = new ProgressInformation(RESOURCE_OBJECT_OPERATION,
mpc.getResourceShadowDiscriminator(), (ProgressInformation.StateType) null);
if (findRelevantStatusItem(progressReportActivities, projectionStatus) == null) {
progressReportActivities.add(createStatusItem(projectionStatus, modelContext));
}
}
}
Expand Down
Expand Up @@ -14,6 +14,8 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.annotation.Experimental;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.delta.ChangeType;
Expand Down Expand Up @@ -185,4 +187,10 @@ default boolean isOfType(@NotNull Class<?> type) {
Class<O> compileTimeClass = getCompileTimeClass();
return compileTimeClass != null && type.isAssignableFrom(compileTimeClass);
}

@Experimental
static <T extends Objectable> PrismObject<T> cast(PrismObject<?> object, Class<T> type) {
//noinspection unchecked
return (PrismObject<T>) object;
}
}
Expand Up @@ -58,6 +58,10 @@ public interface S_ConditionEntry {
* Creates filter matching oid and/or targetTypeName, any of them optional.
* If both are null the result is the same like {@link #isNull()} (null ref OID matches).
*/
S_AtomicFilterExit ref(@Nullable String oid, @Nullable QName targetTypeName);
default S_AtomicFilterExit ref(@Nullable String oid, @Nullable QName targetTypeName) {
return ref(oid, targetTypeName, null);
}

S_AtomicFilterExit ref(@Nullable String oid, @Nullable QName targetTypeName, @Nullable QName relation);
S_AtomicFilterExit isNull();
}
Expand Up @@ -295,11 +295,13 @@ public S_AtomicFilterExit ref(String... oids) {
}

@Override
public S_AtomicFilterExit ref(@Nullable String oid, @Nullable QName targetTypeName) {
if (oid == null && targetTypeName == null) {
public S_AtomicFilterExit ref(@Nullable String oid, @Nullable QName targetTypeName, @Nullable QName relation) {
if (oid == null && targetTypeName == null && relation == null) {
return isNull();
} else {
return ref(new PrismReferenceValueImpl(oid, targetTypeName));
PrismReferenceValueImpl value = new PrismReferenceValueImpl(oid, targetTypeName);
value.setRelation(relation);
return ref(value);
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@
public class RefreshShadowOperation implements DebugDumpable {

private PrismObject<ShadowType> refreshedShadow;

private Collection<ObjectDeltaOperation<ShadowType>> executedDeltas;
private OperationResult refreshResult;

Expand Down Expand Up @@ -66,6 +67,7 @@ public int hashCode() {
return result;
}

@SuppressWarnings("RedundantIfStatement")
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
Expand Down
Expand Up @@ -13,6 +13,8 @@

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType;
Expand All @@ -35,6 +37,9 @@
* @author Radovan Semancik
*/
public class ResourceShadowDiscriminator implements Serializable, DebugDumpable, ShortDumpable, HumanReadableDescribable {

private static final Trace LOGGER = TraceManager.getTrace(ResourceShadowDiscriminator.class);

private static final long serialVersionUID = 346600684011645741L;

private String resourceOid;
Expand Down
Expand Up @@ -32,7 +32,8 @@ public enum RelationTypes {
DEPUTY(SchemaConstants.ORG_DEPUTY, "Deputy", "", "", RelationKindType.DELEGATION, null /* no values */),
APPROVER(SchemaConstants.ORG_APPROVER, "Approver", "fe fe-approver-object", "green", RelationKindType.APPROVER, null, ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
OWNER(SchemaConstants.ORG_OWNER, "Owner", "fe fe-crown-object", "darkorange", RelationKindType.OWNER, null, ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
CONSENT(SchemaConstants.ORG_CONSENT, "Consent", "", "", RelationKindType.CONSENT, null, DATA_PROTECTION);
CONSENT(SchemaConstants.ORG_CONSENT, "Consent", "", "", RelationKindType.CONSENT, null, DATA_PROTECTION),
RELATED(SchemaConstants.ORG_RELATED, "Related", "", "", RelationKindType.RELATED, null);

private final QName relation;
private final String headerLabel;
Expand Down
Expand Up @@ -167,6 +167,12 @@ public abstract class SchemaConstants {
*/
public static final QName ORG_CONSENT = new QName(NS_ORG, "consent");

/**
* Default 'related' relation. Used as a relation value in object references.
* See RelationKind.RELATED for more details.
*/
public static final QName ORG_RELATED = new QName(NS_ORG, "related");

public static final ItemPath PATH_PASSWORD = ItemPath.create(C_CREDENTIALS, CredentialsType.F_PASSWORD);
public static final ItemPath PATH_PASSWORD_VALUE = ItemPath.create(C_CREDENTIALS, CredentialsType.F_PASSWORD,
PasswordType.F_VALUE);
Expand Down
Expand Up @@ -309,7 +309,7 @@ private Set<QName> computeRelationsProcessedOnRecompute() {
private boolean isProcessedOnRecomputeByDefault(QName relation) {
return isOfKind(relation, RelationKindType.MEMBER)
|| isOfKind(relation, RelationKindType.META)
|| isOfKind(relation, RelationKindType.MANAGER) // ok?
|| isOfKind(relation, RelationKindType.MANAGER) // ok?
|| isOfKind(relation, RelationKindType.DELEGATION);
}

Expand Down
Expand Up @@ -1474,6 +1474,18 @@ public void recordFatalError(Throwable cause) {
recordStatus(OperationResultStatus.FATAL_ERROR, cause.getMessage(), cause);
}

/**
* Records a fatal error if it was not recorded before.
* TODO Not 100% safe, because the fatal error could be recorded for some other reason.
* We have to improve error reporting in general.
*/
@Experimental
public void recordFatalErrorIfNeeded(Throwable t) {
if (status != OperationResultStatus.FATAL_ERROR) {
recordFatalError(t);
}
}

public void recordFatalErrorNotFinish(Throwable cause) {
recordStatusNotFinish(OperationResultStatus.FATAL_ERROR, cause.getMessage(), cause);
}
Expand Down
Expand Up @@ -8,25 +8,16 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.RelationRegistry;
import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentSelectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrderConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ServiceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -207,11 +198,8 @@ public static <O extends ObjectType> List<String> determineSubTypes(PrismObject<
}

public static <O extends ObjectType> boolean hasSubtype(PrismObject<O> object, String subtype) {
List<String> objectSubtypes = determineSubTypes(object);
if (objectSubtypes == null) {
return false;
}
return objectSubtypes.contains(subtype);
return determineSubTypes(object)
.contains(subtype);
}

public static <O extends ObjectType> void setSubtype(PrismObject<O> object, List<String> subtypes) {
Expand All @@ -224,4 +212,12 @@ public static <O extends ObjectType> void setSubtype(PrismObject<O> object, Lis
objSubtypes.addAll(subtypes);
}
}

@NotNull
public static <F extends FocusType> List<ObjectReferenceType> getLiveLinkRefs(F focus) {
RelationRegistry relationRegistry = SchemaService.get().relationRegistry();
return focus.getLinkRef().stream()
.filter(ref -> relationRegistry.isMember(ref.getRelation()))
.collect(Collectors.toList());
}
}
Expand Up @@ -30,6 +30,8 @@

import org.apache.commons.lang3.StringUtils;

import static com.evolveum.midpoint.util.MiscUtil.castSafely;

/**
* Utility methods related to ScriptingExpressionType beans.
*/
Expand Down Expand Up @@ -91,7 +93,7 @@ public static <T> T getBeanPropertyValue(ActionExpressionType action, String pro
try {
try {
Object rawValue = PropertyUtils.getSimpleProperty(action, propertyName);
return MiscUtil.cast(rawValue, clazz);
return castSafely(rawValue, clazz);
} catch (NoSuchMethodException e) {
if (Boolean.class.equals(clazz)) {
// Note that getSimpleProperty looks for "getX" instead of our "isX" getter for Boolean (not boolean) props.
Expand All @@ -112,7 +114,7 @@ private static Boolean getBeanBooleanPropertyValue(ActionExpressionType action,
try {
String methodName = "is" + StringUtils.capitalize(propertyName);
Object rawValue = MethodUtils.invokeExactMethod(action, methodName, new Object[0]);
return MiscUtil.cast(rawValue, Boolean.class);
return castSafely(rawValue, Boolean.class);
} catch (NoSuchMethodException e) {
// This can occur when dynamic parameters are used: the action is of generic type, not the specific one.
return null;
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.processor.ObjectFactory;
Expand Down Expand Up @@ -167,6 +168,11 @@ public static ResourceAttributeContainer getAttributesContainer(PrismObject<? ex
return getAttributesContainer(shadow.getValue(), containerName);
}

public static boolean isAttributesContainerRaw(PrismObject<? extends ShadowType> shadow) {
PrismContainer<ShadowAttributesType> container = shadow.findContainer(ShadowType.F_ATTRIBUTES);
return container != null && !(container instanceof ResourceAttributeContainer);
}

public static ResourceAttributeContainer getAttributesContainer(PrismContainerValue<?> cval, QName containerName) {
PrismContainer attributesContainer = cval.findContainer(containerName);
if (attributesContainer == null) {
Expand Down Expand Up @@ -506,6 +512,14 @@ public static boolean isNotDead(PrismObject<ShadowType> shadow) {
return !isDead(shadow);
}

public static boolean isDead(ObjectReferenceType projectionRef) {
return !SchemaService.get().relationRegistry().isMember(projectionRef.getRelation());
}

public static boolean isNotDead(ObjectReferenceType projectionRef) {
return !isDead(projectionRef);
}

public static boolean isExists(ShadowType shadow) {
Boolean exists = shadow.isExists();
return exists == null || exists;
Expand Down Expand Up @@ -897,4 +911,10 @@ public static void removeAllAttributesExceptPrimaryIdentifier(PrismObject<Shadow
}
}
}

public static List<ObjectReferenceType> selectLiveLinks(List<ObjectReferenceType> refs) {
return refs.stream()
.filter(ShadowUtil::isNotDead)
.collect(Collectors.toList());
}
}
Expand Up @@ -22272,6 +22272,24 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="related">
<xsd:annotation>
<xsd:documentation>
Relation "is related to" kind.

Specifies that the subject is somewhat related to the owner, but this relation does not bring any
specific privileges or entitlements or whatever to it. It is just a descriptive information, with
no tangible effect.

Currently used to link shadow owners to their dead shadows. We want to maintain such link but
we do not want to show them e.g. in links counts etc.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="RELATED"/>
<a:since>4.3</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

Expand Down
19 changes: 16 additions & 3 deletions infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java
Expand Up @@ -87,8 +87,8 @@ public static <T> Collection<? extends T> unionExtends(Collection<? extends T>..
return resultSet;
}

public static <T> boolean unorderedCollectionEquals(Collection<T> a, Collection<T> b) {
return unorderedCollectionEquals(a, b, (xa, xb) -> xa.equals(xb));
public static <T> boolean unorderedCollectionEquals(Collection<? extends T> a, Collection<? extends T> b) {
return unorderedCollectionEquals(a, b, Object::equals);
}

/**
Expand Down Expand Up @@ -857,7 +857,7 @@ public static <T> List<T> singletonOrEmptyList(T value) {
return value != null ? singletonList(value) : emptyList();
}

public static <T> T cast(Object value, Class<T> expectedClass) throws SchemaException {
public static <T> T castSafely(Object value, Class<T> expectedClass) throws SchemaException {
if (value == null) {
return null;
} else if (!expectedClass.isAssignableFrom(value.getClass())) {
Expand Down Expand Up @@ -966,6 +966,19 @@ public static <T> T requireNonNull(T value, Supplier<String> messageSupplier) th
}
}

@FunctionalInterface
public interface ExceptionSupplier<E> {
E get();
}

public static <T, E extends Exception> T requireNonNull(T value, ExceptionSupplier<E> exceptionSupplier) throws E {
if (value != null) {
return value;
} else {
throw exceptionSupplier.get();
}
}

public static void checkCollectionImmutable(Collection<?> collection) {
try {
collection.add(null);
Expand Down
Expand Up @@ -44,6 +44,7 @@ public interface ModelContext<F extends ObjectType> extends Serializable, DebugD
@NotNull
ModelElementContext<F> getFocusContextRequired();

@NotNull
Collection<? extends ModelProjectionContext> getProjectionContexts();

ModelProjectionContext findProjectionContext(ResourceShadowDiscriminator rat);
Expand Down
Expand Up @@ -30,7 +30,8 @@ public enum SynchronizationIntent {
KEEP,

/**
* Existing account that should be unlinked (but NOT deleted)
* Existing account that should be unlinked (but NOT deleted). By unlinking we mean physically removing
* a value from `linkRef`. This intent should be used only when really needed.
*/
UNLINK,

Expand Down
Expand Up @@ -33,7 +33,8 @@ public enum SynchronizationPolicyDecision {
KEEP,

/**
* Existing account that is going to be unlinked (but NOT deleted)
* Existing account that should be unlinked (but NOT deleted). By unlinking we mean either physically removing
* a value from `linkRef`.
*/
UNLINK,

Expand Down

0 comments on commit 7730664

Please sign in to comment.