use of com.infiniteautomation.mango.rest.latest.model.AsciiFileTestResultModel in project ma-modules-public by infiniteautomation.
the class AsciiFileDataSourceRestController method validateASCIIString.
@ApiOperation(value = "Validate ASCII", notes = "")
@RequestMapping(method = RequestMethod.POST, value = "/validate-ascii/{xid}", consumes = { "text/plain;charset=UTF-8" })
public List<AsciiFileTestResultModel> validateASCIIString(@RequestBody String ascii, @ApiParam(value = "Valid ASCII data source XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
DataSourceVO ds = service.get(xid);
if (!(ds instanceof AsciiFileDataSourceVO))
throw new BadRequestException(new TranslatableMessage("validate.incompatibleDataSourceType"));
// Message we will work with
String msg = StringEscapeUtils.unescapeJava(ascii);
// Map to store the values vs the points they are for
List<AsciiFileTestResultModel> results = new ArrayList<>();
DataPointDao dpd = DataPointDao.getInstance();
List<DataPointVO> points = dpd.getDataPoints(ds.getId());
for (final DataPointVO vo : points) {
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
AsciiFileTestResultModel result = new AsciiFileTestResultModel();
results.add(result);
result.setSuccess(true);
result.setPointName(vo.getName());
result.setPointXid(vo.getXid());
result.setIdentifier(pointIdentifier);
if (value != null) {
result.setValue(value.getValue().getObjectValue());
result.setTimestamp(new Date(value.getTime()));
}
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
AsciiFileTestResultModel result = new AsciiFileTestResultModel();
results.add(result);
result.setSuccess(false);
result.setPointName(vo.getName());
result.setPointXid(vo.getXid());
result.setError(new TranslatableMessage("dsEdit.file.test.noPointRegexMatch"));
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
AsciiFileTestResultModel result = new AsciiFileTestResultModel();
results.add(result);
result.setSuccess(false);
result.setPointName(vo.getName());
result.setPointXid(vo.getXid());
result.setError(new TranslatableMessage("dsEdit.file.test.noIdentifierFound"));
}
@Override
public void matchGeneralFailure(Exception e) {
AsciiFileTestResultModel result = new AsciiFileTestResultModel();
results.add(result);
result.setSuccess(false);
result.setPointName(vo.getName());
result.setPointXid(vo.getXid());
result.setError(new TranslatableMessage("common.default", e.getMessage()));
}
};
AsciiFilePointLocatorVO locator = vo.getPointLocator();
AsciiFileDataSourceRT.matchPointValueTime(msg, Pattern.compile(locator.getValueRegex()), locator.getPointIdentifier(), locator.getPointIdentifierIndex(), locator.getDataType(), locator.getValueIndex(), locator.getHasTimestamp(), locator.getTimestampIndex(), locator.getTimestampFormat(), callback);
}
return results;
}
Aggregations