Search in sources :

Example 1 with AuditEventTypeModel

use of com.infiniteautomation.mango.rest.latest.model.event.AuditEventTypeModel in project ma-modules-public by infiniteautomation.

the class EventTypesRestController method queryAllEventTypes.

@ApiOperation(value = "Query all available event types", notes = "Not specific to any reference ids, results come back based on type/sub-type combinations", response = EventTypeVOModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET)
public StreamWithTotal<EventTypeVOModel<?, ?, ?>> queryAllEventTypes(@AuthenticationPrincipal PermissionHolder user, Translations translations, ASTNode query) {
    List<EventTypeVOModel<?, ?, ?>> models = new ArrayList<>();
    // Data Source
    DataSourceEventType dset = new DataSourceEventType(0, 0);
    DataSourceEventTypeModel dsetm = new DataSourceEventTypeModel(dset);
    dsetm.setAlarmLevel(null);
    EventTypeVOModel<?, ?, ?> dataSource = new EventTypeVOModel<DataSourceEventType, AbstractDataSourceModel<?>, String>(dsetm, new TranslatableMessage("eventHandlers.dataSourceEvents"), false, true, true);
    dataSource.setAlarmLevel(null);
    models.add(dataSource);
    // Data point
    DataPointEventType dpet = new DataPointEventType(0, 0);
    DataPointEventTypeModel dpetm = new DataPointEventTypeModel(dpet);
    EventTypeVOModel<?, ?, ?> dataPoint = new EventTypeVOModel<DataPointEventType, DataPointModel, AbstractPointEventDetectorModel<?>>(dpetm, new TranslatableMessage("eventHandlers.pointEventDetector"), false, true, true);
    dataPoint.setAlarmLevel(null);
    models.add(dataPoint);
    // Publisher
    PublisherEventType pet = new PublisherEventType(0, 0);
    PublisherEventTypeModel petm = new PublisherEventTypeModel(pet);
    EventTypeVOModel<?, ?, ?> publisher = new EventTypeVOModel<PublisherEventType, AbstractPublisherModel<?, ?>, String>(petm, new TranslatableMessage("eventHandlers.publisherEvents"), false, true, true);
    publisher.setAlarmLevel(null);
    models.add(publisher);
    // System
    // TODO Permissions
    // TODO since we some system event types support referenceId1 and 2 we can't be sure here
    SystemEventType set = new SystemEventType();
    SystemEventTypeModel setm = new SystemEventTypeModel(set);
    EventTypeVOModel<?, ?, ?> system = new EventTypeVOModel<>(setm, new TranslatableMessage("eventHandlers.systemEvents"), null, true, true, true);
    models.add(system);
    // Audit
    // TODO Permissions
    // TODO Audit Event Types will eventually support ref1 & 2
    AuditEventType aet = new AuditEventType();
    AuditEventTypeModel aetm = new AuditEventTypeModel(aet);
    EventTypeVOModel<?, ?, ?> audit = new EventTypeVOModel<>(aetm, new TranslatableMessage("eventHandlers.auditEvents"), null, true, false, false);
    models.add(audit);
    // Module defined
    for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
        if (!def.hasCreatePermission(user, permissionService))
            continue;
        EventType et = def.createDefaultEventType();
        AbstractEventTypeModel<?, ?, ?> model = modelMapper.map(et, AbstractEventTypeModel.class, user);
        models.add(new EventTypeVOModel<>(model, new TranslatableMessage(def.getDescriptionKey()), def.supportsSubType(), def.supportsReferenceId1(), def.supportsReferenceId2()));
    }
    return new FilteredStreamWithTotal<>(models, query, translations);
}
Also used : DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) DataSourceEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.DataSourceEventTypeModel) PublisherEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.PublisherEventTypeModel) ArrayList(java.util.ArrayList) FilteredStreamWithTotal(com.infiniteautomation.mango.rest.latest.model.FilteredStreamWithTotal) SystemEventTypeDefinition(com.serotonin.m2m2.module.SystemEventTypeDefinition) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition) DataPointEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.DataPointEventTypeModel) AuditEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.AuditEventTypeModel) SystemEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.SystemEventTypeModel) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) EventTypeVOModel(com.infiniteautomation.mango.rest.latest.model.event.EventTypeVOModel) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AuditEventTypeModel

use of com.infiniteautomation.mango.rest.latest.model.event.AuditEventTypeModel in project ma-modules-public by infiniteautomation.

