Projects >> fluxtream-app >>44f4d4584182bf7a6434539e8a56c3ecb5343458

Chunk
Conflicting content
package com.fluxtream.connectors.google_latitude;

<<<<<<< HEAD
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
=======
import java.util.List;
>>>>>>> 9e09b3e5648365cade6196c7c1872857a4c25454
import com.fluxtream.connectors.Connector.UpdateStrategyType;
import com.fluxtream.connectors.FileUploadSupport;
import com.fluxtream.connectors.annotations.JsonFacetCollection;
Solution content
package com.fluxtream.connectors.google_latitude;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.fluxtream.connectors.Connector.UpdateStrategyType;
import com.fluxtream.connectors.FileUploadSupport;
import com.fluxtream.connectors.annotations.JsonFacetCollection;
File
GoogleLatitudeUpdater.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
import com.fluxtream.connectors.annotations.Updater;
import com.fluxtream.connectors.location.LocationFacet;
import com.fluxtream.connectors.location.LocationFacetVOCollection;
<<<<<<< HEAD
import com.fluxtream.connectors.updaters.AbstractGoogleOAuthUpdater;
import com.fluxtream.connectors.updaters.UpdateInfo;
import com.fluxtream.domain.ApiKey;
import com.fluxtream.services.ApiDataService;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
=======
import com.fluxtream.connectors.updaters.AbstractUpdater;
import com.fluxtream.connectors.updaters.UpdateInfo;
import com.fluxtream.services.ApiDataService;
import com.fluxtream.services.GuestService;
import com.fluxtream.services.JPADaoService;
import com.google.api.client.http.HttpTransport;
>>>>>>> 9e09b3e5648365cade6196c7c1872857a4c25454
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Solution content
import org.codehaus.jackson.JsonFactory;
import com.fluxtream.connectors.annotations.Updater;
import com.fluxtream.connectors.location.LocationFacet;
import com.fluxtream.connectors.location.LocationFacetVOCollection;
import com.fluxtream.connectors.updaters.AbstractUpdater;
import com.fluxtream.connectors.updaters.UpdateInfo;
import com.fluxtream.domain.ApiKey;
import com.fluxtream.services.ApiDataService;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
File
GoogleLatitudeUpdater.java
Developer's decision
Combination
Kind of conflict
Import
Chunk
Conflicting content
@Component
@Updater(prettyName = "Latitude", value = 2, objectTypes = { LocationFacet.class }, updateStrategyType = UpdateStrategyType.INCREMENTAL)
@JsonFacetCollection(LocationFacetVOCollection.class)
<<<<<<< HEAD
public class GoogleLatitudeUpdater extends AbstractGoogleOAuthUpdater implements FileUploadSupport {
=======
public class GoogleLatitudeUpdater extends AbstractUpdater {

	@Autowired
	GuestService guestService;

	@Autowired
	ApiDataService apiDataService;

    @Autowired
    GoogleOAuth2Helper oAuth2Helper;
>>>>>>> 9e09b3e5648365cade6196c7c1872857a4c25454

    @Autowired
    ApiDataService apiDataService;
Solution content
@Component
@Updater(prettyName = "Latitude", value = 2, objectTypes = { LocationFacet.class }, updateStrategyType = UpdateStrategyType.INCREMENTAL)
@JsonFacetCollection(LocationFacetVOCollection.class)
public class GoogleLatitudeUpdater extends AbstractUpdater implements FileUploadSupport {

    @Autowired
    ApiDataService apiDataService;
File
GoogleLatitudeUpdater.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Class signature
Chunk
Conflicting content
	}

	public void updateConnectorData(UpdateInfo updateInfo) throws Exception {
<<<<<<< HEAD
	}

    @Override
    public int importFile(final ApiKey apiKey, final File f) throws Exception {
        ZipFile zipFile = new ZipFile(f);
        final Enumeration entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            final ZipEntry zipEntry = entries.nextElement();
            if (zipEntry.isDirectory()) continue;
            if (zipEntry.getName().endsWith("LocationHistory.json"))
                return parseLocations(apiKey, zipFile.getInputStream(zipEntry));
        }
        throw new RuntimeException("Couldn't find LocationHistory.json in the uploaded zip file");
    }

    private int parseLocations(final ApiKey apiKey, final InputStream inputStream) throws IOException {
        JsonFactory jfactory = new JsonFactory();
        JsonParser jParser = jfactory.createJsonParser(inputStream);

        JsonToken token;
        List locations = new ArrayList();

        getToLocationData(jParser);

        int nLocations = 0;
        while ((token = jParser.nextToken())!=null) {
            if (token==JsonToken.START_OBJECT) {
                jParser.nextToken();
                parseLocation(apiKey, jParser, locations);
                if (locations.size()==1000) {
                    nLocations += 1000;
                    if (apiKey!=null) apiDataService.addGuestLocations(apiKey.getGuestId(), locations);
                    locations.clear();
                }
            }
        }
        nLocations += locations.size();
        if (apiKey!=null) apiDataService.addGuestLocations(apiKey.getGuestId(), locations);
        return nLocations;
    }

