smmdbapi part 2
api query fully working
This commit is contained in:
parent
bb72ed04ee
commit
5c3cb8398f
Binary file not shown.
Binary file not shown.
@ -204,7 +204,7 @@ public class MainWindowController {
|
||||
fullscreenToggleBtn.setSelected(isFullscreen());
|
||||
cloudSyncToggleBtn.setSelected(isCloudSync());
|
||||
edit.setDisable(true);
|
||||
smmdbBtn.setDisable(true); //TODO
|
||||
smmdbBtn.setDisable(false); //TODO
|
||||
applyColor();
|
||||
}
|
||||
|
||||
@ -476,9 +476,11 @@ public class MainWindowController {
|
||||
void smmdbBtnAction() {
|
||||
//TODO show TODO smmdbAnchorPane
|
||||
|
||||
//TODO start query
|
||||
//start query
|
||||
ArrayList<SmmdbApiDataType> courses = new ArrayList<>(smmdbApiQuery.startQuery());
|
||||
System.out.println(courses.size());
|
||||
|
||||
System.out.println("size: " + courses.size());
|
||||
System.out.println(courses.get(3).getNintendoid());
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* smmdbapi query
|
||||
* start query and return all courses as ArrayList
|
||||
* api query, return all courses as ArrayList
|
||||
*/
|
||||
package application;
|
||||
|
||||
@ -18,13 +18,13 @@ import datatypes.SmmdbApiDataType;
|
||||
|
||||
public class SmmdbApiQuery {
|
||||
|
||||
private String url = "http://smmdb.ddns.net/api/getcourses?";
|
||||
private String URL = "http://smmdb.ddns.net/api/getcourses?";
|
||||
|
||||
public SmmdbApiQuery() {
|
||||
//Auto-generated constructor stub
|
||||
}
|
||||
|
||||
//TODO needs to be tested
|
||||
//start api query
|
||||
public ArrayList<SmmdbApiDataType> startQuery() {
|
||||
ArrayList<Integer> courseIDs = new ArrayList<>();
|
||||
ArrayList<SmmdbApiDataType> course = new ArrayList<>();
|
||||
@ -32,44 +32,96 @@ public class SmmdbApiQuery {
|
||||
|
||||
|
||||
try {
|
||||
URL apiUrl = new URL(url);
|
||||
URL apiUrl = new URL(URL);
|
||||
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
|
||||
output = ina.readLine();
|
||||
ina.close();
|
||||
} catch (IOException e) {
|
||||
//Auto-generated catch block
|
||||
System.out.println("error while making api request or reading response");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
JsonObject mainObject = Json.parse(output).asObject().get("courses").asObject();
|
||||
System.out.println(mainObject);
|
||||
|
||||
|
||||
JsonArray objectAssets = Json.parse(output).asObject().get("order").asArray();
|
||||
|
||||
for (JsonValue asset : objectAssets) {
|
||||
courseIDs.add(asset.asInt());
|
||||
}
|
||||
|
||||
//FIXME if parameter = null query will stop
|
||||
//if value is 9 or "notset" the api returned NULL as value
|
||||
for (int i = 0; i < courseIDs.size(); i++) {
|
||||
System.out.println(i);
|
||||
JsonObject singleObject = mainObject.get(courseIDs.get(i).toString()).asObject();
|
||||
int id = singleObject.getInt("id", 0);
|
||||
int owner = singleObject.getInt("owner", 0);
|
||||
int coursetype = singleObject.getInt("coursetype", 0);
|
||||
int leveltype = singleObject.getInt("leveltype", 0);
|
||||
int difficulty = singleObject.getInt("difficulty", 0);
|
||||
int lastmodified = singleObject.getInt("lastmodified", 0);
|
||||
int uploaded = singleObject.getInt("uploaded", 0);
|
||||
int downloads = singleObject.getInt("downloads", 0);
|
||||
int stars = singleObject.getInt("stars", 0);
|
||||
int ispackage = singleObject.getInt("ispackage", 0);
|
||||
int updatereq = singleObject.getInt("updatereq", 0);
|
||||
// String nintendoid = singleObject.getString("nintendoid", "");
|
||||
String title = singleObject.getString("title", "");
|
||||
|
||||
course.add(new SmmdbApiDataType(id, owner, coursetype, leveltype, difficulty, lastmodified, uploaded, downloads,
|
||||
stars, ispackage, updatereq, title));
|
||||
int id, owner, coursetype, leveltype, difficulty, lastmodified, uploaded, downloads, stars, ispackage, updatereq;
|
||||
String nintendoid, title;
|
||||
JsonObject singleObject = mainObject.get(courseIDs.get(i).toString()).asObject();
|
||||
|
||||
try {
|
||||
id = singleObject.getInt("id", 0);
|
||||
} catch (Exception e) {
|
||||
id = 9;
|
||||
}
|
||||
try {
|
||||
owner = singleObject.getInt("owner", 0);
|
||||
} catch (Exception e) {
|
||||
owner = 9;
|
||||
}
|
||||
try {
|
||||
coursetype = singleObject.getInt("coursetype", 0);
|
||||
} catch (Exception e) {
|
||||
coursetype = 9;
|
||||
}
|
||||
try {
|
||||
leveltype = singleObject.getInt("leveltype", 0);
|
||||
} catch (Exception e) {
|
||||
leveltype = 9;
|
||||
}
|
||||
try {
|
||||
difficulty = singleObject.getInt("difficulty", 0);
|
||||
} catch (Exception e) {
|
||||
difficulty = 9;
|
||||
}
|
||||
try {
|
||||
lastmodified = singleObject.getInt("lastmodified", 0);
|
||||
} catch (Exception e) {
|
||||
lastmodified = 9;
|
||||
}
|
||||
try {
|
||||
uploaded = singleObject.getInt("uploaded", 0);
|
||||
} catch (Exception e) {
|
||||
uploaded = 9;
|
||||
}
|
||||
try {
|
||||
downloads = singleObject.getInt("downloads", 0);
|
||||
} catch (Exception e) {
|
||||
downloads = 9;
|
||||
}
|
||||
try {
|
||||
stars = singleObject.getInt("stars", 0);
|
||||
} catch (Exception e) {
|
||||
stars = 9;
|
||||
}
|
||||
try {
|
||||
ispackage = singleObject.getInt("ispackage", 0);
|
||||
} catch (Exception e) {
|
||||
ispackage = 9;
|
||||
}
|
||||
try {
|
||||
updatereq = singleObject.getInt("updatereq", 0);
|
||||
} catch (Exception e) {
|
||||
updatereq = 9;
|
||||
}
|
||||
try {
|
||||
nintendoid = singleObject.getString("nintendoid", "");
|
||||
} catch (Exception e) {
|
||||
nintendoid = "notset";
|
||||
}
|
||||
try {
|
||||
title = singleObject.getString("title", "");;
|
||||
} catch (Exception e) {
|
||||
title = "notset";
|
||||
}
|
||||
|
||||
course.add(new SmmdbApiDataType(id, owner, coursetype, leveltype, difficulty, lastmodified, uploaded, downloads,
|
||||
stars, ispackage, updatereq, nintendoid, title));
|
||||
}
|
||||
|
||||
return course;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package datatypes;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
@ -20,25 +18,25 @@ public class SmmdbApiDataType {
|
||||
private final IntegerProperty stars = new SimpleIntegerProperty();
|
||||
private final IntegerProperty ispackage = new SimpleIntegerProperty();
|
||||
private final IntegerProperty updatereq = new SimpleIntegerProperty();
|
||||
// private final StringProperty nintendoid = new SimpleStringProperty();
|
||||
private final StringProperty nintendoid = new SimpleStringProperty();
|
||||
private final StringProperty title = new SimpleStringProperty();
|
||||
|
||||
public SmmdbApiDataType(final int id, final int owner, final int coursetype, final int leveltype, final int difficulty,
|
||||
final int lastmodified, final int uploaded, final int downloads, final int stars, final int ispackage,
|
||||
final int updatereq, final String title) {
|
||||
final int updatereq, final String nintendoid, final String title) {
|
||||
this.id.set(id);
|
||||
this.owner.set(owner);
|
||||
this.coursetype.set(coursetype);
|
||||
// this.nintendoid.set(nintendoid);
|
||||
this.leveltype.set(leveltype);
|
||||
this.difficulty.set(difficulty);
|
||||
this.lastmodified.set(lastmodified);
|
||||
this.uploaded.set(uploaded);
|
||||
this.downloads.set(downloads);
|
||||
this.stars.set(stars);
|
||||
this.title.set(title);
|
||||
this.ispackage.set(ispackage);
|
||||
this.updatereq.set(updatereq);
|
||||
this.nintendoid.set(nintendoid);
|
||||
this.title.set(title);
|
||||
}
|
||||
|
||||
public IntegerProperty idProperty(){
|
||||
@ -53,9 +51,9 @@ public class SmmdbApiDataType {
|
||||
return coursetype;
|
||||
}
|
||||
|
||||
// public StringProperty nintendoidProperty(){
|
||||
// return nintendoid;
|
||||
// }
|
||||
public StringProperty nintendoidProperty(){
|
||||
return nintendoid;
|
||||
}
|
||||
|
||||
public IntegerProperty leveltypeProperty(){
|
||||
return leveltype;
|
||||
@ -137,9 +135,9 @@ public class SmmdbApiDataType {
|
||||
return updatereqProperty().get();
|
||||
}
|
||||
|
||||
// public String getNintendoid() {
|
||||
// return nintendoidProperty().get();
|
||||
// }
|
||||
public String getNintendoid() {
|
||||
return nintendoidProperty().get();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return titleProperty().get();
|
||||
@ -189,9 +187,9 @@ public class SmmdbApiDataType {
|
||||
updatereqProperty().set(updatereq);
|
||||
}
|
||||
|
||||
// public final void setNintendoid(String nintendoid) {
|
||||
// nintendoidProperty().set(nintendoid);
|
||||
// }
|
||||
public final void setNintendoid(String nintendoid) {
|
||||
nintendoidProperty().set(nintendoid);
|
||||
}
|
||||
|
||||
public final void setTitle(String title) {
|
||||
titleProperty().set(title);
|
||||
|
Loading…
Reference in New Issue
Block a user