Search in sources :

Example 1 with Common

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

the class MockMangoLifecycle method initialize.

/**
 * Startup a dummy Mango with a basic infrastructure
 */
public void initialize() {
    Common.MA_HOME = System.getProperty("ma.home");
    if (Common.MA_HOME == null)
        Common.MA_HOME = ".";
    // Add in modules
    for (Module module : modules) ModuleRegistry.addModule(module);
    Providers.add(IMangoLifecycle.class, this);
    // TODO Licensing Providers.add(ICoreLicense.class, new CoreLicenseDefinition());
    // TODO Licensing Providers.add(ITimedLicenseRegistrar.class, new TimedLicenseRegistrar());
    Common.free = false;
    // Startup a simulation timer provider
    Providers.add(TimerProvider.class, getSimulationTimerProvider());
    // Make sure that Common and other classes are properly loaded
    Common.envProps = getEnvProps();
    MangoRestSpringConfiguration.initializeObjectMapper();
    Common.JSON_CONTEXT.addResolver(new EventTypeResolver(), EventType.class);
    Common.JSON_CONTEXT.addResolver(new BaseChartRenderer.Resolver(), ChartRenderer.class);
    Common.JSON_CONTEXT.addResolver(new BaseTextRenderer.Resolver(), TextRenderer.class);
    Common.JSON_CONTEXT.addResolver(new EmailRecipientResolver(), EmailRecipient.class);
    Common.JSON_CONTEXT.addResolver(new VirtualSerialPortConfigResolver(), VirtualSerialPortConfig.class);
    Common.JSON_CONTEXT.addConverter(new MapWrapConverter(), MapWrap.class);
    for (Module module : ModuleRegistry.getModules()) {
        module.preInitialize(true, false);
    }
    // Start the Database so we can use Daos (Base Dao requires this)
    if (Common.databaseProxy == null) {
        Common.databaseProxy = getDatabaseProxy();
        Common.databaseProxy.initialize(null);
    }
    // Ensure we start with the proper timer
    Common.backgroundProcessing = getBackgroundProcessing();
    Common.backgroundProcessing.initialize(false);
    for (Module module : ModuleRegistry.getModules()) {
        module.postDatabase(true, false);
    }
    // Utilities
    // So we can add users etc.
    EventType.initialize();
    SystemEventType.initialize();
    AuditEventType.initialize();
    // Setup Common Object Mapper
    Common.objectMapper = new CommonObjectMapper();
    // Do this last as Event Types have listeners
    for (SystemSettingsListenerDefinition def : ModuleRegistry.getSystemSettingListenerDefinitions()) def.registerListener();
    // Event Manager
    Common.eventManager = getEventManager();
    Common.eventManager.initialize(false);
    for (EventManagerListenerDefinition def : ModuleRegistry.getDefinitions(EventManagerListenerDefinition.class)) Common.eventManager.addListener(def);
    Common.runtimeManager = getRuntimeManager();
    Common.runtimeManager.initialize(false);
    if (Common.serialPortManager == null)
        Common.serialPortManager = getSerialPortManager();
    for (Module module : ModuleRegistry.getModules()) {
        module.postInitialize(true, false);
    }
    for (Runnable task : STARTUP_TASKS) {
        try {
            task.run();
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
}
Also used : BaseTextRenderer(com.serotonin.m2m2.view.text.BaseTextRenderer) BaseChartRenderer(com.serotonin.m2m2.view.chart.BaseChartRenderer) SystemSettingsListenerDefinition(com.serotonin.m2m2.module.SystemSettingsListenerDefinition) MapWrapConverter(com.serotonin.m2m2.util.MapWrapConverter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) EmailRecipientResolver(com.serotonin.m2m2.vo.mailingList.EmailRecipientResolver) VirtualSerialPortConfigResolver(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfigResolver) CommonObjectMapper(com.infiniteautomation.mango.util.CommonObjectMapper) Module(com.serotonin.m2m2.module.Module) EventManagerListenerDefinition(com.serotonin.m2m2.module.EventManagerListenerDefinition) EventTypeResolver(com.serotonin.m2m2.rt.event.type.EventTypeResolver)

Example 2 with Common

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

the class CompiledScriptExecutor method execute.

/**
 * Execute the script on the common engine
 * @param script
 * @param context
 * @param additionalContext
 * @param runtime
 * @param dataTypeId
 * @param timestamp
 * @param permissions
 * @param scriptWriter
 * @return
 * @throws ScriptException
 * @throws ResultTypeException
 */
public static PointValueTime execute(CompiledScript script, Map<String, IDataPointValueSource> context, Map<String, Object> additionalContext, long runtime, int dataTypeId, long timestamp, ScriptPermissions permissions, PrintWriter scriptWriter, ScriptLog log, ScriptPointValueSetter setter, List<JsonImportExclusion> importExclusions, boolean testRun) throws ScriptException, ResultTypeException {
    // StopWatch stopWatch = new Log4JStopWatch();
    // stopWatch.start();
    ensureInit();
    // Create the wrapper object context.
    ScriptEngine engine = script.getEngine();
    // Prepare the Engine
    Bindings engineScope = prepareEngine(engine, context, additionalContext, runtime, timestamp, permissions, scriptWriter, log, setter, importExclusions, testRun);
    // Execute.
    Object result;
    try {
        result = script.eval(engineScope);
    } catch (ScriptException e) {
        throw prettyScriptMessage(e);
    }
    PointValueTime value = getResult(engine, result, dataTypeId, timestamp);
    // stopWatch.stop("execute()");
    return value;
}
Also used : ScriptException(javax.script.ScriptException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) Bindings(javax.script.Bindings) ScriptEngine(javax.script.ScriptEngine)

Example 3 with Common

use of com.serotonin.m2m2.Common in project ma-modules-public by infiniteautomation.

the class TranslationsController method publicNamespacedTranslations.

@ApiOperation(value = "Get translations for public namespaces", notes = "Namespace must be base , ie public not public.messages. Returns sub-namespaces too. For > 1 use comma common,public")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/public/{namespaces}")
public ResponseEntity<Map<String, ?>> publicNamespacedTranslations(@ApiParam(value = "Message Namespaces, simmilar to java package structure", allowMultiple = true) @PathVariable String[] namespaces, @ApiParam(value = "Language for translation (must have language pack installed)", allowMultiple = false) @RequestParam(value = "language", required = false) String language, @ApiParam(value = "Use server language for translation", allowMultiple = false) @RequestParam(value = "server", required = false, defaultValue = "false") boolean server, @RequestParam(value = "browser", required = false, defaultValue = "false") boolean browser, HttpServletRequest request) {
    RestProcessResult<Map<String, ?>> result = new RestProcessResult<Map<String, ?>>(HttpStatus.OK);
    // Confirm the requested namespace is indeed public
    for (String namespace : namespaces) {
        if (!this.publicNamespaces.contains(namespace)) {
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    }
    if (result.isOk()) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Locale locale = this.getLocale(language, server, browser, request, Common.getHttpUser());
        resultMap.put("locale", locale.toLanguageTag());
        resultMap.put("translations", getTranslationMap(namespaces, locale));
        return result.createResponseEntity(resultMap);
    }
    return result.createResponseEntity();
}
Also used : Locale(java.util.Locale) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Common

use of com.serotonin.m2m2.Common in project ma-modules-public by infiniteautomation.

the class TranslationsController method namespacedTranslations.

@ApiOperation(value = "Get translations based on namespaces", notes = "Namespace must be base namespace, ie common not common.messages. Returns sub-namespaces too.  For > 1 use comma common,public")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{namespaces}")
public ResponseEntity<Map<String, ?>> namespacedTranslations(@ApiParam(value = "Message Namespaces, simmilar to java package structure", allowMultiple = true) @PathVariable String[] namespaces, @ApiParam(value = "Language for translation (must have language pack installed)", allowMultiple = false) @RequestParam(value = "language", required = false) String language, @ApiParam(value = "Use server language for translation", allowMultiple = false) @RequestParam(value = "server", required = false, defaultValue = "false") boolean server, @RequestParam(value = "browser", required = false, defaultValue = "false") boolean browser, HttpServletRequest request) {
    RestProcessResult<Map<String, ?>> result = new RestProcessResult<Map<String, ?>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Locale locale = this.getLocale(language, server, browser, request, user);
        resultMap.put("locale", locale.toLanguageTag());
        resultMap.put("translations", getTranslationMap(namespaces, locale));
        return result.createResponseEntity(resultMap);
    }
    return result.createResponseEntity();
}
Also used : Locale(java.util.Locale) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Common

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

the class DataSourceEditDwr method editInit.

// 
// 
// Common methods
// 
@DwrPermission(user = true)
public ProcessResult editInit() {
    ProcessResult response = new ProcessResult();
    response.addData("points", getPoints());
    response.addData("alarms", getAlarms());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

HashMap (java.util.HashMap)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 Locale (java.util.Locale)2 Map (java.util.Map)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Version (com.github.zafarkhaja.semver.Version)1 VirtualSerialPortConfigResolver (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfigResolver)1 CommonObjectMapper (com.infiniteautomation.mango.util.CommonObjectMapper)1 StringStringPair (com.serotonin.db.pair.StringStringPair)1 JsonException (com.serotonin.json.JsonException)1 JsonWriter (com.serotonin.json.JsonWriter)1 JsonObject (com.serotonin.json.type.JsonObject)1 JsonString (com.serotonin.json.type.JsonString)1 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 EventManagerListenerDefinition (com.serotonin.m2m2.module.EventManagerListenerDefinition)1