    private void getToLocationData(final JsonParser jParser) throws IOException {
        // get to the first object
        while (jParser.nextToken()!=JsonToken.START_OBJECT);
        String currentName;
        while ((currentName=jParser.getCurrentName())==null)
            jParser.nextToken();
        // if it's one of the location fields, we're good
        if (Arrays.asList("timestampMs", "accuracy", "latitudeE7", "longitudeE7").contains(currentName))
            return;
        // else skip everything until we reach the "locations" array
        while (!jParser.getCurrentName().equals("locations"))
            jParser.nextToken();
        // this recursion should only happen once
        getToLocationData(jParser);
    }

    void parseLocation(final ApiKey apiKey, final JsonParser jParser, final List locations) throws IOException {
        LocationFacet locationFacet = new LocationFacet();
        if (apiKey!=null) {
            locationFacet.apiKeyId = apiKey.getId();
            locationFacet.guestId = apiKey.getGuestId();
        }
        locationFacet.timeUpdated = System.currentTimeMillis();
        locationFacet.source = LocationFacet.Source.GOOGLE_LATITUDE;

        do {
            String fieldName = jParser.getCurrentName();
            jParser.nextToken();
            if (fieldName.equals("timestampMs")) {
                long ts = Long.valueOf(jParser.getText());
                locationFacet.timestampMs = ts;
                locationFacet.start = ts;
                locationFacet.end = ts;
                locationFacet.api = 2;
            } else if (fieldName.equals("accuracy")) {
                int accuracy = jParser.getIntValue();
                locationFacet.accuracy = accuracy;
            } else if (fieldName.equals("latitudeE7")) {
                int lat = jParser.getIntValue();
                locationFacet.latitude = lat/1E7f;
            } else if (fieldName.equals("longitudeE7")) {
                int lon = jParser.getIntValue();
                locationFacet.longitude = lon/1E7f;
            }
        } while (jParser.nextToken() != JsonToken.END_OBJECT);
        locations.add(locationFacet);
    }
=======
        //final LocationFacet newest = jpaDaoService.findOne("location.newest", LocationFacet.class, updateInfo.getGuestId(), updateInfo.apiKey.getId());
        //ApiUpdate lastSuccessfulUpdate = connectorUpdateService
		//		.getLastSuccessfulUpdate(updateInfo.apiKey);
		//loadHistory(updateInfo, newest!=null?newest.start:lastSuccessfulUpdate.ts,
		//		System.currentTimeMillis());
	}

	private void loadHistory(UpdateInfo updateInfo, long from, long to)
			throws Exception {
        //String accessToken = oAuth2Helper.getAccessToken(updateInfo.apiKey);
        //HttpTransport transport = this.getTransport(updateInfo.apiKey);
        //String key = env.get("google_latitudeApiKey");
        //List locationList = executeList(updateInfo, transport,
			//	key, 1000, from, to, accessToken);
        //if (locationList != null && locationList.size() > 0) {
			//List storedLocations = new ArrayList();
			//for (LocationFacet locationResource : locationList) {
			//	if (locationResource.timestampMs==0)
			//		continue;
        //        locationResource.guestId = updateInfo.getGuestId();
        //        locationResource.apiKeyId = updateInfo.apiKey.getId();
			//	locationResource.start = locationResource.timestampMs;
			//	locationResource.end = locationResource.timestampMs;
        //        locationResource.source = LocationFacet.Source.GOOGLE_LATITUDE;
        //        locationResource.apiKeyId = updateInfo.apiKey.getId();
        //        locationResource.api= updateInfo.apiKey.getConnector().value();
        //
			//	storedLocations.add(locationResource);
			//}
        //    apiDataService.addGuestLocations(updateInfo.getGuestId(), storedLocations);
			//Collections.sort(storedLocations);
			//LocationFacet oldest = storedLocations.get(0);
        //    // Check if there is potentially a second or more of data left to get.  If so,
        //    // recurse with a new to time of a second before the oldest location we currently have.
        //    // Otherwise, end now
        //    if(oldest.timestampMs-1000 >= from) {
        //        loadHistory(updateInfo, from, oldest.timestampMs-1000);
        //    }
        //}
	}

	private List executeList(UpdateInfo updateInfo,
			HttpTransport transport, String key, int maxResults, long minTime,
			long maxTime, String accessToken) throws Exception {
		//long then = System.currentTimeMillis();
		//String requestUrl = "request url not set yet";
		//try {
		//	transport.addParser(new JsonCParser());
		//	HttpRequest request = transport.buildGetRequest();
		//	LatitudeUrl latitudeUrl = LatitudeUrl.forLocation();
		//	latitudeUrl.maxResults = String.valueOf(maxResults);
		//	latitudeUrl.granularity = "best";
		//	latitudeUrl.minTime = String.valueOf(minTime);
		//	latitudeUrl.maxTime = String.valueOf(maxTime);
		//	latitudeUrl.put("location", "all");
         //   latitudeUrl.put("key", key);
         //   latitudeUrl.put("access_token", accessToken);
		//	request.url = latitudeUrl;
		//	requestUrl = latitudeUrl.build();
		//	HttpResponse response = request.execute();
		//	List result = response.parseAs(LocationList.class).items;
		//	countSuccessfulApiCall(updateInfo.apiKey,
		//			updateInfo.objectTypes, then, requestUrl);
		//	return result;
		//} catch (Exception e) {
		//	countFailedApiCall(updateInfo.apiKey,
		//			updateInfo.objectTypes, then, requestUrl, Utils.stackTrace(e));
		//	throw e;
		//}
        return null;
	}
