Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotinstaller / IoTInstaller.java
index a0c8f4d710740b6875f1f3c9cc1c9ed8afc11a4a..e281c9e9ec111a7d2f517708840923e2e56a0570 100644 (file)
@@ -41,6 +41,7 @@ public final class IoTInstaller {
        private static final String STR_INSTALL_DEV_ADDRESS_CMD = "-install_dev_add";
        private static final String STR_INSTALL_ZB_ADDRESS_CMD = "-install_zb_add";
        private static final String STR_INSTALL_HOST_CMD = "-install_host";
+       private static final String STR_DELETE_COMMUNICATION_CMD = "-delete_comm";      
        private static final String STR_DELETE_ENTITY_CMD = "-delete_ent";
        private static final String STR_DELETE_ADDRESS_CMD = "-delete_add";
        private static final String STR_DELETE_DEV_ADD_CMD = "-delete_dev_add";
@@ -97,10 +98,6 @@ public final class IoTInstaller {
 
                // Parse configuration file
                // Assumption here is that .config file is written with the correct syntax (need typechecking)
-               //File file = new File(strCfgFileName);
-               //Scanner scanFile = new Scanner(new FileReader(file));
-               //System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
-
                // Initialize String for ID and TYPE
                String strID = "";
                String strType = "";
@@ -218,7 +215,6 @@ public final class IoTInstaller {
         */
        public void extractTableAndInstall(String strCfgFileName) {
                // TO DO: WE PROBABLY NEED TO IMPROVE THE FILE PARSING BUT FOR NOW KEEP IT MINIMUM
-
                try {
 
                        // Parse configuration file
@@ -320,7 +316,6 @@ public final class IoTInstaller {
 
                                strFields[iFieldCnt++] = scanFile.next();
                        }
-
                        // Create a new installer object
                        tbl.setTableName(STR_COMM_TABLE_NAME);
                        tbl.insertEntry(strFields);
@@ -334,6 +329,22 @@ public final class IoTInstaller {
 
                }
        }
+
+       /**
+        * A method to delete relation/communication information from database
+        *
+        * @param  strEntIDSource       String for entity ID source
+        * @param  strEntIDDest         String for entity ID destination
+        * @return                      void
+        */
+       public void deleteComm(String strEntIDSource, String strEntIDDest) {
+
+               // Delete from table IoTMain
+               tbl.setTableName(STR_COMM_TABLE_NAME);
+               String strWhere = "ID_SOURCE='" + strEntIDSource + "' AND ID_DESTINATION='" + strEntIDDest + "';";
+               tbl.deleteEntry(strWhere);
+               System.out.println("IoTInstaller: Removing relation/communication from table " + STR_COMM_TABLE_NAME);
+       }
        
        /**
         * A method to extract device/entity addresses information
@@ -411,7 +422,6 @@ public final class IoTInstaller {
 
                // Insert new address entry
                tbl.insertEntry(strFieldsAddress);
-
                System.out.println("IoTInstaller: Installing a new device/entity address into the system");
        }
 
@@ -431,7 +441,6 @@ public final class IoTInstaller {
                        File file = new File(strCfgFileName);
                        FileInputStream fis = new FileInputStream(file);
                        System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
-
                        installDeviceAddressCore(fis);
 
                } catch (FileNotFoundException ex) {
@@ -491,7 +500,6 @@ public final class IoTInstaller {
 
                        // Insert new address entry
                        tbl.insertEntry(strFieldsAddress);
-
                        System.out.println("IoTInstaller: Installing a new device/entity address into the system");
 
                } catch (FileNotFoundException ex) {
@@ -551,7 +559,6 @@ public final class IoTInstaller {
 
                        // Insert new address entry
                        tbl.insertEntry(strFieldsAddress);
-
                        System.out.println("IoTInstaller: Installing a new device/entity address into the system");
 
                } catch (FileNotFoundException ex) {
@@ -590,7 +597,6 @@ public final class IoTInstaller {
                        // Create a new installer object
                        tbl.setTableName(STR_HOST_TABLE_NAME);
                        tbl.insertEntry(strFields);
-
                        System.out.println("IoTInstaller: Installing a new host into the system");
 
                } catch (FileNotFoundException ex) {
@@ -612,7 +618,6 @@ public final class IoTInstaller {
                tbl.setTableName(STR_HOST_TABLE_NAME);
                String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
                tbl.deleteEntry(strWhere);
-
                System.out.println("IoTInstaller: Deleting a host from the system");
        }
 
@@ -631,7 +636,6 @@ public final class IoTInstaller {
                String strWhere = "ID='" + strEntID + "';";
                tbl.deleteEntry(strWhere);
                System.out.println("IoTInstaller: Removing entity from table " + STR_MAIN_TABLE_NAME);
-
                // Delete from table with type name, e.g. Camera
                tbl.setTableName(strEntType);
                strWhere = "ID='" + strEntID + "';";
@@ -671,7 +675,6 @@ public final class IoTInstaller {
                tbl.setTableName(strEntAddType + strEntID);
                tbl.dropTable();
                System.out.println("IoTInstaller: Dropping class constructor table...");
-
                System.out.println("IoTInstaller: Deleting an entry from the system...");
        }
 
@@ -711,10 +714,11 @@ public final class IoTInstaller {
                System.out.println("IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>");
                System.out.println("IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>");
                System.out.println("IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>");
-               System.out.println("IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id> <ent_type>");
-               System.out.println("IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id> <ent_type>");
-               System.out.println("IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id> <ent_type>");
-               System.out.println("IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>");
+               System.out.println("IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>");
+               System.out.println("IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id> <ent_type>");
+               System.out.println("IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id> <ent_type>");
+               System.out.println("IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id> <ent_type>");
+               System.out.println("IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>");
                System.out.println("IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.");
                System.out.println();
        }
@@ -736,10 +740,11 @@ public final class IoTInstaller {
                helpTxt = helpTxt + "IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add <filename>\n";
                helpTxt = helpTxt + "IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host <filename>\n";
                helpTxt = helpTxt + "IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent <ent_id> <ent_type> <ent_name>\n";
-               helpTxt = helpTxt + "IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id>\n";
-               helpTxt = helpTxt + "IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>\n";
-               helpTxt = helpTxt + "IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>\n";
-               helpTxt = helpTxt + "IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>\n";
+               helpTxt = helpTxt + "IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm <ent_id_source> <ent_id_dest>\n";
+               helpTxt = helpTxt + "IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add <ent_id>\n";
+               helpTxt = helpTxt + "IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>\n";
+               helpTxt = helpTxt + "IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>\n";
+               helpTxt = helpTxt + "IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host <host_address>\n";
                helpTxt = helpTxt + "IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.\n";
                helpTxt = helpTxt + "\n";
 
@@ -788,6 +793,9 @@ public final class IoTInstaller {
                        } else if (args[0].equals(STR_DELETE_ENTITY_CMD)) {
                                iotinst.deleteEntity(args[1], args[2], args[3]);
 
+                       } else if (args[0].equals(STR_DELETE_COMMUNICATION_CMD)) {
+                               iotinst.deleteComm(args[1], args[2]);
+
                        } else if (args[0].equals(STR_DELETE_ADDRESS_CMD)) {
                                iotinst.deleteAddress(STR_ADDRESS_TABLE_NAME, args[1], args[2]);