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());
}
}
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();
}
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!");
}
}
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;
}
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;
}
Aggregations