/** * Create an instance of {@link ScriptExpressionEvaluatorType } * */ public ScriptExpressionEvaluatorType createScriptExpressionEvaluatorType() { return new ScriptExpressionEvaluatorType(); }
/** * Creates a new {@code ScriptExpressionEvaluatorType} instance by deeply copying a given {@code ScriptExpressionEvaluatorType} instance. * * * @param o * The instance to copy. * @throws NullPointerException * if {@code o} is {@code null}. */ public ScriptExpressionEvaluatorType(final ScriptExpressionEvaluatorType o) { // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000 super(o); if (o == null) { throw new NullPointerException("Cannot create a copy of 'ScriptExpressionEvaluatorType' from 'null'."); } // CBuiltinLeafInfo: java.lang.String this.language = ((o.language == null)?null:o.getLanguage()); // CEnumLeafInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionReturnTypeType this.returnType = ((o.returnType == null)?null:o.getReturnType()); // CBuiltinLeafInfo: java.lang.String this.code = ((o.code == null)?null:o.getCode()); }
public ScriptExpressionEvaluatorType code(String value) { setCode(value); return this; }
private MappingType createCondition(String conditionName, char conditionType) { ScriptExpressionEvaluatorType script = new ScriptExpressionEvaluatorType(); switch (conditionType) { case '+': script.setCode("basic.stringify(name) == 'jack1'"); break; case '-': script.setCode("basic.stringify(name) == 'jack'"); break; case '0': script.setCode("basic.stringify(name) == 'never there'"); break; case '!': script.setCode(createDumpConditionCode(conditionName)); break; default: throw new AssertionError(conditionType); } ExpressionType expression = new ExpressionType(); expression.getExpressionEvaluator().add(new ObjectFactory().createScript(script)); VariableBindingDefinitionType source = new VariableBindingDefinitionType(); source.setPath(new ItemPathType(UserType.F_NAME)); MappingType rv = new MappingType(); rv.setName(conditionName); rv.setExpression(expression); rv.getSource().add(source); return rv; }
private String getLanguage(ScriptExpressionEvaluatorType expressionType) { if (expressionType.getLanguage() != null) { return expressionType.getLanguage(); } return DEFAULT_LANGUAGE; }
String codeString = expressionType.getCode(); if (codeString == null) { throw new ExpressionEvaluationException("No script code in " + contextDescription); if (expressionType.isAllowEmptyValues() != null) { allowEmptyValues = expressionType.isAllowEmptyValues();
private String formatCode() { return DebugUtil.excerpt(scriptType.getCode().replaceAll("[\\s\\r\\n]+", " "), MAX_CODE_CHARS); }
@Test public void test130DeputyAssignmentFalseCondition() throws Exception { final String TEST_NAME = "test130DeputyAssignmentFalseCondition"; executeDeputyLimitationsTest(TEST_NAME, null, (a) -> a.beginCondition() .beginExpression() .expressionEvaluator( new JAXBElement<ScriptExpressionEvaluatorType>(new QName("script"), ScriptExpressionEvaluatorType.class, new ScriptExpressionEvaluatorType().code("false")) )); }
@Override protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZero valueDestination, boolean useNew, ExpressionEvaluationContext context, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException { ScriptExpressionReturnTypeType returnType = getExpressionEvaluatorType().getReturnType(); if (returnType == null && isRelative()) { returnType = ScriptExpressionReturnTypeType.SCALAR; } scriptExpression.setAdditionalConvertor(context.getAdditionalConvertor()); return (List<V>) scriptExpression.evaluate(variables, returnType, useNew, contextDescription, task, result); }
/** * Creates and returns a deep copy of a given {@code javax.xml.bind.JAXBElement<com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType>} instance. * * @param e * The instance to copy or {@code null}. * @return * A deep copy of {@code e} or {@code null} if {@code e} is {@code null}. */ @SuppressWarnings("unchecked") private static JAXBElement<ScriptExpressionEvaluatorType> copyOfScriptExpressionEvaluatorTypeElement(final JAXBElement<ScriptExpressionEvaluatorType> e) { // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000 if (e!= null) { final JAXBElement<ScriptExpressionEvaluatorType> copy = new JAXBElement<ScriptExpressionEvaluatorType>(e.getName(), e.getDeclaredType(), e.getScope(), e.getValue()); copy.setNil(e.isNil()); // CClassInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType copy.setValue(((((ScriptExpressionEvaluatorType) copy.getValue()) == null)?null:((ScriptExpressionEvaluatorType) copy.getValue()).clone())); return copy; } return null; }
private void createCustomConstruction(RoleType role, String name, int order) { ConstructionType c = new ConstructionType(prismContext); c.setDescription(name); c.setResourceRef(ObjectTypeUtil.createObjectRef(RESOURCE_DUMMY_EMPTY_OID, ObjectTypes.RESOURCE)); ResourceAttributeDefinitionType nameDef = new ResourceAttributeDefinitionType(); nameDef.setRef(new ItemPathType(ItemPath.create(new QName(SchemaConstants.NS_ICF_SCHEMA, "name")))); MappingType outbound = new MappingType(); outbound.setName(name); ExpressionType expression = new ExpressionType(); ScriptExpressionEvaluatorType script = new ScriptExpressionEvaluatorType(); script.setCode( "import com.evolveum.midpoint.model.impl.lens.TestAssignmentProcessor2\n\n" + "TestAssignmentProcessor2.startCallback('" + name + "')\n" + "this.binding.variables.each {k,v -> TestAssignmentProcessor2.variableCallback(k, v, '" + name + "')}\n" + "TestAssignmentProcessor2.finishCallback('" + name + "')\n" + "return null"); expression.getExpressionEvaluator().add(new ObjectFactory().createScript(script)); outbound.setExpression(expression); nameDef.setOutbound(outbound); c.getAttribute().add(nameDef); AssignmentType a = new AssignmentType(prismContext); a.setDescription("Assignment for " + c.getDescription()); a.setConstruction(c); addAssignmentOrInducement(role, order, a); }
} else if (eval instanceof ScriptExpressionEvaluatorType) { ScriptExpressionEvaluatorType script = (ScriptExpressionEvaluatorType) eval; if (script.getLanguage() == null) { return "groovy"; } else { return StringUtils.substringAfter(script.getLanguage(), "#");
String codeString = expressionType.getCode(); if (codeString == null) { throw new ExpressionEvaluationException("No script code in " + contextDescription); if (expressionType.isAllowEmptyValues() != null) { allowEmptyValues = expressionType.isAllowEmptyValues();
private String getTooltipString() { ExpressionType expression = getMapping().getExpression(); if (expression == null || expression.getExpressionEvaluator().isEmpty()) { return "asIs"; } JAXBElement<?> evalElement = expression.getExpressionEvaluator().get(0); Object eval = evalElement.getValue(); if (QNameUtil.match(evalElement.getName(), SchemaConstants.C_VALUE)) { return getStringConstant(eval); } else if (eval instanceof AsIsExpressionEvaluatorType) { return "asIs"; } else if (eval instanceof ScriptExpressionEvaluatorType) { return ((ScriptExpressionEvaluatorType) eval).getCode(); } else if (eval instanceof ItemPathType) { return String.valueOf(((ItemPathType) eval).getItemPath()); } else { return ""; } }
clone.script = ((this.script == null)?null:((this.getScript() == null)?null:this.getScript().clone())); return clone;
/** * Creates and returns a deep copy of this object. * * * @return * A deep copy of this object. */ @Override public ScriptExpressionEvaluatorType clone() { { // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000 final ScriptExpressionEvaluatorType clone = ((ScriptExpressionEvaluatorType) super.clone()); // CBuiltinLeafInfo: java.lang.String clone.language = ((this.language == null)?null:this.getLanguage()); // CEnumLeafInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionReturnTypeType clone.returnType = ((this.returnType == null)?null:this.getReturnType()); // CBuiltinLeafInfo: java.lang.String clone.code = ((this.code == null)?null:this.getCode()); return clone; } }
/** * Create an instance of {@link ScriptExpressionEvaluatorType } * */ public ScriptExpressionEvaluatorType createScriptExpressionEvaluatorType() { return new ScriptExpressionEvaluatorType(); }
private ScriptExpression createScriptExpression(ScriptExpressionEvaluatorType expressionType, ItemDefinition outputDefinition, String shortDesc) throws ExpressionSyntaxException { ScriptExpression expression = new ScriptExpression(scriptExpressionfactory.getEvaluators().get(expressionType.getLanguage()), expressionType); expression.setOutputDefinition(outputDefinition); expression.setObjectResolver(scriptExpressionfactory.getObjectResolver()); expression.setFunctions(new ArrayList<>(scriptExpressionfactory.getFunctions())); return expression; }
@Test public void testParseExpressionFromJaxb() throws SchemaException, SAXException, IOException, JAXBException { PrismContext prismContext = PrismTestUtil.getPrismContext(); RoleType roleType = PrismTestUtil.parseObjectable(new File(TestConstants.COMMON_DIR, "role.xml"), RoleType.class); // WHEN PrismObject<RoleType> role = roleType.asPrismObject(); role.revive(prismContext); // THEN System.out.println("Parsed role:"); System.out.println(role.debugDump()); role.checkConsistence(); assertPropertyValue(role, RoleType.F_NAME, PrismTestUtil.createPolyString("r3")); PrismAsserts.assertEquals("Wrong number of approver expressions", 1, role.asObjectable().getApproverExpression().size()); Object o = role.asObjectable().getApproverExpression().get(0).getExpressionEvaluator().get(0).getValue(); PrismAsserts.assertEquals("Invalid evaluator type", ScriptExpressionEvaluatorType.class, o.getClass()); String code = ((ScriptExpressionEvaluatorType) o).getCode(); PrismAsserts.assertEquals("Incorrect code parsed", "midpoint.oid2ort(user.getOid())", code); }
/** * Creates a new {@code HookType} instance by deeply copying a given {@code HookType} instance. * * * @param o * The instance to copy. * @throws NullPointerException * if {@code o} is {@code null}. */ public HookType(final HookType o) { // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000 super(); if (o == null) { throw new NullPointerException("Cannot create a copy of 'HookType' from 'null'."); } // CBuiltinLeafInfo: java.lang.String this.name = ((o.name == null)?null:o.getName()); // CBuiltinLeafInfo: java.lang.String this.description = ((o.description == null)?null:o.getDescription()); // CBuiltinLeafInfo: java.lang.Boolean this.enabled = ((o.enabled == null)?null:o.isEnabled()); // CEnumLeafInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.ModelStateType this.state = ((o.state == null)?null:o.getState()); // CBuiltinLeafInfo: javax.xml.namespace.QName this.focusType = ((o.focusType == null)?null:o.getFocusType()); // CBuiltinLeafInfo: java.lang.String this.ref = ((o.ref == null)?null:o.getRef()); // CClassInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType this.script = ((o.script == null)?null:((o.getScript() == null)?null:o.getScript().clone())); }