Search in sources :

Example 16 with AbstractPointEventDetectorVO

use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-modules-public by infiniteautomation.

the class EventTypeV2RestController method getAllDataPointEventTypes.

private void getAllDataPointEventTypes(List<EventTypeModel> types, User user, Integer dataPointId, Integer detectorId) {
    List<DataPointVO> dataPoints = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, true);
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO dpvo : dataPoints) if ((dataPointId == null || dataPointId.intValue() == dpvo.getId()) && dpvo.getEventDetectors() != null)
        for (AbstractPointEventDetectorVO<?> ed : dpvo.getEventDetectors()) if ((detectorId == null || detectorId.intValue() == ed.getId())) {
            EventType dpet = ed.getEventType().createEventType();
            if (admin || Permissions.hasEventTypePermission(user, dpet))
                types.add(dpet.asModel());
        }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType)

Example 17 with AbstractPointEventDetectorVO

use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-modules-public by infiniteautomation.

the class DataPointRestController method copy.

@ApiOperation(value = "Copy data point", notes = "Copy the data point with optional new XID and Name and enable/disable state (default disabled)")
@RequestMapping(method = RequestMethod.PUT, value = "/copy/{xid}", produces = { "application/json" })
public ResponseEntity<DataPointModel> copy(@PathVariable String xid, @ApiParam(value = "Copy's new XID", required = false, defaultValue = "null", allowMultiple = false) @RequestParam(required = false, defaultValue = "null") String copyXid, @ApiParam(value = "Copy's name", required = false, defaultValue = "null", allowMultiple = false) @RequestParam(required = false, defaultValue = "null") String copyName, @ApiParam(value = "Enable/disabled state", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean enabled, UriComponentsBuilder builder, HttpServletRequest request) {
    RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        DataPointVO existing = this.dao.getByXid(xid);
        if (existing == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        // Check permissions
        try {
            if (!Permissions.hasDataSourcePermission(user, existing.getDataSourceId())) {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            }
        } catch (PermissionException e) {
            LOG.warn(e.getMessage(), e);
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        // Determine the new name
        String name;
        if (StringUtils.isEmpty(copyName))
            name = StringUtils.abbreviate(TranslatableMessage.translate(Common.getTranslations(), "common.copyPrefix", existing.getName()), 40);
        else
            name = copyName;
        // Determine the new xid
        String newXid;
        if (StringUtils.isEmpty(copyXid))
            newXid = dao.generateUniqueXid();
        else
            newXid = copyXid;
        // Setup the Copy
        DataPointVO copy = existing.copy();
        copy.setId(Common.NEW_ID);
        copy.setName(name);
        copy.setXid(newXid);
        copy.setEnabled(enabled);
        copy.getComments().clear();
        // Copy the event detectors
        for (AbstractPointEventDetectorVO<?> ped : copy.getEventDetectors()) {
            ped.setId(Common.NEW_ID);
            ped.njbSetDataPoint(copy);
        }
        ProcessResult validation = new ProcessResult();
        copy.validate(validation);
        DataPointModel model = new DataPointModel(copy);
        if (model.validate()) {
            Common.runtimeManager.saveDataPoint(copy);
        } else {
            result.addRestMessage(this.getValidationFailedError());
            return result.createResponseEntity(model);
        }
        // Put a link to the updated data in the header?
        URI location = builder.path("/v1/data-points/{xid}").buildAndExpand(copy.getXid()).toUri();
        result.addRestMessage(getResourceUpdatedMessage(location));
        return result.createResponseEntity(model);
    }
    // Not logged in
    return result.createResponseEntity();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) DataPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel) User(com.serotonin.m2m2.vo.User) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) URI(java.net.URI) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with AbstractPointEventDetectorVO

use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-modules-public by infiniteautomation.

the class VirtualEditDwr method createTestSource.

/**
 * Test Method for debugging system.
 */
