Package com.fitbit.web.context

Examples of com.fitbit.web.context.RequestContext


        return "water";
    }

    @RequestMapping(value = "/water", method = RequestMethod.POST)
    public String showLogWaterPost(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);

        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        List<String> messages = new ArrayList<String>();
        try {
            String amountString = request.getParameter("amount");
            float amount = Float.parseFloat(amountString);
            context.getApiClientService().getClient().logWater(context.getOurUser(), amount, context.getParsedLocalDate());
        } catch (FitbitAPIException e) {
            if (e.getApiErrors() != null) {
                for (FitbitApiError error : e.getApiErrors()) {
                    messages.add(error.getMessage());
                }
View Full Code Here


        return "redirect:/app/water";
    }

    @RequestMapping(value = "/deleteWater", method = RequestMethod.GET)
    public String deleteLogWater(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);

        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        List<String> messages = new ArrayList<String>();
        try {
            String logId = request.getParameter("id");
            context.getApiClientService().getClient().deleteWater(context.getOurUser(), logId);
        } catch (FitbitAPIException e) {
            if (e.getApiErrors() != null) {
                for (FitbitApiError error : e.getApiErrors()) {
                    messages.add(error.getMessage());
                }
View Full Code Here

        return "redirect:/app/water";
    }

    @RequestMapping(value = "/createFoodForm", method = RequestMethod.GET)
    public String showCreateFoodForm(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }
        return "createFood";
View Full Code Here

        return "createFood";
    }

    @RequestMapping(value = "/createFood", method = RequestMethod.POST)
    protected String createFood(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        String name = request.getParameter("name");
        String description = request.getParameter("description");
        Long defaultFoodMeasurementUnitId = getParameterAsLong(request, "defaultFoodMeasurementUnitId", (long) 0);
        Float defaultServingSize = getParameterAsFloat(request, "defaultServingSize", 0f);
        FoodFormType formType = FoodFormType.valueOf(request.getParameter("formType"));

        int caloriesPerServingSize = getParameterAsInteger(request, "caloriesPerServingSize", 0);
        int caloriesFromFat = getParameterAsInteger(request, "caloriesFromFat", 0);
        float totalFat = getParameterAsFloat(request, "totalFat", 0f);
        float transFat = getParameterAsFloat(request, "transFat", 0f);
        float saturatedFat = getParameterAsFloat(request, "saturatedFat", 0f);
        float cholesterol = getParameterAsFloat(request, "cholesterol", 0f);
        float sodium = getParameterAsFloat(request, "sodium", 0f);
        float potassium = getParameterAsFloat(request, "potassium", 0f);
        float totalCarbohydrate = getParameterAsFloat(request, "totalCarbohydrate", 0f);
        float dietaryFiber = getParameterAsFloat(request, "dietaryFiber", 0f);
        float sugars = getParameterAsFloat(request, "sugars", 0f);
        float protein = getParameterAsFloat(request, "protein", 0f);
        float vitaminA = getParameterAsFloat(request, "vitaminA", 0f);
        float vitaminC = getParameterAsFloat(request, "vitaminC", 0f);
        float iron = getParameterAsFloat(request, "iron", 0f);
        float calcium = getParameterAsFloat(request, "calcium", 0f);
        float thiamin = getParameterAsFloat(request, "thiamin", 0f);
        float riboflavin = getParameterAsFloat(request, "riboflavin", 0f);
        float vitaminB6 = getParameterAsFloat(request, "vitaminB6", 0f);
        float vitaminB12 = getParameterAsFloat(request, "vitaminB12", 0f);
        float vitaminE = getParameterAsFloat(request, "vitaminE", 0f);
        float folicAcid = getParameterAsFloat(request, "folicAcid", 0f);
        float niacin = getParameterAsFloat(request, "niacin", 0f);
        float magnesium = getParameterAsFloat(request, "magnesium", 0f);
        float phosphorus = getParameterAsFloat(request, "phosphorus", 0f);
        float iodine = getParameterAsFloat(request, "iodine", 0f);
        float zinc = getParameterAsFloat(request, "zinc", 0f);
        float copper = getParameterAsFloat(request, "copper", 0f);
        float biotin = getParameterAsFloat(request, "biotin", 0f);
        float pantothenicAcid = getParameterAsFloat(request, "pantothenicAcid", 0f);
        float vitaminD = getParameterAsFloat(request, "vitaminD", 0f);

        NutritionalValuesEntry nutritionalValuesEntry = new NutritionalValuesEntry();
        nutritionalValuesEntry.setCalories(caloriesPerServingSize);
        nutritionalValuesEntry.setCaloriesFromFat(caloriesFromFat);
        nutritionalValuesEntry.setTotalFat(totalFat);
        nutritionalValuesEntry.setTransFat(transFat);
        nutritionalValuesEntry.setSaturatedFat(saturatedFat);
        nutritionalValuesEntry.setCholesterol(cholesterol);
        nutritionalValuesEntry.setSodium(sodium);
        nutritionalValuesEntry.setPotassium(potassium);
        nutritionalValuesEntry.setTotalCarbohydrate(totalCarbohydrate);
        nutritionalValuesEntry.setDietaryFiber(dietaryFiber);
        nutritionalValuesEntry.setSugars(sugars);
        nutritionalValuesEntry.setProtein(protein);
        nutritionalValuesEntry.setVitaminA(vitaminA);
        nutritionalValuesEntry.setVitaminC(vitaminC);
        nutritionalValuesEntry.setIron(iron);
        nutritionalValuesEntry.setCalcium(calcium);
        nutritionalValuesEntry.setVitaminB6(vitaminB6);
        nutritionalValuesEntry.setVitaminB12(vitaminB12);
        nutritionalValuesEntry.setThiamin(thiamin);
        nutritionalValuesEntry.setRiboflavin(riboflavin);
        nutritionalValuesEntry.setVitaminE(vitaminE);
        nutritionalValuesEntry.setFolicAcid(folicAcid);
        nutritionalValuesEntry.setNiacin(niacin);
        nutritionalValuesEntry.setMagnesium(magnesium);
        nutritionalValuesEntry.setPhosphorus(phosphorus);
        nutritionalValuesEntry.setIodine(iodine);
        nutritionalValuesEntry.setZinc(zinc);
        nutritionalValuesEntry.setCopper(copper);
        nutritionalValuesEntry.setBiotin(biotin);
        nutritionalValuesEntry.setPantothenicAcid(pantothenicAcid);
        nutritionalValuesEntry.setVitaminD(vitaminD);

        log.info("Creating new food :: name = " + name + ", description = " + description + ", defaultFoodMeasurementUnitId = " + defaultFoodMeasurementUnitId +
                ", defaultServingSize" + defaultServingSize + ", caloriesPerServingSize" + caloriesPerServingSize + ", formType = " + formType);
        List<String> messages = new ArrayList<String>();
        try {
            Food food = context.getApiClientService().getClient().createFood(context.getOurUser(), name, description,
                    defaultFoodMeasurementUnitId, defaultServingSize, formType, nutritionalValuesEntry);
            String message = "Food created :: foodId = " + food.getFoodId() + ", name = " + food.getName();
            messages.add(message);
            log.info(message);
        } catch (FitbitAPIException e) {
View Full Code Here

        return "createFood";
    }

    @RequestMapping(value = "/invitations", method = RequestMethod.GET)
    public String showInvitationsPage(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }
        return "invitations";
View Full Code Here

        return "invitations";
    }

    @RequestMapping(value = "/sendInvitation", method = RequestMethod.POST)
    public String sendInvitation(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        String invitationMethod = request.getParameter("invitationMethod");
        String invitedUserIdOrEMail = request.getParameter("invitedUserIdOrEMail");

        log.info("Sending invitation :: invitationMethod = " + invitationMethod + ", invitedUserIdOrEMail = " + invitedUserIdOrEMail);
        List<String> messages = new ArrayList<String>();
        try {
            if (invitationMethod.equals("USER")) {
                context.getApiClientService().getClient().inviteByUserId(context.getOurUser(), invitedUserIdOrEMail);
            } else if (invitationMethod.equals("EMAIL")) {
                context.getApiClientService().getClient().inviteByEmail(context.getOurUser(), invitedUserIdOrEMail);
            } else {
                throw new IllegalArgumentException("Unknown invitation method.");
            }
            String message = "Invitation for invitedUserIdOrEMail =  " + invitedUserIdOrEMail + "successfully sent.";
            messages.add(message);
View Full Code Here

        return "invitations";
    }

    @RequestMapping(value = "/acceptInvitation", method = RequestMethod.POST)
    public String acceptInvitation(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        String senderUserId = request.getParameter("senderUserId");

        log.info("Accept invitation :: senderUserId = " + senderUserId);
        List<String> messages = new ArrayList<String>();
        try {
            context.getApiClientService().getClient().acceptInvitationFromUser(context.getOurUser(), new FitbitUser(senderUserId));
            String message = "Invitation from senderUserId =  " + senderUserId + " successfully accepted. Congratulations - you are friends.";
            messages.add(message);
            log.info(message);
        } catch (FitbitAPIException e) {
            if (e.getApiErrors() != null) {
View Full Code Here

        return "invitations";
    }

    @RequestMapping(value = "/sleep", method = RequestMethod.GET)
    public String showSleepPage(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }
        return "sleep";
View Full Code Here

        return "sleep";
    }

    @RequestMapping(value = "/getSleepLogs", method = RequestMethod.POST)
    public String getSleepLogs(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        String userId = request.getParameter("userId");
        String date = request.getParameter("date");

        log.info("Get sleep by date :: userId = " + userId + ", date = " + date);
        List<String> messages = new ArrayList<String>();
        Sleep sleep = null;
        try {
            sleep = context.getApiClientService().getClient().getSleep(context.getOurUser(), new FitbitUser(userId), FitbitApiService.getValidLocalDateOrNull(date));
            String message = "Sleep for userId =  '" + userId + "'  received.";
            messages.add(message);
            log.info(message);
        } catch (FitbitAPIException e) {
            populateMessages(messages, e);
View Full Code Here

        return "sleep";
    }

    @RequestMapping(value = "/logSleep", method = RequestMethod.POST)
    public String logSleep(HttpServletRequest request, HttpServletResponse response) {
        RequestContext context = new RequestContext();
        populate(context, request, response);
        if (!isAuthorized(context, request)) {
            showAuthorize(request, response);
        }

        String logDate = request.getParameter("logDate");
        String startTime = request.getParameter("startTime");
        String duration = request.getParameter("duration");

        log.info("Log sleep :: date =  " + logDate + ", startTime = " + startTime + ", duration = " + duration);
        List<String> messages = new ArrayList<String>();
        SleepLog sleepLog;
        try {
            sleepLog = context.getApiClientService().getClient().logSleep(
                    context.getOurUser(),
                    FitbitApiService.getValidLocalDateOrNull(logDate),
                    FitbitApiService.getValidTimeOrNull(startTime),
                    Long.valueOf(duration)
            );
            String message = "Log sleep added. logId =  " + sleepLog.getLogId() + ".";
View Full Code Here

TOP

Related Classes of com.fitbit.web.context.RequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.