Search in sources :

Example 6 with EventType

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);
}
Also used : SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 7 with EventType

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());
}
Also used : LifecycleException(com.serotonin.util.LifecycleException) LocalizableException(com.serotonin.web.i18n.LocalizableException) CompoundDetectorEventType(com.serotonin.m2m2.rt.event.type.CompoundDetectorEventType)

Example 8 with EventType

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) AbstractEventHandlerModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.handlers.AbstractEventHandlerModel) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with EventType

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());
        }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) ArrayList(java.util.ArrayList) List(java.util.List) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO)

Example 10 with EventType

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

Aggregations

EventType (com.serotonin.m2m2.rt.event.type.EventType)10 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)9 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)7 User (com.serotonin.m2m2.vo.User)6 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)4 ArrayList (java.util.ArrayList)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 DataPointEventType (com.serotonin.m2m2.rt.event.type.DataPointEventType)3 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)3 MissingEventType (com.serotonin.m2m2.rt.event.type.MissingEventType)3 PublisherEventType (com.serotonin.m2m2.rt.event.type.PublisherEventType)3 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)3 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)2 UserEventListener (com.serotonin.m2m2.rt.event.UserEventListener)2 LongPair (com.serotonin.m2m2.vo.pair.LongPair)2 DateTime (org.joda.time.DateTime)2 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 JsonException (com.serotonin.json.JsonException)1