use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method getGeneralStatusMessages.
@DwrPermission(user = true)
public final ProcessResult getGeneralStatusMessages() {
ProcessResult result = new ProcessResult();
DataSourceVO<?> vo = Common.getUser().getEditDataSource();
DataSourceRT<?> rt = Common.runtimeManager.getRunningDataSource(vo.getId());
List<TranslatableMessage> messages = new ArrayList<>();
result.addData("messages", messages);
if (rt == null)
messages.add(new TranslatableMessage("dsEdit.notEnabled"));
else {
rt.addStatusMessages(messages);
if (messages.isEmpty())
messages.add(new TranslatableMessage("dsEdit.noStatus"));
}
return result;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method copyDataSource.
@DwrPermission(user = true)
public ProcessResult copyDataSource(int dataSourceId, String name, String xid, String deviceName) {
Permissions.ensureDataSourcePermission(Common.getUser(), dataSourceId);
ProcessResult response = new ProcessResult();
// Create a dummy data source with which to do the validation.
DataSourceVO<?> ds = new MockDataSourceVO();
ds.setName(name);
ds.setXid(xid);
ds.validate(response);
if (!response.getHasMessages()) {
int dsId = DataSourceDao.instance.copyDataSource(dataSourceId, name, xid, deviceName);
response.addData("newId", dsId);
}
return response;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method toggleDataPoint.
@DwrPermission(user = true)
public ProcessResult toggleDataPoint(int dataPointId) {
DataPointVO dataPoint = DataPointDao.instance.getDataPoint(dataPointId);
Permissions.ensureDataSourcePermission(Common.getUser(), dataPoint.getDataSourceId());
dataPoint.setEnabled(!dataPoint.isEnabled());
Common.runtimeManager.saveDataPoint(dataPoint);
ProcessResult response = new ProcessResult();
response.addData("id", dataPointId);
response.addData("enabled", dataPoint.isEnabled());
return response;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method validateScript.
@DwrPermission(user = true)
public ProcessResult validateScript(String script, Integer targetPointId, int type, List<IntStringPair> additionalContext, ScriptPermissions scriptPermissions) {
ProcessResult response = new ProcessResult();
TranslatableMessage message;
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
int targetDataType;
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE || type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE) {
DataPointRT target = targetPointId == null ? null : Common.runtimeManager.getDataPoint(targetPointId.intValue());
if (target == null) {
DataPointVO targetVo = targetPointId == null ? null : DataPointDao.instance.getDataPoint(targetPointId.intValue(), false);
if (targetVo == null) {
if (// These are passed in the validateScript of eventHandlers.jsp
type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", new TranslatableMessage("eventHandlers.noTargetPoint"));
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", new TranslatableMessage("eventHandlers.noTargetPoint"));
return response;
}
if (targetVo.getDefaultCacheSize() == 0)
targetVo.setDefaultCacheSize(1);
target = new DataPointRT(targetVo, targetVo.getPointLocator().createRuntime(), DataSourceDao.instance.getDataSource(targetVo.getDataSourceId()), null);
target.resetValues();
context.put(SetPointEventHandlerVO.TARGET_CONTEXT_KEY, target);
}
targetDataType = target.getDataTypeId();
} else {
targetDataType = DataTypes.ALPHANUMERIC;
}
for (IntStringPair cxt : additionalContext) {
DataPointRT dprt = Common.runtimeManager.getDataPoint(cxt.getKey());
if (dprt == null) {
DataPointVO dpvo = DataPointDao.instance.getDataPoint(cxt.getKey(), false);
if (dpvo == null) {
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
else if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
response.addMessage("emailScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
return response;
}
if (dpvo.getDefaultCacheSize() == 0)
dpvo.setDefaultCacheSize(1);
dprt = new DataPointRT(dpvo, dpvo.getPointLocator().createRuntime(), DataSourceDao.instance.getDataSource(dpvo.getDataSourceId()), null);
dprt.resetValues();
}
context.put(cxt.getValue(), dprt);
}
Map<String, Object> otherContext = new HashMap<String, Object>();
otherContext.put(SetPointEventHandlerVO.EVENT_CONTEXT_KEY, getTestEvent());
if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
otherContext.put("model", new HashMap<String, Object>());
final StringWriter scriptOut = new StringWriter();
final PrintWriter scriptWriter = new PrintWriter(scriptOut);
final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYY HH:mm:ss");
ScriptPointValueSetter loggingSetter = new ScriptPointValueSetter(scriptPermissions) {
@Override
public void set(IDataPointValueSource point, Object value, long timestamp, String annotation) {
DataPointRT dprt = (DataPointRT) point;
if (!dprt.getVO().getPointLocator().isSettable()) {
scriptOut.append("Point " + dprt.getVO().getExtendedName() + " not settable.");
return;
}
if (!Permissions.hasPermission(dprt.getVO().getSetPermission(), permissions.getDataPointSetPermissions())) {
scriptOut.write(new TranslatableMessage("pointLinks.setTest.permissionDenied", dprt.getVO().getXid()).translate(Common.getTranslations()));
return;
}
scriptOut.append("Setting point " + dprt.getVO().getName() + " to " + value + " @" + sdf.format(new Date(timestamp)) + "\r\n");
}
@Override
protected void setImpl(IDataPointValueSource point, Object value, long timestamp, String annotation) {
// not really setting
}
};
try {
CompiledScript compiledScript = CompiledScriptExecutor.compile(script);
PointValueTime pvt = CompiledScriptExecutor.execute(compiledScript, context, otherContext, System.currentTimeMillis(), targetDataType, System.currentTimeMillis(), scriptPermissions, scriptWriter, new ScriptLog(SetPointHandlerRT.NULL_WRITER, LogLevel.FATAL), loggingSetter, null, true);
if (pvt.getValue() == null)
message = new TranslatableMessage("eventHandlers.script.nullResult");
else if (CompiledScriptExecutor.UNCHANGED == pvt.getValue())
message = new TranslatableMessage("eventHandlers.script.successUnchanged");
else
message = new TranslatableMessage("eventHandlers.script.success", pvt.getValue());
// Add the script logging output
response.addData("out", scriptOut.toString().replaceAll("\n", "<br/>"));
} catch (ScriptPermissionsException e) {
message = e.getTranslatableMessage();
} catch (ScriptException e) {
message = new TranslatableMessage("eventHandlers.script.failure", e.getMessage());
} catch (ResultTypeException e) {
message = e.getTranslatableMessage();
}
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", message);
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", message);
else if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
response.addMessage("emailScript", message);
return response;
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method saveProcessEventHandler.
@DwrPermission(user = true)
public ProcessResult saveProcessEventHandler(String eventType, String eventSubtype, int eventTypeRef1, int eventTypeRef2, int handlerId, String xid, String alias, boolean disabled, String activeProcessCommand, int activeProcessTimeout, String inactiveProcessCommand, int inactiveProcessTimeout) {
ProcessEventHandlerVO handler = new ProcessEventHandlerVO();
handler.setDefinition(ModuleRegistry.getEventHandlerDefinition(ProcessEventHandlerDefinition.TYPE_NAME));
handler.setActiveProcessCommand(activeProcessCommand);
handler.setActiveProcessTimeout(activeProcessTimeout);
handler.setInactiveProcessCommand(inactiveProcessCommand);
handler.setInactiveProcessTimeout(inactiveProcessTimeout);
return save(eventType, eventSubtype, eventTypeRef1, eventTypeRef2, handler, handlerId, xid, alias, disabled);
}
Aggregations