use of com.thebluealliance.androidclient.models.District in project the-blue-alliance-android by the-blue-alliance.
the class DistrictsTableTest method testUpdate.
@Test
public void testUpdate() {
District result = DbTableTestDriver.testUpdate(mTable, mDistricts.get(0), district -> district.setDisplayName("Test Dist"), mGson);
assertNotNull(result);
assertEquals("Test Dist", result.getDisplayName());
}
use of com.thebluealliance.androidclient.models.District in project the-blue-alliance-android by the-blue-alliance.
the class DistrictDeserializer method deserialize.
@Override
public District deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject data = jsonElement.getAsJsonObject();
District district = new District();
district.setKey(data.get("key").getAsString());
district.setDisplayName(data.get("display_name").getAsString());
district.setAbbreviation(data.get("abbreviation").getAsString());
district.setYear(data.get("year").getAsInt());
return district;
}
use of com.thebluealliance.androidclient.models.District in project the-blue-alliance-android by the-blue-alliance.
the class EventDeserializer method deserialize.
@Override
public Event deserialize(final JsonElement json, Type typeOf, JsonDeserializationContext context) throws JsonParseException {
final JsonObject object;
try {
object = json.getAsJsonObject();
} catch (JsonSyntaxException | IllegalStateException ex) {
TbaLogger.w("Failed to parse json: " + json.toString());
return null;
}
final Event event = new Event();
if (object.has("key")) {
String key = object.get("key").getAsString();
int year = EventHelper.getYear(key);
event.setKey(key);
event.setYear(year);
}
if (object.has("name")) {
event.setName(object.get("name").getAsString());
}
if (isNull(object.get("address"))) {
event.setAddress("");
} else {
event.setAddress(object.get("address").getAsString());
}
if (isNull(object.get("location_name"))) {
event.setLocationName("");
} else {
event.setLocationName(object.get("location_name").getAsString());
}
if (isNull(object.get("city")) || isNull(object.get("state_prov")) || isNull(object.get("country"))) {
event.setLocation("");
} else {
event.setLocation(object.get("city").getAsString() + ", " + object.get("state_prov").getAsString() + ", " + object.get("country").getAsString());
event.setCity(object.get("city").getAsString());
}
if (object.has("event_type")) {
event.setEventType(object.get("event_type").getAsInt());
}
if (isNull(object.get("start_date"))) {
event.setStartDate("");
} else {
event.setStartDate(object.get("start_date").getAsString());
}
if (!isNull(object.get("week"))) {
event.setWeek(object.get("week").getAsInt() + 1);
} else {
event.setCompetitionWeekFromStartDate();
}
if (isNull(object.get("end_date"))) {
event.setEndDate("");
} else {
event.setEndDate(object.get("end_date").getAsString());
}
// If it is null, simply use the event name as the short name
if (isNull(object.get("short_name"))) {
event.setShortName("");
} else {
event.setShortName(object.get("short_name").getAsString());
}
if (!isNull(object.get("website"))) {
event.setWebsite(object.get("website").getAsString());
}
if (object.has("webcasts")) {
event.setWebcasts(object.get("webcasts").toString());
}
JsonElement district = object.get("district");
if (isNull(district)) {
event.setDistrict(null);
} else {
District districtModel = context.deserialize(object.get("district"), District.class);
event.setDistrict(districtModel);
event.setDistrictKey(districtModel.getKey());
}
return event;
}
use of com.thebluealliance.androidclient.models.District in project the-blue-alliance-android by the-blue-alliance.
the class AddDistrictKeys method call.
@Override
public List<District> call(List<District> districts) {
if (districts == null) {
return null;
}
for (int i = 0; i < districts.size(); i++) {
District district = districts.get(i);
String key = DistrictHelper.generateKey(district.getAbbreviation(), mYear);
district.setKey(key);
district.setYear(mYear);
}
return districts;
}
use of com.thebluealliance.androidclient.models.District in project the-blue-alliance-android by the-blue-alliance.
the class APICache method fetchDistrict.
public Observable<District> fetchDistrict(String districtKey) {
return Observable.create((observer) -> {
try {
District district = mDb.getDistrictsTable().get(districtKey);
observer.onNext(district);
observer.onCompleted();
} catch (Exception e) {
observer.onError(e);
}
});
}
Aggregations