package org.fluxtream.connectors.withings; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.fluxtream.core.domain.AbstractFacet; import org.fluxtream.core.domain.ApiKey; import org.fluxtream.core.domain.ChannelMapping; import org.fluxtream.core.services.impl.BodyTrackHelper; import org.fluxtream.core.services.impl.FieldHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component("withingsFatFreeMass") public class WithingsFatFreeMassFieldHandler implements FieldHandler { @Autowired BodyTrackHelper bodyTrackHelper; @Override public List<BodyTrackHelper.BodyTrackUploadResult> handleField (final ApiKey apiKey, AbstractFacet facet) { WithingsBodyScaleMeasureFacet measureFacet = (WithingsBodyScaleMeasureFacet) facet; if (measureFacet.fatFreeMass == 0) return Arrays.asList(); 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.fatFreeMass); data.add(record); // TODO: check the status code in the BodyTrackUploadResult return Arrays.asList(bodyTrackHelper.uploadToBodyTrack(apiKey , "Withings", Arrays.asList("fatFreeMass"), data)); } @Override public void addToDeclaredChannelMappings(final ApiKey apiKey, final List<ChannelMapping> channelMappings) { ChannelMapping.addToDeclaredMappings(apiKey, 1, apiKey.getConnector().getDeviceNickname(), "fatFreeMass", channelMappings); } }