New web administration interface
[bm-groupware-server.git] / bm-webconfig / webconfig-webapp / src / main / java / net / bionicmessage / funambol / configuration / DeviceUtils.java
blobc7809970c778d1dc9d3d00057730f58548afb9a6
1 /*
2 * WebConfig - a web administration interface for the Funambol DS Server.
3 * Copyright (C) 2008 Mathew McBride
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.bionicmessage.funambol.configuration;
20 import com.funambol.framework.filter.AllClause;
21 import com.funambol.framework.filter.Clause;
22 import com.funambol.framework.filter.LogicalClause;
23 import com.funambol.framework.filter.WhereClause;
24 import com.funambol.framework.server.Sync4jDevice;
25 import com.funambol.framework.server.inventory.DeviceInventory;
26 import com.funambol.framework.server.inventory.DeviceInventoryException;
27 import com.funambol.server.config.Configuration;
29 /**
31 * @author matt
33 public class DeviceUtils {
35 public static Sync4jDevice[] getDevicesBeginningWith(String searchName) throws DeviceInventoryException {
36 Configuration c = Configuration.getConfiguration();
37 DeviceInventory deviceInventory = c.getDeviceInventory();
38 Clause cl = null;
39 if (searchName == null || searchName.length() == 0) {
40 cl = new AllClause();
41 } else {
42 String[] params = {searchName};
43 cl = new WhereClause("id",
44 params,
45 WhereClause.OPT_START_WITH,
46 false);
48 return deviceInventory.queryDevices(cl);
51 public static Sync4jDevice getDeviceById(String devId) throws DeviceInventoryException {
52 Configuration c = Configuration.getConfiguration();
53 DeviceInventory deviceInventory = c.getDeviceInventory();
54 Clause cl = null;
55 String[] params = {devId};
56 cl = new WhereClause("id",
57 params,
58 WhereClause.OPT_EQ,
59 false);
60 Sync4jDevice[] results = deviceInventory.queryDevices(cl);
61 if (results.length == 1)
62 return results[0];
63 return null;
65 public static void setDevice(Sync4jDevice dev) throws DeviceInventoryException {
66 Configuration c = Configuration.getConfiguration();
67 DeviceInventory devInf = c.getDeviceInventory();
68 devInf.setDevice(dev);
70 public static Sync4jDevice[] getDevicesByIds(String[] ids) throws DeviceInventoryException {
71 Configuration c = Configuration.getConfiguration();
72 DeviceInventory devInf = c.getDeviceInventory();
73 WhereClause wcs[] = new WhereClause[ids.length];
74 for (int i = 0; i < ids.length; i++) {
75 String[] val = {ids[i]};
76 WhereClause whereClause = new WhereClause("id",val, WhereClause.OPT_EQ,false);
77 wcs[i] = whereClause;
79 LogicalClause lc = new LogicalClause(LogicalClause.OPT_OR,wcs);
80 Sync4jDevice[] devs = devInf.queryDevices(lc);
81 return devs;