Search in sources :

Example 1 with CachedExpressionEvaluator

use of com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator in project navajo by Dexels.

the class TestExpressionPropertiesCompiled method setup.

@Before
public void setup() {
    // NavajoFactory.getInstance().setExpressionEvaluator(new DefaultExpressionEvaluator());
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    testDoc = NavajoFactory.getInstance().createNavajo();
    topMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(topMessage);
    one = NavajoFactory.getInstance().createProperty(testDoc, "One", Property.INTEGER_PROPERTY, "1", 0, "", Property.DIR_OUT);
    two = NavajoFactory.getInstance().createProperty(testDoc, "Two", Property.EXPRESSION_PROPERTY, "[One]+1", 0, "", Property.DIR_OUT);
    three = NavajoFactory.getInstance().createProperty(testDoc, "Three", Property.EXPRESSION_PROPERTY, "2+1", 0, "", Property.DIR_OUT);
    five = NavajoFactory.getInstance().createProperty(testDoc, "Five", Property.EXPRESSION_PROPERTY, "[Two]+[Three]", 0, "", Property.DIR_OUT);
    topMessage.addProperty(one);
    topMessage.addProperty(two);
    topMessage.addProperty(three);
    topMessage.addProperty(five);
}
Also used : CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Before(org.junit.Before)

Example 2 with CachedExpressionEvaluator

use of com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator in project navajo by Dexels.

the class ExpressionTest method setup.

@Before
public void setup() {
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    testDoc = NavajoFactory.getInstance().createNavajo();
    topMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(topMessage);
    Property pt = NavajoFactory.getInstance().createProperty(testDoc, "TopProp", "1", "", Property.DIR_IN);
    testSelection = NavajoFactory.getInstance().createSelection(testDoc, "option1", "value1", true);
    pt.addSelection(testSelection);
    topMessage.addProperty(pt);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    topMessage.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    Map<String, Object> values = new HashMap<>();
    Map<String, String> types = new HashMap<>();
    values.put("SomeString", "Tralala");
    types.put("SomeString", "string");
    values.put("SomeInteger", 3);
    types.put("SomeInteger", "integer");
    immutableMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), types, values, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
    Map<String, Object> valueparams = new HashMap<>();
    Map<String, String> typeparams = new HashMap<>();
    valueparams.put("SomeString", "Tralala2");
    typeparams.put("SomeString", "string");
    valueparams.put("SomeInteger", 4);
    typeparams.put("SomeInteger", "integer");
    paramMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), typeparams, valueparams, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Before(org.junit.Before)

Example 3 with CachedExpressionEvaluator

use of com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator in project navajo by Dexels.

the class NavajoConfigEmitter method createNavajoConfigConfiguration.

