use of com.serotonin.m2m2.DataType in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method savePointValueImpl.
private long savePointValueImpl(int pointId, int dataType, double dvalue, long time, String svalue, SetPointSource source) {
long id = doInsertLong(POINT_VALUE_INSERT, new Object[] { pointId, dataType, dvalue, time });
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_INSERT, //
new Object[] { id, shortString, longString, writeTranslatableMessage(sourceMessage) }, new int[] { Types.INTEGER, Types.VARCHAR, Types.CLOB, Types.CLOB });
}
return id;
}
use of com.serotonin.m2m2.DataType 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;
}
use of com.serotonin.m2m2.DataType in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method createDataValue.
DataValue createDataValue(ResultSet rs, int firstParameter) throws SQLException {
int dataType = rs.getInt(firstParameter);
DataValue value;
switch(dataType) {
case (DataTypes.NUMERIC):
value = new NumericValue(rs.getDouble(firstParameter + 1));
break;
case (DataTypes.BINARY):
value = new BinaryValue(rs.getDouble(firstParameter + 1) == 1);
break;
case (DataTypes.MULTISTATE):
value = new MultistateValue(rs.getInt(firstParameter + 1));
break;
case (DataTypes.ALPHANUMERIC):
String s = rs.getString(firstParameter + 2);
if (s == null)
s = rs.getString(firstParameter + 3);
value = new AlphanumericValue(s);
break;
case (DataTypes.IMAGE):
value = new ImageValue(Integer.parseInt(rs.getString(firstParameter + 2)), rs.getInt(firstParameter + 1));
break;
default:
value = null;
}
return value;
}
use of com.serotonin.m2m2.DataType in project ma-core-public by infiniteautomation.
the class FileUploadController method prepareResponse.
/**
* @param request
* @param response
* @param model
* @throws IOException
* @throws JsonException
* @throws FileUploadException
*/
private FileUploadView prepareResponse(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws IOException, JsonException, FileUploadException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
String dataType = multipartRequest.getParameter("dataType");
String uploadType = multipartRequest.getParameter("uploadType");
List<Object> fileInfo = new ArrayList<Object>();
Translations translations = ControllerUtils.getTranslations(request);
Iterator<String> itr = multipartRequest.getFileNames();
while (itr.hasNext()) {
MultipartFile file = multipartRequest.getFile(itr.next());
if (!file.isEmpty()) {
Map<String, Object> info = new HashMap<String, Object>();
info.put("filename", file.getOriginalFilename());
info.put("dataType", dataType);
parseFile(file.getInputStream(), info, translations, request);
fileInfo.add(info);
}
}
model.put("fileInfo", fileInfo);
boolean iframe = false;
boolean html5 = false;
boolean flash = false;
if (uploadType.equals("iframe")) {
iframe = true;
response.setContentType("text/html");
} else if (uploadType.equals("html5")) {
html5 = true;
response.setContentType("application/json");
} else if (uploadType.equals("flash")) {
flash = true;
response.setContentType("text/plain");
}
if (iframe || html5) {
return new FileUploadView(iframe);
} else if (flash) {
// TODO handle Flash
throw new ShouldNeverHappenException("Flash upload not supported.");
} else {
throw new ShouldNeverHappenException("Invalid file upload type.");
}
}
use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.
the class ReportPointValueTimeSerializer method getObject.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getObject(byte[], long)
*/
@Override
public ITime getObject(ByteArrayBuilder b, long ts, String seriesId) {
// Get the data type
int dataType = b.getShort();
DataValue dataValue = null;
// Second put in the data value
switch(dataType) {
case DataTypes.ALPHANUMERIC:
String s = b.getString();
dataValue = new AlphanumericValue(s);
break;
case DataTypes.BINARY:
boolean bool = b.getBoolean();
dataValue = new BinaryValue(bool);
break;
case DataTypes.IMAGE:
try {
dataValue = new ImageValue(b.getString());
} catch (InvalidArgumentException e1) {
// Probably no file
}
break;
case DataTypes.MULTISTATE:
int i = b.getInt();
dataValue = new MultistateValue(i);
break;
case DataTypes.NUMERIC:
double d = b.getDouble();
dataValue = new NumericValue(d);
break;
default:
throw new ShouldNeverHappenException("Data type of " + dataType + " is not supported");
}
// Get the annotation
String annotation = b.getString();
if (annotation != null) {
try {
return new AnnotatedPointValueTime(dataValue, ts, TranslatableMessage.deserialize(annotation));
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
} else {
return new PointValueTime(dataValue, ts);
}
}
Aggregations