Search in sources :

Example 56 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method exportDataPoint.

@DwrPermission(user = true)
public String exportDataPoint(int dataPointId) {
    DataSourceVO<?> ds = Common.getUser().getEditDataSource();
    DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
    if (dp == null)
        return null;
    if (dp.getDataSourceId() != ds.getId())
        throw new PermissionException(new TranslatableMessage("common.default", "Wrong data source"), Common.getUser());
    Map<String, Object> data = new LinkedHashMap<>();
    List<DataPointVO> dss = new ArrayList<>();
    dss.add(dp);
    data.put(ConfigurationExportData.DATA_POINTS, dss);
    return EmportDwr.export(data);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) LinkedHashMap(java.util.LinkedHashMap) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 57 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method getPoint.

protected DataPointVO getPoint(int pointId, DataPointDefaulter defaulter) {
    // Added to allow saving point settings from data point edit view
    DataPointVO dp = Common.getUser().getEditPoint();
    DataSourceVO<?> ds = Common.getUser().getEditDataSource();
    if (ds.getId() == Common.NEW_ID)
        throw new ShouldNeverHappenException("Please Save Data Source First.");
    if (pointId == Common.NEW_ID) {
        String deviceName;
        String readPermission = null;
        String setPermission = null;
        if (dp != null) {
            deviceName = dp.getDeviceName();
            readPermission = dp.getReadPermission();
            setPermission = dp.getSetPermission();
        } else {
            deviceName = ds.getName();
        }
        dp = new DataPointVO();
        dp.setXid(DataPointDao.instance.generateUniqueXid());
        dp.setDeviceName(deviceName);
        dp.setId(pointId);
        dp.setDataSourceId(ds.getId());
        dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        dp.setReadPermission(readPermission);
        dp.setSetPermission(setPermission);
        dp.setPointLocator(ds.createPointLocator());
        dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        dp.defaultTextRenderer();
    } else {
        // retain in the user's editing point
        if (dp.getId() != pointId)
            dp = DataPointDao.instance.getFull(pointId);
    }
    // Use the defaulter
    if (defaulter != null && dp != null) {
        if (dp.getId() == Common.NEW_ID)
            defaulter.setDefaultValues(dp);
        else
            defaulter.updateDefaultValues(dp);
    }
    // should use for this point.  If not we must fail.
    if (!(dp.getDataSourceTypeName().equals(ds.getDefinition().getDataSourceTypeName())) || (dp.getDataSourceId() != ds.getId())) {
        throw new RuntimeException("Data point type mismatch to data source type, unable to save.  Are you working with multiple tabs open?");
    }
    Common.getUser().setEditPoint(dp);
    return dp;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 58 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method purgeNow.

// 
// Data purge
// 
@DwrPermission(user = true)
public long purgeNow(int purgeType, int purgePeriod, boolean allData) {
    DataSourceVO<?> ds = Common.getUser().getEditDataSource();
    if (ds.getId() == Common.NEW_ID)
        return 0;
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(ds.getId(), DataPointNameComparator.instance, false);
    Long count = 0L;
    for (DataPointVO point : points) {
        if (allData)
            count += Common.runtimeManager.purgeDataPointValues(point.getId());
        else
            count += Common.runtimeManager.purgeDataPointValues(point.getId(), purgeType, purgePeriod);
    }
    return count;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 59 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class DataSourceListDwr method dataSourceInfo.

@DwrPermission(user = true)
public ProcessResult dataSourceInfo(int dataSourceId) {
    DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(dataSourceId);
    Permissions.ensureDataSourcePermission(Common.getUser(), ds);
    ProcessResult response = new ProcessResult();
    String name = StringUtils.abbreviate(TranslatableMessage.translate(getTranslations(), "common.copyPrefix", ds.getName()), 40);
    response.addData("name", name);
    response.addData("xid", DataSourceDao.instance.generateUniqueXid());
    response.addData("deviceName", name);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 60 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class DataSourceListDwr method init.

@DwrPermission(user = true)
public ProcessResult init() {
    ProcessResult response = new ProcessResult();
    User user = Common.getUser();
    List<DataSourceVO<?>> allDataSources = Common.runtimeManager.getDataSources();
    if (Permissions.hasAdmin(user)) {
        response.addData("dataSources", allDataSources);
        List<StringStringPair> translatedTypes = new ArrayList<>();
        for (String type : ModuleRegistry.getDataSourceDefinitionTypes()) translatedTypes.add(new StringStringPair(type, translate(ModuleRegistry.getDataSourceDefinition(type).getDescriptionKey())));
        StringStringPairComparator.sort(translatedTypes);
        response.addData("types", translatedTypes);
    } else {
        List<DataSourceVO<?>> dataSources = new ArrayList<>();
        for (DataSourceVO<?> ds : allDataSources) {
            if (Permissions.hasDataSourcePermission(user, ds))
                dataSources.add(ds);
        }
        response.addData("dataSources", dataSources);
    }
    return response;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) StringStringPair(com.serotonin.db.pair.StringStringPair) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

User (com.serotonin.m2m2.vo.User)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 ArrayList (java.util.ArrayList)21 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)19 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)18 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)18 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)15 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)15 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 List (java.util.List)10 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)9 AbstractDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel)8 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)6 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)6 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5