Minor changes to tables for device registration phone app integration; these changes...
[iot2.git] / iotjava / iotinstaller / IoTInstaller.java
1 package iotinstaller;
2
3 import iotinstaller.MySQLInterface;
4 import iotinstaller.TableProperty;
5 import iotinstaller.Table;
6
7 import java.io.*;
8 import java.sql.*;
9 import java.util.Scanner;
10 import java.util.Properties;
11
12 /** A class that creates an object for IoT device/entity installation into database
13  *
14  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
15  * @version     1.0
16  * @since       2015-12-01
17  */
18 public final class IoTInstaller {
19
20         /**
21          * IoTInstaller class properties
22          */
23         private Table tbl;
24
25         /**
26          * IoTInstaller class constants
27          */
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;
36
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_ENTITY_CMD = "-delete_ent";
45         private static final String STR_DELETE_ADDRESS_CMD = "-delete_add";
46         private static final String STR_DELETE_DEV_ADD_CMD = "-delete_dev_add";
47         private static final String STR_DELETE_ZB_ADD_CMD = "-delete_zb_add";
48         private static final String STR_DELETE_HOST_CMD = "-delete_host";
49         private static final String STR_HELP_CMD = "-help";
50
51         /**
52          * Class constructor
53          */
54         public IoTInstaller() {
55
56                 // Make this not verbose by default
57                 tbl = new Table(false);
58                 System.out.println("IoTInstaller: Initializing installation..");
59         }
60
61         /**
62          * A method to insert a new entry to the main table (IoTMain)
63          * <p>
64          * This entry can be a new device or a new entity that we should keep track about
65          * A new entry will need a unique ID and a type name from the driver
66          *
67          * @param  strID    string ID to insert device into the main table
68          * @param  strType  string type to insert device into the main table
69          * @return          void
70          */
71         private void insertMainDBEntry(String strID, String strType) {
72
73                 // Creating String array
74                 String[] strFlds = new String[2];
75                 for(int i=0; i<2; i++) {
76                         strFlds[i] = new String();
77                 }
78                 strFlds[0] = strID;
79                 strFlds[1] = strType;
80
81                 // Insert entry through Table object
82                 tbl.setTableName(STR_MAIN_TABLE_NAME);
83                 tbl.insertEntry(strFlds);
84                 System.out.println("IoTInstaller: Inserting a new entry into main table");
85         }
86         
87         /**
88          * A method to extract device/entity information from the user
89          * <p>
90          * Users are supposed to supply the information needed for installation
91          * This is the core of the operation after getting the Scanner object.
92          *
93          * @param  scanFile     Scanner object of source
94          * @return              void
95          */
96         public void extractTableAndInstallCore(Scanner scanFile) {
97
98                 // Parse configuration file
99                 // Assumption here is that .config file is written with the correct syntax (need typechecking)
100                 //File file = new File(strCfgFileName);
101                 //Scanner scanFile = new Scanner(new FileReader(file));
102                 //System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
103
104                 // Initialize String for ID and TYPE
105                 String strID = "";
106                 String strType = "";
107                 String strTypeSpecific = "";
108
109                 // Initialize TableProperty for devices and specific devices
110                 // We have 2 tables,
111                 // e.g. ProximitySensor - table of many ProximitySensor devices
112                 //      ProximitySensorBrandA - table that contains the constructor
113                 //                              information for a specific device
114                 TableProperty[] tpDevice = new TableProperty[1];
115                 TableProperty[] tpDeviceSpecific = new TableProperty[1];
116
117                 // Initialize array of string
118                 String[] strFields = new String[1];
119                 String[] strFieldsSpecific = new String[1];
120
121                 // String for scanning the file
122                 String strScan = "";
123
124                 // Store number of fields here
125                 int iFields = 0;
126                 while (scanFile.hasNext()) {
127
128                         strScan = scanFile.next();
129                         if (strScan.equals("IoTMain")) {
130
131                                 while (scanFile.hasNext()) {
132                                         strScan = scanFile.next();
133
134                                         // Get ID
135                                         if (strScan.equals("ID")) {
136                                                 strID = scanFile.next();
137                                         }
138                                         // Get TYPE
139                                         else if (strScan.equals("TYPE")) {
140                                                 strType = scanFile.next();
141                                         }
142                                         // Get TYPE
143                                         else if (strScan.equals("TYPESPECIFIC")) {
144                                                 strTypeSpecific = scanFile.next();
145                                         } else if (strScan.equals("END")) {
146                                                 // Break out of loop
147                                                 break;
148                                         }
149                                 }
150                         } else if (strScan.equals("Table")) {
151
152                                 // Get number of fields, e.g. Table 3
153                                 iFields = scanFile.nextInt();
154
155                                 // We have device ID and device specific names
156                                 // e.g. ID = PS1; TYPE
157                                 tpDevice = new TableProperty[2];
158                                 tpDevice[0] = new TableProperty();
159                                 tpDevice[0].setField("ID");
160                                 tpDevice[0].setType("VARCHAR");
161                                 tpDevice[0].setLength("5");
162                                 tpDevice[1] = new TableProperty();
163                                 tpDevice[1].setField("TYPE");
164                                 tpDevice[1].setType("VARCHAR");
165                                 tpDevice[1].setLength("30");
166
167                                 // Prepare properties for a specific device
168                                 tpDeviceSpecific = new TableProperty[iFields];
169                                 for (int i=0; i<iFields; i++) {
170                                         tpDeviceSpecific[i] = new TableProperty();
171
172                                         // Looping over the fields
173                                         strScan = scanFile.next();
174                                         tpDeviceSpecific[i].setField(strScan);
175                                         strScan = scanFile.next();
176                                         tpDeviceSpecific[i].setType(strScan);
177                                         strScan = scanFile.next();
178                                         tpDeviceSpecific[i].setLength(strScan);
179                                 }
180                         } else if (strScan.equals("Data")) {
181
182                                 // Get the device information
183                                 strFields = new String[2];
184                                 strFields[0] = strID;
185                                 strFields[1] = strTypeSpecific;
186
187                                 if ((tpDeviceSpecific.length == 1) &&
188                                                 (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
189
190                                         // Get the fields for specific device
191                                         strFieldsSpecific = null;
192                                         System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
193
194                                 } else {
195
196                                         // Get the fields for specific device
197                                         strFieldsSpecific = new String[iFields];
198                                         for (int i=0; i<iFields; i++) {
199                                                 strScan = scanFile.next();
200                                                 strFieldsSpecific[i] = strScan;
201                                         }
202                                 }
203                         }
204                 }
205
206                 installNewEntity(strType, strTypeSpecific, strID, tpDevice,
207                                                                                  tpDeviceSpecific, strFields, strFieldsSpecific);
208                 System.out.println("IoTInstaller: Installing a new entity/device into the system");
209         }
210
211         /**
212          * A method to extract device/entity information from the user
213          * <p>
214          * Users are supposed to supply the information needed for installation
215          *
216          * @param  strCfgFileName String config file name for device/entity
217          * @return                void
218          */
219         public void extractTableAndInstall(String strCfgFileName) {
220                 // TO DO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
221
222                 try {
223
224                         // Parse configuration file
225                         // Assumption here is that .config file is written with the correct syntax (need typechecking)
226                         File file = new File(strCfgFileName);
227                         Scanner scanFile = new Scanner(new FileReader(file));
228                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
229
230             extractTableAndInstallCore(scanFile);
231
232                 } catch (FileNotFoundException ex) {
233
234                         System.out.println("IoTInstaller: Exception: ");
235                         ex.printStackTrace();
236
237                 }
238         }
239
240         /**
241          * A method to install a new entity/device into the database
242          * <p>
243          * 1) Insert this device/entity into the main table IoTMain
244          * 2) Create a new device/entity table if it doesn't exist yet
245          * 3) Insert this entry into the specific device/entity table
246          *
247          * @param  strType           String device type
248          * @param  strTypeSpecific   String device specific type
249          * @param  strID             String unique device/entity ID
250          * @param  tpDevice          array of TableProperty to construct the new table
251          * @param  tpDeviceSpecific  array of TableProperty to construct the new table
252          * @param  strFields         field values of device table
253          * @param  strFieldsSpecific field values of device specific table
254          */
255         private void installNewEntity(String strType, String strTypeSpecific, String strID,
256                 TableProperty[] tpDevice, TableProperty[] tpDeviceSpecific, String[] strFields, String[] strFieldsSpecific) {
257
258                 // Create a new IoTInstaller object
259                 System.out.println("IoTInstaller: Installing device " + strType + " with specific type " + strTypeSpecific);
260                 tbl.setTableName(strType);
261
262                 // 1) Insert this device/entity into the main table IoTMain
263                 insertMainDBEntry(strID, strType);
264
265                 // Device table
266                 // 2) Create a new device/entity table if it doesn't exist yet
267                 tbl.setTableName(strType);
268                 if (tbl.isTableExisting()) {
269                         // table does exist
270                         System.out.println("IoTInstaller: Table " + strType + " exists.. just insert new entry!");
271                 } else {
272                         // table does not exist yet
273                         tbl.createTable(tpDevice, "ID");
274                 }
275
276                 // 3) Insert this entry into the device/entity table
277                 tbl.insertEntry(strFields);
278
279                 // Device specific table
280                 // 2) Create a new device/entity table if it doesn't exist yet
281                 // P.S. We should assume that table doesn't exist yet, and we throw error otherwise!
282                 tbl.setTableName(strTypeSpecific + strID);
283                 tbl.createTable(tpDeviceSpecific, null);
284
285                 // 3) Insert this entry into the device/entity table
286                 if (strFieldsSpecific != null) {
287                         tbl.insertEntry(strFieldsSpecific);
288                 }
289         }
290
291         /**
292          * A method to extract device/entity communication configuration from the user
293          * <p>
294          * Users are supposed to supply the information needed for installation
295          *
296          * @param  strCfgFileName String config file name for device/entity
297          * @return                void
298          */
299         public void extractCommAndInstall(String strCfgFileName) {
300                 // TODO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
301
302                 try {
303
304                         // Parse configuration file
305                         // Assumption here is that .config file is written with the correct syntax (need typechecking)
306                         File file = new File(strCfgFileName);
307                         Scanner scanFile = new Scanner(new FileReader(file));
308
309                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
310
311                         // Field counter
312                         int iFieldCnt = 0;
313
314                         // Initialize array of string
315                         String[] strFields = new String[INT_NUM_COMM_FIELDS];
316                         for(int i=0; i<INT_NUM_COMM_FIELDS; i++) {
317                                 strFields[i] = new String();
318                         }
319                         while (scanFile.hasNext() && (iFieldCnt < INT_NUM_COMM_FIELDS)) {
320
321                                 strFields[iFieldCnt++] = scanFile.next();
322                         }
323
324                         // Create a new installer object
325                         tbl.setTableName(STR_COMM_TABLE_NAME);
326                         tbl.insertEntry(strFields);
327
328                         System.out.println("IoTInstaller: Installing a new communication pattern into the system");
329
330                 } catch (FileNotFoundException ex) {
331
332                         System.out.println("IoTInstaller: Exception: ");
333                         ex.printStackTrace();
334
335                 }
336         }
337         
338         /**
339          * A method to extract device/entity addresses information
340          * <p>
341          * Users are supposed to supply the information needed for installation
342          *
343          * @param  is   InputStream of the input source
344          * @return      void
345          */
346         public void installDeviceAddressCore(InputStream is) {
347
348                 Properties prop = new Properties();
349                 try {
350                         prop.load(is);
351                 } catch (IOException ex) {
352                         ex.printStackTrace();
353                 }
354                 // Initialize string
355                 // We can only install one device address per one time with the following sequence
356                 String[] strFields = new String[2];
357                 String[] strFieldsAddress = null;
358                 // Check for wildcard feature
359                 if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
360                         (prop.getProperty("DESTWILDCARD", null) != null)) {
361                         strFieldsAddress = new String[5];
362                         strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
363                         strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
364                 } else {
365                         strFieldsAddress = new String[3];
366                 }
367                 strFields[0] = prop.getProperty("ID");
368                 strFields[1] = prop.getProperty("ADDRESSFOR");
369                 strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
370                 strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
371                 strFieldsAddress[2] = prop.getProperty("PROTOCOL");
372
373                 // Insert this entry into the main device address table
374                 tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
375                 tbl.insertEntry(strFields);
376
377                 // Create a new table for a specific device address
378                 // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
379                 tbl.setTableName(strFields[1] + strFields[0]);
380
381                 // Table does not exist yet
382                 // Set TableProperty for device address (MAC address)
383                 TableProperty[] tp = null;
384                 // Check for wildcard feature
385                 if (strFieldsAddress.length == 5) {
386                         tp = new TableProperty[5];
387                         tp[3] = new TableProperty();
388                         tp[3].setField("SOURCEWILDCARD");
389                         tp[3].setType("VARCHAR");
390                         tp[3].setLength("5");
391                         tp[4] = new TableProperty();
392                         tp[4].setField("DESTWILDCARD");
393                         tp[4].setType("VARCHAR");
394                         tp[4].setLength("5");
395                 } else {
396                         tp = new TableProperty[3];
397                 }
398                 tp[0] = new TableProperty();
399                 tp[0].setField("DEVICEADDRESS");
400                 tp[0].setType("VARCHAR");
401                 tp[0].setLength("20");
402                 tp[1] = new TableProperty();
403                 tp[1].setField("PORTNUMBER");
404                 tp[1].setType("INT");
405                 tp[1].setLength("11");
406                 tp[2] = new TableProperty();
407                 tp[2].setField("PROTOCOL");
408                 tp[2].setType("VARCHAR");
409                 tp[2].setLength("5");
410                 tbl.createTable(tp, "DEVICEADDRESS");
411
412                 // Insert new address entry
413                 tbl.insertEntry(strFieldsAddress);
414
415                 System.out.println("IoTInstaller: Installing a new device/entity address into the system");
416         }
417
418         /**
419          * A method to extract device/entity addresses information
420          * <p>
421          * Users are supposed to supply the information needed for installation
422          *
423          * @param  strCfgFileName String config file name for device/entity
424          * @return                void
425          */
426         public void installDeviceAddress(String strCfgFileName) {
427
428                 try {
429
430                         // Parse configuration file
431                         File file = new File(strCfgFileName);
432                         FileInputStream fis = new FileInputStream(file);
433                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
434
435                         installDeviceAddressCore(fis);
436
437                 } catch (FileNotFoundException ex) {
438
439                         System.out.println("IoTInstaller: Exception: ");
440                         ex.printStackTrace();
441
442                 }
443         }
444
445         /**
446          * A method to extract Zigbee device addresses information
447          * <p>
448          * Users are supposed to supply the information needed for installation
449          *
450          * @param  strCfgFileName String config file name for device/entity
451          * @return                void
452          */
453         public void installZigbeeAddress(String strCfgFileName) {
454
455                 try {
456
457                         // Parse configuration file
458                         Properties prop = new Properties();
459                         File file = new File(strCfgFileName);
460                         FileInputStream fis = new FileInputStream(file);
461                         try {
462                                 prop.load(fis);
463                         } catch (IOException ex) {
464                                 ex.printStackTrace();
465                         }
466                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
467                         // Initialize string
468                         // We can only install one device address per one time with the following sequence
469                         String[] strFields = new String[2];
470                         String[] strFieldsAddress = new String[1];
471                         strFields[0] = prop.getProperty("ID");
472                         strFields[1] = prop.getProperty("ADDRESSFOR");
473                         strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
474
475                         // Insert this entry into the main device address table
476                         tbl.setTableName(STR_ZB_ADD_TABLE_NAME);
477                         tbl.insertEntry(strFields);
478
479                         // Create a new table for a specific device address
480                         // e.g. AmcrestCameraZBAdd + CM1 = AmcrestCameraZBAddCM1
481                         tbl.setTableName(strFields[1] + strFields[0]);
482
483                         // Table does not exist yet
484                         // Set TableProperty for device address (MAC address)
485                         TableProperty[] tp = new TableProperty[1];
486                         tp[0] = new TableProperty();
487                         tp[0].setField("DEVICEADDRESS");
488                         tp[0].setType("VARCHAR");
489                         tp[0].setLength("25");
490                         tbl.createTable(tp, "DEVICEADDRESS");
491
492                         // Insert new address entry
493                         tbl.insertEntry(strFieldsAddress);
494
495                         System.out.println("IoTInstaller: Installing a new device/entity address into the system");
496
497                 } catch (FileNotFoundException ex) {
498
499                         System.out.println("IoTInstaller: Exception: ");
500                         ex.printStackTrace();
501
502                 }
503         }
504
505         /**
506          * A method to extract simple addresses information, e.g. www.google.com
507          * <p>
508          * Users are supposed to supply the information needed for installation
509          *
510          * @param  strCfgFileName String config file name for device/entity
511          * @return                void
512          */
513         public void installAddress(String strCfgFileName) {
514
515                 try {
516
517                         // Parse configuration file
518                         Properties prop = new Properties();
519                         File file = new File(strCfgFileName);
520                         FileInputStream fis = new FileInputStream(file);
521                         try {
522                                 prop.load(fis);
523                         } catch (IOException ex) {
524                                 ex.printStackTrace();
525                         }
526                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
527                         // Initialize string
528                         // We can only install one device address per one time with the following sequence
529                         String[] strFields = new String[2];
530                         String[] strFieldsAddress = new String[1];
531                         strFields[0] = prop.getProperty("ID");
532                         strFields[1] = prop.getProperty("ADDRESSFOR");
533                         strFieldsAddress[0] = prop.getProperty("ADDRESS");
534
535                         // Insert this entry into the main device address table
536                         tbl.setTableName(STR_ADDRESS_TABLE_NAME);
537                         tbl.insertEntry(strFields);
538
539                         // Create a new table for a specific device address
540                         // e.g. WeatherForecastAdd + WF1 = WeatherForecastAddCM1
541                         tbl.setTableName(strFields[1] + strFields[0]);
542
543                         // Table does not exist yet
544                         // Set TableProperty for device address (MAC address)
545                         TableProperty[] tp = new TableProperty[1];
546                         tp[0] = new TableProperty();
547                         tp[0].setField("ADDRESS");
548                         tp[0].setType("VARCHAR");
549                         tp[0].setLength("50");
550                         tbl.createTable(tp, "ADDRESS");
551
552                         // Insert new address entry
553                         tbl.insertEntry(strFieldsAddress);
554
555                         System.out.println("IoTInstaller: Installing a new device/entity address into the system");
556
557                 } catch (FileNotFoundException ex) {
558
559                         System.out.println("IoTInstaller: Exception: ");
560                         ex.printStackTrace();
561
562                 }
563         }
564
565         /**
566          * A method to extract host information for host installation
567          * <p>
568          * Users are supposed to supply the information needed for installation
569          *
570          * @param  strCfgFileName String config file name for device/entity
571          * @return                void
572          */
573         public void installHost(String strCfgFileName) {
574                 try {
575                         // Parse configuration file
576                         Properties prop = new Properties();
577                         File file = new File(strCfgFileName);
578                         FileInputStream fis = new FileInputStream(file);
579                         try {
580                                 prop.load(fis);
581                         } catch (IOException ex) {
582                                 ex.printStackTrace();
583                         }
584                         System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
585                         // Initialize array of string
586                         String[] strFields = new String[3];
587                         strFields[0] = prop.getProperty("HOSTADDRESS");
588                         strFields[1] = prop.getProperty("PROCESSOR");
589                         strFields[2] = prop.getProperty("MEMORY");
590                         // Create a new installer object
591                         tbl.setTableName(STR_HOST_TABLE_NAME);
592                         tbl.insertEntry(strFields);
593
594                         System.out.println("IoTInstaller: Installing a new host into the system");
595
596                 } catch (FileNotFoundException ex) {
597
598                         System.out.println("IoTInstaller: Exception: ");
599                         ex.printStackTrace();
600
601                 }
602         }
603
604         /**
605          * A method to delete host information from database by putting in host address
606          *
607          * @param  strHostAddress String for host address
608          * @return                void
609          */
610         public void deleteHost(String strHostAddress) {
611
612                 tbl.setTableName(STR_HOST_TABLE_NAME);
613                 String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
614                 tbl.deleteEntry(strWhere);
615
616                 System.out.println("IoTInstaller: Deleting a host from the system");
617         }
618
619         /**
620          * A method to delete entity information from database
621          *
622          * @param  strEntID             String for entity ID
623          * @param  strEntType   String for entity type
624          * @param  strEntName   String for entity name
625          * @return              void
626          */
627         public void deleteEntity(String strEntID, String strEntType, String strEntName) {
628
629                 // Delete from table IoTMain
630                 tbl.setTableName(STR_MAIN_TABLE_NAME);
631                 String strWhere = "ID='" + strEntID + "';";
632                 tbl.deleteEntry(strWhere);
633                 System.out.println("IoTInstaller: Removing entity from table " + STR_MAIN_TABLE_NAME);
634
635                 // Delete from table with type name, e.g. Camera
636                 tbl.setTableName(strEntType);
637                 strWhere = "ID='" + strEntID + "';";
638                 tbl.deleteEntry(strWhere);
639                 System.out.println("IoTInstaller: Removing entity from table type: " + strEntType);
640                 // Drop table if this was the last entry
641                 if (tbl.isTableEmpty()) {
642                         tbl.dropTable();
643                         System.out.println("IoTInstaller: Dropping the table.. It was the last entry!");
644                 }
645
646                 // Drop the table that contains constructor information
647                 tbl.setTableName(strEntName + strEntID);
648                 tbl.dropTable();
649                 System.out.println("IoTInstaller: Dropping class constructor table...");
650
651                 System.out.println("IoTInstaller: Deleting an entry from the system...");
652         }
653
654         /**
655          * A method to delete address information from database
656          *
657          * @param  strTableName         String for main table, i.e. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
658          * @param  strEntID                     String for entity ID, e.g. CM1
659          * @param  strEntAddType        String for entity address type, e.g. AmcrestCameraAdd
660          * @return                                      void
661          */
662         public void deleteAddress(String strTableName, String strEntID, String strEntAddType) {
663
664                 // Delete from main table, e.g. IoTAddress, IoTDeviceAddress, or IoTZigbeeAddress
665                 tbl.setTableName(strTableName);
666                 String strWhere = "ID='" + strEntID + "';";
667                 tbl.deleteEntry(strWhere);
668                 System.out.println("IoTInstaller: Removing entity from table " + strTableName);
669
670                 // Drop the table that contains constructor information
671                 tbl.setTableName(strEntAddType + strEntID);
672                 tbl.dropTable();
673                 System.out.println("IoTInstaller: Dropping class constructor table...");
674
675                 System.out.println("IoTInstaller: Deleting an entry from the system...");
676         }
677
678
679         /**
680          * A method to install a pair of new devices with their communication pattern
681          *
682          * @param  strFirstDeviceFile  String that contains the file name of the fist device
683          * @param  strSecondDeviceFile String that contains the file name of the second device
684          * @param  strCommFile         String that contains the file name of the communication file
685          * @return                     void
686          */
687         public void installPairOfEntities(String strFirstEntityFile,
688                 String strSecondEntityFile, String strCommFile) {
689                 // TODO: NEED TO DO THE INPUT FAILURE CHECKING HERE
690                 // NOW JUST ASSUME THAT THE INPUT FILES ARE GOOD
691
692                 extractTableAndInstall(strFirstEntityFile);
693                 extractTableAndInstall(strSecondEntityFile);
694                 extractCommAndInstall(strCommFile);
695         }
696
697         /**
698          * A method to output help messages
699          *
700          * @return void
701          */
702         public void helpMessages() {
703                 System.out.println();
704                 System.out.println("IoTInstaller: Command line options:");
705                 System.out.println("IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>");
706                 System.out.println("IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>");
707                 System.out.print("IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ");
708                 System.out.println("-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>");
709                 System.out.println("IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>");
710                 System.out.println("IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>");
711                 System.out.println("IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>");
712                 System.out.println("IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>");
713                 System.out.println("IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>");
714                 System.out.println("IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id> <ent_type>");
715                 System.out.println("IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id> <ent_type>");
716                 System.out.println("IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id> <ent_type>");
717                 System.out.println("IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>");
718                 System.out.println("IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.");
719                 System.out.println();
720         }
721
722         /**
723          * A method to output help messages
724          *
725          * @return void
726          */
727         public String helpMessagesString() {
728                 String helpTxt = "\n";
729                 helpTxt = helpTxt + "IoTInstaller: Command line options:\n";
730                 helpTxt = helpTxt + "IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>\n";
731                 helpTxt = helpTxt + "IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>\n";
732                 helpTxt = helpTxt + "IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ";
733                 helpTxt = helpTxt + "-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>\n";
734                 helpTxt = helpTxt + "IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>\n";
735                 helpTxt = helpTxt + "IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>\n";
736                 helpTxt = helpTxt + "IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>\n";
737                 helpTxt = helpTxt + "IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>\n";
738                 helpTxt = helpTxt + "IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>\n";
739                 helpTxt = helpTxt + "IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id>\n";
740                 helpTxt = helpTxt + "IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>\n";
741                 helpTxt = helpTxt + "IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>\n";
742                 helpTxt = helpTxt + "IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>\n";
743                 helpTxt = helpTxt + "IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.\n";
744                 helpTxt = helpTxt + "\n";
745
746                 return helpTxt;
747         }
748
749         /**
750          * Main method that accepts inputs for installation
751          *
752          * @param  args[0]  String that contains the command line parameter
753          * @param  args[1]  String that contains the first file name / entity ID / host address
754          * @param  args[2]  String that contains the second file name
755          * @param  args[3]  String that contains the third file name
756          * @see    helpMessages
757          */
758         public static void main(String[] args) {
759
760                 // Testing IoTInstaller object
761                 IoTInstaller iotinst = new IoTInstaller();
762
763                 // TODO: PROBABLY NEED A BETTER ERROR HANDLING FOR INPUTS HERE
764                 // NOW ASSUME MINIMAL ERROR FOR INPUTS
765                 if (args.length > 0) {
766                         // Check for input parameters
767                         if (args[0].equals(STR_INSTALL_ENTITY_CMD)) {
768                                 iotinst.extractTableAndInstall(args[1]);
769
770                         } else if (args[0].equals(STR_INSTALL_COMMUNICATION_CMD)) {
771                                 iotinst.extractCommAndInstall(args[1]);
772
773                         } else if (args[0].equals(STR_INSTALL_COMPLETE_CMD)) {
774                                 iotinst.installPairOfEntities(args[1], args[2], args[3]);
775
776                         } else if (args[0].equals(STR_INSTALL_ADDRESS_CMD)) {
777                                 iotinst.installAddress(args[1]);
778
779                         } else if (args[0].equals(STR_INSTALL_DEV_ADDRESS_CMD)) {
780                                 iotinst.installDeviceAddress(args[1]);
781
782                         } else if (args[0].equals(STR_INSTALL_ZB_ADDRESS_CMD)) {
783                                 iotinst.installZigbeeAddress(args[1]);
784
785                         } else if (args[0].equals(STR_INSTALL_HOST_CMD)) {
786                                 iotinst.installHost(args[1]);
787
788                         } else if (args[0].equals(STR_DELETE_ENTITY_CMD)) {
789                                 iotinst.deleteEntity(args[1], args[2], args[3]);
790
791                         } else if (args[0].equals(STR_DELETE_ADDRESS_CMD)) {
792                                 iotinst.deleteAddress(STR_ADDRESS_TABLE_NAME, args[1], args[2]);
793
794                         } else if (args[0].equals(STR_DELETE_DEV_ADD_CMD)) {
795                                 iotinst.deleteAddress(STR_DEV_ADD_TABLE_NAME, args[1], args[2]);
796
797                         } else if (args[0].equals(STR_DELETE_ZB_ADD_CMD)) {
798                                 iotinst.deleteAddress(STR_ZB_ADD_TABLE_NAME, args[1], args[2]);
799
800                         } else if (args[0].equals(STR_DELETE_HOST_CMD)) {
801                                 iotinst.deleteHost(args[1]);
802
803                         } else if (args[0].equals(STR_HELP_CMD)) {
804                                 iotinst.helpMessages();
805
806                         } else {
807                                 System.out.println("IoTInstaller: ERROR: Wrong input parameters!");
808                                 iotinst.helpMessages();
809                         }
810                 } else {
811                         System.out.println("IoTInstaller: ERROR: No input parameters detected!");
812                         iotinst.helpMessages();
813                 }
814         }
815
816
817 }