use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class SetPointHandlerRT method raiseFailureEvent.
private void raiseFailureEvent(TranslatableMessage message, EventType et) {
if (et != null && et.isSystemMessage()) {
if (((SystemEventType) et).getSystemEventType().equals(SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE)) {
// The set point attempt failed for an event that is a set point handler failure in the first place.
// Do not propagate the event, but rather just write a log message.
LOG.warn("A set point event due to a set point handler failure itself failed. The failure event " + "has been discarded: " + message.translate(Common.getTranslations()));
return;
}
}
SystemEventType eventType = new SystemEventType(SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE, vo.getId());
if (StringUtils.isBlank(vo.getAlias()))
message = new TranslatableMessage("event.setPointFailed", message);
else
message = new TranslatableMessage("event.setPointFailed.alias", vo.getAlias(), message);
SystemEventType.raiseEvent(eventType, Common.timer.currentTimeMillis(), false, message);
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-core-public by infiniteautomation.
the class CompoundEventDetectorRT method initialize.
//
//
// /
// / Lifecycle interface
// /
//
//
@Override
public void initialize(boolean safe) throws LifecycleException {
// Validate the condition statement.
try {
condition = parseConditionStatement(vo.getCondition());
} catch (ConditionParseException e) {
throw new LifecycleException(e);
}
try {
condition.initialize();
} catch (LocalizableException e) {
throw new LifecycleException(e);
}
condition.initSource(this);
// Create a convenience reference to the event type.
eventType = new CompoundDetectorEventType(vo.getId());
if (!vo.isReturnToNormal())
eventType.setDuplicateHandling(EventType.DuplicateHandling.ALLOW);
// Evaluate the current state.
currentState = condition.evaluate();
if (currentState)
raiseEvent(Common.timer.currentTimeMillis());
else
returnToNormal(Common.timer.currentTimeMillis());
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-modules-public by infiniteautomation.
the class EventHandlerRestController method get.
@ApiOperation(value = "Get EventHandler by XID", notes = "EventType permission required")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "application/sero-json" }, value = "/{xid}")
public ResponseEntity<AbstractEventHandlerModel<?>> get(@ApiParam(value = "Valid Eventh Handler XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<AbstractEventHandlerModel<?>> result = new RestProcessResult<AbstractEventHandlerModel<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
AbstractEventHandlerVO<?> vo = EventHandlerDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
// Check Permissions
if (Permissions.hasAdmin(user))
return result.createResponseEntity(vo.asModel());
else
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("permissions.accessDenied", user.getUsername(), SuperadminPermissionDefinition.GROUP_NAME));
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.rt.event.type.EventType in project ma-modules-public by infiniteautomation.
the class EventTypeV2RestController method getAllDataSourceEventTypes.
private void getAllDataSourceEventTypes(List<EventTypeModel> types, User user, Integer dataSourceId, Integer dataSourceEventId) {
List<DataSourceVO<?>> dataSources = DataSourceDao.instance.getAll();
final boolean admin = Permissions.hasAdmin(user);
for (DataSourceVO<?> dsvo : dataSources) if (dataSourceId == null || dataSourceId.intValue() == dsvo.getId())
for (EventTypeVO dset : (List<EventTypeVO>) dsvo.getEventTypes()) if (dataSourceEventId == null || dataSourceEventId.intValue() == dset.getTypeRef2()) {
EventType et = dset.createEventType();
if (admin || Permissions.hasEventTypePermission(user, et))
types.add(et.asModel());
}
}
use of com.serotonin.m2m2.rt.event.type.EventType 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());
}
}
Aggregations