the class EventTypesRestController method getEventTypes.

/**
 */
private List<EventTypeVOModel<?, ?, ?>> getEventTypes(String typeName, PermissionHolder user) throws NotFoundException {
    // track if the type was a default type
    List<EventTypeVOModel<?, ?, ?>> types = new ArrayList<>();
    boolean found = false;
    switch(typeName) {
        case EventTypeNames.DATA_POINT:
        case EventTypeNames.DATA_SOURCE:
        case EventTypeNames.PUBLISHER:
            throw new BadRequestException();
        case EventTypeNames.SYSTEM:
            found = true;
            for (SystemEventTypeDefinition def : ModuleRegistry.getDefinitions(SystemEventTypeDefinition.class)) {
                EventTypeVO type = SystemEventType.getEventType(def.getTypeName());
                if (type.getEventType().hasPermission(user, permissionService)) {
                    SystemEventTypeModel model = modelMapper.map(type.getEventType(), SystemEventTypeModel.class, user);
                    types.add(new EventTypeVOModel<>(model, type.getDescription(), type.getAlarmLevel(), true, def.supportsReferenceId1(), def.supportsReferenceId2()));
                }
            }
            break;
        case EventTypeNames.AUDIT:
            found = true;
            for (EventTypeVO vo : AuditEventType.getRegisteredEventTypes()) {
                AuditEventType aet = (AuditEventType) vo.getEventType();
                if (aet.hasPermission(user, permissionService)) {
                    AuditEventTypeModel aetm = new AuditEventTypeModel(aet);
                    EventTypeVOModel<?, ?, ?> audit = new EventTypeVOModel<>(aetm, vo.getDescription(), vo.getAlarmLevel(), true, false, false);
                    types.add(audit);
                }
            }
            break;
    }
    if (!found) {
        // Module defined
        for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
            if (StringUtils.equals(typeName, def.getTypeName())) {
                found = true;
                for (EventTypeVO type : def.generatePossibleEventTypesWithSubtype(user, permissionService)) {
                    EventType eventType = type.getEventType();
                    AbstractEventTypeModel<?, ?, ?> model = modelMapper.map(eventType, AbstractEventTypeModel.class, user);
                    types.add(new EventTypeVOModel<>(model, type.getDescription(), type.getAlarmLevel(), def.supportsSubType(), def.supportsReferenceId1(), def.supportsReferenceId2()));
                }
                break;
            }
        }
    }
    if (!found)
        throw new NotFoundException();
    return types;
}
Also used : AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) ArrayList(java.util.ArrayList) SystemEventTypeDefinition(com.serotonin.m2m2.module.SystemEventTypeDefinition) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO) SystemEventTypeDefinition(com.serotonin.m2m2.module.SystemEventTypeDefinition) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition) AuditEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.AuditEventTypeModel) SystemEventTypeModel(com.infiniteautomation.mango.rest.latest.model.event.SystemEventTypeModel) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) EventTypeVOModel(com.infiniteautomation.mango.rest.latest.model.event.EventTypeVOModel)

Aggregations

AuditEventTypeModel (com.infiniteautomation.mango.rest.latest.model.event.AuditEventTypeModel)2 EventTypeVOModel (com.infiniteautomation.mango.rest.latest.model.event.EventTypeVOModel)2 SystemEventTypeModel (com.infiniteautomation.mango.rest.latest.model.event.SystemEventTypeModel)2 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)2 SystemEventTypeDefinition (com.serotonin.m2m2.module.SystemEventTypeDefinition)2 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)2 DataPointEventType (com.serotonin.m2m2.rt.event.type.DataPointEventType)2 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)2 EventType (com.serotonin.m2m2.rt.event.type.EventType)2 PublisherEventType (com.serotonin.m2m2.rt.event.type.PublisherEventType)2 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)2 ArrayList (java.util.ArrayList)2 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)1 FilteredStreamWithTotal (com.infiniteautomation.mango.rest.latest.model.FilteredStreamWithTotal)1 DataPointEventTypeModel (com.infiniteautomation.mango.rest.latest.model.event.DataPointEventTypeModel)1 DataSourceEventTypeModel (com.infiniteautomation.mango.rest.latest.model.event.DataSourceEventTypeModel)1 PublisherEventTypeModel (com.infiniteautomation.mango.rest.latest.model.event.PublisherEventTypeModel)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)1