use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method saveBinaryGraphicComponent.
@DwrPermission(user = true)
public ProcessResult saveBinaryGraphicComponent(String viewComponentId, int zeroImage, int oneImage, boolean displayText, String imageSetId) {
ProcessResult response = new ProcessResult();
// Validate
ImageSet imageSet = getImageSet(imageSetId);
if (imageSet == null)
response.addContextualMessage("graphicRendererBinaryImageSet", "viewEdit.graphic.missingImageSet");
else {
if (zeroImage == -1)
response.addContextualMessage("graphicRendererBinaryImageSetZeroMsg", "viewEdit.graphic.missingZeroImage");
if (oneImage == -1)
response.addContextualMessage("graphicRendererBinaryImageSetOneMsg", "viewEdit.graphic.missingOneImage");
}
if (!response.getHasMessages()) {
BinaryGraphicComponent c = (BinaryGraphicComponent) getViewComponent(viewComponentId);
c.tsetImageSet(imageSet);
c.setZeroImage(zeroImage);
c.setOneImage(oneImage);
c.setDisplayText(displayText);
resetPointComponent(c);
}
return response;
}
use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method checkIsFileReadable.
@DwrPermission(user = true)
public boolean checkIsFileReadable(String path) {
String canonicalPath;
File verify = new File(path);
try {
canonicalPath = verify.getCanonicalPath();
LOG.info("Verifying ASCII file reader path to: " + canonicalPath);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return false;
}
String restrictedPaths = SystemSettingsDao.getValue(AsciiFileSystemSettingsDefinition.RESTRICTED_PATH);
if (!StringUtils.isEmpty(restrictedPaths))
for (String p : restrictedPaths.split(";")) if (path.startsWith(p))
return false;
if (verify.exists())
return verify.canRead();
return false;
}
use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method validateSettings.
@DwrPermission(admin = true)
public ProcessResult validateSettings(Map<String, String> settings) {
ProcessResult response = new ProcessResult();
AsciiFileSystemSettingsDefinition.validate(settings, response);
return response;
}
use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class InternalEditDwr method init.
@DwrPermission(user = true)
public ProcessResult init() {
ProcessResult result = new ProcessResult();
List<StringStringPair> monitors = new ArrayList<StringStringPair>();
for (ValueMonitor<?> monitor : Common.MONITORED_VALUES.getMonitors()) {
monitors.add(new StringStringPair(monitor.getId(), monitor.getName().translate(Common.getTranslations())));
}
result.addData("monitors", monitors);
return result;
}
Aggregations