>>>>>>> 9e09b3e5648365cade6196c7c1872857a4c25454

}
Solution content
	}

	public void updateConnectorData(UpdateInfo updateInfo) throws Exception {
	}

    @Override
    public int importFile(final ApiKey apiKey, final File f) throws Exception {
        ZipFile zipFile = new ZipFile(f);
        final Enumeration entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            final ZipEntry zipEntry = entries.nextElement();
            if (zipEntry.isDirectory()) continue;
            if (zipEntry.getName().endsWith("LocationHistory.json"))
                return parseLocations(apiKey, zipFile.getInputStream(zipEntry));
        }
        throw new RuntimeException("Couldn't find LocationHistory.json in the uploaded zip file");
    }

    private int parseLocations(final ApiKey apiKey, final InputStream inputStream) throws IOException {
        JsonFactory jfactory = new JsonFactory();
        JsonParser jParser = jfactory.createJsonParser(inputStream);

        JsonToken token;
        List locations = new ArrayList();

        getToLocationData(jParser);

        int nLocations = 0;
        while ((token = jParser.nextToken())!=null) {
            if (token==JsonToken.START_OBJECT) {
                jParser.nextToken();
                parseLocation(apiKey, jParser, locations);
                if (locations.size()==1000) {
                    nLocations += 1000;
                    if (apiKey!=null) apiDataService.addGuestLocations(apiKey.getGuestId(), locations);
                    locations.clear();
                }
            }
        }
        nLocations += locations.size();
        if (apiKey!=null) apiDataService.addGuestLocations(apiKey.getGuestId(), locations);
        return nLocations;
    }

    private void getToLocationData(final JsonParser jParser) throws IOException {
        // get to the first object
        while (jParser.nextToken()!=JsonToken.START_OBJECT);
        String currentName;
        while ((currentName=jParser.getCurrentName())==null)
            jParser.nextToken();
        // if it's one of the location fields, we're good
        if (Arrays.asList("timestampMs", "accuracy", "latitudeE7", "longitudeE7").contains(currentName))
            return;
        // else skip everything until we reach the "locations" array
        while (!jParser.getCurrentName().equals("locations"))
            jParser.nextToken();
        // this recursion should only happen once
        getToLocationData(jParser);
    }

    void parseLocation(final ApiKey apiKey, final JsonParser jParser, final List locations) throws IOException {
        LocationFacet locationFacet = new LocationFacet();
        if (apiKey!=null) {
            locationFacet.apiKeyId = apiKey.getId();
            locationFacet.guestId = apiKey.getGuestId();
        }
        locationFacet.timeUpdated = System.currentTimeMillis();
        locationFacet.source = LocationFacet.Source.GOOGLE_LATITUDE;

        do {
            String fieldName = jParser.getCurrentName();
            jParser.nextToken();
            if (fieldName.equals("timestampMs")) {
                long ts = Long.valueOf(jParser.getText());
                locationFacet.timestampMs = ts;
                locationFacet.start = ts;
                locationFacet.end = ts;
                locationFacet.api = 2;
            } else if (fieldName.equals("accuracy")) {
                int accuracy = jParser.getIntValue();
                locationFacet.accuracy = accuracy;
            } else if (fieldName.equals("latitudeE7")) {
                int lat = jParser.getIntValue();
                locationFacet.latitude = lat/1E7f;
            } else if (fieldName.equals("longitudeE7")) {
                int lon = jParser.getIntValue();
                locationFacet.longitude = lon/1E7f;
            }
        } while (jParser.nextToken() != JsonToken.END_OBJECT);
        locations.add(locationFacet);
    }

}
File
GoogleLatitudeUpdater.java
Developer's decision
Version 1
Kind of conflict
Annotation
Comment
Method declaration