From: rtrimana Date: Mon, 2 Oct 2017 18:05:05 +0000 (-0700) Subject: Adding delete relation/communication feature X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5ef9055d86f42777e8a841a9b306e2683c04069d;p=iot2.git Adding delete relation/communication feature --- diff --git a/iotjava/iotinstaller/IoTInstaller.java b/iotjava/iotinstaller/IoTInstaller.java index a0c8f4d..7a93963 100644 --- a/iotjava/iotinstaller/IoTInstaller.java +++ b/iotjava/iotinstaller/IoTInstaller.java @@ -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"; @@ -334,6 +335,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 @@ -711,10 +728,11 @@ public final class IoTInstaller { System.out.println("IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add "); System.out.println("IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host "); System.out.println("IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent "); - System.out.println("IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add "); - System.out.println("IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add "); - System.out.println("IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add "); - System.out.println("IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host "); + System.out.println("IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm "); + System.out.println("IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add "); + System.out.println("IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add "); + System.out.println("IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add "); + System.out.println("IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host "); System.out.println("IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help."); System.out.println(); } @@ -736,10 +754,11 @@ public final class IoTInstaller { helpTxt = helpTxt + "IoTInstaller: 6) Install zigbee device address, e.g. java iotinstaller.IoTInstaller -install_zb_add \n"; helpTxt = helpTxt + "IoTInstaller: 7) Install host, e.g. java iotinstaller.IoTInstaller -install_host \n"; helpTxt = helpTxt + "IoTInstaller: 8) Delete entity, e.g. java iotinstaller.IoTInstaller -delete_ent \n"; - helpTxt = helpTxt + "IoTInstaller: 9) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add \n"; - helpTxt = helpTxt + "IoTInstaller: 10) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add \n"; - helpTxt = helpTxt + "IoTInstaller: 11) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add \n"; - helpTxt = helpTxt + "IoTInstaller: 12) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host \n"; + helpTxt = helpTxt + "IoTInstaller: 9) Delete comm pattern, e.g. java iotinstaller.IoTInstaller -delete_comm \n"; + helpTxt = helpTxt + "IoTInstaller: 10) Delete address, e.g. java iotinstaller.IoTInstaller -delete_add \n"; + helpTxt = helpTxt + "IoTInstaller: 11) Delete device address, e.g. java iotinstaller.IoTInstaller -delete_dev_add \n"; + helpTxt = helpTxt + "IoTInstaller: 12) Delete zigbee device address, e.g. java iotinstaller.IoTInstaller -delete_zb_add \n"; + helpTxt = helpTxt + "IoTInstaller: 13) Delete host, e.g. java iotinstaller.IoTInstaller -delete_host \n"; helpTxt = helpTxt + "IoTInstaller: Type 'java iotinstaller.IoTInstaller -help' to display this help.\n"; helpTxt = helpTxt + "\n"; @@ -788,6 +807,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]); diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin index 466d723..b3625fe 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin index 1d63b58..15c118b 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin index 97f0849..331ee73 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin and b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock index b6450aa..bc35d02 100644 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock and b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin index ecaaa6c..7034f06 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock index f864e15..3ede7c9 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock index bba075a..24c9e46 100644 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock and b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock differ diff --git a/others/lede-gui/.idea/misc.xml b/others/lede-gui/.idea/misc.xml index 7e15d9d..b0a270f 100644 --- a/others/lede-gui/.idea/misc.xml +++ b/others/lede-gui/.idea/misc.xml @@ -27,7 +27,7 @@ - + diff --git a/others/lede-gui/.idea/workspace.xml b/others/lede-gui/.idea/workspace.xml index 49130a1..638cb81 100644 --- a/others/lede-gui/.idea/workspace.xml +++ b/others/lede-gui/.idea/workspace.xml @@ -47,69 +47,83 @@ - + - - - + + + + + - - - - - + + + + + + + + - - + + - - - + + + + + - - + + - - + + - - - - - + + + + + + + + + - - - - - - + + - - + + + + + + + + + @@ -1188,16 +1202,18 @@ @@ -1232,12 +1248,7 @@ - - - - - @@ -1404,6 +1415,11 @@ + + + + + @@ -2024,22 +2040,24 @@ - + - + - + + - + + @@ -2053,8 +2071,6 @@ - - @@ -2078,9 +2094,6 @@ - - - @@ -2148,16 +2161,6 @@ - - - - - - - - - - @@ -2183,17 +2186,6 @@ - - - - - - - - - - - @@ -2212,16 +2204,6 @@ - - - - - - - - - - @@ -2244,33 +2226,51 @@ - + - - + + + + + + + + + - + - - - - + + + + + + + + + + + - + - - - - + + + + + + + + @@ -2280,72 +2280,94 @@ - + - - + + - - - - + + + + + + + + - + - - - - - + + + + + + - + - + + - + - - + + - + + + + + + + + + - + - - + + - + + + + - - + + - - + + + + + + + - + - - + + @@ -2355,11 +2377,31 @@ - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/others/lede-gui/lede-gui.iml b/others/lede-gui/lede-gui.iml index 6d95a2e..dcd85f5 100644 --- a/others/lede-gui/lede-gui.iml +++ b/others/lede-gui/lede-gui.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,14 +69,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/others/lede-gui/src/main/AndroidManifest.xml b/others/lede-gui/src/main/AndroidManifest.xml index 57ca44d..c51ae23 100644 --- a/others/lede-gui/src/main/AndroidManifest.xml +++ b/others/lede-gui/src/main/AndroidManifest.xml @@ -30,8 +30,8 @@ android:label="@string/title_activity_delete_device" android:theme="@style/AppTheme.NoActionBar" /> diff --git a/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java b/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java deleted file mode 100644 index da54025..0000000 --- a/others/lede-gui/src/main/java/com/example/lede2/AddRelationActivity.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.lede2; - -import android.content.Context; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -import java.io.IOException; -import java.io.InputStream; - -public class AddRelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { - - Button doneButton; - TextView databaseInfo; - private SSH_MySQL ssh;//Connection object between Android & Host - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_add_relation); - - doneButton = (Button) findViewById(R.id.doneButton); - databaseInfo = (EditText)findViewById(R.id.textInfoComm); - - doneButton.setOnClickListener(this); - databaseInfo.setOnFocusChangeListener(this); - ssh = new SSH_MySQL(); - // Set config text from file for device - try { - InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_COMM_FILE); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - String text = new String(buffer); - databaseInfo.setGravity(Gravity.LEFT); - databaseInfo.setText(text); - Log.d("LOADINGFILE", "Add comm info file is already loaded!"); - } catch (IOException ex) { - Log.d("LOADINGFILE", "Add comm info file is NOT loaded!"); - ex.printStackTrace(); - } - } - - @Override - public void onClick(View v) { - if(v == doneButton){ - // 1) Create a new file and insert the configuration - // 2) Run iotinstaller code for communication/relation installation - // 3) Remove the existing config file - ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + - MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); - finish(); - } - } - - @Override - public void onFocusChange(View view, boolean hasFocus) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } else { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } - -} diff --git a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java index 7374bf1..d5dc4a5 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java @@ -43,6 +43,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe protected static String DEF_INSTALL_ADDRESS_CMD; protected static String DEF_DELETE_ADDRESS_CMD; protected static String DEF_INSTALL_RELATION_CMD; + protected static String DEF_DELETE_RELATION_CMD; @Override protected void onCreate(Bundle savedInstanceState) { @@ -54,7 +55,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe insertDBButton = (Button) findViewById(R.id.insert_db); deleteDBButton = (Button) findViewById(R.id.delete_db); configButton = (Button) findViewById(R.id.config); - relationButton = (Button) findViewById(R.id.add_comm); + relationButton = (Button) findViewById(R.id.add_del_comm); ssid = (TextView)findViewById(R.id.device_subtype); registerButton.setOnClickListener(this); @@ -85,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe DEF_INSTALL_ADDRESS_CMD = context.getResources().getString(R.string.install_address_cmd); DEF_DELETE_ADDRESS_CMD = context.getResources().getString(R.string.delete_address_cmd); DEF_INSTALL_RELATION_CMD = context.getResources().getString(R.string.add_comm_cmd); + DEF_DELETE_RELATION_CMD = context.getResources().getString(R.string.delete_comm_cmd); ssid.setText(DEF_RSSID); } @@ -117,7 +119,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe startActivity(new Intent(this, DeleteDeviceActivity.class)); } else if (v == relationButton) { Log.d("CLICKING", "Clicking on add communication!"); - startActivity(new Intent(this, AddRelationActivity.class)); + startActivity(new Intent(this, RelationActivity.class)); } } } diff --git a/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java b/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java new file mode 100644 index 0000000..a87b490 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java @@ -0,0 +1,89 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; + +import java.io.IOException; +import java.io.InputStream; + +public class RelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + Button addButton; + Button deleteButton; + EditText databaseInfo; + EditText idSource; + EditText idDestination; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_relation); + + addButton = (Button) findViewById(R.id.addButton); + deleteButton = (Button) findViewById(R.id.delButton); + databaseInfo = (EditText)findViewById(R.id.textInfoComm); + idSource = (EditText)findViewById(R.id.id_source); + idDestination = (EditText)findViewById(R.id.id_destination); + + addButton.setOnClickListener(this); + deleteButton.setOnClickListener(this); + databaseInfo.setOnFocusChangeListener(this); + idSource.setOnFocusChangeListener(this); + idDestination.setOnFocusChangeListener(this); + ssh = new SSH_MySQL(); + // Set config text from file for device + try { + InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_COMM_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + String text = new String(buffer); + databaseInfo.setGravity(Gravity.LEFT); + databaseInfo.setText(text); + Log.d("LOADINGFILE", "Add comm info file is already loaded!"); + } catch (IOException ex) { + Log.d("LOADINGFILE", "Add comm info file is NOT loaded!"); + ex.printStackTrace(); + } + } + + @Override + public void onClick(View v) { + if(v == addButton){ + // 1) Create a new file and insert the configuration + // 2) Run iotinstaller code for communication/relation installation + // 3) Remove the existing config file + ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); + finish(); + } + if(v == deleteButton){ + // Delete a communication/relation entry + ssh.execute(MainActivity.DEF_DELETE_RELATION_CMD + " " + idSource.getText().toString() + + " " + idDestination.getText().toString()); + finish(); + } + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + +} diff --git a/others/lede-gui/src/main/res/layout/activity_add_relation.xml b/others/lede-gui/src/main/res/layout/activity_add_relation.xml deleted file mode 100644 index 8454deb..0000000 --- a/others/lede-gui/src/main/res/layout/activity_add_relation.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - -