Search in sources :

Example 1 with Constants

use of com.serotonin.m2m2.Constants in project ma-core-public by infiniteautomation.

the class M2M2ContextListener method constantsInitialize.

// 
// 
// Constants
// 
private void constantsInitialize(ServletContext ctx) {
    ctx.setAttribute("constants.Common.NEW_ID", Common.NEW_ID);
    ctx.setAttribute("constants.DataTypes.BINARY", DataTypes.BINARY);
    ctx.setAttribute("constants.DataTypes.MULTISTATE", DataTypes.MULTISTATE);
    ctx.setAttribute("constants.DataTypes.NUMERIC", DataTypes.NUMERIC);
    ctx.setAttribute("constants.DataTypes.ALPHANUMERIC", DataTypes.ALPHANUMERIC);
    ctx.setAttribute("constants.DataTypes.IMAGE", DataTypes.IMAGE);
    ctx.setAttribute("constants.Permissions.DataPointAccessTypes.NONE", Permissions.DataPointAccessTypes.NONE);
    ctx.setAttribute("constants.Permissions.DataPointAccessTypes.READ", Permissions.DataPointAccessTypes.READ);
    ctx.setAttribute("constants.Permissions.DataPointAccessTypes.SET", Permissions.DataPointAccessTypes.SET);
    ctx.setAttribute("constants.Permissions.DataPointAccessTypes.DATA_SOURCE", Permissions.DataPointAccessTypes.DATA_SOURCE);
    ctx.setAttribute("constants.Permissions.DataPointAccessTypes.ADMIN", Permissions.DataPointAccessTypes.ADMIN);
    ctx.setAttribute("constants.EventType.EventTypeNames.DATA_POINT", EventType.EventTypeNames.DATA_POINT);
    ctx.setAttribute("constants.EventType.EventTypeNames.DATA_SOURCE", EventType.EventTypeNames.DATA_SOURCE);
    ctx.setAttribute("constants.EventType.EventTypeNames.SYSTEM", EventType.EventTypeNames.SYSTEM);
    ctx.setAttribute("constants.EventType.EventTypeNames.PUBLISHER", EventType.EventTypeNames.PUBLISHER);
    ctx.setAttribute("constants.EventType.EventTypeNames.AUDIT", EventType.EventTypeNames.AUDIT);
    ctx.setAttribute("constants.SystemEventType.TYPE_SYSTEM_STARTUP", SystemEventType.TYPE_SYSTEM_STARTUP);
    ctx.setAttribute("constants.SystemEventType.TYPE_SYSTEM_SHUTDOWN", SystemEventType.TYPE_SYSTEM_SHUTDOWN);
    ctx.setAttribute("constants.SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED", SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED);
    ctx.setAttribute("constants.SystemEventType.TYPE_USER_LOGIN", SystemEventType.TYPE_USER_LOGIN);
    ctx.setAttribute("constants.SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE", SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE);
    ctx.setAttribute("constants.SystemEventType.TYPE_EMAIL_SEND_FAILURE", SystemEventType.TYPE_EMAIL_SEND_FAILURE);
    ctx.setAttribute("constants.SystemEventType.TYPE_PROCESS_FAILURE", SystemEventType.TYPE_PROCESS_FAILURE);
    ctx.setAttribute("constants.SystemEventType.TYPE_LICENSE_CHECK", SystemEventType.TYPE_LICENSE_CHECK);
    ctx.setAttribute("constants.SystemEventType.TYPE_UPGRADE_CHECK", SystemEventType.TYPE_UPGRADE_CHECK);
    ctx.setAttribute("constants.AuditEventType.TYPE_DATA_SOURCE", AuditEventType.TYPE_DATA_SOURCE);
    ctx.setAttribute("constants.AuditEventType.TYPE_DATA_POINT", AuditEventType.TYPE_DATA_POINT);
    ctx.setAttribute("constants.AuditEventType.TYPE_EVENT_DETECTOR", AuditEventType.TYPE_EVENT_DETECTOR);
    ctx.setAttribute("constants.AuditEventType.TYPE_EVENT_HANDLER", AuditEventType.TYPE_EVENT_HANDLER);
    ctx.setAttribute("constants.UserComment.TYPE_EVENT", UserCommentVO.TYPE_EVENT);
    ctx.setAttribute("constants.UserComment.TYPE_POINT", UserCommentVO.TYPE_POINT);
    String[] codes = { "common.access.read", "common.access.set", "common.alarmLevel.none", "common.alarmLevel.info", "common.alarmLevel.important", "common.alarmLevel.warning", "common.alarmLevel.urgent", "common.alarmLevel.critical", "common.alarmLevel.lifeSafety", "common.alarmLevel.doNotLog", "common.alarmLevel.ignore", "common.disabled", "common.administrator", "common.user", "common.disabledToggle", "common.enabledToggle", "common.maximize", "common.minimize", "common.loading", "js.help.error", "js.help.related", "js.help.lastUpdated", "common.sendTestEmail", "js.email.noRecipients", "js.email.addMailingList", "js.email.addUser", "js.email.addAddress", "js.email.noRecipForEmail", "js.email.testSent", "events.silence", "events.unsilence", "header.mute", "header.unmute" };
    Map<String, TranslatableMessage> messages = new HashMap<>();
    for (String code : codes) messages.put(code, new TranslatableMessage(code));
    ctx.setAttribute("clientSideMessages", messages);
    SessionCookieConfig sessionCookieConfig = ctx.getSessionCookieConfig();
    sessionCookieConfig.setHttpOnly(true);
    sessionCookieConfig.setName(Common.getCookieName());
}
Also used : HashMap(java.util.HashMap) SessionCookieConfig(javax.servlet.SessionCookieConfig) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 2 with Constants

use of com.serotonin.m2m2.Constants in project atlasmap by atlasmap.

the class AtlasTestData method generateAtlasMapping.

public static AtlasMapping generateAtlasMapping() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("generated.mapping." + UUID.randomUUID().toString().replace('-', '.'));
    mapping.getProperties().getProperty().addAll(generateAtlasProperties());
    mapping.setConstants(new Constants());
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Constants(io.atlasmap.v2.Constants)

Example 3 with Constants

use of com.serotonin.m2m2.Constants in project ma-core-public by infiniteautomation.

the class MangoJavaScriptService method compile.

/**
 * Compile a script to be run and add global bindings
 */
public CompiledScript compile(String script, boolean wrapInFunction) throws ScriptError {
    try {
        final ScriptEngine engine = newEngine();
        // Add constants to the context
        Bindings globalBindings = new SimpleBindings();
        // left here for legacy compatibility
        globalBindings.put("SECOND", Common.TimePeriods.SECONDS);
        globalBindings.put("MINUTE", Common.TimePeriods.MINUTES);
        globalBindings.put("HOUR", Common.TimePeriods.HOURS);
        globalBindings.put("DAY", Common.TimePeriods.DAYS);
        globalBindings.put("WEEK", Common.TimePeriods.WEEKS);
        globalBindings.put("MONTH", Common.TimePeriods.MONTHS);
        globalBindings.put("YEAR", Common.TimePeriods.YEARS);
        for (IntStringPair isp : Common.TIME_PERIOD_CODES.getIdKeys()) globalBindings.put(Common.TIME_PERIOD_CODES.getCode(isp.getKey()), isp.getKey());
        for (IntStringPair isp : Common.ROLLUP_CODES.getIdKeys(Common.Rollups.NONE)) globalBindings.put(Common.ROLLUP_CODES.getCode(isp.getKey()), isp.getKey());
        // Add in Additional Utilities with Global Scope
        globalBindings.put(DateTimeUtility.CONTEXT_KEY, new DateTimeUtility());
        globalBindings.put(UnitUtility.CONTEXT_KEY, new UnitUtility());
        engine.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE);
        String toCompile;
        if (wrapInFunction) {
            toCompile = SCRIPT_PREFIX + script + SCRIPT_SUFFIX;
        } else {
            toCompile = script;
        }
        return ((Compilable) engine).compile(toCompile);
    } catch (ScriptException e) {
        throw ScriptError.create(e, wrapInFunction);
    }
}
Also used : ScriptException(javax.script.ScriptException) IntStringPair(com.serotonin.db.pair.IntStringPair) SimpleBindings(javax.script.SimpleBindings) Compilable(javax.script.Compilable) DateTimeUtility(com.serotonin.m2m2.rt.script.DateTimeUtility) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) UnitUtility(com.serotonin.m2m2.rt.script.UnitUtility) ScriptEngine(javax.script.ScriptEngine)

Aggregations

IntStringPair (com.serotonin.db.pair.IntStringPair)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 DateTimeUtility (com.serotonin.m2m2.rt.script.DateTimeUtility)1 UnitUtility (com.serotonin.m2m2.rt.script.UnitUtility)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 Constants (io.atlasmap.v2.Constants)1 HashMap (java.util.HashMap)1 Bindings (javax.script.Bindings)1 Compilable (javax.script.Compilable)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptException (javax.script.ScriptException)1 SimpleBindings (javax.script.SimpleBindings)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1