@DwrPermission(admin = true)
public void createTestSource() {
    VirtualDataSourceVO ds = new VirtualDataSourceVO();
    DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition("VIRTUAL");
    ds = (VirtualDataSourceVO) def.baseCreateDataSourceVO();
    ds.setId(Common.NEW_ID);
    ds.setXid(DataSourceDao.instance.generateUniqueXid());
    ds.setName("Test Virtual");
    ds.setEnabled(true);
    ds.setUpdatePeriods(5);
    ds.setUpdatePeriodType(TimePeriods.SECONDS);
    ds.setPolling(true);
    ProcessResult response = new ProcessResult();
    ds.validate(response);
    if (!response.getHasMessages())
        Common.runtimeManager.saveDataSource(ds);
    else
        throw new RuntimeException("Invalid data!");
    DataPointDao dpDao = DataPointDao.instance;
    // Create Test Points
    for (int i = 0; i < 10; i++) {
        VirtualPointLocatorVO pointLocator = ds.createPointLocator();
        // Create a Random Points
        pointLocator.setDataTypeId(DataTypes.NUMERIC);
        pointLocator.setChangeTypeId(ChangeTypeVO.Types.RANDOM_ANALOG);
        pointLocator.getRandomAnalogChange().setMin(0);
        pointLocator.getRandomAnalogChange().setMax(100);
        pointLocator.getRandomAnalogChange().setStartValue("1");
        pointLocator.setSettable(true);
        DataPointVO dp = new DataPointVO();
        dp.setXid(dpDao.generateUniqueXid());
        dp.setName("Virtual Random " + i);
        dp.setDataSourceId(ds.getId());
        dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        dp.setDeviceName(ds.getName());
        dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        dp.defaultTextRenderer();
        // Setup the Chart Renderer
        ImageChartRenderer chartRenderer = new ImageChartRenderer(TimePeriods.DAYS, 5);
        dp.setChartRenderer(chartRenderer);
        dp.setPointLocator(pointLocator);
        dp.setEnabled(true);
        dp.setSettable(true);
        dp.setDefaultCacheSize(0);
        dp.validate(response);
        if (!response.getHasMessages())
            Common.runtimeManager.saveDataPoint(dp);
        else
            throw new RuntimeException("Invalid data!");
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) VirtualDataSourceVO(com.serotonin.m2m2.virtual.vo.VirtualDataSourceVO) VirtualPointLocatorVO(com.serotonin.m2m2.virtual.vo.VirtualPointLocatorVO) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 19 with AbstractPointEventDetectorVO

use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-core-public by infiniteautomation.

the class DataPointDwr method getEventDetectorOptions.

/**
 * Get a list of available Point Event Detectors for this point
 *
 * @param vo
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getEventDetectorOptions(int dataTypeId) {
    ProcessResult response = new ProcessResult();
    List<EventDetectorDefinition<?>> definitions = ModuleRegistry.getEventDetectorDefinitions();
    List<StringStringPair> list = new ArrayList<StringStringPair>();
    for (EventDetectorDefinition<?> definition : definitions) {
        AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
        if (vo instanceof AbstractPointEventDetectorVO) {
            AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) vo;
            if (ped.supports(dataTypeId)) {
                list.add(new StringStringPair(definition.getDescriptionKey(), definition.getEventDetectorTypeName()));
            }
        }
    }
    response.addData("options", list);
    return response;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) EventDetectorDefinition(com.serotonin.m2m2.module.EventDetectorDefinition) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 20 with AbstractPointEventDetectorVO

use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO 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)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)21 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)17 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)8 ArrayList (java.util.ArrayList)7 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 User (com.serotonin.m2m2.vo.User)3 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ServerErrorException (com.infiniteautomation.mango.rest.v2.exception.ServerErrorException)2 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 JsonException (com.serotonin.json.JsonException)2 JsonArray (com.serotonin.json.type.JsonArray)2 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)2 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)2 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)2