use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.
the class BaseDwr method setPointImpl.
protected void setPointImpl(DataPointVO point, String valueStr, SetPointSource source) {
if (point == null)
return;
if (valueStr == null)
Common.runtimeManager.relinquish(point.getId());
else {
// Convert the string value into an object.
DataValue value = DataValue.stringToValue(valueStr, point.getPointLocator().getDataTypeId());
// do reverse conversion of renderer
TextRenderer tr = point.getTextRenderer();
if (point.getPointLocator().getDataTypeId() == DataTypes.NUMERIC && tr instanceof ConvertingRenderer) {
ConvertingRenderer cr = (ConvertingRenderer) tr;
UnitConverter converter = cr.getRenderedUnit().getConverterTo(cr.getUnit());
double convertedValue = converter.convert(value.getDoubleValue());
value = new NumericValue(convertedValue);
}
Common.runtimeManager.setDataPointValue(point.getId(), value, source);
}
}
use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.
the class MockPointValueDao method savePointValueSync.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.PointValueDao#savePointValueSync(int, com.serotonin.m2m2.rt.dataImage.PointValueTime, com.serotonin.m2m2.rt.dataImage.SetPointSource)
*/
@Override
public PointValueTime savePointValueSync(int pointId, PointValueTime pointValue, SetPointSource source) {
List<PointValueTime> pvts = data.get(pointId);
if (pvts == null) {
pvts = new ArrayList<>();
data.put(pointId, pvts);
}
PointValueTime newPvt = null;
if (source != null)
newPvt = new AnnotatedPointValueTime(pointValue.getValue(), pointValue.getTime(), source.getSetPointSourceMessage());
else
newPvt = new PointValueTime(pointValue.getValue(), pointValue.getTime());
pvts.add(newPvt);
// Keep in time order?
Collections.sort(pvts);
return newPvt;
}
use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method updatePointValueImpl.
long updatePointValueImpl(final int pointId, final PointValueTime pvt, final SetPointSource source, boolean async) {
DataValue value = pvt.getValue();
final int dataType = DataTypes.getDataType(value);
double dvalue = 0;
String svalue = null;
if (dataType == DataTypes.IMAGE) {
ImageValue imageValue = (ImageValue) value;
dvalue = imageValue.getType();
if (imageValue.isSaved())
svalue = Long.toString(imageValue.getId());
} else if (value.hasDoubleRepresentation())
dvalue = value.getDoubleValue();
else
svalue = value.getStringValue();
// Check if we need to create an annotation.
long id;
try {
if (svalue != null || source != null || dataType == DataTypes.IMAGE)
async = false;
id = updatePointValue(pointId, dataType, dvalue, pvt.getTime(), svalue, source, async);
} catch (ConcurrencyFailureException e) {
// Still failed to insert after all of the retries. Store the data
synchronized (UNSAVED_POINT_UPDATES) {
UNSAVED_POINT_UPDATES.add(new UnsavedPointUpdate(pointId, pvt, source));
}
return -1;
}
// Check if we need to save an image
if (dataType == DataTypes.IMAGE) {
ImageValue imageValue = (ImageValue) value;
if (!imageValue.isSaved()) {
imageValue.setId(id);
File file = new File(Common.getFiledataPath(), imageValue.getFilename());
// Write the file.
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
StreamUtils.transfer(new ByteArrayInputStream(imageValue.getData()), out);
} catch (IOException e) {
// Rethrow as an RTE
throw new ImageSaveException(e);
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
// no op
}
}
// Allow the data to be GC'ed
imageValue.setData(null);
}
}
clearUnsavedPointUpdates();
return id;
}
use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method updatePointValueAnnotation.
private void updatePointValueAnnotation(long id, int dataType, String svalue, SetPointSource source) {
if (svalue == null && dataType == DataTypes.IMAGE)
svalue = Long.toString(id);
// Check if we need to create an annotation.
TranslatableMessage sourceMessage = null;
if (source != null)
sourceMessage = source.getSetPointSourceMessage();
if (svalue != null || sourceMessage != null) {
String shortString = null;
String longString = null;
if (svalue != null) {
if (svalue.length() > 128)
longString = svalue;
else
shortString = svalue;
}
//
ejt.update(//
POINT_VALUE_ANNOTATION_UPDATE + "WHERE pointValueId = ?", //
new Object[] { shortString, longString, writeTranslatableMessage(sourceMessage), id }, new int[] { Types.VARCHAR, Types.CLOB, Types.CLOB, Types.INTEGER });
}
}
use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method savePointValueSync.
/**
* Only the PointValueCache should call this method during runtime. Do not use.
*/
@Override
public PointValueTime savePointValueSync(int pointId, PointValueTime pointValue, SetPointSource source) {
long id = savePointValueImpl(pointId, pointValue, source, false);
PointValueTime savedPointValue;
int retries = 5;
while (true) {
try {
savedPointValue = getPointValue(id);
break;
} catch (ConcurrencyFailureException e) {
if (retries <= 0)
throw e;
retries--;
}
}
return savedPointValue;
}
Aggregations