Skip to content

Commit

Permalink
It compiles! (Typed script variable definitions)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 18, 2019
1 parent 422f121 commit 63048ad
Show file tree
Hide file tree
Showing 47 changed files with 383 additions and 261 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 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 @@ -1345,7 +1345,7 @@ private OperationResult executeResultScriptHook(OperationResult result) {

OperationResultType resultType = result.createOperationResultType();

variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, resultType);
variables.put(ExpressionConstants.VAR_INPUT, resultType, OperationResultType.class);

ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task, topResult);
PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple = expression.evaluate(context);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 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 @@ -133,7 +133,7 @@ private String getExpressionValue(ExpressionType expressionType, String contextD
DOMUtil.XSD_STRING);
Expression<PrismPropertyValue<String>,PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, contextDesc, task, result);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, object);
variables.put(ExpressionConstants.VAR_OBJECT, object, object.asPrismContainerValue().getDefinition());
addAdditionalExpressionVariables(variables);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = expression.evaluate(context);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,16 +16,21 @@

package com.evolveum.midpoint.init;

import java.io.File;
import java.util.Arrays;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.Validate;
import org.springframework.security.core.context.SecurityContext;

import com.evolveum.midpoint.model.api.ScriptExecutionResult;
import com.evolveum.midpoint.model.api.ScriptingService;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ReportTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
Expand All @@ -34,16 +39,8 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.Validate;
import org.springframework.security.core.context.SecurityContext;

import java.io.File;
import java.util.*;

/**
* @author lazyman
Expand Down Expand Up @@ -170,7 +167,7 @@ private <O extends ObjectType> Boolean executeScript(PrismProperty<Object> expre
Object parsed = expression.getAnyValue().getValue();
ScriptExecutionResult executionResult =
parsed instanceof ExecuteScriptType ?
scripting.evaluateExpression((ExecuteScriptType) parsed, Collections.emptyMap(),
scripting.evaluateExpression((ExecuteScriptType) parsed, VariablesMap.emptyMap(),
false, task, result) :
scripting.evaluateExpression((ScriptingExpressionType) parsed, task, result);
result.recordSuccess();
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2017 Evolveum
* Copyright (c) 2015-2019 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 @@ -127,7 +127,7 @@ protected IModel<String> getDefaltParentOrgModel() {
@Override
protected void addAdditionalExpressionVariables(ExpressionVariables variables) {
List<OrgType> parentOrgs = getModelObject().getParentOrg();
variables.addVariableDefinition(ExpressionConstants.VAR_ORGS, parentOrgs);
variables.putList(ExpressionConstants.VAR_ORGS, parentOrgs);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 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 @@ -74,19 +74,19 @@ public class ResourceActivationEditor extends BasePanel<ResourceActivationDefini
private static final String ID_T_VALID_T_IN = "validToInboundTooltip";

//Default mapping inbound/outbound sources/targets
public static final String EXISTENCE_DEFAULT_SOURCE = "&" + ExpressionConstants.VAR_LEGAL.getLocalPart();
public static final String ADM_STATUS_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/administrativeStatus";
public static final String ADM_STATUS_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/administrativeStatus";
public static final String VALID_TO_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/validTo";
public static final String VALID_TO_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/validTo";
public static final String VALID_TO_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/validTo";
public static final String VALID_TO_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/validTo";
public static final String VALID_FROM_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/validFrom";
public static final String VALID_FROM_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/validFrom";
public static final String VALID_FROM_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION.getLocalPart() + "/activation/validFrom";
public static final String VALID_FROM_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS.getLocalPart() + "/activation/validFrom";
public static final String EXISTENCE_DEFAULT_SOURCE = "&" + ExpressionConstants.VAR_LEGAL;
public static final String ADM_STATUS_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/administrativeStatus";
public static final String ADM_STATUS_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/administrativeStatus";
public static final String ADM_STATUS_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/administrativeStatus";
public static final String VALID_TO_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validTo";
public static final String VALID_TO_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validTo";
public static final String VALID_TO_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validTo";
public static final String VALID_TO_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validTo";
public static final String VALID_FROM_OUT_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validFrom";
public static final String VALID_FROM_OUT_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validFrom";
public static final String VALID_FROM_IN_SOURCE_DEFAULT = "&" + ExpressionConstants.VAR_PROJECTION + "/activation/validFrom";
public static final String VALID_FROM_IN_TARGET_DEFAULT = "&" + ExpressionConstants.VAR_FOCUS + "/activation/validFrom";

private boolean isInitialized = false;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import com.evolveum.midpoint.model.api.ScriptExecutionException;
import com.evolveum.midpoint.model.api.ScriptExecutionResult;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
Expand Down Expand Up @@ -46,8 +47,6 @@
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import java.util.Collections;

/**
* @author lazyman
*/
Expand Down Expand Up @@ -144,7 +143,7 @@ private void startPerformed(AjaxRequestTarget target) {
//noinspection ConstantConditions
ScriptExecutionResult executionResult =
parsed instanceof ExecuteScriptType ?
getScriptingService().evaluateExpression((ExecuteScriptType) parsed, Collections.emptyMap(),
getScriptingService().evaluateExpression((ExecuteScriptType) parsed, VariablesMap.emptyMap(),
false, task, result) :
getScriptingService().evaluateExpression((ScriptingExpressionType) parsed, task, result);
result.recordStatus(OperationResultStatus.SUCCESS, createStringResource("PageBulkAction.message.startPerformed.success", executionResult.getDataOutput().size()).getString());
Expand Down
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.util;

import java.util.Collection;
Expand Down Expand Up @@ -139,8 +154,8 @@ public void validate(IValidatable<T> validatable) {
return;
}
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, valueToValidate);
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, getObjectType());
variables.put(ExpressionConstants.VAR_INPUT, valueToValidate, valueToValidate.getClass());
variables.putObject(ExpressionConstants.VAR_OBJECT, (ObjectType)getObjectType(), ObjectType.class);
// addAdditionalExpressionVariables(variables);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple;
Expand Down
Expand Up @@ -18,8 +18,15 @@
import com.evolveum.midpoint.prism.path.ItemName;

