3 import iotinstaller.MySQLInterface;
4 import iotinstaller.TableProperty;
5 import iotinstaller.Table;
9 import java.util.Scanner;
10 import java.util.Properties;
12 /** A class that creates an object for IoT device/entity installation into database
14 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
18 public final class IoTInstaller {
21 * IoTInstaller class properties
26 * IoTInstaller class constants
28 private static final String STR_MAIN_TABLE_NAME = "IoTMain";
29 private static final String STR_COMM_TABLE_NAME = "IoTComm";
30 private static final String STR_HOST_TABLE_NAME = "IoTComputeNode";
31 private static final String STR_ADDRESS_TABLE_NAME = "IoTAddress";
32 private static final String STR_DEV_ADD_TABLE_NAME = "IoTDeviceAddress";
33 private static final String STR_ZB_ADD_TABLE_NAME = "IoTZigbeeAddress";
34 private static final int INT_NUM_COMM_FIELDS = 5;
35 private static final int INT_NUM_HOST_FIELDS = 3;
37 private static final String STR_INSTALL_ENTITY_CMD = "-install_ent";
38 private static final String STR_INSTALL_COMMUNICATION_CMD = "-install_comm";
39 private static final String STR_INSTALL_COMPLETE_CMD = "-install_comp";
40 private static final String STR_INSTALL_ADDRESS_CMD = "-install_add";
41 private static final String STR_INSTALL_DEV_ADDRESS_CMD = "-install_dev_add";
42 private static final String STR_INSTALL_ZB_ADDRESS_CMD = "-install_zb_add";
43 private static final String STR_INSTALL_HOST_CMD = "-install_host";
44 private static final String STR_DELETE_COMMUNICATION_CMD = "-delete_comm";
45 private static final String STR_DELETE_ENTITY_CMD = "-delete_ent";
46 private static final String STR_DELETE_ADDRESS_CMD = "-delete_add";
47 private static final String STR_DELETE_DEV_ADD_CMD = "-delete_dev_add";
48 private static final String STR_DELETE_ZB_ADD_CMD = "-delete_zb_add";
49 private static final String STR_DELETE_HOST_CMD = "-delete_host";
50 private static final String STR_HELP_CMD = "-help";
55 public IoTInstaller() {
57 // Make this not verbose by default
58 tbl = new Table(false);
59 System.out.println("IoTInstaller: Initializing installation..");
63 * A method to insert a new entry to the main table (IoTMain)
65 * This entry can be a new device or a new entity that we should keep track about
66 * A new entry will need a unique ID and a type name from the driver
68 * @param strID string ID to insert device into the main table
69 * @param strType string type to insert device into the main table
72 private void insertMainDBEntry(String strID, String strType) {
74 // Creating String array
75 String[] strFlds = new String[2];
76 for(int i=0; i<2; i++) {
77 strFlds[i] = new String();
82 // Insert entry through Table object
83 tbl.setTableName(STR_MAIN_TABLE_NAME);
84 tbl.insertEntry(strFlds);
85 System.out.println("IoTInstaller: Inserting a new entry into main table");
89 * A method to extract device/entity information from the user
91 * Users are supposed to supply the information needed for installation
92 * This is the core of the operation after getting the Scanner object.
94 * @param scanFile Scanner object of source
97 public void extractTableAndInstallCore(Scanner scanFile) {
99 // Parse configuration file
100 // Assumption here is that .config file is written with the correct syntax (need typechecking)
101 // Initialize String for ID and TYPE
104 String strTypeSpecific = "";
106 // Initialize TableProperty for devices and specific devices
108 // e.g. ProximitySensor - table of many ProximitySensor devices
109 // ProximitySensorBrandA - table that contains the constructor
110 // information for a specific device
111 TableProperty[] tpDevice = new TableProperty[1];
112 TableProperty[] tpDeviceSpecific = new TableProperty[1];
114 // Initialize array of string
115 String[] strFields = new String[1];
116 String[] strFieldsSpecific = new String[1];
118 // String for scanning the file
121 // Store number of fields here
123 while (scanFile.hasNext()) {
125 strScan = scanFile.next();
126 if (strScan.equals("IoTMain")) {
128 while (scanFile.hasNext()) {
129 strScan = scanFile.next();
132 if (strScan.equals("ID")) {
133 strID = scanFile.next();
136 else if (strScan.equals("TYPE")) {
137 strType = scanFile.next();
140 else if (strScan.equals("TYPESPECIFIC")) {
141 strTypeSpecific = scanFile.next();
142 } else if (strScan.equals("END")) {
147 } else if (strScan.equals("Table")) {
149 // Get number of fields, e.g. Table 3
150 iFields = scanFile.nextInt();
152 // We have device ID and device specific names
153 // e.g. ID = PS1; TYPE
154 tpDevice = new TableProperty[2];
155 tpDevice[0] = new TableProperty();
156 tpDevice[0].setField("ID");
157 tpDevice[0].setType("VARCHAR");
158 tpDevice[0].setLength("5");
159 tpDevice[1] = new TableProperty();
160 tpDevice[1].setField("TYPE");
161 tpDevice[1].setType("VARCHAR");
162 tpDevice[1].setLength("30");
164 // Prepare properties for a specific device
165 tpDeviceSpecific = new TableProperty[iFields];
166 for (int i=0; i<iFields; i++) {
167 tpDeviceSpecific[i] = new TableProperty();
169 // Looping over the fields
170 strScan = scanFile.next();
171 tpDeviceSpecific[i].setField(strScan);
172 strScan = scanFile.next();
173 tpDeviceSpecific[i].setType(strScan);
174 strScan = scanFile.next();
175 tpDeviceSpecific[i].setLength(strScan);
177 } else if (strScan.equals("Data")) {
179 // Get the device information
180 strFields = new String[2];
181 strFields[0] = strID;
182 strFields[1] = strTypeSpecific;
184 if ((tpDeviceSpecific.length == 1) &&
185 (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
187 // Get the fields for specific device
188 strFieldsSpecific = null;
189 System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
193 // Get the fields for specific device
194 strFieldsSpecific = new String[iFields];
195 for (int i=0; i<iFields; i++) {
196 strScan = scanFile.next();
197 strFieldsSpecific[i] = strScan;
203 installNewEntity(strType, strTypeSpecific, strID, tpDevice,
204 tpDeviceSpecific, strFields, strFieldsSpecific);
205 System.out.println("IoTInstaller: Installing a new entity/device into the system");
209 * A method to extract device/entity information from the user
211 * Users are supposed to supply the information needed for installation
213 * @param strCfgFileName String config file name for device/entity
216 public void extractTableAndInstall(String strCfgFileName) {
217 // TO DO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
220 // Parse configuration file
221 // Assumption here is that .config file is written with the correct syntax (need typechecking)
222 File file = new File(strCfgFileName);
223 Scanner scanFile = new Scanner(new FileReader(file));
224 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
226 extractTableAndInstallCore(scanFile);
228 } catch (FileNotFoundException ex) {
230 System.out.println("IoTInstaller: Exception: ");
231 ex.printStackTrace();
237 * A method to install a new entity/device into the database
239 * 1) Insert this device/entity into the main table IoTMain
240 * 2) Create a new device/entity table if it doesn't exist yet
241 * 3) Insert this entry into the specific device/entity table
243 * @param strType String device type
244 * @param strTypeSpecific String device specific type
245 * @param strID String unique device/entity ID
246 * @param tpDevice array of TableProperty to construct the new table
247 * @param tpDeviceSpecific array of TableProperty to construct the new table
248 * @param strFields field values of device table
249 * @param strFieldsSpecific field values of device specific table
251 private void installNewEntity(String strType, String strTypeSpecific, String strID,
252 TableProperty[] tpDevice, TableProperty[] tpDeviceSpecific, String[] strFields, String[] strFieldsSpecific) {
254 // Create a new IoTInstaller object
255 System.out.println("IoTInstaller: Installing device " + strType + " with specific type " + strTypeSpecific);
256 tbl.setTableName(strType);
258 // 1) Insert this device/entity into the main table IoTMain
259 insertMainDBEntry(strID, strType);
262 // 2) Create a new device/entity table if it doesn't exist yet
263 tbl.setTableName(strType);
264 if (tbl.isTableExisting()) {
266 System.out.println("IoTInstaller: Table " + strType + " exists.. just insert new entry!");
268 // table does not exist yet
269 tbl.createTable(tpDevice, "ID");
272 // 3) Insert this entry into the device/entity table
273 tbl.insertEntry(strFields);
275 // Device specific table
276 // 2) Create a new device/entity table if it doesn't exist yet
277 // P.S. We should assume that table doesn't exist yet, and we throw error otherwise!
278 tbl.setTableName(strTypeSpecific + strID);
279 tbl.createTable(tpDeviceSpecific, null);
281 // 3) Insert this entry into the device/entity table
282 if (strFieldsSpecific != null) {
283 tbl.insertEntry(strFieldsSpecific);
288 * A method to extract device/entity communication configuration from the user
290 * Users are supposed to supply the information needed for installation
292 * @param strCfgFileName String config file name for device/entity
295 public void extractCommAndInstall(String strCfgFileName) {
296 // TODO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
300 // Parse configuration file
301 // Assumption here is that .config file is written with the correct syntax (need typechecking)
302 File file = new File(strCfgFileName);
303 Scanner scanFile = new Scanner(new FileReader(file));
305 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
310 // Initialize array of string
311 String[] strFields = new String[INT_NUM_COMM_FIELDS];
312 for(int i=0; i<INT_NUM_COMM_FIELDS; i++) {
313 strFields[i] = new String();
315 while (scanFile.hasNext() && (iFieldCnt < INT_NUM_COMM_FIELDS)) {
317 strFields[iFieldCnt++] = scanFile.next();
319 // Create a new installer object
320 tbl.setTableName(STR_COMM_TABLE_NAME);
321 tbl.insertEntry(strFields);
323 System.out.println("IoTInstaller: Installing a new communication pattern into the system");
325 } catch (FileNotFoundException ex) {
327 System.out.println("IoTInstaller: Exception: ");
328 ex.printStackTrace();
334 * A method to delete relation/communication information from database
336 * @param strEntIDSource String for entity ID source
337 * @param strEntIDDest String for entity ID destination
340 public void deleteComm(String strEntIDSource, String strEntIDDest) {
342 // Delete from table IoTMain
343 tbl.setTableName(STR_COMM_TABLE_NAME);
344 String strWhere = "ID_SOURCE='" + strEntIDSource + "' AND ID_DESTINATION='" + strEntIDDest + "';";
345 tbl.deleteEntry(strWhere);
346 System.out.println("IoTInstaller: Removing relation/communication from table " + STR_COMM_TABLE_NAME);
350 * A method to extract device/entity addresses information
352 * Users are supposed to supply the information needed for installation
354 * @param is InputStream of the input source
357 public void installDeviceAddressCore(InputStream is) {
359 Properties prop = new Properties();
362 } catch (IOException ex) {
363 ex.printStackTrace();
366 // We can only install one device address per one time with the following sequence
367 String[] strFields = new String[2];
368 String[] strFieldsAddress = null;
369 // Check for wildcard feature
370 if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
371 (prop.getProperty("DESTWILDCARD", null) != null)) {
372 strFieldsAddress = new String[5];
373 strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
374 strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
376 strFieldsAddress = new String[3];
378 strFields[0] = prop.getProperty("ID");
379 strFields[1] = prop.getProperty("ADDRESSFOR");
380 strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
381 strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
382 strFieldsAddress[2] = prop.getProperty("PROTOCOL");
384 // Insert this entry into the main device address table
385 tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
386 tbl.insertEntry(strFields);
388 // Create a new table for a specific device address
389 // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
390 tbl.setTableName(strFields[1] + strFields[0]);
392 // Table does not exist yet
393 // Set TableProperty for device address (MAC address)
394 TableProperty[] tp = null;
395 // Check for wildcard feature
396 if (strFieldsAddress.length == 5) {
397 tp = new TableProperty[5];
398 tp[3] = new TableProperty();
399 tp[3].setField("SOURCEWILDCARD");
400 tp[3].setType("VARCHAR");
401 tp[3].setLength("5");
402 tp[4] = new TableProperty();
403 tp[4].setField("DESTWILDCARD");
404 tp[4].setType("VARCHAR");
405 tp[4].setLength("5");
407 tp = new TableProperty[3];
409 tp[0] = new TableProperty();
410 tp[0].setField("DEVICEADDRESS");
411 tp[0].setType("VARCHAR");
412 tp[0].setLength("20");
413 tp[1] = new TableProperty();
414 tp[1].setField("PORTNUMBER");
415 tp[1].setType("INT");
416 tp[1].setLength("11");
417 tp[2] = new TableProperty();
418 tp[2].setField("PROTOCOL");
419 tp[2].setType("VARCHAR");
420 tp[2].setLength("5");
421 tbl.createTable(tp, "DEVICEADDRESS");
423 // Insert new address entry
424 tbl.insertEntry(strFieldsAddress);
425 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
429 * A method to extract device/entity addresses information
431 * Users are supposed to supply the information needed for installation
433 * @param strCfgFileName String config file name for device/entity
436 public void installDeviceAddress(String strCfgFileName) {
440 // Parse configuration file
441 File file = new File(strCfgFileName);
442 FileInputStream fis = new FileInputStream(file);
443 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
444 installDeviceAddressCore(fis);
446 } catch (FileNotFoundException ex) {
448 System.out.println("IoTInstaller: Exception: ");
449 ex.printStackTrace();
455 * A method to extract Zigbee device addresses information
457 * Users are supposed to supply the information needed for installation
459 * @param strCfgFileName String config file name for device/entity
462 public void installZigbeeAddress(String strCfgFileName) {
466 // Parse configuration file
467 Properties prop = new Properties();
468 File file = new File(strCfgFileName);
469 FileInputStream fis = new FileInputStream(file);
472 } catch (IOException ex) {
473 ex.printStackTrace();
475 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
477 // We can only install one device address per one time with the following sequence
478 String[] strFields = new String[2];
479 String[] strFieldsAddress = new String[1];
480 strFields[0] = prop.getProperty("ID");
481 strFields[1] = prop.getProperty("ADDRESSFOR");
482 strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
484 // Insert this entry into the main device address table
485 tbl.setTableName(STR_ZB_ADD_TABLE_NAME);
486 tbl.insertEntry(strFields);
488 // Create a new table for a specific device address
489 // e.g. AmcrestCameraZBAdd + CM1 = AmcrestCameraZBAddCM1
490 tbl.setTableName(strFields[1] + strFields[0]);
492 // Table does not exist yet
493 // Set TableProperty for device address (MAC address)
494 TableProperty[] tp = new TableProperty[1];
495 tp[0] = new TableProperty();
496 tp[0].setField("DEVICEADDRESS");
497 tp[0].setType("VARCHAR");
498 tp[0].setLength("25");
499 tbl.createTable(tp, "DEVICEADDRESS");
501 // Insert new address entry
502 tbl.insertEntry(strFieldsAddress);
503 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
505 } catch (FileNotFoundException ex) {
507 System.out.println("IoTInstaller: Exception: ");
508 ex.printStackTrace();
514 * A method to extract simple addresses information, e.g. www.google.com
516 * Users are supposed to supply the information needed for installation
518 * @param strCfgFileName String config file name for device/entity
521 public void installAddress(String strCfgFileName) {
525 // Parse configuration file
526 Properties prop = new Properties();
527 File file = new File(strCfgFileName);
528 FileInputStream fis = new FileInputStream(file);
531 } catch (IOException ex) {
532 ex.printStackTrace();
534 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
536 // We can only install one device address per one time with the following sequence
537 String[] strFields = new String[2];
538 String[] strFieldsAddress = new String[1];
539 strFields[0] = prop.getProperty("ID");
540 strFields[1] = prop.getProperty("ADDRESSFOR");
541 strFieldsAddress[0] = prop.getProperty("ADDRESS");
543 // Insert this entry into the main device address table
544 tbl.setTableName(STR_ADDRESS_TABLE_NAME);
545 tbl.insertEntry(strFields);
547 // Create a new table for a specific device address
548 // e.g. WeatherForecastAdd + WF1 = WeatherForecastAddCM1
549 tbl.setTableName(strFields[1] + strFields[0]);
551 // Table does not exist yet
552 // Set TableProperty for device address (MAC address)
553 TableProperty[] tp = new TableProperty[1];
554 tp[0] = new TableProperty();
555 tp[0].setField("ADDRESS");
556 tp[0].setType("VARCHAR");
557 tp[0].setLength("50");
558 tbl.createTable(tp, "ADDRESS");
560 // Insert new address entry
561 tbl.insertEntry(strFieldsAddress);
562 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
564 } catch (FileNotFoundException ex) {
566 System.out.println("IoTInstaller: Exception: ");
567 ex.printStackTrace();
573 * A method to extract host information for host installation
575 * Users are supposed to supply the information needed for installation
577 * @param strCfgFileName String config file name for device/entity
580 public void installHost(String strCfgFileName) {
582 // Parse configuration file
583 Properties prop = new Properties();
584 File file = new File(strCfgFileName);
585 FileInputStream fis = new FileInputStream(file);
588 } catch (IOException ex) {
589 ex.printStackTrace();
591 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
592 // Initialize array of string
593 String[] strFields = new String[3];
594 strFields[0] = prop.getProperty("HOSTADDRESS");
595 strFields[1] = prop.getProperty("PROCESSOR");
596 strFields[2] = prop.getProperty("MEMORY");
597 // Create a new installer object
598 tbl.setTableName(STR_HOST_TABLE_NAME);
599 tbl.insertEntry(strFields);
600 System.out.println("IoTInstaller: Installing a new host into the system");
602 } catch (FileNotFoundException ex) {
604 System.out.println("IoTInstaller: Exception: ");
605 ex.printStackTrace();
611 * A method to delete host information from database by putting in host address
613 * @param strHostAddress String for host address
616 public void deleteHost(String strHostAddress) {
618 tbl.setTableName(STR_HOST_TABLE_NAME);
619 String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
620 tbl.deleteEntry(strWhere);
621 System.out.println("IoTInstaller: Deleting a host from the system");
625 * A method to delete entity information from database
627 * @param strEntID String for entity ID
628 * @param strEntType String for entity type
629 * @param strEntName String for entity name
632 public void deleteEntity(String strEntID, String strEntType, String strEntName) {
634 // Delete from table IoTMain
635 tbl.setTableName(STR_MAIN_TABLE_NAME);
636 String strWhere = "ID='" + strEntID + "';";
637 tbl.deleteEntry(strWhere);
638 System.out.println("IoTInstaller: Removing entity from table " + STR_MAIN_TABLE_NAME);
639 // Delete from table with type name, e.g. Camera
640 tbl.setTableName(strEntType);
641 strWhere = "ID='" + strEntID + "';";
642 tbl.deleteEntry(strWhere);
643 System.out.println("IoTInstaller: Removing entity from table type: " + strEntType);
644 // Drop table if this was the last entry
645 if (tbl.isTableEmpty()) {
647 System.out.println("IoTInstaller: Dropping the table.. It was the last entry!");
650 // Drop the table that contains constructor information
651 tbl.setTableName(strEntName + strEntID);
653 System.out.println("IoTInstaller: Dropping class constructor table...");
655 System.out.println("IoTInstaller: Deleting an entry from the system...");
659 * A method to delete address information from database
661 * @param strTableName String for main table, i.e. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
662 * @param strEntID String for entity ID, e.g. CM1
663 * @param strEntAddType String for entity address type, e.g. AmcrestCameraAdd
666 public void deleteAddress(String strTableName, String strEntID, String strEntAddType) {
668 // Delete from main table, e.g. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
669 tbl.setTableName(strTableName);
670 String strWhere = "ID='" + strEntID + "';";
671 tbl.deleteEntry(strWhere);
672 System.out.println("IoTInstaller: Removing entity from table " + strTableName);
674 // Drop the table that contains constructor information
675 tbl.setTableName(strEntAddType + strEntID);
677 System.out.println("IoTInstaller: Dropping class constructor table...");
678 System.out.println("IoTInstaller: Deleting an entry from the system...");
683 * A method to install a pair of new devices with their communication pattern
685 * @param strFirstDeviceFile String that contains the file name of the fist device
686 * @param strSecondDeviceFile String that contains the file name of the second device
687 * @param strCommFile String that contains the file name of the communication file
690 public void installPairOfEntities(String strFirstEntityFile,
691 String strSecondEntityFile, String strCommFile) {
692 // TODO: NEED TO DO THE INPUT FAILURE CHECKING HERE
693 // NOW JUST ASSUME THAT THE INPUT FILES ARE GOOD
695 extractTableAndInstall(strFirstEntityFile);
696 extractTableAndInstall(strSecondEntityFile);
697 extractCommAndInstall(strCommFile);
701 * A method to output help messages
705 public void helpMessages() {
706 System.out.println();
707 System.out.println("IoTInstaller: Command line options:");
708 System.out.println("IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>");
709 System.out.println("IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>");
710 System.out.print("IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ");
711 System.out.println("-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>");
712 System.out.println("IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>");
713 System.out.println("IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>");
714 System.out.println("IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>");
715 System.out.println("IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>");
716 System.out.println("IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>");
717 System.out.println("IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>");
718 System.out.println("IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id> <ent_type>");
719 System.out.println("IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id> <ent_type>");
720 System.out.println("IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id> <ent_type>");
721 System.out.println("IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>");
722 System.out.println("IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.");
723 System.out.println();
727 * A method to output help messages
731 public String helpMessagesString() {
732 String helpTxt = "\n";
733 helpTxt = helpTxt + "IoTInstaller: Command line options:\n";
734 helpTxt = helpTxt + "IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>\n";
735 helpTxt = helpTxt + "IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>\n";
736 helpTxt = helpTxt + "IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ";
737 helpTxt = helpTxt + "-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>\n";
738 helpTxt = helpTxt + "IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>\n";
739 helpTxt = helpTxt + "IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>\n";
740 helpTxt = helpTxt + "IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>\n";
741 helpTxt = helpTxt + "IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>\n";
742 helpTxt = helpTxt + "IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>\n";
743 helpTxt = helpTxt + "IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>\n";
744 helpTxt = helpTxt + "IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id>\n";
745 helpTxt = helpTxt + "IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>\n";
746 helpTxt = helpTxt + "IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>\n";
747 helpTxt = helpTxt + "IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>\n";
748 helpTxt = helpTxt + "IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.\n";
749 helpTxt = helpTxt + "\n";
755 * Main method that accepts inputs for installation
757 * @param args[0] String that contains the command line parameter
758 * @param args[1] String that contains the first file name / entity ID / host address
759 * @param args[2] String that contains the second file name
760 * @param args[3] String that contains the third file name
763 public static void main(String[] args) {
765 // Testing IoTInstaller object
766 IoTInstaller iotinst = new IoTInstaller();
768 // TODO: PROBABLY NEED A BETTER ERROR HANDLING FOR INPUTS HERE
769 // NOW ASSUME MINIMAL ERROR FOR INPUTS
770 if (args.length > 0) {
771 // Check for input parameters
772 if (args[0].equals(STR_INSTALL_ENTITY_CMD)) {
773 iotinst.extractTableAndInstall(args[1]);
775 } else if (args[0].equals(STR_INSTALL_COMMUNICATION_CMD)) {
776 iotinst.extractCommAndInstall(args[1]);
778 } else if (args[0].equals(STR_INSTALL_COMPLETE_CMD)) {
779 iotinst.installPairOfEntities(args[1], args[2], args[3]);
781 } else if (args[0].equals(STR_INSTALL_ADDRESS_CMD)) {
782 iotinst.installAddress(args[1]);
784 } else if (args[0].equals(STR_INSTALL_DEV_ADDRESS_CMD)) {
785 iotinst.installDeviceAddress(args[1]);
787 } else if (args[0].equals(STR_INSTALL_ZB_ADDRESS_CMD)) {
788 iotinst.installZigbeeAddress(args[1]);
790 } else if (args[0].equals(STR_INSTALL_HOST_CMD)) {
791 iotinst.installHost(args[1]);
793 } else if (args[0].equals(STR_DELETE_ENTITY_CMD)) {
794 iotinst.deleteEntity(args[1], args[2], args[3]);
796 } else if (args[0].equals(STR_DELETE_COMMUNICATION_CMD)) {
797 iotinst.deleteComm(args[1], args[2]);
799 } else if (args[0].equals(STR_DELETE_ADDRESS_CMD)) {
800 iotinst.deleteAddress(STR_ADDRESS_TABLE_NAME, args[1], args[2]);
802 } else if (args[0].equals(STR_DELETE_DEV_ADD_CMD)) {
803 iotinst.deleteAddress(STR_DEV_ADD_TABLE_NAME, args[1], args[2]);
805 } else if (args[0].equals(STR_DELETE_ZB_ADD_CMD)) {
806 iotinst.deleteAddress(STR_ZB_ADD_TABLE_NAME, args[1], args[2]);
808 } else if (args[0].equals(STR_DELETE_HOST_CMD)) {
809 iotinst.deleteHost(args[1]);
811 } else if (args[0].equals(STR_HELP_CMD)) {
812 iotinst.helpMessages();
815 System.out.println("IoTInstaller: ERROR: Wrong input parameters!");
816 iotinst.helpMessages();
819 System.out.println("IoTInstaller: ERROR: No input parameters detected!");
820 iotinst.helpMessages();