use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO 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;
}
use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method validatePoint.
protected ProcessResult validatePoint(int id, String xid, String name, PointLocatorVO<?> locator, DataPointDefaulter defaulter, boolean includePointList) {
ProcessResult response = new ProcessResult();
// This saving of the point into the User is a bad idea, need to rework to
// pass the point back and forth to page.
DataPointVO dp = getPoint(id, defaulter);
dp.setXid(xid);
dp.setName(name);
dp.setPointLocator(locator);
// Confirm that we are assinging a point to the correct data source
DataSourceVO<?> ds = DataSourceDao.instance.get(dp.getDataSourceId());
PointLocatorVO<?> plvo = ds.createPointLocator();
if (plvo.getClass() != locator.getClass()) {
response.addGenericMessage("validate.invalidType");
return response;
}
// If we are a new point then only validate the basics
if (id == Common.NEW_ID) {
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!DataPointDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (StringUtils.isBlank(name))
response.addContextualMessage("name", "validate.required");
// Load in the default Template
DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(locator.getDataTypeId());
if (template != null) {
template.updateDataPointVO(dp);
}
// Should really be done elsewhere
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
} else if (id == DataPointDwr.COPY_ID) {
dp.setId(Common.NEW_ID);
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!DataPointDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (StringUtils.isBlank(name))
response.addContextualMessage("name", "validate.required");
} else {
// New validation on save for all settings on existing points
dp.validate(response);
if (dp.getChartRenderer() != null)
dp.getChartRenderer().validate(response);
if (dp.getTextRenderer() != null)
dp.getTextRenderer().validate(response);
}
// Validate Locator
locator.validate(response, dp);
if (!response.getHasMessages()) {
try {
Common.runtimeManager.saveDataPoint(dp);
} catch (DuplicateKeyException e) {
response.addGenericMessage("pointEdit.detectors.duplicateXid");
return response;
} catch (LicenseViolatedException e) {
response.addMessage(e.getErrorMessage());
return response;
}
if (defaulter != null)
defaulter.postSave(dp);
response.addData("id", dp.getId());
response.addData("vo", dp);
if (includePointList)
response.addData("points", getPoints());
// Set the User Point
Common.getUser().setEditPoint(dp);
}
return response;
}
use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method getInitData.
@DwrPermission(user = true)
public Map<String, Object> getInitData() {
User user = Common.getHttpUser();
Permissions.ensureDataSourcePermission(user);
Map<String, Object> model = new HashMap<>();
// Get the data sources.
List<DataSourceVO<?>> dss = DataSourceDao.instance.getDataSources();
// Create a lookup of data sources to quickly determine data point permissions.
Map<Integer, DataSourceVO<?>> dslu = new HashMap<>();
for (DataSourceVO<?> ds : dss) dslu.put(ds.getId(), ds);
// Get the data points
List<DataPointBean> allPoints = new ArrayList<>();
List<EventSourceBean> dataPoints = new ArrayList<>();
List<DataPointVO> dps = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, true);
final boolean admin = Permissions.hasAdmin(user);
for (DataPointVO dp : dps) {
if (!admin && !Permissions.hasDataSourcePermission(user, dslu.get(dp.getDataSourceId())))
continue;
allPoints.add(new DataPointBean(dp));
if (dp.getEventDetectors().size() > 0) {
EventSourceBean source = new EventSourceBean();
source.setId(dp.getId());
source.setName(dp.getExtendedName());
for (AbstractPointEventDetectorVO<?> ped : dp.getEventDetectors()) {
EventTypeVO dpet = ped.getEventType();
dpet.setHandlers(EventHandlerDao.instance.getEventHandlers(dpet));
source.getEventTypes().add(dpet);
}
dataPoints.add(source);
}
}
// Get the data sources
List<EventSourceBean> dataSources = new ArrayList<>();
for (DataSourceVO<?> ds : dss) {
if (!admin && !Permissions.hasDataSourcePermission(user, ds))
continue;
if (ds.getEventTypes().size() > 0) {
EventSourceBean source = new EventSourceBean();
source.setId(ds.getId());
source.setName(ds.getName());
for (EventTypeVO dset : ds.getEventTypes()) {
dset.setHandlers(EventHandlerDao.instance.getEventHandlers(dset));
source.getEventTypes().add(dset);
}
dataSources.add(source);
}
}
Map<String, Map<String, Object>> userEventTypes = new LinkedHashMap<>();
model.put("userEventTypes", userEventTypes);
for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
if (!def.getHandlersRequireAdmin()) {
List<EventTypeVO> vos = def.getEventTypeVOs();
for (EventTypeVO vo : vos) vo.setHandlers(EventHandlerDao.instance.getEventHandlers(vo));
Map<String, Object> info = new HashMap<>();
info.put("vos", vos);
info.put("iconPath", def.getIconPath());
info.put("description", translate(def.getDescriptionKey()));
userEventTypes.put(def.getTypeName(), info);
}
}
if (admin) {
// Get the publishers
List<EventSourceBean> publishers = new ArrayList<>();
for (PublisherVO<? extends PublishedPointVO> p : PublisherDao.instance.getPublishers(new PublisherDao.PublisherNameComparator())) {
if (p.getEventTypes().size() > 0) {
EventSourceBean source = new EventSourceBean();
source.setId(p.getId());
source.setName(p.getName());
for (EventTypeVO pet : p.getEventTypes()) {
pet.setHandlers(EventHandlerDao.instance.getEventHandlers(pet));
source.getEventTypes().add(pet);
}
publishers.add(source);
}
}
model.put(SchemaDefinition.PUBLISHERS_TABLE, publishers);
// Get the system events
List<EventTypeVO> systemEvents = new ArrayList<>();
for (EventTypeVO sets : SystemEventType.EVENT_TYPES) {
sets.setHandlers(EventHandlerDao.instance.getEventHandlers(sets));
systemEvents.add(sets);
}
model.put("systemEvents", systemEvents);
// Get the audit events
List<EventTypeVO> auditEvents = new ArrayList<>();
for (EventTypeVO aets : AuditEventType.EVENT_TYPES) {
aets.setHandlers(EventHandlerDao.instance.getEventHandlers(aets));
auditEvents.add(aets);
}
model.put("auditEvents", auditEvents);
Map<String, Map<String, Object>> adminEventTypes = new LinkedHashMap<>();
model.put("adminEventTypes", adminEventTypes);
for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
if (def.getHandlersRequireAdmin()) {
List<EventTypeVO> vos = def.getEventTypeVOs();
for (EventTypeVO vo : vos) vo.setHandlers(EventHandlerDao.instance.getEventHandlers(vo));
Map<String, Object> info = new HashMap<>();
info.put("vos", vos);
info.put("iconPath", def.getIconPath());
info.put("description", translate(def.getDescriptionKey()));
adminEventTypes.put(def.getTypeName(), info);
}
}
}
model.put("userNewScriptPermissions", new ScriptPermissions(user));
// Get the mailing lists.
model.put(SchemaDefinition.MAILING_LISTS_TABLE, MailingListDao.instance.getMailingLists());
// Get the users.
model.put(SchemaDefinition.USERS_TABLE, UserDao.instance.getUsers());
model.put("allPoints", allPoints);
model.put(SchemaDefinition.DATAPOINTS_TABLE, dataPoints);
model.put(SchemaDefinition.DATASOURCES_TABLE, dataSources);
return model;
}
use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO 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;
}
use of com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO in project ma-core-public by infiniteautomation.
the class DataPointEditDwr method addEventDetector.
@DwrPermission(user = true)
public AbstractPointEventDetectorVO<?> addEventDetector(String typeName, int newId) {
DataPointVO dp = getDataPoint();
EventDetectorDefinition<?> definition = ModuleRegistry.getEventDetectorDefinition(typeName);
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) definition.baseCreateEventDetectorVO();
ped.setXid(EventDetectorDao.instance.generateUniqueXid());
ped.setName("");
ped.setId(newId);
synchronized (dp) {
ped.setSourceId(dp.getId());
ped.njbSetDataPoint(dp);
dp.getEventDetectors().add(ped);
}
return ped;
}
Aggregations