use of com.serotonin.m2m2.ImageSaveException 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.ImageSaveException 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);
}
use of com.serotonin.m2m2.ImageSaveException in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method savePointValueImpl.
long savePointValueImpl(final int pointId, final PointValueTime pointValue, final SetPointSource source, boolean async) {
DataValue value = pointValue.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 = savePointValue(pointId, dataType, dvalue, pointValue.getTime(), svalue, source, async);
} catch (ConcurrencyFailureException e) {
// Still failed to insert after all of the retries. Store the data
synchronized (UNSAVED_POINT_VALUES) {
UNSAVED_POINT_VALUES.add(new UnsavedPointValue(pointId, pointValue, 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);
}
}
clearUnsavedPointValues();
clearUnsavedPointUpdates();
return id;
}
Aggregations