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 //File file = new File(strCfgFileName);
102 //Scanner scanFile = new Scanner(new FileReader(file));
103 //System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
105 // Initialize String for ID and TYPE
108 String strTypeSpecific = "";
110 // Initialize TableProperty for devices and specific devices
112 // e.g. ProximitySensor - table of many ProximitySensor devices
113 // ProximitySensorBrandA - table that contains the constructor
114 // information for a specific device
115 TableProperty[] tpDevice = new TableProperty[1];
116 TableProperty[] tpDeviceSpecific = new TableProperty[1];
118 // Initialize array of string
119 String[] strFields = new String[1];
120 String[] strFieldsSpecific = new String[1];
122 // String for scanning the file
125 // Store number of fields here
127 while (scanFile.hasNext()) {
129 strScan = scanFile.next();
130 if (strScan.equals("IoTMain")) {
132 while (scanFile.hasNext()) {
133 strScan = scanFile.next();
136 if (strScan.equals("ID")) {
137 strID = scanFile.next();
140 else if (strScan.equals("TYPE")) {
141 strType = scanFile.next();
144 else if (strScan.equals("TYPESPECIFIC")) {
145 strTypeSpecific = scanFile.next();
146 } else if (strScan.equals("END")) {
151 } else if (strScan.equals("Table")) {
153 // Get number of fields, e.g. Table 3
154 iFields = scanFile.nextInt();
156 // We have device ID and device specific names
157 // e.g. ID = PS1; TYPE
158 tpDevice = new TableProperty[2];
159 tpDevice[0] = new TableProperty();
160 tpDevice[0].setField("ID");
161 tpDevice[0].setType("VARCHAR");
162 tpDevice[0].setLength("5");
163 tpDevice[1] = new TableProperty();
164 tpDevice[1].setField("TYPE");
165 tpDevice[1].setType("VARCHAR");
166 tpDevice[1].setLength("30");
168 // Prepare properties for a specific device
169 tpDeviceSpecific = new TableProperty[iFields];
170 for (int i=0; i<iFields; i++) {
171 tpDeviceSpecific[i] = new TableProperty();
173 // Looping over the fields
174 strScan = scanFile.next();
175 tpDeviceSpecific[i].setField(strScan);
176 strScan = scanFile.next();
177 tpDeviceSpecific[i].setType(strScan);
178 strScan = scanFile.next();
179 tpDeviceSpecific[i].setLength(strScan);
181 } else if (strScan.equals("Data")) {
183 // Get the device information
184 strFields = new String[2];
185 strFields[0] = strID;
186 strFields[1] = strTypeSpecific;
188 if ((tpDeviceSpecific.length == 1) &&
189 (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
191 // Get the fields for specific device
192 strFieldsSpecific = null;
193 System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
197 // Get the fields for specific device
198 strFieldsSpecific = new String[iFields];
199 for (int i=0; i<iFields; i++) {
200 strScan = scanFile.next();
201 strFieldsSpecific[i] = strScan;
207 installNewEntity(strType, strTypeSpecific, strID, tpDevice,
208 tpDeviceSpecific, strFields, strFieldsSpecific);
209 System.out.println("IoTInstaller: Installing a new entity/device into the system");
213 * A method to extract device/entity information from the user
215 * Users are supposed to supply the information needed for installation
217 * @param strCfgFileName String config file name for device/entity
220 public void extractTableAndInstall(String strCfgFileName) {
221 // TO DO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
225 // Parse configuration file
226 // Assumption here is that .config file is written with the correct syntax (need typechecking)
227 File file = new File(strCfgFileName);
228 Scanner scanFile = new Scanner(new FileReader(file));
229 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
231 extractTableAndInstallCore(scanFile);
233 } catch (FileNotFoundException ex) {
235 System.out.println("IoTInstaller: Exception: ");
236 ex.printStackTrace();
242 * A method to install a new entity/device into the database
244 * 1) Insert this device/entity into the main table IoTMain
245 * 2) Create a new device/entity table if it doesn't exist yet
246 * 3) Insert this entry into the specific device/entity table
248 * @param strType String device type
249 * @param strTypeSpecific String device specific type
250 * @param strID String unique device/entity ID
251 * @param tpDevice array of TableProperty to construct the new table
252 * @param tpDeviceSpecific array of TableProperty to construct the new table
253 * @param strFields field values of device table
254 * @param strFieldsSpecific field values of device specific table
256 private void installNewEntity(String strType, String strTypeSpecific, String strID,
257 TableProperty[] tpDevice, TableProperty[] tpDeviceSpecific, String[] strFields, String[] strFieldsSpecific) {
259 // Create a new IoTInstaller object
260 System.out.println("IoTInstaller: Installing device " + strType + " with specific type " + strTypeSpecific);
261 tbl.setTableName(strType);
263 // 1) Insert this device/entity into the main table IoTMain
264 insertMainDBEntry(strID, strType);
267 // 2) Create a new device/entity table if it doesn't exist yet
268 tbl.setTableName(strType);
269 if (tbl.isTableExisting()) {
271 System.out.println("IoTInstaller: Table " + strType + " exists.. just insert new entry!");
273 // table does not exist yet
274 tbl.createTable(tpDevice, "ID");
277 // 3) Insert this entry into the device/entity table
278 tbl.insertEntry(strFields);
280 // Device specific table
281 // 2) Create a new device/entity table if it doesn't exist yet
282 // P.S. We should assume that table doesn't exist yet, and we throw error otherwise!
283 tbl.setTableName(strTypeSpecific + strID);
284 tbl.createTable(tpDeviceSpecific, null);
286 // 3) Insert this entry into the device/entity table
287 if (strFieldsSpecific != null) {
288 tbl.insertEntry(strFieldsSpecific);
293 * A method to extract device/entity communication configuration from the user
295 * Users are supposed to supply the information needed for installation
297 * @param strCfgFileName String config file name for device/entity
300 public void extractCommAndInstall(String strCfgFileName) {
301 // TODO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
305 // Parse configuration file
306 // Assumption here is that .config file is written with the correct syntax (need typechecking)
307 File file = new File(strCfgFileName);
308 Scanner scanFile = new Scanner(new FileReader(file));
310 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
315 // Initialize array of string
316 String[] strFields = new String[INT_NUM_COMM_FIELDS];
317 for(int i=0; i<INT_NUM_COMM_FIELDS; i++) {
318 strFields[i] = new String();
320 while (scanFile.hasNext() && (iFieldCnt < INT_NUM_COMM_FIELDS)) {
322 strFields[iFieldCnt++] = scanFile.next();
325 // Create a new installer object
326 tbl.setTableName(STR_COMM_TABLE_NAME);
327 tbl.insertEntry(strFields);
329 System.out.println("IoTInstaller: Installing a new communication pattern into the system");
331 } catch (FileNotFoundException ex) {
333 System.out.println("IoTInstaller: Exception: ");
334 ex.printStackTrace();
340 * A method to delete relation/communication information from database
342 * @param strEntIDSource String for entity ID source
343 * @param strEntIDDest String for entity ID destination
346 public void deleteComm(String strEntIDSource, String strEntIDDest) {
348 // Delete from table IoTMain
349 tbl.setTableName(STR_COMM_TABLE_NAME);
350 String strWhere = "ID_SOURCE='" + strEntIDSource + "' AND ID_DESTINATION='" + strEntIDDest + "';";
351 tbl.deleteEntry(strWhere);
352 System.out.println("IoTInstaller: Removing relation/communication from table " + STR_COMM_TABLE_NAME);
356 * A method to extract device/entity addresses information
358 * Users are supposed to supply the information needed for installation
360 * @param is InputStream of the input source
363 public void installDeviceAddressCore(InputStream is) {
365 Properties prop = new Properties();
368 } catch (IOException ex) {
369 ex.printStackTrace();
372 // We can only install one device address per one time with the following sequence
373 String[] strFields = new String[2];
374 String[] strFieldsAddress = null;
375 // Check for wildcard feature
376 if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
377 (prop.getProperty("DESTWILDCARD", null) != null)) {
378 strFieldsAddress = new String[5];
379 strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
380 strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
382 strFieldsAddress = new String[3];
384 strFields[0] = prop.getProperty("ID");
385 strFields[1] = prop.getProperty("ADDRESSFOR");
386 strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
387 strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
388 strFieldsAddress[2] = prop.getProperty("PROTOCOL");
390 // Insert this entry into the main device address table
391 tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
392 tbl.insertEntry(strFields);
394 // Create a new table for a specific device address
395 // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
396 tbl.setTableName(strFields[1] + strFields[0]);
398 // Table does not exist yet
399 // Set TableProperty for device address (MAC address)
400 TableProperty[] tp = null;
401 // Check for wildcard feature
402 if (strFieldsAddress.length == 5) {
403 tp = new TableProperty[5];
404 tp[3] = new TableProperty();
405 tp[3].setField("SOURCEWILDCARD");
406 tp[3].setType("VARCHAR");
407 tp[3].setLength("5");
408 tp[4] = new TableProperty();
409 tp[4].setField("DESTWILDCARD");
410 tp[4].setType("VARCHAR");
411 tp[4].setLength("5");
413 tp = new TableProperty[3];
415 tp[0] = new TableProperty();
416 tp[0].setField("DEVICEADDRESS");
417 tp[0].setType("VARCHAR");
418 tp[0].setLength("20");
419 tp[1] = new TableProperty();
420 tp[1].setField("PORTNUMBER");
421 tp[1].setType("INT");
422 tp[1].setLength("11");
423 tp[2] = new TableProperty();
424 tp[2].setField("PROTOCOL");
425 tp[2].setType("VARCHAR");
426 tp[2].setLength("5");
427 tbl.createTable(tp, "DEVICEADDRESS");
429 // Insert new address entry
430 tbl.insertEntry(strFieldsAddress);
432 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
436 * A method to extract device/entity addresses information
438 * Users are supposed to supply the information needed for installation
440 * @param strCfgFileName String config file name for device/entity
443 public void installDeviceAddress(String strCfgFileName) {
447 // Parse configuration file
448 File file = new File(strCfgFileName);
449 FileInputStream fis = new FileInputStream(file);
450 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
452 installDeviceAddressCore(fis);
454 } catch (FileNotFoundException ex) {
456 System.out.println("IoTInstaller: Exception: ");
457 ex.printStackTrace();
463 * A method to extract Zigbee device addresses information
465 * Users are supposed to supply the information needed for installation
467 * @param strCfgFileName String config file name for device/entity
470 public void installZigbeeAddress(String strCfgFileName) {
474 // Parse configuration file
475 Properties prop = new Properties();
476 File file = new File(strCfgFileName);
477 FileInputStream fis = new FileInputStream(file);
480 } catch (IOException ex) {
481 ex.printStackTrace();
483 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
485 // We can only install one device address per one time with the following sequence
486 String[] strFields = new String[2];
487 String[] strFieldsAddress = new String[1];
488 strFields[0] = prop.getProperty("ID");
489 strFields[1] = prop.getProperty("ADDRESSFOR");
490 strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
492 // Insert this entry into the main device address table
493 tbl.setTableName(STR_ZB_ADD_TABLE_NAME);
494 tbl.insertEntry(strFields);
496 // Create a new table for a specific device address
497 // e.g. AmcrestCameraZBAdd + CM1 = AmcrestCameraZBAddCM1
498 tbl.setTableName(strFields[1] + strFields[0]);
500 // Table does not exist yet
501 // Set TableProperty for device address (MAC address)
502 TableProperty[] tp = new TableProperty[1];
503 tp[0] = new TableProperty();
504 tp[0].setField("DEVICEADDRESS");
505 tp[0].setType("VARCHAR");
506 tp[0].setLength("25");
507 tbl.createTable(tp, "DEVICEADDRESS");
509 // Insert new address entry
510 tbl.insertEntry(strFieldsAddress);
512 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
514 } catch (FileNotFoundException ex) {
516 System.out.println("IoTInstaller: Exception: ");
517 ex.printStackTrace();
523 * A method to extract simple addresses information, e.g. www.google.com
525 * Users are supposed to supply the information needed for installation
527 * @param strCfgFileName String config file name for device/entity
530 public void installAddress(String strCfgFileName) {
534 // Parse configuration file
535 Properties prop = new Properties();
536 File file = new File(strCfgFileName);
537 FileInputStream fis = new FileInputStream(file);
540 } catch (IOException ex) {
541 ex.printStackTrace();
543 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
545 // We can only install one device address per one time with the following sequence
546 String[] strFields = new String[2];
547 String[] strFieldsAddress = new String[1];
548 strFields[0] = prop.getProperty("ID");
549 strFields[1] = prop.getProperty("ADDRESSFOR");
550 strFieldsAddress[0] = prop.getProperty("ADDRESS");
552 // Insert this entry into the main device address table
553 tbl.setTableName(STR_ADDRESS_TABLE_NAME);
554 tbl.insertEntry(strFields);
556 // Create a new table for a specific device address
557 // e.g. WeatherForecastAdd + WF1 = WeatherForecastAddCM1
558 tbl.setTableName(strFields[1] + strFields[0]);
560 // Table does not exist yet
561 // Set TableProperty for device address (MAC address)
562 TableProperty[] tp = new TableProperty[1];
563 tp[0] = new TableProperty();
564 tp[0].setField("ADDRESS");
565 tp[0].setType("VARCHAR");
566 tp[0].setLength("50");
567 tbl.createTable(tp, "ADDRESS");
569 // Insert new address entry
570 tbl.insertEntry(strFieldsAddress);
572 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
574 } catch (FileNotFoundException ex) {
576 System.out.println("IoTInstaller: Exception: ");
577 ex.printStackTrace();
583 * A method to extract host information for host installation
585 * Users are supposed to supply the information needed for installation
587 * @param strCfgFileName String config file name for device/entity
590 public void installHost(String strCfgFileName) {
592 // Parse configuration file
593 Properties prop = new Properties();
594 File file = new File(strCfgFileName);
595 FileInputStream fis = new FileInputStream(file);
598 } catch (IOException ex) {
599 ex.printStackTrace();
601 System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
602 // Initialize array of string
603 String[] strFields = new String[3];
604 strFields[0] = prop.getProperty("HOSTADDRESS");
605 strFields[1] = prop.getProperty("PROCESSOR");
606 strFields[2] = prop.getProperty("MEMORY");
607 // Create a new installer object
608 tbl.setTableName(STR_HOST_TABLE_NAME);
609 tbl.insertEntry(strFields);
611 System.out.println("IoTInstaller: Installing a new host into the system");
613 } catch (FileNotFoundException ex) {
615 System.out.println("IoTInstaller: Exception: ");
616 ex.printStackTrace();
622 * A method to delete host information from database by putting in host address
624 * @param strHostAddress String for host address
627 public void deleteHost(String strHostAddress) {
629 tbl.setTableName(STR_HOST_TABLE_NAME);
630 String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
631 tbl.deleteEntry(strWhere);
633 System.out.println("IoTInstaller: Deleting a host from the system");
637 * A method to delete entity information from database
639 * @param strEntID String for entity ID
640 * @param strEntType String for entity type
641 * @param strEntName String for entity name
644 public void deleteEntity(String strEntID, String strEntType, String strEntName) {
646 // Delete from table IoTMain
647 tbl.setTableName(STR_MAIN_TABLE_NAME);
648 String strWhere = "ID='" + strEntID + "';";
649 tbl.deleteEntry(strWhere);
650 System.out.println("IoTInstaller: Removing entity from table " + STR_MAIN_TABLE_NAME);
652 // Delete from table with type name, e.g. Camera
653 tbl.setTableName(strEntType);
654 strWhere = "ID='" + strEntID + "';";
655 tbl.deleteEntry(strWhere);
656 System.out.println("IoTInstaller: Removing entity from table type: " + strEntType);
657 // Drop table if this was the last entry
658 if (tbl.isTableEmpty()) {
660 System.out.println("IoTInstaller: Dropping the table.. It was the last entry!");
663 // Drop the table that contains constructor information
664 tbl.setTableName(strEntName + strEntID);
666 System.out.println("IoTInstaller: Dropping class constructor table...");
668 System.out.println("IoTInstaller: Deleting an entry from the system...");
672 * A method to delete address information from database
674 * @param strTableName String for main table, i.e. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
675 * @param strEntID String for entity ID, e.g. CM1
676 * @param strEntAddType String for entity address type, e.g. AmcrestCameraAdd
679 public void deleteAddress(String strTableName, String strEntID, String strEntAddType) {
681 // Delete from main table, e.g. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
682 tbl.setTableName(strTableName);
683 String strWhere = "ID='" + strEntID + "';";
684 tbl.deleteEntry(strWhere);
685 System.out.println("IoTInstaller: Removing entity from table " + strTableName);
687 // Drop the table that contains constructor information
688 tbl.setTableName(strEntAddType + strEntID);
690 System.out.println("IoTInstaller: Dropping class constructor table...");
692 System.out.println("IoTInstaller: Deleting an entry from the system...");
697 * A method to install a pair of new devices with their communication pattern
699 * @param strFirstDeviceFile String that contains the file name of the fist device
700 * @param strSecondDeviceFile String that contains the file name of the second device
701 * @param strCommFile String that contains the file name of the communication file
704 public void installPairOfEntities(String strFirstEntityFile,
705 String strSecondEntityFile, String strCommFile) {
706 // TODO: NEED TO DO THE INPUT FAILURE CHECKING HERE
707 // NOW JUST ASSUME THAT THE INPUT FILES ARE GOOD
709 extractTableAndInstall(strFirstEntityFile);
710 extractTableAndInstall(strSecondEntityFile);
711 extractCommAndInstall(strCommFile);
715 * A method to output help messages
719 public void helpMessages() {
720 System.out.println();
721 System.out.println("IoTInstaller: Command line options:");
722 System.out.println("IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>");
723 System.out.println("IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>");
724 System.out.print("IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ");
725 System.out.println("-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>");
726 System.out.println("IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>");
727 System.out.println("IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>");
728 System.out.println("IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>");
729 System.out.println("IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>");
730 System.out.println("IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>");
731 System.out.println("IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>");
732 System.out.println("IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id> <ent_type>");
733 System.out.println("IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id> <ent_type>");
734 System.out.println("IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id> <ent_type>");
735 System.out.println("IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>");
736 System.out.println("IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.");
737 System.out.println();
741 * A method to output help messages
745 public String helpMessagesString() {
746 String helpTxt = "\n";
747 helpTxt = helpTxt + "IoTInstaller: Command line options:\n";
748 helpTxt = helpTxt + "IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>\n";
749 helpTxt = helpTxt + "IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>\n";
750 helpTxt = helpTxt + "IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ";
751 helpTxt = helpTxt + "-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>\n";
752 helpTxt = helpTxt + "IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>\n";
753 helpTxt = helpTxt + "IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>\n";
754 helpTxt = helpTxt + "IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>\n";
755 helpTxt = helpTxt + "IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>\n";
756 helpTxt = helpTxt + "IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>\n";
757 helpTxt = helpTxt + "IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>\n";
758 helpTxt = helpTxt + "IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id>\n";
759 helpTxt = helpTxt + "IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>\n";
760 helpTxt = helpTxt + "IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>\n";
761 helpTxt = helpTxt + "IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>\n";
762 helpTxt = helpTxt + "IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.\n";
763 helpTxt = helpTxt + "\n";
769 * Main method that accepts inputs for installation
771 * @param args[0] String that contains the command line parameter
772 * @param args[1] String that contains the first file name / entity ID / host address
773 * @param args[2] String that contains the second file name
774 * @param args[3] String that contains the third file name
777 public static void main(String[] args) {
779 // Testing IoTInstaller object
780 IoTInstaller iotinst = new IoTInstaller();
782 // TODO: PROBABLY NEED A BETTER ERROR HANDLING FOR INPUTS HERE
783 // NOW ASSUME MINIMAL ERROR FOR INPUTS
784 if (args.length > 0) {
785 // Check for input parameters
786 if (args[0].equals(STR_INSTALL_ENTITY_CMD)) {
787 iotinst.extractTableAndInstall(args[1]);
789 } else if (args[0].equals(STR_INSTALL_COMMUNICATION_CMD)) {
790 iotinst.extractCommAndInstall(args[1]);
792 } else if (args[0].equals(STR_INSTALL_COMPLETE_CMD)) {
793 iotinst.installPairOfEntities(args[1], args[2], args[3]);
795 } else if (args[0].equals(STR_INSTALL_ADDRESS_CMD)) {
796 iotinst.installAddress(args[1]);
798 } else if (args[0].equals(STR_INSTALL_DEV_ADDRESS_CMD)) {
799 iotinst.installDeviceAddress(args[1]);
801 } else if (args[0].equals(STR_INSTALL_ZB_ADDRESS_CMD)) {
802 iotinst.installZigbeeAddress(args[1]);
804 } else if (args[0].equals(STR_INSTALL_HOST_CMD)) {
805 iotinst.installHost(args[1]);
807 } else if (args[0].equals(STR_DELETE_ENTITY_CMD)) {
808 iotinst.deleteEntity(args[1], args[2], args[3]);
810 } else if (args[0].equals(STR_DELETE_COMMUNICATION_CMD)) {
811 iotinst.deleteComm(args[1], args[2]);
813 } else if (args[0].equals(STR_DELETE_ADDRESS_CMD)) {
814 iotinst.deleteAddress(STR_ADDRESS_TABLE_NAME, args[1], args[2]);
816 } else if (args[0].equals(STR_DELETE_DEV_ADD_CMD)) {
817 iotinst.deleteAddress(STR_DEV_ADD_TABLE_NAME, args[1], args[2]);
819 } else if (args[0].equals(STR_DELETE_ZB_ADD_CMD)) {
820 iotinst.deleteAddress(STR_ZB_ADD_TABLE_NAME, args[1], args[2]);
822 } else if (args[0].equals(STR_DELETE_HOST_CMD)) {
823 iotinst.deleteHost(args[1]);
825 } else if (args[0].equals(STR_HELP_CMD)) {
826 iotinst.helpMessages();
829 System.out.println("IoTInstaller: ERROR: Wrong input parameters!");
830 iotinst.helpMessages();
833 System.out.println("IoTInstaller: ERROR: No input parameters detected!");
834 iotinst.helpMessages();