21
21
*/
22
22
23
23
import com .devicehive .auth .HivePrincipal ;
24
+ import com .devicehive .model .FilterEntity ;
24
25
import com .devicehive .model .eventbus .Filter ;
25
26
import com .devicehive .model .query .PluginReqisterQuery ;
26
27
import com .devicehive .vo .DeviceVO ;
28
+ import com .devicehive .vo .PluginVO ;
27
29
import org .slf4j .Logger ;
28
30
import org .slf4j .LoggerFactory ;
29
31
import org .springframework .beans .factory .annotation .Autowired ;
@@ -50,44 +52,44 @@ public FilterService(BaseDeviceService deviceService) {
50
52
this .deviceService = deviceService ;
51
53
}
52
54
53
- public Set <Filter > createFilters (PluginReqisterQuery query ) {
55
+ public Set <Filter > createFilters (FilterEntity filterEntity ) {
54
56
HivePrincipal principal = (HivePrincipal ) SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ();
55
57
Set <Filter > filters ;
56
- if (query .getDeviceId () != null ) {
57
- DeviceVO device = deviceService .findByIdWithPermissionsCheck (query .getDeviceId (), principal );
58
+ if (filterEntity .getDeviceId () != null ) {
59
+ DeviceVO device = deviceService .findByIdWithPermissionsCheck (filterEntity .getDeviceId (), principal );
58
60
if (device == null ) {
59
- logger .error ("Could not find device with id={}" , query .getDeviceId ());
61
+ logger .error ("Could not find device with id={}" , filterEntity .getDeviceId ());
60
62
}
61
- if (query .getNames () != null ) {
62
- filters = toStringSet (query .getNames ()).stream ().map (name ->
63
- new Filter (device .getNetworkId (), device .getDeviceTypeId (), query .getDeviceId (), null , name ))
63
+ if (filterEntity .getNames () != null ) {
64
+ filters = toStringSet (filterEntity .getNames ()).stream ().map (name ->
65
+ new Filter (device .getNetworkId (), device .getDeviceTypeId (), filterEntity .getDeviceId (), null , name ))
64
66
.collect (Collectors .toSet ());
65
67
} else {
66
- filters = Collections .singleton (new Filter (device .getNetworkId (), device .getDeviceTypeId (), query .getDeviceId (), null , null ));
68
+ filters = Collections .singleton (new Filter (device .getNetworkId (), device .getDeviceTypeId (), filterEntity .getDeviceId (), null , null ));
67
69
}
68
70
} else {
69
- if (query .getNetworkIds () == null && query .getDeviceTypeIds () == null ) {
70
- if (query .getNames () != null ) {
71
- filters = toStringSet (query .getNames ()).stream ().map (name ->
71
+ if (filterEntity .getNetworkIds () == null && filterEntity .getDeviceTypeIds () == null ) {
72
+ if (filterEntity .getNames () != null ) {
73
+ filters = toStringSet (filterEntity .getNames ()).stream ().map (name ->
72
74
new Filter (null , null , null , null , name ))
73
75
.collect (Collectors .toSet ());
74
76
} else {
75
77
filters = Collections .singleton (new Filter ());
76
78
}
77
79
} else {
78
- Set <Long > networks = toLongSet (query .getNetworkIds ());
80
+ Set <Long > networks = toLongSet (filterEntity .getNetworkIds ());
79
81
if (networks .isEmpty ()) {
80
82
networks = principal .getNetworkIds ();
81
83
}
82
- Set <Long > deviceTypes = toLongSet (query .getDeviceTypeIds ());
84
+ Set <Long > deviceTypes = toLongSet (filterEntity .getDeviceTypeIds ());
83
85
if (deviceTypes .isEmpty ()) {
84
86
deviceTypes = principal .getDeviceTypeIds ();
85
87
}
86
88
final Set <Long > finalDeviceTypes = deviceTypes ;
87
89
filters = networks .stream ()
88
90
.flatMap (network -> finalDeviceTypes .stream ().flatMap (deviceType -> {
89
- if (query .getNames () != null ) {
90
- return toStringSet (query .getNames ()).stream ().map (name ->
91
+ if (filterEntity .getNames () != null ) {
92
+ return toStringSet (filterEntity .getNames ()).stream ().map (name ->
91
93
new Filter (network , deviceType , null , null , name )
92
94
);
93
95
} else {
0 commit comments