use of com.serotonin.m2m2.DataType 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.DataType 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.DataType in project ma-core-public by infiniteautomation.
the class DeltamationCommon method validatePoint.
public static DataPointVO validatePoint(int pointId, String name, ProcessResult response, Integer dataType, boolean requireSettable) {
DataPointDao points = DataPointDao.instance;
DataPointVO point = points.getDataPoint(pointId);
if (point == null) {
response.addContextualMessage(name, "validate.noPoint");
return null;
}
if (requireSettable && !point.getPointLocator().isSettable()) {
response.addContextualMessage(name, "validate.pointNotSettable", point.getName());
}
if (dataType != null && point.getPointLocator().getDataTypeId() != dataType) {
response.addContextualMessage(name, "validate.pointWrongType", point.getName());
}
return point;
}
use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.
the class PointValueImportResult method saveValue.
public void saveValue(LegacyXidPointValueTimeModel model) {
if (valid) {
// Validate the model against our point
long timestamp = model.getTimestamp();
if (timestamp == 0)
timestamp = Common.timer.currentTimeMillis();
try {
DataValue value;
switch(vo.getPointLocator().getDataType()) {
case ALPHANUMERIC:
value = new AlphanumericValue((String) model.getValue());
break;
case BINARY:
value = new BinaryValue((Boolean) model.getValue());
break;
case MULTISTATE:
if (model.getValue() instanceof String) {
try {
value = vo.getTextRenderer().parseText((String) model.getValue(), vo.getPointLocator().getDataType());
} catch (Exception e) {
// Lots can go wrong here so let the user know
result.addContextualMessage("value", "event.valueParse.textParse", e.getMessage());
return;
}
} else {
value = new MultistateValue(((Number) model.getValue()).intValue());
}
break;
case NUMERIC:
value = new NumericValue(((Number) model.getValue()).doubleValue());
break;
default:
result.addContextualMessage("dataType", "common.default", vo.getPointLocator().getDataType() + " data type not supported yet");
return;
}
PointValueTime pvt;
if (model.getAnnotation() == null) {
pvt = new PointValueTime(value, timestamp);
} else {
pvt = new AnnotatedPointValueTime(value, timestamp, new TranslatableMessage("common.default", model.getAnnotation()));
}
if (rt == null) {
dao.savePointValueAsync(vo, pvt);
} else {
rt.savePointValueDirectToCache(pvt, null, true, true, fireEvents);
}
total++;
} catch (Exception e) {
if (e instanceof ClassCastException) {
result.addContextualMessage("dataType", "event.ds.dataType");
} else {
result.addContextualMessage("value", "common.default", e.getMessage());
}
}
}
}
use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.
the class VirtualPointLocatorModel method toVO.
@Override
public VirtualPointLocatorVO toVO() {
VirtualPointLocatorVO vo = new VirtualPointLocatorVO();
vo.setDataType(DataType.fromName(dataType));
vo.setChangeTypeId(ChangeTypeVO.CHANGE_TYPE_CODES.getId(changeType));
vo.setSettable(settable);
switch(vo.getChangeTypeId()) {
case ChangeTypeVO.Types.ALTERNATE_BOOLEAN:
AlternateBooleanChangeVO abc = new AlternateBooleanChangeVO();
abc.setStartValue(startValue);
vo.setAlternateBooleanChange(abc);
break;
case ChangeTypeVO.Types.ANALOG_ATTRACTOR:
AnalogAttractorChangeVO aac = new AnalogAttractorChangeVO();
aac.setStartValue(startValue);
aac.setMaxChange(maxChange);
aac.setVolatility(volatility);
Integer attractionPointId = DataPointDao.getInstance().getIdByXid(attractionPointXid);
if (attractionPointId != null) {
aac.setAttractionPointId(attractionPointId);
}
vo.setAnalogAttractorChange(aac);
break;
case ChangeTypeVO.Types.BROWNIAN:
BrownianChangeVO bc = new BrownianChangeVO();
bc.setStartValue(startValue);
bc.setMin(min);
bc.setMax(max);
bc.setMaxChange(maxChange);
vo.setBrownianChange(bc);
break;
case ChangeTypeVO.Types.INCREMENT_ANALOG:
IncrementAnalogChangeVO iac = new IncrementAnalogChangeVO();
iac.setStartValue(startValue);
iac.setMin(min);
iac.setMax(max);
iac.setChange(change);
iac.setRoll(roll);
vo.setIncrementAnalogChange(iac);
break;
case ChangeTypeVO.Types.INCREMENT_MULTISTATE:
IncrementMultistateChangeVO imc = new IncrementMultistateChangeVO();
imc.setStartValue(startValue);
imc.setValues(values);
imc.setRoll(roll);
vo.setIncrementMultistateChange(imc);
break;
case ChangeTypeVO.Types.NO_CHANGE:
NoChangeVO nc = new NoChangeVO();
nc.setStartValue(startValue);
vo.setNoChange(nc);
break;
case ChangeTypeVO.Types.RANDOM_ANALOG:
RandomAnalogChangeVO rac = new RandomAnalogChangeVO();
rac.setStartValue(startValue);
rac.setMin(min);
rac.setMax(max);
vo.setRandomAnalogChange(rac);
break;
case ChangeTypeVO.Types.RANDOM_BOOLEAN:
RandomBooleanChangeVO rbc = new RandomBooleanChangeVO();
rbc.setStartValue(startValue);
vo.setRandomBooleanChange(rbc);
break;
case ChangeTypeVO.Types.RANDOM_MULTISTATE:
RandomMultistateChangeVO rmc = new RandomMultistateChangeVO();
rmc.setStartValue(startValue);
rmc.setValues(values);
vo.setRandomMultistateChange(rmc);
break;
case ChangeTypeVO.Types.SINUSOIDAL:
SinusoidalChangeVO sc = new SinusoidalChangeVO();
sc.setStartValue(startValue);
sc.setAmplitude(amplitude);
sc.setOffset(offset);
sc.setPeriod(period);
sc.setPhaseShift(phaseShift);
vo.setSinusoidalChange(sc);
break;
}
return vo;
}
Aggregations