Skip to content

Commit 15269a1

Browse files
committed
added new CMD and PARAMETERS (Mesh-Node stuff) and smaller things
1 parent 0545720 commit 15269a1

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

src/main/java/net/b07z/sepia/server/core/assistant/CMD.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class CMD {
3434
final public static String LISTS = "lists"; //parameters: type, action, info
3535
final public static String LOCATION = "location"; //parameters: search, poi (like italian restaurant, supermarket etc. ...)
3636
final public static String MATCH = "match"; //parameters: info
37+
final public static String MESH_NODE_PLUGIN = "mesh_node_plugin"; //parameters: node_url, node_plugin_name, node_plugin_data, reply_success, reply_fail
3738
final public static String MOBILITY = "mobility"; //parameters: location_start, location_end, type, time
3839
final public static String MOVIES = "movies"; //parameters: search, type (genre), info (actor,director)
3940
final public static String MUSIC = "music"; //parameters: search, type (genre), info (artist?)

src/main/java/net/b07z/sepia/server/core/assistant/PARAMETERS.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,17 @@ public class PARAMETERS {
104104
final public static String LIST_TYPE = "list_type"; //type of list (e.g. shopping, todo, ...)
105105
final public static String LIST_SUBTYPE = "list_subtype"; //sub-type aka name of list (e.g. my great ..., my macys ...)
106106

107+
//MESH NODE PLUGIN
108+
final public static String MESH_NODE_URL = "node_url"; //URL to mesh node
109+
final public static String MESH_NODE_PLUGIN_NAME = "node_plugin_name"; //name of mesh node plugin
110+
final public static String MESH_NODE_PLUGIN_DATA = "node_plugin_data"; //data (e.g. as JSON string) for node plugin
111+
107112
//------------ control parameters -------------
108113

109114
//CHATS and QUESTIONS
110-
final public static String REPLY = "reply"; //a reply the assistant should give submitted as parameter from client
115+
final public static String REPLY = "reply"; //a reply the assistant should give submitted as parameter from client (for certain services that use it)
116+
final public static String REPLY_SUCCESS = "reply_success"; //a reply used for success (for certain services that use it)
117+
final public static String REPLY_FAIL = "reply_fail"; //a reply used for fail (for certain services that use it)
111118
final public static String ANY_ANSWER = "any_answer"; //if you don't have a particular parameter that is missing but you ask a previously undefined question you can store the answer here. Maybe add dialog_state to it.
112119

113120
//CUSTOM SERVICES (do we still need this?)

src/main/java/net/b07z/sepia/server/core/tools/FilesAndStreams.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ public static List<String> getLinesFromStream(InputStream stream, Charset charse
102102
}
103103

104104
/**
105-
* Get an ArrayList of "File"s from a directory path.
105+
* Get an List of "File"s from a directory path.
106106
* @param directoryName - path to directory
107-
* @param files - ArrayList of files to populate (or null -> creates ArrayList)
107+
* @param files - List of files to populate (or null -> creates ArrayList)
108108
* @param doSubfolders - include sub-folders?
109109
* @return list or null
110110
*/
@@ -114,23 +114,68 @@ public static List<File> directoryToFileList(String directoryName, List<File> fi
114114
files = new ArrayList<>();
115115
}
116116

117-
// get all the files from a directory
117+
//get all the files from a directory
118118
File[] fList = directory.listFiles();
119119
if (fList == null){
120120
return null;
121121
}
122122
//System.out.println(directory.list().length); //debug
123-
for (File file : fList) {
124-
if (file.isFile()) {
123+
for (File file : fList){
124+
if (file.isFile()){
125125
files.add(file);
126126
//System.out.println(file.toString()); //debug
127-
} else if (file.isDirectory() & doSubfolders) {
127+
}else if (file.isDirectory() & doSubfolders){
128128
//listAllFiles(file.getAbsolutePath(), files, doSubfolders);
129129
directoryToFileList(file.getPath(), files, doSubfolders);
130130
}
131131
}
132132
return files;
133133
}
134+
/**
135+
* Get an List of directories at path. Will skip files.
136+
* @param path - path to search for directories
137+
* @param directories - List of files to populate (or null -> creates ArrayList)
138+
* @return list or null
139+
*/
140+
public static List<File> getDirectoriesAtPath(String path, List<File> directories) {
141+
File directory = new File(path);
142+
if (directories == null){
143+
directories = new ArrayList<>();
144+
}
145+
146+
//get everything at path
147+
File[] fList = directory.listFiles();
148+
if (fList == null){
149+
return null;
150+
}
151+
//System.out.println(directory.list().length); //debug
152+
for (File file : fList){
153+
if (!file.isFile()){
154+
directories.add(file);
155+
//System.out.println(file.toString()); //debug
156+
}
157+
}
158+
return directories;
159+
}
160+
161+
/**
162+
* Delete folder with all of it's content. This is necessary because Java's internal file.delete()
163+
* cannot delete non-empty folders.
164+
* @param folder - folder to delete
165+
*/
166+
public static void deleteFolder(File folder) {
167+
File[] files = folder.listFiles();
168+
if(files!=null) { //some JVMs return null for empty dirs
169+
for(File f: files) {
170+
if(f.isDirectory()) {
171+
deleteFolder(f);
172+
} else {
173+
f.delete();
174+
}
175+
}
176+
}
177+
folder.delete();
178+
}
134179

135180
/**
136181
* Read file and return as list.

src/main/java/net/b07z/sepia/server/core/users/AuthenticationAssistAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ public boolean authenticate(JSONObject info) {
6363

6464
//Status?
6565
if (!Connectors.httpSuccess(response)){
66-
log.warn("No success in auth response for user '" + userid + "', returning false: " + response);
66+
log.warn("Authentication ERROR for user '" + userid + "' - original msg.: " + response);
6767
errorCode = 3; //connection error, wrong parameters?
6868
return false;
6969
}
7070
else{
7171
String result = (String) response.get("result");
7272
if (result.equals("fail")){
73-
log.warn("'fail' in auth response for user '" + userid + "', returning false: " + response);
73+
log.warn("Authentication failed for user '" + userid + "' - original msg.: " + response);
7474
errorCode = 2; //authentication failed
7575
return false;
7676
}

0 commit comments

Comments
 (0)