@Override public ISearchResults<IDeviceGroupElement> listDeviceGroupElements(String groupToken, ISearchCriteria criteria) throws SiteWhereException { return delegate.listDeviceGroupElements(groupToken, criteria); }
@Override public ISearchResults<IDeviceGroupElement> listDeviceGroupElements(UUID groupId, ISearchCriteria criteria) throws SiteWhereException { return getDelegate().listDeviceGroupElements(groupId, criteria); }
/** * Get the list of unique devices in a group. (Recurses into subgroups and * removes duplicates) * * @param groupToken * @return * @throws SiteWhereException */ public static Collection<IDevice> getDevicesInGroup(String groupToken, ITenant tenant) throws SiteWhereException { Map<String, IDevice> devices = new HashMap<String, IDevice>(); ISearchResults<IDeviceGroupElement> elements = SiteWhere.getServer().getDeviceManagement(tenant) .listDeviceGroupElements(groupToken, SearchCriteria.ALL); for (IDeviceGroupElement element : elements.getResults()) { switch (element.getType()) { case Device: { devices.put(element.getElementId(), SiteWhere.getServer().getDeviceManagement(tenant) .getDeviceByHardwareId(element.getElementId())); break; } case Group: { Collection<IDevice> subDevices = getDevicesInGroup(element.getElementId(), tenant); for (IDevice subDevice : subDevices) { devices.put(subDevice.getHardwareId(), subDevice); } break; } } } return devices.values(); }
/** * Get the list of unique devices in a group. (Recurses into subgroups and * removes duplicates). Also prevents loops in group references. * * @param groupId * @param deviceManagement * @param assetManagement * @param devices * @param groups * @throws SiteWhereException */ protected static void getDevicesInGroup(UUID groupId, IDeviceManagement deviceManagement, IAssetManagement assetManagement, Map<String, IDevice> devices, Map<String, IDeviceGroup> groups) throws SiteWhereException { ISearchResults<IDeviceGroupElement> elements = deviceManagement.listDeviceGroupElements(groupId, SearchCriteria.ALL); DeviceGroupElementMarshalHelper helper = new DeviceGroupElementMarshalHelper(deviceManagement); for (IDeviceGroupElement element : elements.getResults()) { MarshaledDeviceGroupElement inflated = helper.convert(element, assetManagement); if (inflated.getDevice() != null) { IDevice device = inflated.getDevice(); devices.put(device.getToken(), device); } else if (inflated.getDeviceGroup() != null) { IDeviceGroup nested = inflated.getDeviceGroup(); // Prevent loops. if (groups.get(nested.getToken()) != null) { } } } }
SearchCriteria criteria = new SearchCriteria(page, pageSize); ISearchResults<IDeviceGroupElement> results = SiteWhere.getServer() .getDeviceManagement(getTenant(servletRequest)).listDeviceGroupElements(groupToken, criteria); List<IDeviceGroupElement> elmConv = new ArrayList<IDeviceGroupElement>(); for (IDeviceGroupElement elm : results.getResults()) {
@Override public void listDeviceGroupElements(GListDeviceGroupElementsRequest request, StreamObserver<GListDeviceGroupElementsResponse> responseObserver) { try { GrpcUtils.handleServerMethodEntry(this, DeviceManagementGrpc.getListDeviceGroupElementsMethod()); ISearchResults<IDeviceGroupElement> apiResult = getDeviceManagement().listDeviceGroupElements( CommonModelConverter.asApiUuid(request.getGroupId()), CommonModelConverter.asApiSearchCriteria(request.getCriteria().getPaging())); GListDeviceGroupElementsResponse.Builder response = GListDeviceGroupElementsResponse.newBuilder(); GDeviceGroupElementsSearchResults.Builder results = GDeviceGroupElementsSearchResults.newBuilder(); for (IDeviceGroupElement apiElement : apiResult.getResults()) { results.addElements(DeviceModelConverter.asGrpcDeviceGroupElement(apiElement)); } results.setCount(apiResult.getNumResults()); response.setResults(results.build()); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } catch (Throwable e) { GrpcUtils.handleServerMethodException(DeviceManagementGrpc.getListDeviceGroupElementsMethod(), e, responseObserver); } finally { GrpcUtils.handleServerMethodExit(DeviceManagementGrpc.getListDeviceGroupElementsMethod()); } }