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