Search in sources :

Example 66 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class AbstractRTDwr method save.

/**
 * Save the Process
 * @return
 */
@DwrPermission(admin = true)
@Override
public ProcessResult save(VO vo) {
    ProcessResult response = new ProcessResult();
    vo.validate(response);
    if (!response.getHasMessages()) {
        // Save it
        try {
            runtimeManager.save(vo);
        } catch (Exception e) {
            // Handle the exceptions.
            // TODO Clean up and generify these messages to some central place
            LOG.error(e);
            if (e instanceof DuplicateKeyException)
                response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.alreadyExists"));
            else
                response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.unableToSave"));
        }
    }
    response.addData("vo", vo);
    // In case there are errors
    response.addData("id", vo.getId());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 67 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class DataPointDetailsDwr method getStatsChartData.

@DwrPermission(user = true)
public ProcessResult getStatsChartData(int periodType, int period, boolean includeSum) {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    DataPointVO pointVO = Common.getUser(request).getEditPoint();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("point", pointVO);
    StatisticsChartRenderer r = new StatisticsChartRenderer(periodType, period, includeSum);
    r.addDataToModel(model, pointVO);
    ProcessResult response = new ProcessResult();
    response.addData("stats", generateContent(request, "statsChart.jsp", model));
    addAsof(response);
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 68 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class DataPointDetailsDwr method getImageChartData.

@DwrPermission(user = true)
public ProcessResult getImageChartData(int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, int fromSecond, boolean fromNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, int toSecond, boolean toNone, int width, int height, boolean useCache) {
    DateTimeZone dtz = Common.getUser().getDateTimeZoneInstance();
    DateTime from = createDateTime(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, fromNone, dtz);
    DateTime to = createDateTime(toYear, toMonth, toDay, toHour, toMinute, toSecond, toNone, dtz);
    StringBuilder htmlData = new StringBuilder();
    htmlData.append("<img src=\"chart/ft_");
    htmlData.append(Common.timer.currentTimeMillis());
    htmlData.append('_');
    htmlData.append(fromNone ? -1 : from.getMillis());
    htmlData.append('_');
    htmlData.append(toNone ? -1 : to.getMillis());
    htmlData.append('_');
    htmlData.append(getDataPointVO().getId());
    htmlData.append(".png?w=");
    htmlData.append(width);
    htmlData.append("&h=");
    htmlData.append(height);
    if (useCache)
        htmlData.append("&useCache=true");
    htmlData.append("\" alt=\"" + translate("common.imageChart") + "\"/>");
    ProcessResult response = new ProcessResult();
    response.addData("chart", htmlData.toString());
    addAsof(response);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 69 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class DataPointDwr method enableDisable.

@DwrPermission(user = true)
public ProcessResult enableDisable(int dataPointId, boolean enabled) {
    DataPointVO dataPoint = DataPointDao.instance.getDataPoint(dataPointId, false);
    Permissions.ensureDataSourcePermission(Common.getUser(), dataPoint.getDataSourceId());
    if (enabled)
        DataPointDao.instance.setEventDetectors(dataPoint);
    Common.runtimeManager.enableDataPoint(dataPoint, enabled);
    ProcessResult response = new ProcessResult();
    response.addData("id", dataPointId);
    response.addData("enabled", dataPoint.isEnabled());
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 70 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class DataPointDwr method getFull.

/*
     * (non-Javadoc)
     * 
     * @see com.deltamation.mango.downtime.web.AbstractBasicDwr#getFull(int)
     */
@DwrPermission(user = true)
@Override
public ProcessResult getFull(int id) {
    DataPointVO vo;
    User user = Common.getUser();
    if (id == Common.NEW_ID) {
        vo = dao.getNewVo();
        // TODO Need to sort this out another way, this will wreck
        // when users have mulitple tabs open in a browser
        DataSourceVO<?> ds = user.getEditDataSource();
        vo.setXid(dao.generateUniqueXid());
        vo.setPointLocator(ds.createPointLocator());
        vo.setDataSourceId(ds.getId());
        vo.setDataSourceName(ds.getName());
        vo.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        vo.setDataSourceXid(ds.getXid());
        vo.setDeviceName(ds.getName());
        vo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        vo.defaultTextRenderer();
    } else {
        vo = dao.getFull(id);
    }
    // Should check permissions?
    // Permissions.ensureDataSourcePermission(user, vo.getDataSourceId());
    user.setEditPoint(vo);
    // TODO Need to deal with point value defaulter
    ProcessResult response = new ProcessResult();
    response.addData("vo", vo);
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)165 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)132 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 User (com.serotonin.m2m2.vo.User)31 ArrayList (java.util.ArrayList)28 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)27 JsonException (com.serotonin.json.JsonException)21 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)20 JsonObject (com.serotonin.json.type.JsonObject)13 HashMap (java.util.HashMap)12 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)11 StringStringPair (com.serotonin.db.pair.StringStringPair)9 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)9 IOException (java.io.IOException)9 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)8 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)8 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)8 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)7 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7