use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class VarNames method jsonReadVarContext.
public static void jsonReadVarContext(JsonObject json, List<IntStringPair> context) throws JsonException {
JsonArray jsonContext = json.getJsonArray("context");
if (jsonContext != null) {
context.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonContext) {
JsonObject jo = jv.toJsonObject();
String xid = jo.getString("dataPointXid");
if (xid == null)
throw new TranslatableJsonException("emport.error.meta.missing", "dataPointXid");
Integer dpid = dataPointDao.getIdByXid(xid);
if (dpid == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
String var = jo.getString("varName");
if (var == null)
throw new TranslatableJsonException("emport.error.meta.missing", "varName");
context.add(new IntStringPair(dpid, var));
}
}
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class ChartExportServlet method exportCsv.
/**
* Do the export as a CSV File
* @param response
* @param from
* @param to
* @param def
* @param user
* @throws IOException
*/
private void exportCsv(HttpServletRequest request, HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
// Stream the content.
response.setContentType("text/csv");
final Translations translations = Common.getTranslations();
final ExportCsvStreamer exportCreator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
final ExportDataValue edv = new ExportDataValue();
MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int rowIndex) {
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
else
edv.setAnnotation(null);
exportCreator.pointData(edv);
}
};
for (int pointId : def.getPointIds()) {
DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
if (Permissions.hasDataPointReadPermission(user, dp)) {
ExportPointInfo pointInfo = new ExportPointInfo();
pointInfo.setXid(dp.getXid());
pointInfo.setPointName(dp.getName());
pointInfo.setDeviceName(dp.getDeviceName());
pointInfo.setTextRenderer(dp.getTextRenderer());
pointInfo.setDataPointId(pointId);
exportCreator.startPoint(pointInfo);
pointValueDao.getPointValuesBetween(pointId, from, to, callback);
}
}
exportCreator.done();
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class ScriptContextVariable method contextToString.
public static String contextToString(List<ScriptContextVariable> context) {
DataPointDao dataPointDao = DataPointDao.instance;
StringBuilder sb = new StringBuilder();
boolean first = true;
for (ScriptContextVariable ivp : context) {
DataPointVO dp = dataPointDao.getDataPoint(ivp.getDataPointId(), false);
if (first) {
first = false;
} else
sb.append(", ");
sb.append("{ name=");
if (dp == null)
sb.append("?");
else
sb.append(dp.getExtendedName()).append(", varName=");
sb.append(ivp.getVariableName()).append(", updateContext=").append(ivp.isContextUpdate()).append("}");
}
return sb.toString();
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class ScriptContextVariable method jsonWriteVarContext.
public static void jsonWriteVarContext(ObjectWriter writer, List<ScriptContextVariable> context) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
JsonArray pointList = new JsonArray();
for (ScriptContextVariable p : context) {
String xid = dataPointDao.getXidById(p.getDataPointId());
JsonObject point = new JsonObject();
pointList.add(point);
point.put("varName", new JsonString(p.getVariableName()));
point.put("dataPointXid", new JsonString(xid));
point.put("updateContext", new JsonBoolean(p.isContextUpdate()));
}
writer.writeEntry("context", pointList);
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class ScriptContextVariable method jsonReadVarContext.
/**
* Read in context,
* @param json
* @param context
* @return if my XID is in the context, return the name it has to map into the VO otherwise return null
* @throws JsonException
*/
public static String jsonReadVarContext(JsonObject json, List<ScriptContextVariable> context, boolean isContextUpdate) throws JsonException {
JsonArray jsonContext = json.getJsonArray("context");
if (jsonContext != null) {
context.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonContext) {
JsonObject jo = jv.toJsonObject();
String xid = jo.getString("dataPointXid");
if (xid == null)
throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
Integer dpid = dataPointDao.getIdByXid(xid);
if (dpid == null) {
// This can also happen if the point is in its own context (Bug from legacy systems).
throw new TranslatableJsonException("emport.error.missingPoint", xid);
}
// For compatibility with varName and variableName json types
String var = jo.getString("varName");
if (var == null) {
var = jo.getString("variableName");
if (var == null)
throw new TranslatableJsonException("emport.error.context.missing", "varName");
}
// Default for legacy systems
if (jo.containsKey("updateContext"))
isContextUpdate = jo.getBoolean("updateContext");
context.add(new ScriptContextVariable(dpid, var, isContextUpdate));
}
}
return json.getString("variableName");
}
Aggregations