com.cedarsoftware.ncube.GroovyMethod.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of n-cube Show documentation
Show all versions of n-cube Show documentation
Multi-dimensional Rule Engine
package com.cedarsoftware.ncube
import groovy.transform.CompileStatic
import ncube.grv.exp.NCubeGroovyExpression
import ncube.grv.method.NCubeGroovyController
/**
* This class is used to hold Groovy Programs. The code must start
* with method declarations. The outer class wrapper is built for
* you. You must at least the following method:
* Object run(Map args)
* {
* // your code here
* }
*
* You can have additional methods, as well as write classes in
* between the methods. The code in the methods can be written as
* Java, or if you wish to use the excellent Groovy short-cuts, go
* for it. Check out the Groovy short-hand notation for Map access
* which is described below.For example, Maps can be accessed like
* this (the following 3 are equivalent):
* 1) input.get('BU')
* 2) input['BU']
* 3) input.BU
*
* There are variables available to you to access in your expression
* supplied by ncube. The passed in Map contains the following keys:
* input which is the input coordinate Map that was used to get to
* the the cell containing the expression. output is a Map that your
* expression can write to. This allows the program calling into the ncube
* to get multiple return values, with possible structure to each one (a
* graph return). ncube is the current ncube of the cell containing
* the expression. ncubeMgr is a reference to the NCubeManager class
* so that you can access other ncubes. stack which is a List of
* StackEntry's where element 0 is the StackEntry for the currently executing
* cell. Element 1 would be the cell that called into the current cell (if it
* was during the same execution cycle). The StackEntry contains the name
* of the cube as one field, and the coordinate that called into this cell.
*
* @author John DeRegnaucourt ([email protected])
*
* Copyright (c) Cedar Software LLC
*
* 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.
*/
@CompileStatic
class GroovyMethod extends GroovyBase
{
// Private constructor only for serialization.
private GroovyMethod() {}
GroovyMethod(String cmd, String url = null, boolean cacheable = false)
{
super(cmd, url, cacheable)
}
protected String buildGroovy(Map ctx, String className, String theirGroovy)
{
return theirGroovy
}
protected Object invokeRunMethod(NCubeGroovyExpression instance) throws Exception
{
NCubeGroovyController controller = (NCubeGroovyController) instance
return controller.run(L2CacheKey)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy