use of com.google.api.client.util.ArrayMap in project iosched by google.
the class RemoteUserDataHelper method asUserData.
/**
* Builds and returns a {@link UserData} object from a {@link UserDataModel}. The returned
* object can be used to write data to the user data endpoint.
*
* @param model Data from the user data endpoint represented as a {@link UserDataModel}.
*/
static UserData asUserData(UserDataModel model) {
UserData userData = new UserData();
JsonMap bookmarkedSessionsJsonMap = new JsonMap();
for (final Map.Entry<String, UserDataModel.StarredSession> entry : model.getStarredSessions().entrySet()) {
ArrayMap<String, String> arrayMap = new ArrayMap<>();
arrayMap.put(SESSION_ID, entry.getKey());
arrayMap.put(IN_SCHEDULE, String.valueOf(entry.getValue().inSchedule));
arrayMap.put(TIMESTAMP_UTC, String.valueOf(entry.getValue().timestamp));
bookmarkedSessionsJsonMap.set(entry.getKey(), arrayMap);
}
userData.setBookmarkedSessions(bookmarkedSessionsJsonMap);
List<String> reviewSessionsList = new ArrayList<>();
for (String reviewedSessionId : model.getFeedbackSubmittedSessionIds()) {
reviewSessionsList.add(reviewedSessionId);
}
userData.setReviewedSessions(reviewSessionsList);
return userData;
}
use of com.google.api.client.util.ArrayMap in project iosched by google.
the class RemoteUserDataHelper method getRemoteReservedSessions.
/**
* Returns a user's reserved/waitlisted sessions stored in the user data endpoint.
*
* @param remoteUserDataJson A {@link UserData} object representing the user's data.
*/
static Map<String, UserDataModel.ReservedSession> getRemoteReservedSessions(UserData remoteUserDataJson) {
Map<String, UserDataModel.ReservedSession> result = new HashMap<>();
JsonMap jsonMap = remoteUserDataJson.getReservedSessions();
if (jsonMap != null) {
for (Object o : jsonMap.values()) {
String sessionID = String.valueOf(((ArrayMap) o).get(SESSION_ID));
Status status = Status.valueOf(String.valueOf(((ArrayMap) o).get(STATUS)));
int valueToInsert;
switch(status) {
case RESERVED:
valueToInsert = ScheduleContract.MyReservations.RESERVATION_STATUS_RESERVED;
break;
case WAITLISTED:
valueToInsert = ScheduleContract.MyReservations.RESERVATION_STATUS_WAITLISTED;
break;
default:
valueToInsert = ScheduleContract.MyReservations.RESERVATION_STATUS_UNRESERVED;
}
long timestampUTC = Long.parseLong(String.valueOf(((ArrayMap) o).get(TIMESTAMP_UTC)));
result.put(sessionID, new UserDataModel.ReservedSession(valueToInsert, timestampUTC));
}
}
return result;
}
use of com.google.api.client.util.ArrayMap in project iosched by google.
the class RemoteUserDataHelper method getRemoteBookmarkedSessions.
/**
* Returns a user's bookmarked/starred sessions stored in the user data endpoint.
*
* @param remoteUserDataJson A {@link UserData} object representing the user's data.
*/
static Map<String, UserDataModel.StarredSession> getRemoteBookmarkedSessions(UserData remoteUserDataJson) {
Map<String, UserDataModel.StarredSession> result = new HashMap<>();
JsonMap jsonMap = remoteUserDataJson.getBookmarkedSessions();
if (jsonMap != null) {
for (Object o : jsonMap.values()) {
String sessionID = String.valueOf(((ArrayMap) o).get(SESSION_ID));
boolean inSchedule = Boolean.parseBoolean(String.valueOf(((ArrayMap) o).get(IN_SCHEDULE)));
long timestampUTC = Long.parseLong(String.valueOf(((ArrayMap) o).get(TIMESTAMP_UTC)));
result.put(sessionID, new UserDataModel.StarredSession(inSchedule, timestampUTC));
}
}
return result;
}