use of com.infiniteautomation.asciifile.vo.AsciiFilePointLocatorVO in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method testString.
@DwrPermission(user = true)
public ProcessResult testString(int dsId, String raw) {
final ProcessResult pr = new ProcessResult();
// Message we will work with
String msg;
if (dsId == -1) {
pr.addContextualMessage("testString", "dsEdit.file.test.needsSave");
return pr;
}
msg = StringEscapeUtils.unescapeJava(raw);
// Map to store the values vs the points they are for
final List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
pr.addData("results", results);
DataPointDao dpd = DataPointDao.instance;
List<DataPointVO> points = dpd.getDataPoints(dsId, null);
for (final DataPointVO vo : points) {
final Map<String, Object> result = new HashMap<String, Object>();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
result.put("success", "true");
result.put("name", vo.getName());
result.put("identifier", pointIdentifier);
result.put("value", value != null ? value.toString() : "null");
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noPointRegexMatch").translate(Common.getTranslations()));
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noIdentifierFound").translate(Common.getTranslations()));
}
@Override
public void matchGeneralFailure(Exception e) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("common.default", e.getMessage()).translate(Common.getTranslations()));
}
};
AsciiFilePointLocatorVO locator = vo.getPointLocator();
AsciiFileDataSourceRT.matchPointValueTime(msg, Pattern.compile(locator.getValueRegex()), locator.getPointIdentifier(), locator.getPointIdentifierIndex(), locator.getDataTypeId(), locator.getValueIndex(), locator.getHasTimestamp(), locator.getTimestampIndex(), locator.getTimestampFormat(), callback);
if (result.size() > 0) {
results.add(result);
}
}
return pr;
}
use of com.infiniteautomation.asciifile.vo.AsciiFilePointLocatorVO in project ma-modules-public by infiniteautomation.
the class AsciiFileDataSourceRT method fileEvent.
private void fileEvent(List<DataPointRT> dataPoints) {
// Should never happen
if (this.file == null) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailedFileNotSetup"));
return;
}
if (restrictedPath) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("dsEdit.file.pathRestrictedBy", vo.getFilePath()));
return;
}
// The file is modified or we've just started, so read it.
try {
BufferedReader reader = new BufferedReader(new FileReader(this.file));
String msg;
if (!dataPoints.isEmpty()) {
// TODO optimize to be better than numLines*numPoints
while ((msg = reader.readLine()) != null) {
// Give all points the chance to find their data
for (final DataPointRT dp : dataPoints) {
AsciiFilePointLocatorRT pl = dp.getPointLocator();
final AsciiFilePointLocatorVO plVo = pl.getVo();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
if (!plVo.getHasTimestamp())
dp.updatePointValue(value);
else
dp.savePointValueDirectToCache(value, null, true, true);
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
// N/A
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
// N/A
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), false, new TranslatableMessage("file.event.insufficientGroups", dp.getVO().getExtendedName()));
}
@Override
public void matchGeneralFailure(Exception e) {
if (e instanceof ParseException)
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.dateParseFailed", e.getMessage()));
else if (e instanceof NumberFormatException) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
} else
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
}
};
matchPointValueTime(msg, pl.getValuePattern(), plVo.getPointIdentifier(), plVo.getPointIdentifierIndex(), plVo.getDataTypeId(), plVo.getValueIndex(), plVo.getHasTimestamp(), plVo.getTimestampIndex(), plVo.getTimestampFormat(), callback);
}
}
reader.close();
returnToNormal(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis());
}
} catch (FileNotFoundException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound", e.getMessage()));
} catch (IOException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
} catch (NumberFormatException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
}
}
Aggregations