"Blackboard never used" check introduced

This commit is contained in:
Caesar2011
2019-01-28 17:30:08 +01:00
parent 068344ff5c
commit 86d8078aca
6 changed files with 54 additions and 16 deletions

View File

@@ -79,7 +79,14 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
mBBLogin.testLoginToken(success, success1 -> { mBBLogin.testLoginToken(success, success1 -> {
login.set(success1.toJsonString()); login.set(success1.toJsonString());
latch.countDown(); latch.countDown();
}, errorFunc); }, error -> {
if (error.getCode() == 100270) {
// Blackboard never used
success.setNotAvailable();
login.set(success.toJsonString());
}
errorFunc.onError(error);
});
}, errorFunc); }, errorFunc);
break; break;
default: default:

View File

@@ -35,7 +35,7 @@ public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
@Override @Override
protected void upgradeKVV(final String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) { protected void upgradeKVV(final String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) {
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null) { if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!")); errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!"));
return; return;
} }
@@ -92,7 +92,7 @@ public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
@Override @Override
protected void upgradeBB(String ID, NetworkCallback<ArrayList<Announcement>> callback, NetworkErrorCallback errorCallback) { protected void upgradeBB(String ID, NetworkCallback<ArrayList<Announcement>> callback, NetworkErrorCallback errorCallback) {
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null) { if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
errorCallback.onError(new NetworkError(101214, 500, "Currently running in offline mode!")); errorCallback.onError(new NetworkError(101214, 500, "Currently running in offline mode!"));
return; return;
} }
@@ -122,14 +122,7 @@ public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
text = String.valueOf(fromHtml(text)); text = String.valueOf(fromHtml(text));
String createdBy = "";//site.getString("createdByDisplayName"); String createdBy = "";//site.getString("createdByDisplayName");
long createdOn = UtilsDate.stringToMillis(site.getString("startDateRestriction"), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); long createdOn = UtilsDate.stringToMillis(site.getString("startDateRestriction"), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
//long createdOn = 0;//site.getLong("createdOn");
// Extract attachment links
//JSONArray attachments = site.getJSONArray("attachments");
ArrayList<String> urls = new ArrayList<>(); ArrayList<String> urls = new ArrayList<>();
/*for (int j = 0; j < attachments.length(); j++) {
urls.add(attachments.getJSONObject(j).optString("url", null));
}*/
announcements.add(new Announcement(id, title, text, createdBy, createdOn, urls)); announcements.add(new Announcement(id, title, text, createdBy, createdOn, urls));
} catch (JSONException e) { } catch (JSONException e) {

View File

@@ -9,10 +9,8 @@ import org.json.JSONObject;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.concurrent.CountDownLatch;
import java.util.regex.MatchResult; import java.util.regex.MatchResult;
import de.sebse.fuplanner.services.kvv.types.Lecturer; import de.sebse.fuplanner.services.kvv.types.Lecturer;
@@ -164,6 +162,10 @@ public class ModulesList extends HTTPService {
errorCallback.onError(new NetworkError(101110, 500, "Currently running in offline mode!")); errorCallback.onError(new NetworkError(101110, 500, "Currently running in offline mode!"));
return; return;
} }
if (!mLogin.getLoginTokenKVV().isAvailable()) {
callback.onResponse(new Modules(mLogin.getLoginTokenKVV().getUsername()));
return;
}
get("https://kvv.imp.fu-berlin.de/direct/site.json", mLogin.getLoginTokenKVV().getCookies(), response -> { get("https://kvv.imp.fu-berlin.de/direct/site.json", mLogin.getLoginTokenKVV().getCookies(), response -> {
String body = response.getParsed(); String body = response.getParsed();
if (body == null) { if (body == null) {
@@ -227,6 +229,10 @@ public class ModulesList extends HTTPService {
errorCallback.onError(new NetworkError(101120, 500, "Currently running in offline mode!")); errorCallback.onError(new NetworkError(101120, 500, "Currently running in offline mode!"));
return; return;
} }
if (!mLogin.getLoginTokenBB().isAvailable()) {
callback.onResponse(modulesKVV);
return;
}
get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/users/%s/courses", mLogin.getLoginTokenBB().getId()), mLogin.getLoginTokenBB().getCookies(), response -> { get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/users/%s/courses", mLogin.getLoginTokenBB().getId()), mLogin.getLoginTokenBB().getCookies(), response -> {
String body = response.getParsed(); String body = response.getParsed();
if (body == null) { if (body == null) {

View File

@@ -18,6 +18,7 @@ public class LoginTokenBB {
private final String s_session_id; private final String s_session_id;
private final String session_id; private final String session_id;
private final String username; private final String username;
private boolean isAvailable = true;
@Nullable private String id; @Nullable private String id;
@Nullable private String studentId; @Nullable private String studentId;
@@ -48,6 +49,17 @@ public class LoginTokenBB {
public void setAdditionals(String id, String studentId) { public void setAdditionals(String id, String studentId) {
this.id = id; this.id = id;
this.studentId = studentId; this.studentId = studentId;
this.isAvailable = true;
}
public void setNotAvailable() {
this.id = null;
this.studentId = null;
this.isAvailable = false;
}
public boolean isAvailable() {
return isAvailable;
} }
public String getUsername() { public String getUsername() {
@@ -102,6 +114,7 @@ public class LoginTokenBB {
json.put("username", username); json.put("username", username);
json.put("id", id); json.put("id", id);
json.put("studentId", studentId); json.put("studentId", studentId);
json.put("isAvailable", isAvailable);
} catch (JSONException e) { } catch (JSONException e) {
return null; return null;
} }
@@ -120,6 +133,9 @@ public class LoginTokenBB {
json.getString("id"), json.getString("id"),
json.getString("studentId") json.getString("studentId")
); );
if (!json.optBoolean("isAvailable", true)) {
token.setNotAvailable();
}
return token; return token;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -17,6 +17,7 @@ import de.sebse.fuplanner.tools.CustomAccountManager;
public class LoginTokenKVV { public class LoginTokenKVV {
private final String username; private final String username;
private final String JSESSIONID; private final String JSESSIONID;
private boolean isAvailable = true;
@Nullable private String fullName; @Nullable private String fullName;
@Nullable private String email; @Nullable private String email;
@@ -46,6 +47,17 @@ public class LoginTokenKVV {
public void setAdditionals(String fullName, String email) { public void setAdditionals(String fullName, String email) {
this.fullName = fullName; this.fullName = fullName;
this.email = email; this.email = email;
this.isAvailable = true;
}
public void setNotAvailable() {
this.fullName = null;
this.email = null;
this.isAvailable = false;
}
public boolean isAvailable() {
return isAvailable;
} }
public String getUsername() { public String getUsername() {
@@ -95,6 +107,7 @@ public class LoginTokenKVV {
json.put("JSESSIONID", JSESSIONID); json.put("JSESSIONID", JSESSIONID);
json.put("fullName", fullName); json.put("fullName", fullName);
json.put("email", email); json.put("email", email);
json.put("isAvailable", isAvailable);
} catch (JSONException e) { } catch (JSONException e) {
return null; return null;
} }
@@ -112,6 +125,9 @@ public class LoginTokenKVV {
json.getString("fullName"), json.getString("fullName"),
json.getString("email") json.getString("email")
); );
if (!json.optBoolean("isAvailable", true)) {
token.setNotAvailable();
}
return token; return token;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -14,7 +14,7 @@ https://lms.fu-berlin.de/learn/api/public/v1/users/_203980_1/courses
## Course details ## Course details
https://lms.fu-berlin.de/learn/api/v1/courses/_122802_1 https://lms.fu-berlin.de/learn/api/public/v1/courses/_122802_1
The field "courseId" in Blackboard can be matched to "props/kvv_lvnumbers" in "http://kvv.imp.fu-berlin.de/direct/site/<SITE_ID>" The field "courseId" in Blackboard can be matched to "props/kvv_lvnumbers" in "http://kvv.imp.fu-berlin.de/direct/site/<SITE_ID>"
@@ -25,7 +25,7 @@ The field "courseId" in Blackboard can be matched to "props/kvv_lvnumbers" in "h
+ lvNumber + lvNumber
* parse "courseId" * parse "courseId"
+ title + title
* "displayName" * "name"
+ lecturer + lecturer
* https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/users * https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/users
* Find Instructor * Find Instructor
@@ -33,7 +33,7 @@ The field "courseId" in Blackboard can be matched to "props/kvv_lvnumbers" in "h
+ type + type
* parse "courseId" ('Vorlesung'/'Seminar'/...?) * parse "courseId" ('Vorlesung'/'Seminar'/...?)
+ description + description
* description * ""
+ ID + ID
* id * id
@@ -86,4 +86,4 @@ https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/contents
+ https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/contents/_3635282_1/attachments + https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/contents/_3635282_1/attachments
+ text: "body" + text: "body"
- Attachment-Download - Attachment-Download
+ https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/contents/_3635282_1/attachments/_2838023_1/download + https://lms.fu-berlin.de/learn/api/public/v1/courses/_127131_1/contents/_3635282_1/attachments/_2838023_1/download