Search in sources :

Example 1 with JsonMap

use of com.google.samples.apps.iosched.rpc.userdata.model.JsonMap 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;
}
Also used : UserData(com.google.samples.apps.iosched.rpc.userdata.model.UserData) ArrayList(java.util.ArrayList) ArrayMap(com.google.api.client.util.ArrayMap) JsonMap(com.google.samples.apps.iosched.rpc.userdata.model.JsonMap) HashMap(java.util.HashMap) ArrayMap(com.google.api.client.util.ArrayMap) JsonMap(com.google.samples.apps.iosched.rpc.userdata.model.JsonMap) Map(java.util.Map)

Example 2 with JsonMap

use of com.google.samples.apps.iosched.rpc.userdata.model.JsonMap 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;
}
Also used : HashMap(java.util.HashMap) ArrayMap(com.google.api.client.util.ArrayMap) JsonMap(com.google.samples.apps.iosched.rpc.userdata.model.JsonMap)

Example 3 with JsonMap

use of com.google.samples.apps.iosched.rpc.userdata.model.JsonMap 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;
}
Also used : HashMap(java.util.HashMap) ArrayMap(com.google.api.client.util.ArrayMap) JsonMap(com.google.samples.apps.iosched.rpc.userdata.model.JsonMap)

Aggregations

ArrayMap (com.google.api.client.util.ArrayMap)3 JsonMap (com.google.samples.apps.iosched.rpc.userdata.model.JsonMap)3 HashMap (java.util.HashMap)3 UserData (com.google.samples.apps.iosched.rpc.userdata.model.UserData)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1