Search in sources :

Example 1 with DataPointVO

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

the class RuntimeManagerImpl method restartDataPoint.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#restartDataPoint(com.serotonin.m2m2.vo.DataPointVO)
     */
@Override
public void restartDataPoint(DataPointVO vo) {
    boolean restarted = false;
    synchronized (dataPoints) {
        // Remove this point from the data image if it is there. If not, just quit.
        DataPointRT p = dataPoints.remove(vo.getId());
        // Remove it from the data source, and terminate it.
        if (p != null) {
            try {
                getRunningDataSource(p.getDataSourceId()).removeDataPoint(p);
            } catch (Exception e) {
                LOG.error("Failed to stop point RT with ID: " + vo.getId() + " stopping point.", e);
            }
            DataPointListener l = getDataPointListeners(vo.getId());
            if (l != null)
                l.pointTerminated();
            p.terminate();
            this.startDataPoint(p.getVO(), null);
            restarted = true;
        }
    }
    if (!restarted) {
        // The data poit wasn't really running. Ensure the event detectors and enable
        if (vo.getEventDetectors() == null)
            DataPointDao.instance.setEventDetectors(vo);
        vo.setEnabled(true);
        startDataPoint(vo, null);
        DataPointDao.instance.saveEnabledColumn(vo);
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 2 with DataPointVO

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

the class DataPointEventsByTagQueryDefinition method createQuery.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
     */
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
    JsonNode tagsNode = parameters.get("tags");
    ObjectReader reader = Common.objectMapper.getObjectReader(Map.class);
    Map<String, String> tags = reader.readValue(tagsNode);
    // Lookup data points by tag
    List<Object> args = new ArrayList<>();
    args.add("typeRef1");
    DataPointDao.instance.dataPointsForTags(tags, user, new MappedRowCallback<DataPointVO>() {

        @Override
        public void row(DataPointVO dp, int index) {
            if (Permissions.hasDataPointReadPermission(user, dp)) {
                args.add(Integer.toString(dp.getId()));
            }
        }
    });
    // Create Event Query for these Points
    if (args.size() > 0) {
        ASTNode query = new ASTNode("in", args);
        query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
        query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
        // TODO Should we force a limit if none is supplied?
        if (parameters.has("limit")) {
            int offset = 0;
            int limit = parameters.get("limit").asInt();
            if (parameters.has("offset"))
                offset = parameters.get("offset").asInt();
            query = addAndRestriction(query, new ASTNode("limit", limit, offset));
        }
        return query;
    } else {
        return new ASTNode("limit", 0, 0);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) ASTNode(net.jazdw.rql.parser.ASTNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 3 with DataPointVO

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

the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidSetPermission.

/**
 * Does a user have data point set permissions?
 * @param vo
 * @return
 */
public boolean hasDataPointXidSetPermission(String xid) {
    User user = (User) this.getPrincipal();
    DataPointVO vo = DataPointDao.instance.getByXid(xid);
    return (vo != null) && Permissions.hasDataPointSetPermission(user, vo);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User)

Example 4 with DataPointVO

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

the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidReadPermission.

/**
 * Does a user have data point read permissions?
 * @param vo
 * @return
 */
public boolean hasDataPointXidReadPermission(String xid) {
    User user = (User) this.getPrincipal();
    DataPointVO vo = DataPointDao.instance.getByXid(xid);
    return (vo != null) && Permissions.hasDataPointReadPermission(user, vo);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User)

Example 5 with DataPointVO

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

the class ChartExportServlet method exportExcel.

/**
 * Do the export as Excel XLSX File
 * @param response
 * @param from
 * @param to
 * @param def
 * @param user
 * @throws IOException
 */
private void exportExcel(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("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    final List<PointValueEmporter> sheetEmporters = new ArrayList<PointValueEmporter>();
    final AtomicInteger sheetIndex = new AtomicInteger();
    sheetEmporters.add(new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get()));
    final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    emporter.prepareExport(bos);
    emporter.prepareSheetExport(sheetEmporters.get(0));
    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);
            sheetEmporters.get(sheetIndex.get()).exportRow(edv);
            if (sheetEmporters.get(sheetIndex.get()).getRowsAdded() >= emporter.getMaxRowsPerSheet()) {
                ExportPointInfo info = sheetEmporters.get(sheetIndex.get()).getPointInfo();
                sheetIndex.incrementAndGet();
                PointValueEmporter sheetEmporter = new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get());
                sheetEmporter.setPointInfo(info);
                sheetEmporters.add(sheetEmporter);
                emporter.prepareSheetExport(sheetEmporters.get(sheetIndex.get()));
            }
        }
    };
    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());
            sheetEmporters.get(sheetIndex.get()).setPointInfo(pointInfo);
            pointValueDao.getPointValuesBetween(pointId, from, to, callback);
        }
    }
    emporter.finishExport();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ArrayList(java.util.ArrayList) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MappedRowCallback(com.serotonin.db.MappedRowCallback) PointValueEmporter(com.serotonin.m2m2.rt.dataImage.PointValueEmporter) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)196 User (com.serotonin.m2m2.vo.User)62 ArrayList (java.util.ArrayList)53 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)48 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)40 HashMap (java.util.HashMap)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)32 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)30 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)29 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)28 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)26 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)21 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)21 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)16 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)15 List (java.util.List)15 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)14 IOException (java.io.IOException)12