Skip to content

Commit

Permalink
Fix task/result handling in OrgStructFunctionsImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 12, 2019
1 parent 3321094 commit e8297d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
Expand Up @@ -1009,6 +1009,10 @@ Collection<String> getManagersOidsExceptUser(@NotNull Collection<ObjectReference

Task getCurrentTask();

OperationResult getCurrentResult();

OperationResult getCurrentResult(String operationName);

ModelContext unwrapModelContext(LensContextType lensContextType) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException;

<F extends FocusType> boolean isDirectlyAssigned(F focusType, String targetOid);
Expand Down
Expand Up @@ -799,7 +799,8 @@ public Task getCurrentTask() {
return rv;
}

private OperationResult getCurrentResult() {
@Override
public OperationResult getCurrentResult() {
OperationResult rv = ModelExpressionThreadLocalHolder.getCurrentResult();
if (rv == null) {
// fallback (MID-4130): but maybe we should instead make sure ModelExpressionThreadLocalHolder is set up correctly
Expand All @@ -811,7 +812,8 @@ private OperationResult getCurrentResult() {
return rv;
}

private OperationResult getCurrentResult(String operationName) {
@Override
public OperationResult getCurrentResult(String operationName) {
OperationResult currentResult = getCurrentResult();
if (currentResult == null) {
return new OperationResult(operationName);
Expand Down
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.model.impl.expr;

import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.model.api.expr.OrgStructFunctions;
import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.PrismContext;
Expand All @@ -29,7 +30,6 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -54,19 +54,16 @@
public class OrgStructFunctionsImpl implements OrgStructFunctions {

private static final Trace LOGGER = TraceManager.getTrace(OrgStructFunctionsImpl.class);
private static final String CLASS_DOT = OrgStructFunctions.class.getName() + ".";

@Autowired
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;

@Autowired
private ModelService modelService;

@Autowired
private PrismContext prismContext;

@Autowired
private RelationRegistry relationRegistry;
@Autowired private ModelService modelService;
@Autowired private PrismContext prismContext;
@Autowired private RelationRegistry relationRegistry;
@Autowired private MidpointFunctions midpointFunctions;

/**
* Returns a list of user's managers. Formally, for each Org O which this user has (any) relation to,
Expand Down Expand Up @@ -223,7 +220,7 @@ public OrgType getOrgByOid(String oid, boolean preAuthorized) throws SchemaExcep
public OrgType getOrgByName(String name, boolean preAuthorized) throws SchemaException, SecurityViolationException {
PolyString polyName = new PolyString(name);
ObjectQuery q = ObjectQueryUtil.createNameQuery(polyName, prismContext);
List<PrismObject<OrgType>> result = searchObjects(OrgType.class, q, getCurrentResult(), preAuthorized);
List<PrismObject<OrgType>> result = searchObjects(OrgType.class, q, midpointFunctions.getCurrentResult(), preAuthorized);
if (result.isEmpty()) {
return null;
}
Expand Down Expand Up @@ -345,11 +342,10 @@ public <T extends ObjectType> T getObject(Class<T> type, String oid, boolean pre
CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
PrismObject<T> prismObject;
if (preAuthorized) {
prismObject = repositoryService.getObject(type, oid, null, getCurrentResult());
prismObject = repositoryService.getObject(type, oid, null, midpointFunctions.getCurrentResult());
} else {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createExecutionPhase());
OperationResult result = new OperationResult("getObject");
prismObject = modelService.getObject(type, oid, options, getCurrentTask(), result);
prismObject = modelService.getObject(type, oid, options, midpointFunctions.getCurrentTask(), midpointFunctions.getCurrentResult(CLASS_DOT + "getObject"));
}
return prismObject.asObjectable();
}
Expand All @@ -361,18 +357,10 @@ private <T extends ObjectType> List<PrismObject<T>> searchObjects(Class<T> clazz
} else {
try {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createExecutionPhase());
return modelService.searchObjects(clazz, query, options, getCurrentTask(), result);
return modelService.searchObjects(clazz, query, options, midpointFunctions.getCurrentTask(), result);
} catch (ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
throw new SystemException("Couldn't search objects: " + e.getMessage(), e);
}
}
}

private Task getCurrentTask() {
return ModelExpressionThreadLocalHolder.getCurrentTask();
}

private OperationResult getCurrentResult() {
return ModelExpressionThreadLocalHolder.getCurrentResult();
}
}

0 comments on commit e8297d2

Please sign in to comment.