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());
}
}
}
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;
}
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();
}
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();
}
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;
}
Aggregations