import java.sql.*;
import java.util.Scanner;
import java.util.Properties;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
/** A class that creates an object for IoT device/entity installation into database
*
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";
private static final String STR_DELETE_ZB_ADD_CMD = "-delete_zb_add";
private static final String STR_DELETE_HOST_CMD = "-delete_host";
private static final String STR_HELP_CMD = "-help";
+ private static final String DATABASE_GET = "-get";
+ private static final String APPEND_TYPE = "-appendType";
+ private static final String UPDATE_SETLIST = "-updateSetList";
+ private static final String UPDATE_IOTDEVICEADDRESS = "-updateIoTDeviceAddress";
+ private static final String UPDATE_IDSUBTYPE = "-updateIDSubtype";
/**
* Class constructor
tbl.insertEntry(strFlds);
System.out.println("IoTInstaller: Inserting a new entry into main table");
}
+
+ /**
+ * A method to extract device/entity information from the user
+ * <p>
+ * Users are supposed to supply the information needed for installation
+ * This is the core of the operation after getting the Scanner object.
+ *
+ * @param scanFile Scanner object of source
+ * @return void
+ */
+ public void extractTableAndInstallCore(Scanner scanFile) {
+
+ // Parse configuration file
+ // Assumption here is that .config file is written with the correct syntax (need typechecking)
+ // Initialize String for ID and TYPE
+ String strID = "";
+ String strType = "";
+ String strTypeSpecific = "";
+
+ // Initialize TableProperty for devices and specific devices
+ // We have 2 tables,
+ // e.g. ProximitySensor - table of many ProximitySensor devices
+ // ProximitySensorBrandA - table that contains the constructor
+ // information for a specific device
+ TableProperty[] tpDevice = new TableProperty[1];
+ TableProperty[] tpDeviceSpecific = new TableProperty[1];
+
+ // Initialize array of string
+ String[] strFields = new String[1];
+ String[] strFieldsSpecific = new String[1];
+
+ // String for scanning the file
+ String strScan = "";
+
+ // Store number of fields here
+ int iFields = 0;
+ while (scanFile.hasNext()) {
+
+ strScan = scanFile.next();
+ if (strScan.equals("IoTMain")) {
+
+ while (scanFile.hasNext()) {
+ strScan = scanFile.next();
+
+ // Get ID
+ if (strScan.equals("ID")) {
+ strID = scanFile.next();
+ }
+ // Get TYPE
+ else if (strScan.equals("TYPE")) {
+ strType = scanFile.next();
+ }
+ // Get TYPE
+ else if (strScan.equals("TYPESPECIFIC")) {
+ strTypeSpecific = scanFile.next();
+ } else if (strScan.equals("END")) {
+ // Break out of loop
+ break;
+ }
+ }
+ } else if (strScan.equals("Table")) {
+
+ // Get number of fields, e.g. Table 3
+ iFields = scanFile.nextInt();
+
+ // We have device ID and device specific names
+ // e.g. ID = PS1; TYPE
+ tpDevice = new TableProperty[2];
+ tpDevice[0] = new TableProperty();
+ tpDevice[0].setField("ID");
+ tpDevice[0].setType("VARCHAR");
+ tpDevice[0].setLength("5");
+ tpDevice[1] = new TableProperty();
+ tpDevice[1].setField("TYPE");
+ tpDevice[1].setType("VARCHAR");
+ tpDevice[1].setLength("30");
+
+ // Prepare properties for a specific device
+ tpDeviceSpecific = new TableProperty[iFields];
+ for (int i=0; i<iFields; i++) {
+ tpDeviceSpecific[i] = new TableProperty();
+
+ // Looping over the fields
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setField(strScan);
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setType(strScan);
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setLength(strScan);
+ }
+ } else if (strScan.equals("Data")) {
+
+ // Get the device information
+ strFields = new String[2];
+ strFields[0] = strID;
+ strFields[1] = strTypeSpecific;
+
+ if ((tpDeviceSpecific.length == 1) &&
+ (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
+
+ // Get the fields for specific device
+ strFieldsSpecific = null;
+ System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
+
+ } else {
+
+ // Get the fields for specific device
+ strFieldsSpecific = new String[iFields];
+ for (int i=0; i<iFields; i++) {
+ strScan = scanFile.next();
+ strFieldsSpecific[i] = strScan;
+ }
+ }
+ }
+ }
+
+ installNewEntity(strType, strTypeSpecific, strID, tpDevice,
+ tpDeviceSpecific, strFields, strFieldsSpecific);
+ System.out.println("IoTInstaller: Installing a new entity/device into the system");
+ }
/**
* A method to extract device/entity information from the user
*/
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
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 = "";
- String strTypeSpecific = "";
-
- // Initialize TableProperty for devices and specific devices
- // We have 2 tables,
- // e.g. ProximitySensor - table of many ProximitySensor devices
- // ProximitySensorBrandA - table that contains the constructor
- // information for a specific device
- TableProperty[] tpDevice = new TableProperty[1];
- TableProperty[] tpDeviceSpecific = new TableProperty[1];
-
- // Initialize array of string
- String[] strFields = new String[1];
- String[] strFieldsSpecific = new String[1];
-
- // String for scanning the file
- String strScan = "";
-
- // Store number of fields here
- int iFields = 0;
- while (scanFile.hasNext()) {
-
- strScan = scanFile.next();
- if (strScan.equals("IoTMain")) {
-
- while (scanFile.hasNext()) {
- strScan = scanFile.next();
-
- // Get ID
- if (strScan.equals("ID")) {
- strID = scanFile.next();
- }
- // Get TYPE
- else if (strScan.equals("TYPE")) {
- strType = scanFile.next();
- }
- // Get TYPE
- else if (strScan.equals("TYPESPECIFIC")) {
- strTypeSpecific = scanFile.next();
- } else if (strScan.equals("END")) {
- // Break out of loop
- break;
- }
- }
- } else if (strScan.equals("Table")) {
-
- // Get number of fields, e.g. Table 3
- iFields = scanFile.nextInt();
-
- // We have device ID and device specific names
- // e.g. ID = PS1; TYPE
- tpDevice = new TableProperty[2];
- tpDevice[0] = new TableProperty();
- tpDevice[0].setField("ID");
- tpDevice[0].setType("VARCHAR");
- tpDevice[0].setLength("5");
- tpDevice[1] = new TableProperty();
- tpDevice[1].setField("TYPE");
- tpDevice[1].setType("VARCHAR");
- tpDevice[1].setLength("30");
-
- // Prepare properties for a specific device
- tpDeviceSpecific = new TableProperty[iFields];
- for (int i=0; i<iFields; i++) {
- tpDeviceSpecific[i] = new TableProperty();
-
- // Looping over the fields
- strScan = scanFile.next();
- tpDeviceSpecific[i].setField(strScan);
- strScan = scanFile.next();
- tpDeviceSpecific[i].setType(strScan);
- strScan = scanFile.next();
- tpDeviceSpecific[i].setLength(strScan);
- }
- } else if (strScan.equals("Data")) {
-
- // Get the device information
- strFields = new String[2];
- strFields[0] = strID;
- strFields[1] = strTypeSpecific;
-
- if ((tpDeviceSpecific.length == 1) &&
- (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
-
- // Get the fields for specific device
- strFieldsSpecific = null;
- System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
-
- } else {
-
- // Get the fields for specific device
- strFieldsSpecific = new String[iFields];
- for (int i=0; i<iFields; i++) {
- strScan = scanFile.next();
- strFieldsSpecific[i] = strScan;
- }
- }
- }
- }
-
- installNewEntity(strType, strTypeSpecific, strID, tpDevice,
- tpDeviceSpecific, strFields, strFieldsSpecific);
- System.out.println("IoTInstaller: Installing a new entity/device into the system");
+ extractTableAndInstallCore(scanFile);
} catch (FileNotFoundException ex) {
strFields[iFieldCnt++] = scanFile.next();
}
-
// Create a new installer object
tbl.setTableName(STR_COMM_TABLE_NAME);
tbl.insertEntry(strFields);
}
}
+ /**
+ * 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
+ * <p>
+ * Users are supposed to supply the information needed for installation
+ *
+ * @param is InputStream of the input source
+ * @return void
+ */
+ public void installDeviceAddressCore(InputStream is) {
+
+ Properties prop = new Properties();
+ try {
+ prop.load(is);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ // Initialize string
+ // We can only install one device address per one time with the following sequence
+ String[] strFields = new String[2];
+ String[] strFieldsAddress = null;
+ // Check for wildcard feature
+ if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
+ (prop.getProperty("DESTWILDCARD", null) != null)) {
+ strFieldsAddress = new String[5];
+ strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
+ strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
+ } else {
+ strFieldsAddress = new String[3];
+ }
+ strFields[0] = prop.getProperty("ID");
+ strFields[1] = prop.getProperty("ADDRESSFOR");
+ strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
+ strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
+ strFieldsAddress[2] = prop.getProperty("PROTOCOL");
+
+ // Insert this entry into the main device address table
+ tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
+ tbl.insertEntry(strFields);
+
+ // Create a new table for a specific device address
+ // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
+ tbl.setTableName(strFields[1] + strFields[0]);
+
+ // Table does not exist yet
+ // Set TableProperty for device address (MAC address)
+ TableProperty[] tp = null;
+ // Check for wildcard feature
+ if (strFieldsAddress.length == 5) {
+ tp = new TableProperty[5];
+ tp[3] = new TableProperty();
+ tp[3].setField("SOURCEWILDCARD");
+ tp[3].setType("VARCHAR");
+ tp[3].setLength("5");
+ tp[4] = new TableProperty();
+ tp[4].setField("DESTWILDCARD");
+ tp[4].setType("VARCHAR");
+ tp[4].setLength("5");
+ } else {
+ tp = new TableProperty[3];
+ }
+ tp[0] = new TableProperty();
+ tp[0].setField("DEVICEADDRESS");
+ tp[0].setType("VARCHAR");
+ tp[0].setLength("20");
+ tp[1] = new TableProperty();
+ tp[1].setField("PORTNUMBER");
+ tp[1].setType("INT");
+ tp[1].setLength("11");
+ tp[2] = new TableProperty();
+ tp[2].setField("PROTOCOL");
+ tp[2].setType("VARCHAR");
+ tp[2].setLength("5");
+ tbl.createTable(tp, "DEVICEADDRESS");
+
+ // Insert new address entry
+ tbl.insertEntry(strFieldsAddress);
+ System.out.println("IoTInstaller: Installing a new device/entity address into the system");
+ }
+
/**
* A method to extract device/entity addresses information
* <p>
try {
// Parse configuration file
- Properties prop = new Properties();
File file = new File(strCfgFileName);
FileInputStream fis = new FileInputStream(file);
- try {
- prop.load(fis);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
- // Initialize string
- // We can only install one device address per one time with the following sequence
- String[] strFields = new String[2];
- String[] strFieldsAddress = null;
- // Check for wildcard feature
- if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
- (prop.getProperty("DESTWILDCARD", null) != null)) {
- strFieldsAddress = new String[5];
- strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
- strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
- } else {
- strFieldsAddress = new String[3];
- }
- strFields[0] = prop.getProperty("ID");
- strFields[1] = prop.getProperty("ADDRESSFOR");
- strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
- strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
- strFieldsAddress[2] = prop.getProperty("PROTOCOL");
-
- // Insert this entry into the main device address table
- tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
- tbl.insertEntry(strFields);
-
- // Create a new table for a specific device address
- // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
- tbl.setTableName(strFields[1] + strFields[0]);
-
- // Table does not exist yet
- // Set TableProperty for device address (MAC address)
- TableProperty[] tp = null;
- // Check for wildcard feature
- if (strFieldsAddress.length == 5) {
- tp = new TableProperty[5];
- tp[3] = new TableProperty();
- tp[3].setField("SOURCEWILDCARD");
- tp[3].setType("VARCHAR");
- tp[3].setLength("5");
- tp[4] = new TableProperty();
- tp[4].setField("DESTWILDCARD");
- tp[4].setType("VARCHAR");
- tp[4].setLength("5");
- } else {
- tp = new TableProperty[3];
- }
- tp[0] = new TableProperty();
- tp[0].setField("DEVICEADDRESS");
- tp[0].setType("VARCHAR");
- tp[0].setLength("20");
- tp[1] = new TableProperty();
- tp[1].setField("PORTNUMBER");
- tp[1].setType("INT");
- tp[1].setLength("11");
- tp[2] = new TableProperty();
- tp[2].setField("PROTOCOL");
- tp[2].setType("VARCHAR");
- tp[2].setLength("5");
- tbl.createTable(tp, "DEVICEADDRESS");
-
- // Insert new address entry
- tbl.insertEntry(strFieldsAddress);
-
- System.out.println("IoTInstaller: Installing a new device/entity address into the system");
+ installDeviceAddressCore(fis);
} catch (FileNotFoundException ex) {
// Insert new address entry
tbl.insertEntry(strFieldsAddress);
-
System.out.println("IoTInstaller: Installing a new device/entity address into the system");
} catch (FileNotFoundException ex) {
}
}
-
/**
* A method to extract simple addresses information, e.g. www.google.com
* <p>
// Insert new address entry
tbl.insertEntry(strFieldsAddress);
-
System.out.println("IoTInstaller: Installing a new device/entity address into the system");
} catch (FileNotFoundException ex) {
// 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) {
tbl.setTableName(STR_HOST_TABLE_NAME);
String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
tbl.deleteEntry(strWhere);
-
System.out.println("IoTInstaller: Deleting a host from the system");
}
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 + "';";
System.out.println("IoTInstaller: Deleting an entry from the system...");
}
-
+
/**
* A method to delete address information from database
*
tbl.setTableName(strEntAddType + strEntID);
tbl.dropTable();
System.out.println("IoTInstaller: Dropping class constructor table...");
-
System.out.println("IoTInstaller: Deleting an entry from the system...");
}
*
* @return void
*/
- private void helpMessages() {
+ public void helpMessages() {
System.out.println();
System.out.println("IoTInstaller: Command line options:");
System.out.println("IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>");
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>");
- System.out.println("IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add <ent_id>");
- System.out.println("IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add <ent_id>");
- 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();
}
+ /**
+ * A method to output help messages
+ *
+ * @return void
+ */
+ public String helpMessagesString() {
+ String helpTxt = "\n";
+ helpTxt = helpTxt + "IoTInstaller: Command line options:\n";
+ helpTxt = helpTxt + "IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent <filename>\n";
+ helpTxt = helpTxt + "IoTInstaller: 2) Install comm pattern, e.g. java iotinstaller.IoTInstaller -install_comm <filename>\n";
+ helpTxt = helpTxt + "IoTInstaller: 3) Install two devices and comm pattern, e.g. java iotinstaller.IoTInstaller ";
+ helpTxt = helpTxt + "-install_comp <first_entity_filename> <second_entity_filename> <communication_filename>\n";
+ helpTxt = helpTxt + "IoTInstaller: 4) Install address, e.g. java iotinstaller.IoTInstaller -install_add <filename>\n";
+ helpTxt = helpTxt + "IoTInstaller: 5) Install device address, e.g. java iotinstaller.IoTInstaller -install_dev_add <filename>\n";
+ 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 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";
+
+ return helpTxt;
+ }
+
+ /**
+ * Kevin's Code
+ * @author Kevin Truong<kctruon1@uci.edu>
+ * */
+
+ public static void formatWrite(String string, HashMap<String, ArrayList<HashSet<String>>> hashMap, HashMap<String, HashSet<String>> hashMap2, HashMap<String, String> hashMap3) throws IOException {
+ BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(string));
+
+ for (String string2 : hashMap2.keySet()) {
+ bufferedWriter.write("Type: \n");
+ bufferedWriter.write(string2 + '\n');
+ bufferedWriter.write("TAG: \n");
+ int n = 0;
+ for (String string3 : hashMap2.get(string2)) {
+ String string4 = hashMap3.get(string3);
+ if (string4 != null && n == 0) {
+ string4 = string4.substring(0, 2);
+ bufferedWriter.write(string4 + '\n');
+ } else if (string4 == null && n == 0) {
+ bufferedWriter.write(string4 + '\n');
+ }
+ ++n;
+ bufferedWriter.write("Subtype: \n");
+ bufferedWriter.write(string3 + '\n');
+ for (int i = 0; i < hashMap.get(string3).size(); ++i) {
+ if (i == 0) {
+ bufferedWriter.write("AddressInfo:\n");
+ for (String string5 : hashMap.get(string3).get(0)) {
+ bufferedWriter.write(string5 + '\n');
+ }
+ continue;
+ }
+ bufferedWriter.write("DeviceInfo:\n");
+ for (String string5 : hashMap.get(string3).get(1)) {
+ bufferedWriter.write(string5 + '\n');
+ }
+ }
+ }
+ bufferedWriter.write("endType \n\n");
+ }
+ bufferedWriter.close();
+ }
+
+ public static void actualDeviceInfoWrite(ArrayList<String[][]> arrayList, String string) throws IOException {
+ BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(string));
+ for (String[][] arrstring : arrayList) {
+ for (int i = 0; i < arrstring.length; ++i) {
+ bufferedWriter.write(arrstring[i][1] + " " + arrstring[i][0] + '\n');
+ }
+ bufferedWriter.newLine();
+ }
+ bufferedWriter.close();
+ }
+
+ public static void configSetWrite(String string, ArrayList<String[][]> arrayList, HashMap<String, HashSet<String>> hashMap) throws IOException {
+ BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(string));
+ for (String string2 : hashMap.keySet()) {
+ boolean bl = false;
+ bufferedWriter.write("START\n" + string2 + "\n");
+ block1 : for (String string3 : hashMap.get(string2)) {
+ for (String[][] arrstring : arrayList) {
+ if (!string3.equals(arrstring[0][1])) continue;
+ for (int i = 0; i < arrstring.length; ++i) {
+ bufferedWriter.write(arrstring[i][1] + " " + arrstring[i][0] + '\n');
+ }
+ continue block1;
+ }
+ }
+ bufferedWriter.write("END\n\n");
+ }
+ bufferedWriter.close();
+ }
+
+ public static HashMap<String, Integer> getNumAddresses(HashSet<String> hashSet) {
+ HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
+ Properties properties = new Properties();
+ for (String string : hashSet) {
+ String string2 = "../SupportedDevices/AddressInformation/" + string + ".config";
+ try {
+ properties.load(new FileInputStream(string2));
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ int n = Integer.parseInt(properties.getProperty("ADDRESSES"));
+ hashMap.put(string, n);
+ }
+ return hashMap;
+ }
+
+ public static HashMap<String, Integer> getZBAddresses(HashSet<String> hashSet) {
+ HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
+ Properties properties = new Properties();
+ for (String string : hashSet) {
+ String string2 = "../SupportedDevices/AddressInformation/" + string + ".config";
+ try {
+ properties.load(new FileInputStream(string2));
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ int n = Integer.parseInt(properties.getProperty("ZBADDRESSES"));
+ hashMap.put(string, n);
+ }
+ return hashMap;
+ }
+
+ public static void appendToFile(String string, String string2) {
+ try {
+ FileWriter fileWriter = new FileWriter(string2, true);
+ BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
+ PrintWriter printWriter = new PrintWriter(bufferedWriter);
+ printWriter.print(string);
+ printWriter.close();
+ bufferedWriter.close();
+ fileWriter.close();
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ }
+
+ public static void overrideFileWrite(String string, String string2) {
+ try {
+ BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(string2));
+ bufferedWriter.write(string);
+ bufferedWriter.close();
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ }
+
+ public static void formatForMultipleAddresses(String string, int n, int n2, int n3, HashMap<String, ArrayList<HashSet<String>>> hashMap, Properties properties, int n4, String string2) {
+ string = string + "TYPE_" + n + "_" + n2 + "_ADDRESS_FIELDS=";
+ n4 = 0;
+ for (int i = 0; i < n3; ++i) {
+ String string3 = new String();
+ for (String string4 : hashMap.get(string2).get(0)) {
+ if (n4 == 0) {
+ string = string + string4 + " ";
+ }
+ string3 = string3 + string4 + "_" + n + "_" + n2 + "_ADD_" + i + "=" + properties.getProperty(new StringBuilder().append(string4).append("_").append(i + 1).toString()) + "\n";
+ }
+ if (n4 == 0) {
+ string = string + "\n";
+ }
+ string = string + string3;
+ ++n4;
+ }
+ }
+
+ public static void getAddressInfo(String string, HashMap<String, ArrayList<HashSet<String>>> hashMap, HashMap<String, String> hashMap2, HashMap<String, HashSet<String>> hashMap3) {
+ Properties properties = new Properties();
+ int n = 0;
+ Set set = new HashSet();
+ set = hashMap3.keySet();
+ IoTInstaller.overrideFileWrite((String)("NUM_OF_TYPES=" + set.size() + "\n\n"), (String)string);
+ for (String string2 : hashMap3.keySet()) {
+ int n2 = 0;
+ int n3 = 0;
+ String string3 = new String();
+ string3 = string3 + "TYPE_" + n + "=" + string2 + "\n";
+ for (String string4 : hashMap3.get(string2)) {
+ int n4;
+ String string5;
+ String string6 = "../SupportedDevices/AddressInformation/" + string4 + ".config";
+ try {
+ properties.load(new FileInputStream(string6));
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ if (n3 == 0) {
+ string3 = string3 + "TAG_" + n + "=" + hashMap2.get(string4).substring(0, 2) + "\n";
+ string3 = string3 + "SUBTYPE_" + n + "=" + hashMap3.get(string2).size() + "\n";
+ ++n3;
+ }
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "=" + string4 + "\n";
+ int n5 = Integer.parseInt(properties.getProperty("ADDRESSES"));
+ int n6 = Integer.parseInt(properties.getProperty("ZBADDRESSES"));
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_NUM_OF_ZBADDRESSES=" + n6 + "\n";
+ if (n6 != 0) {
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_ZBADDRESS_FIELDS=";
+ n3 = 0;
+ for (n4 = 0; n4 < n6; ++n4) {
+ string5 = new String();
+ for (String string7 : hashMap.get(string4).get(2)) {
+ if (n3 == 0) {
+ string3 = string3 + string7 + " ";
+ }
+ string5 = string5 + "ZB" + string7 + "_" + n + "_" + n2 + "_ZBADD_" + n4 + "=" + properties.getProperty(new StringBuilder().append(string7).append("_").append(n4 + 1).toString()) + "\n";
+ }
+ if (n3 == 0) {
+ string3 = string3 + "\n";
+ }
+ string3 = string3 + string5;
+ ++n3;
+ }
+ }
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_NUM_OF_ADDRESSES=" + n5 + "\n";
+ if (n5 != 0) {
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_ADDRESS_FIELDS=";
+ n3 = 0;
+ for (n4 = 0; n4 < n5; ++n4) {
+ string5 = new String();
+ for (String string7 : hashMap.get(string4).get(0)) {
+ if (n3 == 0) {
+ string3 = string3 + string7 + " ";
+ }
+ string5 = string5 + string7 + "_" + n + "_" + n2 + "_ADD_" + n4 + "=" + properties.getProperty(new StringBuilder().append(string7).append("_").append(n4 + 1).toString()) + "\n";
+ }
+ if (n3 == 0) {
+ string3 = string3 + "\n";
+ }
+ string3 = string3 + string5;
+ ++n3;
+ }
+ }
+ n4 = Integer.parseInt(properties.getProperty("DEVICEINFO"));
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_NUM_OF_DEVICE_INFO=" + n4 + "\n";
+ if (n4 > 0) {
+ string5 = new String();
+ n3 = 0;
+ for (String string7 : hashMap.get(string4).get(1)) {
+ if (string7.length() > 0) {
+ if (n3 == 0) {
+ string3 = string3 + "TYPE_" + n + "_" + n2 + "_DEVICE_FIELDS=";
+ }
+ string3 = string3 + string7 + " ";
+ string5 = string5 + string7 + "_" + n + "_" + n2 + "=USER\n";
+ }
+ ++n3;
+ }
+ string3 = string3 + "\n";
+ ++n3;
+ string3 = string3 + string5;
+ }
+ ++n2;
+ }
+ string3 = string3 + "\n";
+ ++n;
+ IoTInstaller.appendToFile((String)string3, (String)string);
+ }
+ }
+
+ void getIoTDeviceAddressInfoAndOutput(HashMap<String, HashSet<String>> hashMap) {
+ int n;
+ Table table = new Table("IoTDeviceAddress", false);
+ String[][] arrstring = table.getGeneralDBTable();
+ String string = new String();
+ string = string + "START\n";
+ string = string + "IoTDeviceAddress\n";
+ for (n = 0; n < arrstring.length; ++n) {
+ string = string + arrstring[n][1] + " " + arrstring[n][0] + "\n";
+ }
+ string = string + "END\n\n";
+ IoTInstaller.overrideFileWrite((String)string, (String)"IoTDeviceAddress.config");
+ table = new Table("IoTZigbeeAddress", false);
+ arrstring = table.getGeneralDBTable();
+ string = new String();
+ string = string + "START\n";
+ string = string + "IoTZigbeeAddress\n";
+ for (n = 0; n < arrstring.length; ++n) {
+ string = string + arrstring[n][1] + " " + arrstring[n][0] + "\n";
+ }
+ string = string + "END\n\n";
+ IoTInstaller.appendToFile((String)string, (String)"IoTDeviceAddress.config");
+ }
+
+ public void getInformationFromDatabase(String string) {
+ Scanner scanner;
+ System.out.println("Initializing -get...");
+ ArrayList<String> arrayList = new ArrayList<String>();
+ ArrayList<String[][]> arrayList2 = new ArrayList<String[][]>();
+ String string2 = new String("AddressInformation.config");
+ String string3 = new String("SetList.config");
+ String string4 = new String("DatabaseInformation.config");
+ String string5 = new String("IDSubtypeInformation.config");
+ HashMap<String, HashSet<String>> hashMap = new HashMap<String, HashSet<String>>();
+ HashMap<String, ArrayList<HashSet<String>>> hashMap2 = new HashMap<String, ArrayList<HashSet<String>>>();
+ HashMap<String, String> hashMap3 = new HashMap<String, String>();
+ try {
+ File file = new File(string);
+ InputStream IS = new FileInputStream(file);
+ scanner = new Scanner(IS);
+ while (scanner.hasNext()) {
+ arrayList.add(scanner.next());
+ }
+ }
+ catch (FileNotFoundException fileNotFoundException) {
+ System.out.print("File Error: ");
+ fileNotFoundException.printStackTrace();
+ }
+
+ for (int i = 0; i < arrayList.size(); ++i) {
+ HashSet<String> object = new HashSet<String>();
+ Table tbl = new Table(arrayList.get(i), false);
+ String[][] arrstring = tbl.getGeneralDBTable();
+ arrayList2.add(arrstring);
+ object.clear();
+ for (int j = 0; j < arrstring.length; ++j) {
+ object.add(arrstring[j][1]);
+ }
+ hashMap.putIfAbsent(arrayList.get(i), object);
+ HashMap<String, Integer> hashMap4 = IoTInstaller.getNumAddresses(object);
+ HashMap<String, Integer> hashMap5 = IoTInstaller.getZBAddresses(object);
+ for(String x : object){
+ ArrayList<HashSet<String>> arrayList3 = new ArrayList<HashSet<String>>();
+ for (int j = 0; j < arrstring.length; ++j) {
+ if (!x.equals(arrstring[j][1])) continue;
+ hashMap3.putIfAbsent(x, arrstring[j][0]);
+ }
+ arrayList3.clear();
+ if (hashMap4.get(x) > 1) {
+ tbl.setTableName(x + "Add1" + hashMap3.get(x));
+ if (tbl.isTableExisting()) {
+ tbl = new Table(x + "Add1" + hashMap3.get(x), false);
+ arrayList3.add(tbl.getColumnNames());
+ } else {
+ arrayList3.add(new HashSet<String>());
+ }
+ hashMap2.putIfAbsent(x, arrayList3);
+ } else {
+ tbl.setTableName(x + "Add" + hashMap3.get(x));
+ if (tbl.isTableExisting()) {
+ tbl = new Table(x + "Add" + hashMap3.get(x), false);
+ arrayList3.add(tbl.getColumnNames());
+ } else {
+ arrayList3.add(new HashSet<String>());
+ }
+ }
+ tbl.setTableName(x + hashMap3.get(x));
+
+ if (tbl.isTableExisting()) {
+ tbl = new Table(x + hashMap3.get(x), false);
+ arrayList3.add(tbl.getColumnNames());
+ } else {
+ arrayList3.add(new HashSet<String>());
+ }
+ if (hashMap5.get(x) != 0) {
+ tbl.setTableName(x + "ZBAdd" + hashMap3.get(x));
+ if (tbl.isTableExisting()) {
+ tbl = new Table(x + "ZBAdd" + hashMap3.get(x), false);
+ arrayList3.add(tbl.getColumnNames());
+ } else {
+ arrayList3.add(new HashSet<String>());
+ }
+ } else {
+ arrayList3.add(new HashSet<String>());
+ }
+ hashMap2.putIfAbsent(x, arrayList3);
+ }
+ }
+ IoTInstaller.getAddressInfo((String)string2, hashMap2, hashMap3, hashMap);
+ this.getIoTDeviceAddressInfoAndOutput(hashMap);
+ try {
+ IoTInstaller.actualDeviceInfoWrite(arrayList2, (String)string5);
+ IoTInstaller.configSetWrite((String)string3, arrayList2, hashMap);
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ System.out.println("Done Executing -get");
+ }
+
+ public void addNewType(String string) {
+ System.out.println("Initializing -appendType...");
+ IoTInstaller.appendToFile((String)string, (String)"AllDevices.config");
+ System.out.println("Done Executing -appendType");
+ }
+
+ public void updateSetList(String string) {
+ Scanner scanner;
+ Table tbl;
+ System.out.println("Updating SetList...");
+ String string2 = new String("SetList.config");
+ ArrayList<String> arrayList = new ArrayList<String>();
+ ArrayList<String[][]> arrayList2 = new ArrayList<String[][]>();
+ HashMap<String, HashSet<String>> hashMap = new HashMap<String, HashSet<String>>();
+ try {
+ File file = new File(string);
+ InputStream IS = new FileInputStream(file);
+ scanner = new Scanner(IS);
+ while (scanner.hasNext()) {
+ arrayList.add(scanner.next());
+ }
+ }
+ catch (FileNotFoundException fileNotFoundException) {
+ System.out.print("File Error: ");
+ fileNotFoundException.printStackTrace();
+ }
+ for (int i = 0; i < arrayList.size(); ++i) {
+ HashSet<String> object = new HashSet<String>();
+ tbl = new Table(arrayList.get(i), false);
+ String[][] arrstring = tbl.getGeneralDBTable();
+ arrayList2.add(arrstring);
+ object.clear();
+ for (int j = 0; j < arrstring.length; ++j) {
+ object.add(arrstring[j][1]);
+ }
+ hashMap.putIfAbsent(arrayList.get(i), object);
+ }
+
+ try {
+ IoTInstaller.configSetWrite((String)string2, arrayList2, hashMap);
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ System.out.println("Done Updating Setlist!");
+ }
+
+ public void updateIoTDeviceAddress(String string) {
+ Scanner scanner;
+ Table tbl;
+ System.out.println("Updating IoTDeviceAddress...");
+ String string2 = new String("IoTDeviceAddress.config");
+ ArrayList<String> arrayList = new ArrayList<String>(); // Holds types
+ ArrayList<String[][]> arrayList2 = new ArrayList<String[][]>();
+ HashMap<String, HashSet<String>> hashMap = new HashMap<String, HashSet<String>>();
+ try {
+ File file = new File(string);
+ InputStream IS = new FileInputStream(file);
+ scanner = new Scanner(IS);
+ while (scanner.hasNext()) {
+ arrayList.add(scanner.next());
+ }
+ }
+ catch (FileNotFoundException fileNotFoundException) {
+ System.out.print("File Error: ");
+ fileNotFoundException.printStackTrace();
+ }
+ for (int i = 0; i < arrayList.size(); ++i) {
+ HashSet<String> object = new HashSet<String>();
+ tbl = new Table(arrayList.get(i), false);
+ String[][] arrstring = tbl.getGeneralDBTable();
+ arrayList2.add(arrstring);
+ object.clear();
+ for (int j = 0; j < arrstring.length; ++j) {
+ object.add(arrstring[j][1]);
+ }
+ hashMap.putIfAbsent(arrayList.get(i), object);
+ }
+
+ this.getIoTDeviceAddressInfoAndOutput(hashMap);
+
+ System.out.println("Done Updating IoTDeviceAddress!");
+ }
+
+ public void updateIDSub(String string) {
+ FileInputStream fileInputStream;
+ String[][] arrstring;
+ Scanner scanner;
+ Table tbl;
+ System.out.println("Updating IDSubtype.config...");
+ ArrayList<String> arrayList = new ArrayList<String>();
+ ArrayList<String[][]> arrayList2 = new ArrayList<String[][]>();
+ try {
+ File file = new File(string);
+ InputStream IS = new FileInputStream(file);
+ scanner = new Scanner(IS);
+ while (scanner.hasNext()) {
+ arrayList.add(scanner.next());
+ }
+ }
+ catch (FileNotFoundException fileNotFoundException) {
+ System.out.print("File Error: ");
+ fileNotFoundException.printStackTrace();
+ }
+ for (int i = 0; i < arrayList.size(); ++i) {
+ tbl = new Table((String)arrayList.get(i), false);
+ arrstring = tbl.getGeneralDBTable();
+ arrayList2.add(arrstring);
+ }
+
+ try {
+ IoTInstaller.actualDeviceInfoWrite(arrayList2, (String)"IDSubtypeInformation.config");
+ }
+ catch (IOException iOException) {
+ iOException.printStackTrace();
+ }
+ System.out.println("Done Updating!");
+ }
+
+ // End of Kevin's code
+
/**
* Main method that accepts inputs for installation
*
} 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]);
} else if (args[0].equals(STR_HELP_CMD)) {
iotinst.helpMessages();
+ } else if (args[0].equals("-get")) {
+ iotinst.getInformationFromDatabase("../SupportedDevices/"+args[1]);
+
+ } else if (args[0].equals("-appendType")) {
+ iotinst.addNewType("../SupportedDevices/"+args[1]);
+
+ } else if (args[0].equals("-updateIoTDeviceAddress")) {
+ iotinst.updateIoTDeviceAddress("../SupportedDevices/"+args[1]);
+
+ } else if (args[0].equals("-updateSetList")) {
+ iotinst.updateSetList("../SupportedDevices/"+args[1]);
+
+ } else if (args[0].equals("-updateIDSubtype")) {
+ iotinst.updateIDSub("../SupportedDevices/"+args[1]);
+
} else {
System.out.println("IoTInstaller: ERROR: Wrong input parameters!");
iotinst.helpMessages();
+
}
} else {
System.out.println("IoTInstaller: ERROR: No input parameters detected!");
iotinst.helpMessages();
}
}
-
-
}