Resource in KVV aktualliesiert
This commit is contained in:
@@ -470,7 +470,16 @@ class KVVModuleList extends HTTPService {
|
|||||||
String title = site.getString("title");
|
String title = site.getString("title");
|
||||||
long modifiedDate = site.getLong("modifiedDate");
|
long modifiedDate = site.getLong("modifiedDate");
|
||||||
String url = site.getString("url");
|
String url = site.getString("url");
|
||||||
resources.add(new Resource(author, title, modifiedDate, url));
|
boolean visible = site.getBoolean("visible");
|
||||||
|
String type = site.getString("type");
|
||||||
|
String container = site.getString("container");
|
||||||
|
if (type.equals("collection")){
|
||||||
|
resources.add(new Resource.Folder(author, title, modifiedDate, url, visible, container));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resources.add(new Resource.File(author, title, modifiedDate, url, visible, container, type));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@@ -478,14 +487,30 @@ class KVVModuleList extends HTTPService {
|
|||||||
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
|
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<Resource> root = new ArrayList<>();
|
||||||
|
for (Resource res: resources) {//Verzeichnisstrucktur anlegen
|
||||||
|
if (!res.getContainer().equals("/content/group/")) {
|
||||||
|
if (res.getContainer().equals("/content/group/"+ID+"/")){//ist File im Hauptordner
|
||||||
|
root.add(res);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (Resource res2: resources) { // im Unterordner
|
||||||
|
if (res2.getUrl().endsWith(res.getContainer()) && res2 instanceof Resource.Folder){
|
||||||
|
((Resource.Folder) res2).add(res);//File bzw. Ordner anfügen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.d(root);
|
||||||
|
|
||||||
// Empty resources *may be* because token is invalid -> check
|
// Empty resources *may be* because token is invalid -> check
|
||||||
if (resources.size() == 0)
|
if (root.size() == 0)
|
||||||
testLogin(token, token -> callback.onResponse(resources), errorCallback);
|
testLogin(token, token -> callback.onResponse(root), errorCallback);
|
||||||
else
|
else
|
||||||
callback.onResponse(resources);
|
callback.onResponse(root);
|
||||||
|
|
||||||
|
|
||||||
callback.onResponse(resources);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class Resource implements Serializable {
|
||||||
|
|
||||||
public class Resource implements Serializable {
|
protected final String author;
|
||||||
|
protected final long modifiedDate;
|
||||||
private final String author;
|
protected final String title;
|
||||||
private final long modifiedDate;
|
protected final String url;
|
||||||
private final String title;
|
protected final boolean visible;
|
||||||
private final String url;
|
protected final String container;
|
||||||
|
|
||||||
|
|
||||||
public Resource(String author, String title, long modifiedDate, String url) {
|
public Resource(String author, String title, long modifiedDate, String url, boolean visible, String container) {
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.modifiedDate = modifiedDate;
|
this.modifiedDate = modifiedDate;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
this.visible = visible;
|
||||||
|
this.container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
@@ -35,16 +39,67 @@ public class Resource implements Serializable {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String getContainer() {
|
||||||
public String toString() {
|
return container;
|
||||||
return "Resource{" +
|
|
||||||
"author='" + author + '\'' +
|
|
||||||
", modifiedDate=" + modifiedDate +
|
|
||||||
", title='" + title + '\'' +
|
|
||||||
", url='" + url + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVisible() {
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class File extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
public File(String author, String title, long modifiedDate, String url, boolean visible, String container, String type) {
|
||||||
|
super(author, title, modifiedDate, url, visible, container);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Resource{" +
|
||||||
|
"author='" + author + '\'' +
|
||||||
|
", modifiedDate=" + modifiedDate +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", url='" + url + '\'' +
|
||||||
|
", type='" + type + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Folder extends Resource{
|
||||||
|
|
||||||
|
private final ArrayList<Resource> childs;
|
||||||
|
public Folder(String author, String title, long modifiedDate, String url, boolean visible, String container) {
|
||||||
|
super(author, title, modifiedDate, url, visible, container);
|
||||||
|
childs = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Resource res){
|
||||||
|
childs.add(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource get(int id){
|
||||||
|
return childs.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size(){
|
||||||
|
return childs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Resource{" +
|
||||||
|
"author='" + author + '\'' +
|
||||||
|
", modifiedDate=" + modifiedDate +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", url='" + url + '\'' +
|
||||||
|
", childs='" + childs + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user