Ressourcen hinzugefügt

This commit is contained in:
Joshua
2018-08-02 16:37:12 +02:00
parent 0c5e6d5f57
commit 13501308b3
3 changed files with 114 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import de.sebse.fuplanner.services.KVV.types.Lecturer;
import de.sebse.fuplanner.services.KVV.types.LoginToken;
import de.sebse.fuplanner.services.KVV.types.Modules;
import de.sebse.fuplanner.services.KVV.types.AssignmentList;
import de.sebse.fuplanner.services.KVV.types.Ressource;
import de.sebse.fuplanner.tools.AsyncQueue;
import de.sebse.fuplanner.services.KVV.types.EventList;
import de.sebse.fuplanner.tools.Regex;
@@ -173,7 +174,8 @@ class KVVModuleList extends HTTPService {
() -> this.getAssignments(module, successCb, errorCb, forceRefresh),
() -> this.getEvents(module, successCb, errorCb, forceRefresh),
() -> this.getAnnouncements(module, successCb, errorCb, forceRefresh),
() -> this.getGradebook(module, successCb, errorCb, forceRefresh)
() -> this.getGradebook(module, successCb, errorCb, forceRefresh),
() -> this.getRessourcen(module, successCb, errorCb, forceRefresh)
};
items.set(methods.length);
for (Runnable method: methods) {
@@ -437,6 +439,65 @@ class KVVModuleList extends HTTPService {
}
public void getRessourcen(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
queueModuleDetails.add(module.getID(), () -> {
if (module.ressource != null && !forceRefresh) {
callback.onResponse(module);
queueModuleDetails.next(module.getID());
return;
}
getRessourcenUpgrade(module.getID(), success -> {
module.ressource = success;
callback.onResponse(module);
queueModuleDetails.next(module.getID());
}, queueModuleDetails.check(module.getID(), errorCallback));
});
}
private void getRessourcenUpgrade(String ID, final NetworkCallback<ArrayList<Ressource>> callback, final NetworkErrorCallback errorCallback) {
//log.d("Ressourcen Aufgerufen");
if (token == null) {
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
return;
}
get(String.format("https://kvv.imp.fu-berlin.de/direct/content/site/%s.json", ID ), token.getCookies(), response ->{
String body = response.getParsed();
if (body == null) {
errorCallback.onError(new NetworkError(101601, 403, "No Ressourcen retrieved!"));
return;
}
ArrayList<Ressource> ressourcen = new ArrayList<>();
try {
JSONObject json = new JSONObject(body);
JSONArray sites = json.getJSONArray("content_collection");
for (int i = 0; i < sites.length(); i++) {
JSONObject site = sites.getJSONObject(i);
String author = site.getString("author");
String title = site.getString("title");
long modifiedDate = site.getLong("modifiedDate");
String url = site.getString("url");
//log.d("Ressourcen:", author, title, modifiedDate, url);
ressourcen.add(new Ressource(author, title, modifiedDate, url));
}
} catch (JSONException e) {
e.printStackTrace();
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse Ressourcen!"));
return;
}
// Empty announcements may *may be* because token is invalid -> check
if (ressourcen.size() == 0)
testLogin(token, token -> callback.onResponse(ressourcen), errorCallback);
else
callback.onResponse(ressourcen);
callback.onResponse(ressourcen);
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get Ressourcen for Ressourcen!")));
}

View File

@@ -96,6 +96,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
newModule.assignments = oldModule.assignments;
newModule.events = oldModule.events;
newModule.gradebook = oldModule.gradebook;
newModule.ressource = oldModule.ressource;
}
}
}
@@ -112,6 +113,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
@Nullable public AssignmentList assignments;
@Nullable public EventList events;
@Nullable public ArrayList<Gradebook> gradebook;
public ArrayList<Ressource> ressource;
/*private Module() {
this(null, null, null, null, null);

View File

@@ -0,0 +1,50 @@
package de.sebse.fuplanner.services.KVV.types;
import java.io.Serializable;
public class Ressource implements Serializable {
private final String author;
private final long modifiedDate;
private final String title;
private final String url;
public Ressource(String author, String title, long modifiedDate, String url) {
this.author = author;
this.title = title;
this.modifiedDate = modifiedDate;
this.url = url;
}
public String getAuthor() {
return author;
}
public long getModifiedDate() {
return modifiedDate;
}
public String getTitle() {
return title;
}
public String getUrl() {
return url;
}
@Override
public String toString() {
return "Ressource{" +
"author='" + author + '\'' +
", modifiedDate=" + modifiedDate +
", title='" + title + '\'' +
", url='" + url + '\'' +
'}';
}
}