Skip to content

Commit

Permalink
isFullShadow midpoint script function (MID-3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jan 16, 2017
1 parent c0b97de commit da4b9a6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1009,4 +1009,7 @@ <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query)
ObjectDeltaType getResourceDelta(ModelContext context, String resourceOid) throws SchemaException;

Protector getProtector();

boolean isFullShadow();

}
Expand Up @@ -484,6 +484,16 @@ public ShadowType getLinkedShadow(FocusType focus, String resourceOid, ShadowKin
}
return null;
}

@Override
public boolean isFullShadow() {
LensProjectionContext projectionContext = getProjectionContext();
if (projectionContext == null) {
LOGGER.debug("Call to isFullShadow while there is no projection context");
return false;
}
return projectionContext.isFullShadow();
}

public <T> Integer countAccounts(String resourceOid, QName attributeName, T attributeValue) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
OperationResult result = getCurrentResult(MidpointFunctions.class.getName()+".countAccounts");
Expand Down Expand Up @@ -641,6 +651,10 @@ public boolean handle(PrismObject<ShadowType> object, OperationResult parentResu
return isUniqueHolder.getValue();
}

private LensProjectionContext getProjectionContext() {
return ModelExpressionThreadLocalHolder.getProjectionContext();
}

private Task getCurrentTask() {
return ModelExpressionThreadLocalHolder.getCurrentTask();
}
Expand All @@ -657,7 +671,7 @@ private OperationResult getCurrentResult(String operationName) {
return currentResult;
}
}

private OperationResult createSubresult(String operationName) {
OperationResult currentResult = ModelExpressionThreadLocalHolder.getCurrentResult();
if (currentResult == null) {
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.model.common.expression.Expression;
import com.evolveum.midpoint.model.common.expression.ExpressionEvaluationContext;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.model.impl.lens.LensProjectionContext;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
Expand Down Expand Up @@ -72,6 +73,14 @@ public static <F extends ObjectType> LensContext<F> getLensContext() {
return (LensContext<F>) env.getLensContext();
}

public static <F extends ObjectType> LensProjectionContext getProjectionContext() {
ExpressionEnvironment<ObjectType> env = getExpressionEnvironment();
if (env == null) {
return null;
}
return env.getProjectionContext();
}

public static Task getCurrentTask() {
ExpressionEnvironment<ObjectType> env = getExpressionEnvironment();
if (env == null) {
Expand Down
Expand Up @@ -34,6 +34,7 @@
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.model.impl.lens.LensElementContext;
import com.evolveum.midpoint.model.impl.lens.LensUtil;
import com.evolveum.midpoint.model.impl.lens.LensProjectionContext;
import com.evolveum.midpoint.model.impl.trigger.RecomputeTriggerHandler;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
Expand Down Expand Up @@ -77,8 +78,14 @@ public class MappingEvaluator {

public <V extends PrismValue, D extends ItemDefinition, F extends ObjectType> void evaluateMapping(
Mapping<V,D> mapping, LensContext<F> lensContext, Task task, OperationResult parentResult) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
evaluateMapping(mapping, lensContext, null, task, parentResult);
}

public <V extends PrismValue, D extends ItemDefinition, F extends ObjectType> void evaluateMapping(
Mapping<V,D> mapping, LensContext<F> lensContext, LensProjectionContext projContext, Task task, OperationResult parentResult) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
ExpressionEnvironment<F> env = new ExpressionEnvironment<>();
env.setLensContext(lensContext);
env.setProjectionContext(projContext);
env.setCurrentResult(parentResult);
env.setCurrentTask(task);
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(env);
Expand Down
Expand Up @@ -268,7 +268,7 @@ public StringPolicyType resolve() {
}

Mapping<V,D> mapping = mappingBuilder.build();
mappingEvaluator.evaluateMapping(mapping, context, task, result);
mappingEvaluator.evaluateMapping(mapping, context, projCtx, task, result);

return mapping;
}
Expand Down
Expand Up @@ -126,30 +126,35 @@
<expression>
<script> <!-- MID-3661 -->
<code>
log.error("XXXXX locality: "+locality)
log.error("locality: "+locality)
def fixedDrink = []
if (account) {
log.error("XXXXX account:\n"+basic.debugDump(account,1))
log.error("account:\n"+basic.debugDump(account,1))
def drink = basic.getAttributeValues(account, 'drink')
log.error("XXXXX drink(1): "+drink)
log.error("drink(1): "+drink)
if (drink != null) {
drink.each {
if (!it?.startsWith('rum')) {
fixedDrink.add(it)
}
}
log.error("XXXXX fixedDrink(2): "+fixedDrink)
log.error("fixedDrink(2): "+fixedDrink)
if (locality != null) {
fixedDrink.add('rum from ' + locality);
}
log.error("XXXXX fixedDrink(3): "+fixedDrink)
log.error("fixedDrink(3): "+fixedDrink)
}
}
log.error("XXXXX fixedDrink(4): "+fixedDrink)
log.error("fixedDrink(4): "+fixedDrink)
return fixedDrink
</code>
</script>
</expression>
<condition>
<script>
<code>midpoint.isFullShadow()</code>
</script>
</condition>
</outbound>
</attribute>
<attribute>
Expand Down

0 comments on commit da4b9a6

Please sign in to comment.