/**
* @author semancik
*
* Constants for all names of the variables in the system.
*
* It is good to have all the names gathered in one place. It is better when a new
* variable is introduced. If all the names are in the same place, it is better to
* see if the variable is redundant (already used eslewhere). Or if new variable is
* really needed, seeing all the other names will make it easier to keep the same
* convention through the system.
*
* @author Radovan Semancik
*/
public class ExpressionConstants {

Expand Down Expand Up @@ -120,15 +127,42 @@ public class ExpressionConstants {
public static final String VAR_TASK = "task";
public static final String VAR_RULE_EVALUATION_CONTEXT = "ruleEvaluationContext";
public static final String VAR_STAGE_DEFINITION = "stageDefinition";
public static final String VAR_ITEM_TO_APPROVE = "itemToApprove";

public static final String VAR_OBJECT_DISPLAY_INFORMATION = "objectDisplayInformation";
public static final String VAR_TARGET_DISPLAY_INFORMATION = "targetDisplayInformation";

public static final String VAR_PERFORMER = "performer";
public static final String VAR_OUTPUT = "output";
public static final String VAR_EVENT = "event";
public static final String VAR_REQUESTER = "requester";
public static final String VAR_REQUESTEE = "requestee";
public static final String VAR_ASSIGNEE = "assignee";
public static final String VAR_ASSOCIATION = "association";
public static final String VAR_SHADOW_DISCRIMINATOR = "shadowDiscriminator";

public static final String VAR_POLICY_RULE = "policyRule";
public static final String VAR_POLICY_ACTION = "policyAction";
public static final String VAR_LOGIN_MODE = "loginMode";

// Notification variables
public static final String VAR_TRANSPORT_NAME = "transportName";
public static final String VAR_FROM = "from";
public static final String VAR_ENCODED_FROM = "encodedFrom";
public static final String VAR_TO = "to";
public static final String VAR_TO_LIST = "toList";
public static final String VAR_ENCODED_TO = "encodedTo";
public static final String VAR_ENCODED_TO_LIST = "encodedToList";
public static final String VAR_MESSAGE_TEXT = "messageText";
public static final String VAR_ENCODED_MESSAGE_TEXT = "encodedMessageText";
public static final String VAR_MESSAGE = "message";
public static final String VAR_TEXT_FORMATTER = "textFormatter";
public static final String VAR_NOTIFICATION_FUNCTIONS = "notificationFunctions";

// Do we need those?
public static final String VAR_OBJECT_DELTA = "objectDelta";

// Too vague. modelContext or prismConext should be used instead.
@Deprecated
public static final String VAR_CONTEXT = "context";
}
Expand Up @@ -87,9 +87,6 @@ public abstract class SchemaConstants {
public static final ItemName C_RESOURCE = new ItemName(NS_C, "resource");
public static final ItemName C_RESULT = new ItemName(NS_C, "result");
public static final ItemName C_USER = new ItemName(NS_C, "user");
public static final ItemName C_REQUESTER = new ItemName(NS_C, "requester");
public static final ItemName C_REQUESTEE = new ItemName(NS_C, "requestee");
public static final ItemName C_ASSIGNEE = new ItemName(NS_C, "assignee");
public static final ItemName C_OBJECT_TEMPLATE = new ItemName(NS_C, "objectTemplate");
public static final ItemName C_OBJECT_TEMPLATE_REF = new ItemName(NS_C, "objectTemplateRef");
public static final QName C_OBJECT_TEMPLATE_TYPE = new QName(NS_C, "ObjectTemplateType");
Expand Down Expand Up @@ -461,33 +458,13 @@ public abstract class SchemaConstants {

public static final ItemName S_PIPELINE_DATA = new ItemName(NS_SCRIPTING, "pipelineData");

public static final ItemName C_EVENT = new ItemName(NS_C, "event");
public static final ItemName C_EVENT_HANDLER = new ItemName(NS_C, "eventHandler"); // TODO: no such element in common-3 - is it OK?
public static final ItemName C_TEXT_FORMATTER = new ItemName(NS_C, "textFormatter");
public static final ItemName C_NOTIFICATION_FUNCTIONS = new ItemName(NS_C, "notificationFunctions");

public static final ItemName C_TRANSPORT_NAME = new ItemName(NS_C, "transportName");
public static final ItemName C_FROM = new ItemName(NS_C, "from");
public static final ItemName C_ENCODED_FROM = new ItemName(NS_C, "encodedFrom");
public static final ItemName C_TO = new ItemName(NS_C, "to");
public static final ItemName C_TO_LIST = new ItemName(NS_C, "toList");
public static final ItemName C_ENCODED_TO = new ItemName(NS_C, "encodedTo");
public static final ItemName C_ENCODED_TO_LIST = new ItemName(NS_C, "encodedToList");
public static final ItemName C_MESSAGE_TEXT = new ItemName(NS_C, "messageText");
public static final ItemName C_ENCODED_MESSAGE_TEXT = new ItemName(NS_C, "encodedMessageText");
public static final ItemName C_MESSAGE = new ItemName(NS_C, "message");
public static final ItemName C_WORK_ITEM = new ItemName(NS_C, "workItem");
public static final ItemName C_WF_PROCESS_INSTANCE = new ItemName(NS_C, "wfProcessInstance");

public static final ItemName APIT_ITEM_LIST = new ItemName(SchemaConstants.NS_API_TYPES, "itemList");
public static final ItemName C_ASSIGNMENT = new ItemName(SchemaConstants.NS_C, "assignment");

public static final ItemName C_NAME = new ItemName(SchemaConstants.NS_C, "name");

public static final ItemName FAULT_MESSAGE_ELEMENT_NAME = new ItemName(NS_FAULT, "fault");
public static final ItemName C_MODEL_CONTEXT = new ItemName(NS_C, "modelContext");
public static final ItemName C_ITEM_TO_APPROVE = new ItemName(NS_C, "itemToApprove");
public static final ItemName C_SHADOW_DISCRIMINATOR = new ItemName(NS_C, "shadowDiscriminator");

// Lifecycle

Expand Down
Expand Up @@ -31,8 +31,10 @@ public class TypedValue<T> {
/**
* Value may be null. This means variable without a value.
* But even in that case definition should be provided.
* The value is not T, it is Object. The value may not be in its
* final form yet. It may get converted later.
*/
private T value;
private Object value;

/**
* Definition should be filled in for all value that can be described using Prism definitions.
Expand All @@ -57,23 +59,23 @@ public TypedValue(Item<?, ?> prismItem) {
}
}

public TypedValue(T value, ItemDefinition<?> definition) {
public TypedValue(Object value, ItemDefinition<?> definition) {
super();
this.value = value;
this.definition = definition;
}

public TypedValue(T value, Class<T> typeClass) {
public TypedValue(Object value, Class<T> typeClass) {
super();
this.value = value;
this.typeClass = typeClass;
}

public T getValue() {
public Object getValue() {
return value;
}

public void setValue(T value) {
public void setValue(Object value) {
this.value = value;
}

Expand Down

0 comments on commit 63048ad

Please sign in to comment.