Search in sources :

Example 1 with ImageValue

use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.

the class ReportPointValueTimeSerializer method putBytes.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getBytes(com.serotonin.m2m2.db.dao.nosql.NoSQLDataEntry)
	 */
@Override
public void putBytes(ByteArrayBuilder b, ITime obj, long timestamp, String seriesId) {
    PointValueTime value = (PointValueTime) obj;
    // First put in the data type
    b.putShort((short) value.getValue().getDataType());
    // Second put in the data value
    switch(value.getValue().getDataType()) {
        case DataTypes.ALPHANUMERIC:
            b.putString(value.getStringValue());
            break;
        case DataTypes.BINARY:
            b.putBoolean(value.getBooleanValue());
            break;
        case DataTypes.IMAGE:
            ImageValue imageValue = (ImageValue) value.getValue();
            if (!imageValue.isSaved()) {
                throw new ImageSaveException(new IOException("Image not saved."));
            }
            b.putString(imageValue.getFilename());
            break;
        case DataTypes.MULTISTATE:
            b.putInt(value.getIntegerValue());
            break;
        case DataTypes.NUMERIC:
            b.putDouble(value.getDoubleValue());
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + value.getValue().getDataType() + " is not supported");
    }
    // Put in annotation
    if (value.isAnnotated()) {
        AnnotatedPointValueTime apv = (AnnotatedPointValueTime) value;
        b.putString(apv.getSourceMessage().serialize());
    } else
        b.putString(null);
}
Also used : AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 2 with ImageValue

use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.

the class ReportDao method reportInstanceDataSQL.

public void reportInstanceDataSQL(int instanceId, final ExportDataStreamHandler handler) {
    // Retrieve point information.
    List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {

        @Override
        public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            int i = 0;
            ExportPointInfo rp = new ExportPointInfo();
            rp.setReportPointId(rs.getInt(++i));
            rp.setDeviceName(rs.getString(++i));
            rp.setPointName(rs.getString(++i));
            rp.setXid(rs.getString(++i));
            rp.setDataType(rs.getInt(++i));
            String startValue = rs.getString(++i);
            if (startValue != null)
                rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
            rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
            rp.setColour(rs.getString(++i));
            rp.setWeight(rs.getFloat(++i));
            rp.setConsolidatedChart(charToBool(rs.getString(++i)));
            rp.setPlotType(rs.getInt(++i));
            return rp;
        }
    });
    final ExportDataValue edv = new ExportDataValue();
    for (final ExportPointInfo point : pointInfos) {
        if (point.getDataType() == DataTypes.IMAGE) {
            DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
            if (vo != null)
                point.setDataPointId(vo.getId());
            else
                point.setDataPointId(-1);
        }
        handler.startPoint(point);
        edv.setReportPointId(point.getReportPointId());
        final int dataType = point.getDataType();
        ejt.query(REPORT_INSTANCE_DATA_SELECT + "where rd.reportInstancePointId=? order by rd.ts", new Object[] { point.getReportPointId() }, new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
                switch(dataType) {
                    case (DataTypes.NUMERIC):
                        edv.setValue(new NumericValue(rs.getDouble(1)));
                        break;
                    case (DataTypes.BINARY):
                        edv.setValue(new BinaryValue(rs.getDouble(1) == 1));
                        break;
                    case (DataTypes.MULTISTATE):
                        edv.setValue(new MultistateValue(rs.getInt(1)));
                        break;
                    case (DataTypes.ALPHANUMERIC):
                        edv.setValue(new AlphanumericValue(rs.getString(2)));
                        if (rs.wasNull())
                            edv.setValue(new AlphanumericValue(rs.getString(3)));
                        break;
                    case (DataTypes.IMAGE):
                        edv.setValue(new ImageValue(Integer.parseInt(rs.getString(2)), rs.getInt(1)));
                        break;
                    default:
                        edv.setValue(null);
                }
                edv.setTime(rs.getLong(4));
                edv.setAnnotation(BaseDao.readTranslatableMessage(rs, 5));
                handler.pointData(edv);
            }
        });
    }
    handler.done();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 3 with ImageValue

use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.

the class WatchListDwr method createWatchListState.

/**
 * Convenience method for creating a populated view state.
 */
private WatchListState createWatchListState(HttpServletRequest request, DataPointVO pointVO, RuntimeManager rtm, Map<String, Object> model, User user) {
    // Get the data point status from the data image.
    DataPointRT point = rtm.getDataPoint(pointVO.getId());
    WatchListState state = new WatchListState();
    state.setId(Integer.toString(pointVO.getId()));
    PointValueTime pointValue = prepareBasePointState(Integer.toString(pointVO.getId()), state, pointVO, point, model);
    setEvents(pointVO, user, model, pointEventsLimit);
    if (pointValue != null && pointValue.getValue() instanceof ImageValue) {
        // Text renderers don't help here. Create a thumbnail.
        setImageText(request, state, pointVO, model, pointValue);
    } else
        setPrettyText(state, pointVO, model, pointValue);
    if (pointVO.isSettable())
        setChange(pointVO, state, point, request, model, user);
    if (state.getValue() != null)
        setChart(pointVO, state, request, model);
    setMessages(state, request, getModule().getWebPath() + "/web/snippet/watchListMessages.jsp", model);
    return state;
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 4 with ImageValue

use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-modules-public by infiniteautomation.

the class MobileWatchListHandler method createState.

private MobileWatchListState createState(HttpServletRequest request, DataPointVO pointVO) {
    MobileWatchListState state = new MobileWatchListState();
    state.setId(Integer.toString(pointVO.getId()));
    state.setName(pointVO.getExtendedName());
    // Get the data point status from the data image.
    DataPointRT pointRT = Common.runtimeManager.getDataPoint(pointVO.getId());
    if (pointRT == null)
        state.setDisabled(true);
    else {
        PointValueTime pvt = pointRT.getPointValue();
        state.setTime(Functions.getTime(pvt));
        if (pvt != null && pvt.getValue() instanceof ImageValue) {
            // Text renderers don't help here. Create a thumbnail.
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("point", pointVO);
            model.put("pointValue", pvt);
            state.setValue(BaseDwr.generateContent(request, "imageValueThumbnail.jsp", model));
        } else
            state.setValue(Functions.getHtmlText(pointVO, pvt));
    }
    return state;
}
Also used : HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Example 5 with ImageValue

use of com.serotonin.m2m2.rt.dataImage.types.ImageValue in project ma-core-public by infiniteautomation.

the class ImagePointWrapper method ago.

public byte[] ago(int periodType, int periods) {
    long from = DateUtils.minus(getContext().getRuntime(), periodType, periods);
    PointValueTime pvt = point.getPointValueBefore(from);
    if (pvt == null)
        return null;
    return ((ImageValue) pvt.getValue()).getData();
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Aggregations

ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)15 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)9 ArrayList (java.util.ArrayList)6 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)5 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 IOException (java.io.IOException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)5 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)4 ImageSaveException (com.serotonin.m2m2.ImageSaveException)4 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 List (java.util.List)4 RQLToObjectListQuery (com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)3