Search in sources :

Example 36 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class DataSourceDwr method finishCopy.

@DwrPermission(user = true)
public ProcessResult finishCopy(int copyFromId, int newId) {
    ProcessResult result = new ProcessResult();
    if (!result.getHasMessages()) {
        this.dao.copyDataSourcePoints(copyFromId, newId);
        result.addData("vo", dao.get(newId));
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 37 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class DataSourceDwr method get.

@DwrPermission(user = true)
@Override
public ProcessResult get(int id) {
    ProcessResult response;
    try {
        if (id > 0) {
            response = super.get(id);
            // Kludge for modules to be able to use a default edit point for some of their tools (Bacnet for example needs this for adding lots of points)
            // This is an issue for opening AllDataPoints Point because it opens the Datasource too.
            // TODO to fix this we need to fix DataSourceEditDwr to not save the editing DataPoint state in the User, this will propogate into existing modules...
            DataSourceVO<?> vo = (DataSourceVO<?>) response.getData().get("vo");
            // Quick fix to ensure we don't keep the edit point around if we have switched data sources
            if ((Common.getUser().getEditPoint() == null) || (Common.getUser().getEditPoint().getDataSourceId() != vo.getId()) || (Common.getUser().getEditPoint().getDataSourceTypeName() != vo.getDefinition().getDataSourceTypeName())) {
                DataPointVO dp = new DataPointVO();
                dp.setXid(DataPointDao.instance.generateUniqueXid());
                dp.setDataSourceId(vo.getId());
                dp.setDataSourceTypeName(vo.getDefinition().getDataSourceTypeName());
                dp.setDeviceName(vo.getName());
                dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
                dp.defaultTextRenderer();
                dp.setXid(DataPointDao.instance.generateUniqueXid());
                dp.setPointLocator(vo.createPointLocator());
                Common.getUser().setEditPoint(dp);
            }
        } else {
            throw new ShouldNeverHappenException("Unable to get a new DataSource.");
        }
        // Setup the page info
        response.addData("editPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getEditPagePath());
        response.addData("statusPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getStatusPagePath());
    } catch (Exception e) {
        LOG.error(e.getMessage());
        response = new ProcessResult();
        response.addMessage(new TranslatableMessage("table.error.dwr", e.getMessage()));
    }
    return response;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 38 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method togglePoint.

@DwrPermission(user = true)
public ProcessResult togglePoint(int dataPointId) {
    ProcessResult response = super.toggleDataPoint(dataPointId);
    response.addData("points", getPoints());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 39 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method getGeneralStatusMessages.

@DwrPermission(user = true)
public final ProcessResult getGeneralStatusMessages() {
    ProcessResult result = new ProcessResult();
    DataSourceVO<?> vo = Common.getUser().getEditDataSource();
    DataSourceRT<?> rt = Common.runtimeManager.getRunningDataSource(vo.getId());
    List<TranslatableMessage> messages = new ArrayList<>();
    result.addData("messages", messages);
    if (rt == null)
        messages.add(new TranslatableMessage("dsEdit.notEnabled"));
    else {
        rt.addStatusMessages(messages);
        if (messages.isEmpty())
            messages.add(new TranslatableMessage("dsEdit.noStatus"));
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 40 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class DataSourceListDwr method copyDataSource.

@DwrPermission(user = true)
public ProcessResult copyDataSource(int dataSourceId, String name, String xid, String deviceName) {
    Permissions.ensureDataSourcePermission(Common.getUser(), dataSourceId);
    ProcessResult response = new ProcessResult();
    // Create a dummy data source with which to do the validation.
    DataSourceVO<?> ds = new MockDataSourceVO();
    ds.setName(name);
    ds.setXid(xid);
    ds.validate(response);
    if (!response.getHasMessages()) {
        int dsId = DataSourceDao.instance.copyDataSource(dataSourceId, name, xid, deviceName);
        response.addData("newId", dsId);
    }
    return response;
}
Also used : MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) 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