Search in sources :

Example 31 with DwrPermission

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;
}
Also used : BinaryGraphicComponent(com.serotonin.m2m2.gviews.component.BinaryGraphicComponent) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ImageSet(com.serotonin.m2m2.view.ImageSet) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 32 with DwrPermission

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) MatchCallback(com.infiniteautomation.mango.regex.MatchCallback) AsciiFilePointLocatorVO(com.infiniteautomation.asciifile.vo.AsciiFilePointLocatorVO) IOException(java.io.IOException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) HashMap(java.util.HashMap) Map(java.util.Map) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 33 with DwrPermission

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;
}
Also used : File(java.io.File) IOException(java.io.IOException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 34 with DwrPermission

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 35 with DwrPermission

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;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6