Skip to content

Commit

Permalink
Do cosmetic code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 11, 2023
1 parent b21729e commit 6274b8d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public <T extends ObjectType> String addObject(PrismObject<T> object, ModelExecu
OperationResult result = parentResult.createSubresult(ADD_OBJECT);
result.addParam(OperationResult.PARAM_OBJECT, object);

ModelImplUtils.resolveReferences(object, repository, false, false, EvaluationTimeType.IMPORT, true, result);
ModelImplUtils.resolveReferences(
object, repository, false, false,
EvaluationTimeType.IMPORT, true, result);

String oid;
RepositoryCache.enterLocalCaches(cacheConfigurationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(
// if plain import is requested, we simply evaluate filters in ADD operation (and we do not force reevaluation if OID is already set)
for (ObjectDelta<? extends ObjectType> delta : deltas) {
if (delta.isAdd()) {
ModelImplUtils.resolveReferences(delta.getObjectToAdd(), cacheRepositoryService, false, false, EvaluationTimeType.IMPORT, true, result);
ModelImplUtils.resolveReferences(
delta.getObjectToAdd(), cacheRepositoryService,
false, false, EvaluationTimeType.IMPORT,
true, result);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

/**
* Extension of validator used to import objects to the repository.
* <p/>
*
* In addition to validating the objects the importer also tries to resolve the
* references and may also do other repository-related stuff.
*
Expand Down Expand Up @@ -177,7 +177,7 @@ public void handleGlobalError(OperationResult currentResult) {
}
}
validator.setStopAfterErrors(stopAfterErrors);
if (options != null && options.isCompatMode() != null && options.isCompatMode()) {
if (options != null && Boolean.TRUE.equals(options.isCompatMode())) {
validator.setCompatMode(true);
}
validator.validate(input, parentResult, OperationConstants.IMPORT_OBJECT);
Expand All @@ -203,8 +203,9 @@ private <T extends Objectable> EventResult importParsedObject(PrismObject<T> pri

object = migrator.migrate(object);

ModelImplUtils.resolveReferences(object, repository,
options != null && options.isReferentialIntegrity() != null && options.isReferentialIntegrity(),
ModelImplUtils.resolveReferences(
object, repository,
options != null && Boolean.TRUE.equals(options.isReferentialIntegrity()),
false, EvaluationTimeType.IMPORT, false, objectResult);

objectResult.computeStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;

import static com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection;

Expand Down Expand Up @@ -232,7 +228,8 @@ public static <F extends ObjectType> ConflictResolutionType getConflictResolutio
* @param enforceReferentialIntegrity If true, missing reference causes fatal error when processing (if false, only warning is issued).
* @param forceFilterReevaluation If true, references are reevaluated even if OID is present. (Given that filter is present as well, of course.)
*/
public static <T extends ObjectType> void resolveReferences(PrismObject<T> object, RepositoryService repository,
public static <T extends ObjectType> void resolveReferences(
PrismObject<T> object, RepositoryService repository,
boolean enforceReferentialIntegrity, boolean forceFilterReevaluation, EvaluationTimeType resolutionTime,
boolean throwExceptionOnFailure,
OperationResult result) {
Expand All @@ -241,7 +238,8 @@ public static <T extends ObjectType> void resolveReferences(PrismObject<T> objec
if (!(visitable instanceof PrismReferenceValue)) {
return;
}
resolveRef((PrismReferenceValue)visitable, repository, enforceReferentialIntegrity, forceFilterReevaluation,
resolveRef(
(PrismReferenceValue)visitable, repository, enforceReferentialIntegrity, forceFilterReevaluation,
resolutionTime, object.toString(), throwExceptionOnFailure, result);
};
object.accept(visitor);
Expand All @@ -251,8 +249,8 @@ public static <T extends ObjectType> void resolveReferences(PrismObject<T> objec
* Resolves references contained in ADD and REPLACE value sets for item modifications in a given ObjectDelta.
* (specially treats collisions with values to be deleted)
*/

public static <T extends ObjectType> void resolveReferences(ObjectDelta<T> objectDelta, RepositoryService repository,
public static <T extends ObjectType> void resolveReferences(
ObjectDelta<T> objectDelta, RepositoryService repository,
boolean enforceReferentialIntegrity, boolean forceFilterReevaluation,
EvaluationTimeType resolutionTime, boolean throwExceptionOnFailure,
OperationResult result) {
Expand All @@ -261,7 +259,8 @@ public static <T extends ObjectType> void resolveReferences(ObjectDelta<T> objec
if (!(visitable instanceof PrismReferenceValue)) {
return;
}
resolveRef((PrismReferenceValue)visitable, repository, enforceReferentialIntegrity, forceFilterReevaluation,
resolveRef(
(PrismReferenceValue) visitable, repository, enforceReferentialIntegrity, forceFilterReevaluation,
resolutionTime, objectDelta.toString(), throwExceptionOnFailure, result);
};
// We could use objectDelta.accept(visitor), but we want to visit only values to add and replace
Expand Down Expand Up @@ -299,38 +298,35 @@ static void applyVisitorToValues(Collection<? extends PrismValue> values, ItemDe
}
}

public static void resolveRef(PrismReferenceValue refVal, RepositoryService repository,
boolean enforceReferentialIntegrity, boolean forceFilterReevaluation, EvaluationTimeType evaluationTimeType,
/**
* Resolves a filter in a reference. Skips the resolution if there's an expression in a filter.
* (Currently checks only the top level!)
*/
public static void resolveRef(
PrismReferenceValue refVal, RepositoryService repository,
boolean enforceReferentialIntegrity, boolean forceFilterReevaluation, EvaluationTimeType evaluationTime,
String contextDesc, boolean throwExceptionOnFailure, OperationResult parentResult) {
PrismContext prismContext = PrismContext.get();
String refName = refVal.getParent() != null ?
refVal.getParent().getElementName().toString() : "(unnamed)";

if ((refVal.getResolutionTime() != null && refVal.getResolutionTime() != evaluationTimeType) ||
(refVal.getResolutionTime() == null && evaluationTimeType != EvaluationTimeType.IMPORT)) {
LOGGER.trace("Skipping resolution of reference {} in {} because the resolutionTime is set to {}", refName, contextDesc, refVal.getResolutionTime());
var effectiveResolutionTime = refVal.getEffectiveResolutionTime();
if (effectiveResolutionTime != evaluationTime) {
LOGGER.trace("Skipping resolution of reference {} in {} because the resolutionTime is set to {}",
refName, contextDesc, effectiveResolutionTime);
return;
}

OperationResult result = parentResult.createMinorSubresult(OPERATION_RESOLVE_REFERENCE);
result.addContext(OperationResult.CONTEXT_ITEM, refName);

QName typeQName = null;
if (refVal.getTargetType() != null) {
typeQName = refVal.getTargetType();
}
if (typeQName == null) {
PrismReferenceDefinition definition = (PrismReferenceDefinition) refVal.getParent().getDefinition();
if (definition != null) {
typeQName = definition.getTargetTypeName();
}
}
QName typeQName = refVal.determineTargetTypeName();
Class<? extends ObjectType> type = ObjectType.class;
if (typeQName != null) {
type = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
if (type == null) {
result.recordWarning("Unknown type specified in reference or definition of reference " + refName + ": "
+ typeQName);
result.recordWarning(
"Unknown type specified in reference or definition of reference " + refName + ": " + typeQName);
type = ObjectType.class;
}
}
Expand Down Expand Up @@ -396,14 +392,14 @@ public static void resolveRef(PrismReferenceValue refVal, RepositoryService repo
// No OID and we have filter. Let's check the filter a bit
ObjectFilter objFilter;
try{
PrismObjectDefinition objDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
PrismObjectDefinition<?> objDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
objFilter = prismContext.getQueryConverter().parseFilter(filter, objDef);
} catch (SchemaException ex){
LOGGER.error("Failed to convert object filter from filter because of: "+ ex.getMessage() + "; filter: " + filter.debugDump(), ex);
throw new SystemException("Failed to convert object filter from filter. Reason: " + ex.getMessage(), ex);
}

LOGGER.trace("Resolving using filter {}", objFilter.debugDump());
LOGGER.trace("Resolving using filter {}", objFilter.debugDumpLazily());
List<PrismObject<? extends ObjectType>> objects;
QName objectType = refVal.getTargetType();
if (objectType == null) {
Expand All @@ -415,7 +411,7 @@ public static void resolveRef(PrismReferenceValue refVal, RepositoryService repo
return;
}

if (containExpression(objFilter)){
if (containExpression(objFilter)) {
result.recordSuccessIfUnknown();
return;
}
Expand Down Expand Up @@ -464,20 +460,11 @@ public static void resolveRef(PrismReferenceValue refVal, RepositoryService repo
result.recordSuccessIfUnknown();
}

// TODO what about expressions in deeper filters (e.g. when using AND/OR/NOT?)
private static boolean containExpression(ObjectFilter filter) {
if (filter == null) {
return false;
}
if (filter instanceof InOidFilter && ((InOidFilter) filter).getExpression() != null) {
return true;
}
if (filter instanceof FullTextFilter && ((FullTextFilter) filter).getExpression() != null) {
return true;
}
if (filter instanceof ValueFilter && ((ValueFilter) filter).getExpression() != null) {
return true;
}
return false;
return filter instanceof InOidFilter inOidFilter && inOidFilter.getExpression() != null
|| filter instanceof FullTextFilter fullTextFilter && fullTextFilter.getExpression() != null
|| filter instanceof ValueFilter<?, ?> valueFilter && valueFilter.getExpression() != null;
}

public static void encrypt(Collection<ObjectDelta<? extends ObjectType>> deltas, Protector protector, ModelExecuteOptions options,
Expand All @@ -495,9 +482,10 @@ public static void encrypt(Collection<ObjectDelta<? extends ObjectType>> deltas,
}
}

public static void setRequestee(Task task, LensContext context) {
public static void setRequestee(Task task, LensContext<?> context) {
PrismObject<? extends ObjectType> object;
if (context != null && context.getFocusContext() != null
if (context != null
&& context.getFocusContext() != null
&& UserType.class.isAssignableFrom(context.getFocusContext().getObjectTypeClass())) {
object = context.getFocusContext().getObjectAny();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@

/**
* Activity handler for report import.
*
* Note that we cannot support legacy URI here. The reason is that from the URI itself we cannot distinguish report export
* from report import. This is possible only after retrieving the report definition - and this is just too late for
* the activity framework.
*
* So we simply do not support legacy URI for importing reports. (Or we could devise a separate URI for this, if needed.)
*/
@Component
public class ClassicReportImportActivityHandler
Expand Down

0 comments on commit 6274b8d

Please sign in to comment.