Fix: don't fetch name of deleted alarm originator. Add ability to create dynamic subscriptions for alarms.
This commit is contained in:
parent
25af06f25d
commit
849f53ca4c
@ -44,7 +44,7 @@ import java.util.stream.Collectors;
|
|||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class AlarmController extends BaseController {
|
public class AlarmController extends BaseController {
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Alarm getAlarmById(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
public Alarm getAlarmById(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
||||||
@ -57,7 +57,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/info/{alarmId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/alarm/info/{alarmId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AlarmInfo getAlarmInfoById(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
public AlarmInfo getAlarmInfoById(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
||||||
@ -70,7 +70,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm", method = RequestMethod.POST)
|
@RequestMapping(value = "/alarm", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Alarm saveAlarm(@RequestBody Alarm alarm) throws ThingsboardException {
|
public Alarm saveAlarm(@RequestBody Alarm alarm) throws ThingsboardException {
|
||||||
@ -82,7 +82,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/{alarmId}/ack", method = RequestMethod.POST)
|
@RequestMapping(value = "/alarm/{alarmId}/ack", method = RequestMethod.POST)
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
public void ackAlarm(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
public void ackAlarm(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
||||||
@ -96,7 +96,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/{alarmId}/clear", method = RequestMethod.POST)
|
@RequestMapping(value = "/alarm/{alarmId}/clear", method = RequestMethod.POST)
|
||||||
@ResponseStatus(value = HttpStatus.OK)
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
public void clearAlarm(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
public void clearAlarm(@PathVariable("alarmId") String strAlarmId) throws ThingsboardException {
|
||||||
@ -110,7 +110,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TimePageData<AlarmInfo> getAlarms(
|
public TimePageData<AlarmInfo> getAlarms(
|
||||||
@ -143,7 +143,7 @@ public class AlarmController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AlarmSeverity getHighestAlarmSeverity(
|
public AlarmSeverity getHighestAlarmSeverity(
|
||||||
|
|||||||
@ -227,6 +227,9 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
|
|||||||
alarmFutures.add(Futures.transform(
|
alarmFutures.add(Futures.transform(
|
||||||
entityService.fetchEntityNameAsync(alarmInfo.getOriginator()), (Function<String, AlarmInfo>)
|
entityService.fetchEntityNameAsync(alarmInfo.getOriginator()), (Function<String, AlarmInfo>)
|
||||||
originatorName -> {
|
originatorName -> {
|
||||||
|
if (originatorName == null) {
|
||||||
|
originatorName = "Deleted";
|
||||||
|
}
|
||||||
alarmInfo.setOriginatorName(originatorName);
|
alarmInfo.setOriginatorName(originatorName);
|
||||||
return alarmInfo;
|
return alarmInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
|
|||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Not Implemented!");
|
throw new IllegalStateException("Not Implemented!");
|
||||||
}
|
}
|
||||||
entityName = Futures.transform(hasName, (Function<HasName, String>) hasName1 -> hasName1.getName() );
|
entityName = Futures.transform(hasName, (Function<HasName, String>) hasName1 -> hasName1 != null ? hasName1.getName() : null );
|
||||||
return entityName;
|
return entityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,6 @@ public class BaseRelationService implements RelationService {
|
|||||||
for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) {
|
for (RelationTypeGroup typeGroup : RelationTypeGroup.values()) {
|
||||||
inboundRelationsList.add(relationDao.findAllByTo(entity, typeGroup));
|
inboundRelationsList.add(relationDao.findAllByTo(entity, typeGroup));
|
||||||
}
|
}
|
||||||
Futures.allAsList(inboundRelationsList);
|
|
||||||
ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList);
|
ListenableFuture<List<List<EntityRelation>>> inboundRelations = Futures.allAsList(inboundRelationsList);
|
||||||
ListenableFuture<List<Boolean>> inboundDeletions = Futures.transform(inboundRelations, new AsyncFunction<List<List<EntityRelation>>, List<Boolean>>() {
|
ListenableFuture<List<Boolean>> inboundDeletions = Futures.transform(inboundRelations, new AsyncFunction<List<List<EntityRelation>>, List<Boolean>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -35,6 +35,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
|
|||||||
prepareAllowedEntityTypesList: prepareAllowedEntityTypesList,
|
prepareAllowedEntityTypesList: prepareAllowedEntityTypesList,
|
||||||
getEntityKeys: getEntityKeys,
|
getEntityKeys: getEntityKeys,
|
||||||
createDatasourcesFromSubscriptionsInfo: createDatasourcesFromSubscriptionsInfo,
|
createDatasourcesFromSubscriptionsInfo: createDatasourcesFromSubscriptionsInfo,
|
||||||
|
createAlarmSourceFromSubscriptionInfo: createAlarmSourceFromSubscriptionInfo,
|
||||||
getRelatedEntities: getRelatedEntities,
|
getRelatedEntities: getRelatedEntities,
|
||||||
saveRelatedEntity: saveRelatedEntity,
|
saveRelatedEntity: saveRelatedEntity,
|
||||||
getRelatedEntity: getRelatedEntity,
|
getRelatedEntity: getRelatedEntity,
|
||||||
@ -757,6 +758,26 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createAlarmSourceFromSubscriptionInfo(subscriptionInfo) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
var datasources = [];
|
||||||
|
if (subscriptionInfo.entityId && subscriptionInfo.entityType) {
|
||||||
|
getEntity(subscriptionInfo.entityType, subscriptionInfo.entityId, {ignoreLoading: true}).then(
|
||||||
|
function success(entity) {
|
||||||
|
createDatasourceFromSubscription(subscriptionInfo, datasources, entity);
|
||||||
|
var alarmSource = datasources[0];
|
||||||
|
deferred.resolve(alarmSource);
|
||||||
|
},
|
||||||
|
function fail() {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
function processSubscriptionsInfo(index, subscriptionsInfo, datasources, deferred) {
|
function processSubscriptionsInfo(index, subscriptionsInfo, datasources, deferred) {
|
||||||
if (index < subscriptionsInfo.length) {
|
if (index < subscriptionsInfo.length) {
|
||||||
var subscriptionInfo = validateSubscriptionInfo(subscriptionsInfo[index]);
|
var subscriptionInfo = validateSubscriptionInfo(subscriptionsInfo[index]);
|
||||||
@ -858,6 +879,9 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
|
|||||||
if (subscriptionInfo.functions) {
|
if (subscriptionInfo.functions) {
|
||||||
createDatasourceKeys(subscriptionInfo.functions, types.dataKeyType.function, datasource, datasources);
|
createDatasourceKeys(subscriptionInfo.functions, types.dataKeyType.function, datasource, datasources);
|
||||||
}
|
}
|
||||||
|
if (subscriptionInfo.alarmFields) {
|
||||||
|
createDatasourceKeys(subscriptionInfo.alarmFields, types.dataKeyType.alarm, datasource, datasources);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDatasourceKeys(keyInfos, type, datasource, datasources) {
|
function createDatasourceKeys(keyInfos, type, datasource, datasources) {
|
||||||
|
|||||||
@ -61,47 +61,57 @@ export default angular.module('thingsboard.types', [])
|
|||||||
},
|
},
|
||||||
alarmFields: {
|
alarmFields: {
|
||||||
createdTime: {
|
createdTime: {
|
||||||
|
keyName: 'createdTime',
|
||||||
value: "createdTime",
|
value: "createdTime",
|
||||||
name: "alarm.created-time",
|
name: "alarm.created-time",
|
||||||
time: true
|
time: true
|
||||||
},
|
},
|
||||||
startTime: {
|
startTime: {
|
||||||
|
keyName: 'startTime',
|
||||||
value: "startTs",
|
value: "startTs",
|
||||||
name: "alarm.start-time",
|
name: "alarm.start-time",
|
||||||
time: true
|
time: true
|
||||||
},
|
},
|
||||||
endTime: {
|
endTime: {
|
||||||
|
keyName: 'endTime',
|
||||||
value: "endTs",
|
value: "endTs",
|
||||||
name: "alarm.end-time",
|
name: "alarm.end-time",
|
||||||
time: true
|
time: true
|
||||||
},
|
},
|
||||||
ackTime: {
|
ackTime: {
|
||||||
|
keyName: 'ackTime',
|
||||||
value: "ackTs",
|
value: "ackTs",
|
||||||
name: "alarm.ack-time",
|
name: "alarm.ack-time",
|
||||||
time: true
|
time: true
|
||||||
},
|
},
|
||||||
clearTime: {
|
clearTime: {
|
||||||
|
keyName: 'clearTime',
|
||||||
value: "clearTs",
|
value: "clearTs",
|
||||||
name: "alarm.clear-time",
|
name: "alarm.clear-time",
|
||||||
time: true
|
time: true
|
||||||
},
|
},
|
||||||
originator: {
|
originator: {
|
||||||
|
keyName: 'originator',
|
||||||
value: "originatorName",
|
value: "originatorName",
|
||||||
name: "alarm.originator"
|
name: "alarm.originator"
|
||||||
},
|
},
|
||||||
originatorType: {
|
originatorType: {
|
||||||
|
keyName: 'originatorType',
|
||||||
value: "originator.entityType",
|
value: "originator.entityType",
|
||||||
name: "alarm.originator-type"
|
name: "alarm.originator-type"
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
|
keyName: 'type',
|
||||||
value: "type",
|
value: "type",
|
||||||
name: "alarm.type"
|
name: "alarm.type"
|
||||||
},
|
},
|
||||||
severity: {
|
severity: {
|
||||||
|
keyName: 'severity',
|
||||||
value: "severity",
|
value: "severity",
|
||||||
name: "alarm.severity"
|
name: "alarm.severity"
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
|
keyName: 'status',
|
||||||
value: "status",
|
value: "status",
|
||||||
name: "alarm.status"
|
name: "alarm.status"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,11 +96,11 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, types) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var defaultAlarmFields = [
|
var defaultAlarmFields = [
|
||||||
'createdTime',
|
types.alarmFields.createdTime.keyName,
|
||||||
'originator',
|
types.alarmFields.originator.keyName,
|
||||||
'type',
|
types.alarmFields.type.keyName,
|
||||||
'severity',
|
types.alarmFields.severity.keyName,
|
||||||
'status'
|
types.alarmFields.status.keyName
|
||||||
];
|
];
|
||||||
|
|
||||||
var defaultAlarmDataKeys = [];
|
var defaultAlarmDataKeys = [];
|
||||||
@ -376,10 +376,20 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, types) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createKey(keyInfo, type, datasources) {
|
function createKey(keyInfo, type, datasources) {
|
||||||
|
var label;
|
||||||
|
if (type === types.dataKeyType.alarm && !keyInfo.label) {
|
||||||
|
var alarmField = types.alarmFields[keyInfo.name];
|
||||||
|
if (alarmField) {
|
||||||
|
label = $translate.instant(alarmField.name)+'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!label) {
|
||||||
|
label = keyInfo.label || keyInfo.name;
|
||||||
|
}
|
||||||
var dataKey = {
|
var dataKey = {
|
||||||
name: keyInfo.name,
|
name: keyInfo.name,
|
||||||
type: type,
|
type: type,
|
||||||
label: keyInfo.label || keyInfo.name,
|
label: label,
|
||||||
color: genNextColor(datasources),
|
color: genNextColor(datasources),
|
||||||
funcBody: keyInfo.funcBody,
|
funcBody: keyInfo.funcBody,
|
||||||
settings: {},
|
settings: {},
|
||||||
|
|||||||
@ -36,6 +36,8 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
|
|||||||
$scope.rpcEnabled = false;
|
$scope.rpcEnabled = false;
|
||||||
$scope.executingRpcRequest = false;
|
$scope.executingRpcRequest = false;
|
||||||
|
|
||||||
|
vm.dashboardTimewindow = dashboardTimewindow;
|
||||||
|
|
||||||
var gridsterItemInited = false;
|
var gridsterItemInited = false;
|
||||||
var subscriptionInited = false;
|
var subscriptionInited = false;
|
||||||
var widgetSizeDetected = false;
|
var widgetSizeDetected = false;
|
||||||
@ -192,9 +194,20 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entityService.createDatasourcesFromSubscriptionsInfo(subscriptionsInfo).then(
|
var createDatasourcesPromise;
|
||||||
function (datasources) {
|
if (options.type == types.widgetType.alarm.value) {
|
||||||
options.datasources = datasources;
|
createDatasourcesPromise = entityService.createAlarmSourceFromSubscriptionInfo(subscriptionsInfo);
|
||||||
|
} else {
|
||||||
|
createDatasourcesPromise = entityService.createDatasourcesFromSubscriptionsInfo(subscriptionsInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
createDatasourcesPromise.then(
|
||||||
|
function (result) {
|
||||||
|
if (options.type == types.widgetType.alarm.value) {
|
||||||
|
options.alarmSource = result;
|
||||||
|
} else {
|
||||||
|
options.datasources = result;
|
||||||
|
}
|
||||||
createSubscription(options, subscribe).then(
|
createSubscription(options, subscribe).then(
|
||||||
function success(subscription) {
|
function success(subscription) {
|
||||||
if (useDefaultComponents) {
|
if (useDefaultComponents) {
|
||||||
@ -213,7 +226,7 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
|
|||||||
|
|
||||||
function createSubscription(options, subscribe) {
|
function createSubscription(options, subscribe) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
options.dashboardTimewindow = dashboardTimewindow;
|
options.dashboardTimewindow = vm.dashboardTimewindow;
|
||||||
new Subscription(subscriptionContext, options).then(
|
new Subscription(subscriptionContext, options).then(
|
||||||
function success(subscription) {
|
function success(subscription) {
|
||||||
widgetContext.subscriptions[subscription.id] = subscription;
|
widgetContext.subscriptions[subscription.id] = subscription;
|
||||||
@ -234,7 +247,7 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
|
|||||||
options.useDashboardTimewindow = angular.isDefined(widget.config.useDashboardTimewindow)
|
options.useDashboardTimewindow = angular.isDefined(widget.config.useDashboardTimewindow)
|
||||||
? widget.config.useDashboardTimewindow : true;
|
? widget.config.useDashboardTimewindow : true;
|
||||||
|
|
||||||
options.timeWindowConfig = options.useDashboardTimewindow ? dashboardTimewindow : widget.config.timewindow;
|
options.timeWindowConfig = options.useDashboardTimewindow ? vm.dashboardTimewindow : widget.config.timewindow;
|
||||||
options.legendConfig = null;
|
options.legendConfig = null;
|
||||||
|
|
||||||
if ($scope.displayLegend) {
|
if ($scope.displayLegend) {
|
||||||
@ -504,6 +517,10 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$on('dashboardTimewindowChanged', function (event, newDashboardTimewindow) {
|
||||||
|
vm.dashboardTimewindow = newDashboardTimewindow;
|
||||||
|
});
|
||||||
|
|
||||||
$scope.$on("$destroy", function () {
|
$scope.$on("$destroy", function () {
|
||||||
onDestroy();
|
onDestroy();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user