More robust blackboard module checking
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
@@ -265,30 +266,35 @@ public class ModulesList extends HTTPService {
|
|||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(body1);
|
JSONObject json = new JSONObject(body1);
|
||||||
String name = json.getString("name");
|
String name = json.getString("name");
|
||||||
String type = Regex.regex("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]*)([A-Z]*)", json.getString("courseId"), 1);
|
String type, lvNumber, semYear, semType;
|
||||||
String lvNumber = Regex.regex("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]*)([A-Z]*)", json.getString("courseId"), 2);
|
Semester semester = null;
|
||||||
String semYear = Regex.regex("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]*)([A-Z]*)", json.getString("courseId"), 3);
|
HashSet<String> lvNumberSet = new HashSet<>();
|
||||||
String semType = Regex.regex("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]*)([A-Z]*)", json.getString("courseId"), 4);
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
try {
|
||||||
|
Matcher match = Regex.match("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]*)([A-Z]*)", json.getString("courseId"));
|
||||||
|
type = match.group(1);
|
||||||
|
lvNumber = match.group(2);
|
||||||
|
semYear = match.group(3);
|
||||||
|
semType = match.group(4);
|
||||||
|
semester = new Semester(semType.equals("W") ? Semester.SEM_WS : Semester.SEM_SS, Integer.valueOf(semYear));
|
||||||
|
lvNumberSet.add(lvNumber);
|
||||||
for (Modules.Module module: modulesKVV) {
|
for (Modules.Module module: modulesKVV) {
|
||||||
if (module.lvNumber.contains(lvNumber)) {
|
if (module.lvNumber.contains(lvNumber)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashSet<String> lvNumberSet = new HashSet<>();
|
} catch (NoSuchFieldException e) {
|
||||||
lvNumberSet.add(lvNumber);
|
type = "Project";
|
||||||
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
modulesKVV.addModule(new Semester(semType.equals("W") ? Semester.SEM_WS : Semester.SEM_SS, Integer.valueOf(semYear)), lvNumberSet, name, new LinkedHashSet<>(), type, "", courseId, Modules.TYPE_BB);
|
modulesKVV.addModule(semester, lvNumberSet, name, new LinkedHashSet<>(), type, "", courseId, Modules.TYPE_BB);
|
||||||
latch[0]--;
|
latch[0]--;
|
||||||
if (latch[0] == 0)
|
if (latch[0] == 0)
|
||||||
callback.onResponse(modulesKVV);
|
callback.onResponse(modulesKVV);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
errorCallback.onError(new NetworkError(101125, 403, "Cannot parse module list!"));
|
errorCallback.onError(new NetworkError(101125, 403, "Cannot parse module list!"));
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101127, 403, "Cannot parse module list!"));
|
|
||||||
}
|
}
|
||||||
}, error -> errorCallback.onError(new NetworkError(101126, error.networkResponse.statusCode, "Cannot get module list!")));
|
}, error -> errorCallback.onError(new NetworkError(101126, error.networkResponse.statusCode, "Cannot get module list!")));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ public class Regex {
|
|||||||
return matcher.group(group);
|
return matcher.group(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Matcher match(@Language("Regexp") String regex, String match) throws NoSuchFieldException {
|
||||||
|
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
||||||
|
Matcher matcher = pattern.matcher(match);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
throw new NoSuchFieldException(String.format("Pattern: %s - String: %s", regex, match));
|
||||||
|
}
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
public static Iterable<MatchResult> allMatches(@Language("Regexp") String regex, final CharSequence input) {
|
public static Iterable<MatchResult> allMatches(@Language("Regexp") String regex, final CharSequence input) {
|
||||||
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
||||||
return () -> new Iterator<MatchResult>() {
|
return () -> new Iterator<MatchResult>() {
|
||||||
|
|||||||
Reference in New Issue
Block a user