private void initChannelMapping(ApiKey apiKey, final List<CalendarConfig> calendarConfigs) {
    bodyTrackHelper.deleteChannelMappings(apiKey);
    ChannelMapping mapping = new ChannelMapping();
    mapping.deviceName = "google_calendar";
    mapping.channelName = "events";
    mapping.timeType = ChannelMapping.TimeType.gmt;
    mapping.channelType = ChannelMapping.ChannelType.timespan;
    mapping.guestId = apiKey.getGuestId();
    mapping.apiKeyId = apiKey.getId();
    bodyTrackHelper.persistChannelMapping(mapping);

    BodyTrackHelper.ChannelStyle channelStyle = new BodyTrackHelper.ChannelStyle();
    channelStyle.timespanStyles = new BodyTrackHelper.MainTimespanStyle();
    channelStyle.timespanStyles.defaultStyle = new BodyTrackHelper.TimespanStyle();
    channelStyle.timespanStyles.defaultStyle.fillColor = "#92da46";
    channelStyle.timespanStyles.defaultStyle.borderColor = "#92da46";
    channelStyle.timespanStyles.defaultStyle.borderWidth = 2;
    channelStyle.timespanStyles.defaultStyle.top = 1.0;
    channelStyle.timespanStyles.defaultStyle.bottom = 1.0;
    channelStyle.timespanStyles.values = new HashMap();

    GoogleCalendarConnectorSettings connectorSettings =
        (GoogleCalendarConnectorSettings) settingsService.getConnectorSettings(apiKey.getId());
    int n = calendarConfigs.size();
    if (connectorSettings != null) {
      n = 0;
      for (CalendarConfig calendar : connectorSettings.calendars) {
        if (!calendar.hidden) n++;
      }
    }
    double rowHeight = 1.f / (n * 2 + 1);
    int i = 0;
    for (CalendarConfig config : calendarConfigs) {
      if (connectorSettings != null && config.hidden) continue;

      BodyTrackHelper.TimespanStyle stylePart = new BodyTrackHelper.TimespanStyle();

      final int rowsFromTop = (i + 1) * 2 - 1;

      stylePart.top = (double) rowsFromTop * rowHeight - (rowHeight * 0.25);
      stylePart.bottom = stylePart.top + rowHeight + (rowHeight * 0.25);
      stylePart.fillColor = config.backgroundColor;
      stylePart.borderColor = config.backgroundColor;
      channelStyle.timespanStyles.values.put(config.id, stylePart);
      i++;
    }

    bodyTrackHelper.setDefaultStyle(apiKey.getGuestId(), "google_calendar", "events", channelStyle);
  }
  @Override
  public void handleField(final long guestId, AbstractFacet facet) {
    WithingsBodyScaleMeasureFacet measureFacet = (WithingsBodyScaleMeasureFacet) facet;
    if (measureFacet.weight == 0) return;

    List<List<Object>> data = new ArrayList<List<Object>>();
    List<Object> record = new ArrayList<Object>();
    // Creating the array [time, bedTime_in_hours] to insert in datastore
    record.add(((double) facet.start) / 1000.0);
    record.add(measureFacet.weight);
    data.add(record);

    // TODO: check the status code in the BodyTrackUploadResult
    bodyTrackHelper.uploadToBodyTrack(guestId, "Withings", Arrays.asList("weight"), data);
  }