private void createNavajoConfigConfiguration(URL configurationUrl, String rootPath) throws IOException, SystemException {
    InputStream is = configurationUrl.openStream();
    logger.debug("Setting up configuration for rootpath: {}", rootPath);
    logger.debug("Setting up configuration url: {}", configurationUrl);
    Dictionary<String, Object> data = new Hashtable<>();
    Navajo configuration = NavajoFactory.getInstance().createNavajo(is);
    Message body = configuration.getMessage("server-configuration");
    if (body == null) {
        throw new SystemException(-1, "Could not read configuration file server.xml");
    }
    // Get the instance name.
    data.put("instanceName", getInstanceName(body));
    // Get the instance group.
    data.put("instanceGroup", getInstanceGroup(body));
    String configPath = properDir(rootPath + getMessageValueWithDefault("paths/configuration", "config", body));
    String adapterPath = properDir(rootPath + getMessageValueWithDefault("paths/adapters", "adapters", body));
    String scriptPath = properDir(rootPath + getMessageValueWithDefault("paths/scripts", "scripts", body));
    data.put("configPath", configPath);
    data.put("adapterPath", adapterPath);
    data.put("scriptPath", scriptPath);
    Property resourceProperty = body.getProperty("paths/resource");
    if (resourceProperty != null) {
        String resourcePath = properDir(rootPath + resourceProperty.getValue());
        data.put("resourcePath", resourcePath);
    }
    String compiledScriptPath = (body.getProperty("paths/compiled-scripts") != null ? properDir(rootPath + body.getProperty("paths/compiled-scripts").getValue()) : "");
    data.put("compiledScriptPath", compiledScriptPath);
    Property descriptionProviderProperty = body.getProperty("description-provider/class");
    String descriptionProviderClass = null;
    if (descriptionProviderProperty != null) {
        descriptionProviderClass = descriptionProviderProperty.getValue();
        if (descriptionProviderClass != null) {
            data.put("descriptionProviderClass", descriptionProviderClass);
        }
    }
    Dictionary<String, Object> d = new Hashtable<>();
    d.put("enable", true);
    injectConfiguration("navajo.server.statistics", d);
    Property s = body.getProperty("parameters/async_timeout");
    // default 1 hour.
    double asyncTimeout = 3600 * 1000;
    if (s != null) {
        asyncTimeout = Float.parseFloat(s.getValue()) * 1000;
    }
    boolean enableAsync = (body.getProperty("parameters/enable_async") == null || body.getProperty("parameters/enable_async").getValue().equals("true"));
    d = new Hashtable<>();
    d.put("enable", enableAsync);
    d.put("asyncTimeout", asyncTimeout);
    injectConfiguration("navajo.server.async", d);
    boolean enableIntegrityWorker = (body.getProperty("parameters/enable_integrity") == null || body.getProperty("parameters/enable_integrity").getValue().equals("true"));
    d = new Hashtable<>();
    d.put("enable", enableIntegrityWorker);
    injectConfiguration("navajo.server.integrity", d);
    boolean enableLockManager = (body.getProperty("parameters/enable_locks") == null || body.getProperty("parameters/enable_locks").getValue().equals("true"));
    d = new Hashtable<>();
    d.put("enable", enableLockManager);
    injectConfiguration("navajo.server.lockmanager", d);
    int maxAccessSetSize = (body.getProperty("parameters/max_webservices") == null ? MAX_ACCESS_SET_SIZE : Integer.parseInt(body.getProperty("parameters/max_webservices").getValue()));
    data.put("maxAccessSetSize", maxAccessSetSize);
    data.put("compileScripts", true);
    // Get document class implementation.
    String documentClass = "com.dexels.navajo.document.base.BaseNavajoFactoryImpl";
    data.put("documentClass", documentClass);
    if (documentClass != null) {
        System.setProperty("com.dexels.navajo.DocumentImplementation", documentClass);
        NavajoFactory.resetImplementation();
        NavajoFactory.getInstance();
        NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    }
    addAllProperties(body.getMessage("parameters"), data);
    updateIfChanged("navajo.server.config", data);
}
Also used : Message(com.dexels.navajo.document.Message) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) Navajo(com.dexels.navajo.document.Navajo) SystemException(com.dexels.navajo.script.api.SystemException) Property(com.dexels.navajo.document.Property) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator)

Example 4 with CachedExpressionEvaluator

use of com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator in project navajo by Dexels.

the class AdminMap method setDocumentClass.

public void setDocumentClass(String s) throws UserException {
    try {
        Class.forName(s);
    } catch (Exception e) {
        throw new UserException(-1, "Could not find document implementation: " + s);
    }
    System.setProperty("com.dexels.navajo.DocumentImplementation", s);
    NavajoFactory.resetImplementation();
    NavajoFactory.getInstance().setTempDir(DispatcherFactory.getInstance().getTempDir());
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    logger.debug("Document class is now: {}", getDocumentClass());
}
Also used : UserException(com.dexels.navajo.script.api.UserException) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Aggregations

CachedExpressionEvaluator (com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator)4 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)2 Before (org.junit.Before)2 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)1 Navajo (com.dexels.navajo.document.Navajo)1 MappableException (com.dexels.navajo.script.api.MappableException)1 SystemException (com.dexels.navajo.script.api.SystemException)1 UserException (com.dexels.navajo.script.api.UserException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1