use of com.infiniteautomation.mango.rest.latest.model.event.DataSourceEventTypeModel in project ma-modules-public by infiniteautomation.
the class EventTypesRestController method getEventTypesForSubtype.
/**
* Generate a list of all event types generalized by sub-type
*/
private List<EventTypeVOModel<?, ?, ?>> getEventTypesForSubtype(String typeName, String subtype, 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:
// There is no subtype for data points
if (subtype != null)
throw new BadRequestException();
// Get Event Detectors, ensure only 1 data point in list
// TODO via query instead
List<AbstractPointEventDetectorVO> detectors = this.eventDetectorDao.getAllPointEventDetectors();
Map<Integer, DataPointVO> uniquePointsMap = new HashMap<>();
for (AbstractPointEventDetectorVO detector : detectors) {
uniquePointsMap.put(detector.getDataPoint().getId(), detector.getDataPoint());
}
for (DataPointVO vo : uniquePointsMap.values()) {
// Shortcut to check permissions via event type
if (dataPointService.hasReadPermission(user, vo)) {
DataPointEventTypeModel model = new DataPointEventTypeModel(new DataPointEventType(vo.getDataSourceId(), vo.getId(), 0, null), modelMapper.map(vo, DataPointModel.class, user));
types.add(new EventTypeVOModel<DataPointEventType, DataPointModel, AbstractPointEventDetectorModel<?>>(model, new TranslatableMessage("event.eventsFor", vo.getName()), false, true, true));
}
}
found = true;
break;
case EventTypeNames.DATA_SOURCE:
// There is no subtype for data sources
if (subtype != null)
throw new BadRequestException();
for (DataSourceVO vo : dataSourceDao.getAll()) {
if (permissionService.hasPermission(user, vo.getReadPermission())) {
AbstractDataSourceModel<?> dsModel = modelMapper.map(vo, AbstractDataSourceModel.class, user);
DataSourceEventTypeModel model = new DataSourceEventTypeModel(new DataSourceEventType(vo.getId(), 0), dsModel);
types.add(new EventTypeVOModel<DataSourceEventType, AbstractDataSourceModel<?>, String>(model, new TranslatableMessage("event.eventsFor", vo.getName()), false, true, true));
}
}
found = true;
break;
case EventTypeNames.PUBLISHER:
// There is no subtype for publishers
if (subtype != null)
throw new BadRequestException();
// There are no permissions for publishers
if (!permissionService.hasAdminRole(user))
break;
for (PublisherVO vo : publisherDao.getAll()) {
AbstractPublisherModel<?, ?> publisherModel = modelMapper.map(vo, AbstractPublisherModel.class, user);
PublisherEventTypeModel model = new PublisherEventTypeModel(new PublisherEventType(vo.getId(), 0), publisherModel);
types.add(new EventTypeVOModel<PublisherEventType, AbstractPublisherModel<?, ?>, String>(model, new TranslatableMessage("event.eventsFor", vo.getName()), false, true, true));
}
found = true;
break;
case EventTypeNames.SYSTEM:
// System
for (SystemEventTypeDefinition def : ModuleRegistry.getDefinitions(SystemEventTypeDefinition.class)) {
if (!StringUtils.equals(def.getTypeName(), subtype))
continue;
found = true;
for (EventTypeVO type : def.generatePossibleEventTypesWithReferenceId1(user, subtype)) {
SystemEventType eventType = (SystemEventType) type.getEventType();
SystemEventTypeModel model = modelMapper.map(eventType, SystemEventTypeModel.class, user);
types.add(new EventTypeVOModel<>(model, type.getDescription(), type.getAlarmLevel(), true, def.supportsReferenceId1(), def.supportsReferenceId2()));
}
break;
}
break;
case EventTypeNames.AUDIT:
// Audit does not yet support reference id 1
throw new BadRequestException();
}
if (!found) {
// Module defined
for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
if (StringUtils.equals(typeName, def.getTypeName())) {
found = true;
for (EventTypeVO type : def.generatePossibleEventTypesWithReferenceId1(user, subtype, 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;
}
use of com.infiniteautomation.mango.rest.latest.model.event.DataSourceEventTypeModel 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.DataSourceEventTypeModel in project ma-modules-public by infiniteautomation.
the class EventTypesRestController method getEventTypesForSubtypeAndReferenceId1.
/**
* Generate a list of all event types generalized by sub-type and referenceId1
*/
private List<EventTypeVOModel<?, ?, ?>> getEventTypesForSubtypeAndReferenceId1(String typeName, String subtype, Integer referenceId1, 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:
// There is no subtype for data points
if (subtype != null)
throw new BadRequestException();
DataPointVO dp = this.dataPointService.get(referenceId1);
for (AbstractPointEventDetectorVO vo : eventDetectorDao.getWithSource(dp.getId(), dp)) {
AbstractPointEventDetectorModel<?> edm = modelMapper.map(vo, AbstractPointEventDetectorModel.class, user);
EventTypeVO type = vo.getEventType();
DataPointEventType eventType = (DataPointEventType) type.getEventType();
DataPointEventTypeModel model = new DataPointEventTypeModel(eventType, modelMapper.map(dp, DataPointModel.class, user), edm);
types.add(new EventTypeVOModel<DataPointEventType, DataPointModel, AbstractPointEventDetectorModel<?>>(model, type.getDescription(), type.getAlarmLevel(), false, true, true));
}
found = true;
break;
case EventTypeNames.DATA_SOURCE:
// There is no subtype for data sources
if (subtype != null)
throw new BadRequestException();
DataSourceVO ds = dataSourceDao.get(referenceId1);
if (ds == null)
throw new NotFoundException();
permissionService.ensurePermission(user, ds.getReadPermission());
AbstractDataSourceModel<?> dsModel = modelMapper.map(ds, AbstractDataSourceModel.class, user);
for (EventTypeVO type : ds.getEventTypes()) {
DataSourceEventType eventType = (DataSourceEventType) type.getEventType();
DataSourceEventTypeModel model = new DataSourceEventTypeModel(eventType, dsModel);
types.add(new EventTypeVOModel<DataSourceEventType, AbstractDataSourceModel<?>, String>(model, type.getDescription(), type.getAlarmLevel(), false, true, true));
}
found = true;
break;
case EventTypeNames.PUBLISHER:
// There is no subtype for publishers
if (subtype != null)
throw new BadRequestException();
// There are no permissions for publishers
if (!permissionService.hasAdminRole(user))
throw new PermissionException(new TranslatableMessage("permission.exception.doesNotHaveRequiredPermission", user), user);
PublisherVO pub = publisherDao.get(referenceId1);
if (pub == null)
throw new NotFoundException();
for (EventTypeVO type : pub.getEventTypes()) {
PublisherEventType eventType = (PublisherEventType) type.getEventType();
AbstractPublisherModel<?, ?> publisherModel = modelMapper.map(pub, AbstractPublisherModel.class, user);
PublisherEventTypeModel model = new PublisherEventTypeModel(eventType, publisherModel);
types.add(new EventTypeVOModel<PublisherEventType, AbstractPublisherModel<?, ?>, String>(model, type.getDescription(), type.getAlarmLevel(), false, true, true));
}
found = true;
break;
case EventTypeNames.SYSTEM:
// System
for (SystemEventTypeDefinition def : ModuleRegistry.getDefinitions(SystemEventTypeDefinition.class)) {
if (!StringUtils.equals(def.getTypeName(), subtype))
continue;
found = true;
for (EventTypeVO type : def.generatePossibleEventTypesWithReferenceId2(user, subtype, referenceId1)) {
SystemEventType eventType = (SystemEventType) type.getEventType();
SystemEventTypeModel model = modelMapper.map(eventType, SystemEventTypeModel.class, user);
types.add(new EventTypeVOModel<>(model, type.getDescription(), type.getAlarmLevel(), true, def.supportsReferenceId1(), def.supportsReferenceId2()));
}
break;
}
break;
case EventTypeNames.AUDIT:
// Audit does not yet support reference id 2
throw new BadRequestException();
}
if (!found) {
// Module defined
for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
if (StringUtils.equals(typeName, def.getTypeName())) {
found = true;
for (EventTypeVO type : def.generatePossibleEventTypesWithReferenceId2(user, subtype, referenceId1, permissionService)) {
EventType eventType = type.getEventType();
if (!StringUtils.equals(eventType.getEventSubtype(), subtype))
continue;
if (!eventType.hasPermission(user, permissionService))
continue;
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