Search in sources :

Example 26 with DataPointDao

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));
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonString(com.serotonin.json.type.JsonString)

Example 27 with DataPointDao

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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) MappedRowCallback(com.serotonin.db.MappedRowCallback) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportCsvStreamer(com.serotonin.m2m2.vo.export.ExportCsvStreamer) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) Translations(com.serotonin.m2m2.i18n.Translations)

Example 28 with DataPointDao

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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao)

Example 29 with DataPointDao

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);
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonObject(com.serotonin.json.type.JsonObject) JsonBoolean(com.serotonin.json.type.JsonBoolean) JsonString(com.serotonin.json.type.JsonString) JsonString(com.serotonin.json.type.JsonString)

Example 30 with DataPointDao

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");
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonString(com.serotonin.json.type.JsonString)

Aggregations

DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)21 JsonArray (com.serotonin.json.type.JsonArray)8 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)8 User (com.serotonin.m2m2.vo.User)8 JsonObject (com.serotonin.json.type.JsonObject)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 ArrayList (java.util.ArrayList)6 JsonValue (com.serotonin.json.type.JsonValue)5 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 HashMap (java.util.HashMap)5 IntStringPair (com.serotonin.db.pair.IntStringPair)4 JsonString (com.serotonin.json.type.JsonString)4 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 InvalidArgumentException (com.serotonin.InvalidArgumentException)3 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 ReportPointVO (com.serotonin.m2m2.reports.vo.ReportPointVO)3 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)3 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)3