Example #1
0
    @Override
    protected Boolean doInBackground(LotLocation... lotLocation) {

      AmazonSimpleDBClient instance = SimpleDB.getInstance();
      if (instance != null) {

        // this was being used when we were pulling flags from the LotLocation db and then updating
        // a single column value
        // by 1 to increment continually however felt it was better to store separately so that we
        // can get more data on it
        //                int flagCount = 0;
        //
        //                SelectResult result = instance.select(new SelectRequest("select flags from
        // `Locations` where itemName() = '" + lotLocation[0].getId() + "'"));
        //                if (result != null) {
        //                    //grab the flag count currently in place for the lot then increment it
        // by 1
        //                    String flagCountString =
        // ((Attribute)result.getItems().get(0).getAttributes().toArray()[0]).getValue();
        //                    flagCount = flagCountString == null || flagCountString.isEmpty() ? 0 :
        // Integer.valueOf(flagCountString);
        //                    flagCount += 1;
        //                }

        String deviceId = Generator.getUniquePsuedoID();

        PutAttributesRequest request = new PutAttributesRequest().withDomainName("Location_Flags");
        request.setItemName(lotLocation[0].getId() + "," + deviceId);

        Collection<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
        attributes.add(new ReplaceableAttribute("location_id", lotLocation[0].getId(), true));
        attributes.add(new ReplaceableAttribute("flagged_by", deviceId, true));
        attributes.add(new ReplaceableAttribute("date_time", new DateTime().toString(), true));
        request.setAttributes(attributes);

        boolean success = true;
        try {
          SimpleDB.getInstance().putAttributes(request);
        } catch (Exception e) {
          success = false;
          Log.e(
              "AddLotFlagTask",
              "Failure trying to update flag count for location [" + lotLocation[0] + "]",
              e);
        }

        return success;
      } else return false;
    }
 protected Void doInBackground(Void... voids) {
   domainNameList = SimpleDB.getMoreDomainNames();
   for (String domain : domainNameList) {
     Log.e("DOMAIN", domain);
   }
   return null;
 }
Example #3
0
    protected Void doInBackground(List<LotLocation>... locations) {
      try {
        int count = locations[0].size();
        for (LotLocation placemark : locations[0]) {
          ReplaceableAttribute descriptionAttribute =
              new ReplaceableAttribute("description", placemark.getDescription(), Boolean.TRUE);
          ReplaceableAttribute latAttribute =
              new ReplaceableAttribute(
                  "lat", String.valueOf(placemark.getPoint().latitude), Boolean.TRUE);
          ReplaceableAttribute lngAttribute =
              new ReplaceableAttribute(
                  "lng", String.valueOf(placemark.getPoint().longitude), Boolean.TRUE);

          List attrs = new ArrayList(3);
          attrs.add(descriptionAttribute);
          attrs.add(latAttribute);
          attrs.add(lngAttribute);

          PutAttributesRequest par =
              new PutAttributesRequest(
                  "Locations", new Generator().getRandomID("LOT-ADMIN-"), attrs);
          SimpleDB.getInstance().putAttributes(par);

          publishProgress((int) ((count-- / (float) locations[0].size()) * 100));
        }
      } catch (Exception e) {
        Log.e("LoadLocationsTask", "Failure attempting to load locations in background task", e);
      }

      return null;
    }
Example #4
0
    @Override
    protected TreeMap<Float, DropsiteLocation> doInBackground(
        android.location.Location... location) {

      TreeMap<Float, DropsiteLocation> locations = new TreeMap<Float, DropsiteLocation>();

      try {

        if (location[0] != null) {
          android.location.Location currentLocation = location[0];

          SelectResult result =
              SimpleDB.getInstance()
                  .select(new SelectRequest("select * from `Dropsites` limit 25"));
          for (Item dropsite : result.getItems()) {
            android.location.Location dropsiteLocation =
                new android.location.Location(currentLocation.getProvider());

            DropsiteLocation internalDropsiteLocation = new DropsiteLocation();
            internalDropsiteLocation.setId(dropsite.getName());

            // used to temporarily store hours of open and close for each location
            Hashtable<Integer, String> dateOpen = new Hashtable<Integer, String>();
            Hashtable<Integer, String> dateClose = new Hashtable<Integer, String>();

            for (Attribute attribute : dropsite.getAttributes()) {

              if (attribute.getName().equalsIgnoreCase("location"))
                internalDropsiteLocation.setLocation(attribute.getValue());
              if (attribute.getName().equalsIgnoreCase("description"))
                internalDropsiteLocation.setDescription(attribute.getValue());

              if (attribute.getName().equalsIgnoreCase("start_collection"))
                internalDropsiteLocation.setDateOpen(DateTime.parse(attribute.getValue()));
              if (attribute.getName().equalsIgnoreCase("end_collection"))
                internalDropsiteLocation.setDateClose(DateTime.parse(attribute.getValue()));

              if (attribute.getName().equalsIgnoreCase("lat"))
                dropsiteLocation.setLatitude(Double.parseDouble(attribute.getValue()));
              if (attribute.getName().equalsIgnoreCase("lng"))
                dropsiteLocation.setLongitude(Double.parseDouble(attribute.getValue()));

              if (attribute.getName().equalsIgnoreCase("city"))
                internalDropsiteLocation.setCityCode(attribute.getValue());
            }

            // store the location of the lot
            internalDropsiteLocation.setPoint(
                new LatLng(dropsiteLocation.getLatitude(), dropsiteLocation.getLongitude()));

            // save it to our locations listing to return back to the consumer
            locations.put(currentLocation.distanceTo(dropsiteLocation), internalDropsiteLocation);
          }
        }
      } catch (Exception e) {
        Log.e("GetDropsitesTask", "Failure attempting to get locations", e);
      }

      return locations;
    }
Example #5
0
    @Override
    protected Boolean doInBackground(LotLocation... lotLocation) {
      PutAttributesRequest request = new PutAttributesRequest().withDomainName("Locations");
      request.setItemName(new Generator().getRandomID(LOT_USER_PREFIX));

      Collection<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
      attributes.add(
          new ReplaceableAttribute(
              "lat",
              Double.toString(ImplLocationService.INSTANCE.getCurrentLocation().getLatitude()),
              true));
      attributes.add(
          new ReplaceableAttribute(
              "lng",
              Double.toString(ImplLocationService.INSTANCE.getCurrentLocation().getLongitude()),
              true));
      attributes.add(new ReplaceableAttribute("location", lotLocation[0].getLocation(), true));
      attributes.add(new ReplaceableAttribute("business", lotLocation[0].getBusiness(), true));
      attributes.add(new ReplaceableAttribute("phone", lotLocation[0].getPhone(), true));
      attributes.add(
          new ReplaceableAttribute("description", lotLocation[0].getDescription(), true));
      attributes.add(
          new ReplaceableAttribute("amex", lotLocation[0].isAcceptsAmex() ? "1" : "0", true));
      attributes.add(
          new ReplaceableAttribute(
              "discover", lotLocation[0].isAcceptsDiscover() ? "1" : "0", true));
      attributes.add(
          new ReplaceableAttribute(
              "mastercard", lotLocation[0].isAcceptsMastercard() ? "1" : "0", true));
      attributes.add(
          new ReplaceableAttribute("visa", lotLocation[0].isAcceptsVisa() ? "1" : "0", true));
      attributes.add(new ReplaceableAttribute("added_by", Generator.getUniquePsuedoID(), true));
      attributes.add(new ReplaceableAttribute("date_added", new DateTime().toString(), true));
      attributes.add(new ReplaceableAttribute("active", "1", true));
      request.setAttributes(attributes);

      boolean success = true;
      try {
        SimpleDB.getInstance().putAttributes(request);
      } catch (Exception e) {
        success = false;
        Log.e(
            "AddLotLocationTask",
            "Failure trying to write lot location [" + lotLocation[0] + "]",
            e);
      }

      return success;
    }
    protected Void doInBackground(Void... voids) {

      try {
        SimpleDB.createItem(domainName.getSelectedItem().toString(), itemName.getText().toString());

      } catch (AmazonServiceException e) {
        if ("InvalidClientTokenId".equals(e.getErrorCode())) {
          putRefreshError();
        } else {
          setStackAndPost(e);
        }
      } catch (Throwable e) {
        setStackAndPost(e);
      }

      return null;
    }
 protected Void doInBackground(Void... voids) {
   domainNameList = SimpleDB.getDomainNames(NUM_DOMAINS);
   return null;
 }
Example #8
0
    @Override
    protected TreeMap<Float, LotLocation> doInBackground(android.location.Location... location) {

      TreeMap<Float, LotLocation> locations = new TreeMap<Float, LotLocation>();

      try {

        // null checking party ahead, majority stems form no connection, perhaps a connection
        // manager could centralize this
        if (location[0] != null) {
          android.location.Location currentLocation = location[0];

          AmazonSimpleDBClient instance = SimpleDB.getInstance();
          if (instance != null) {

            SelectResult result =
                instance.select(
                    new SelectRequest("select * from `Locations` where active = '1' limit 50"));
            if (result != null) {
              for (Item lot : result.getItems()) {
                android.location.Location lotLocation =
                    new android.location.Location(currentLocation.getProvider());

                LotLocation internalLotLocation = new LotLocation();
                internalLotLocation.setId(lot.getName());

                // used to temporarily store hours of open and close for each location
                Hashtable<Integer, String> hoursOpen = new Hashtable<Integer, String>();
                Hashtable<Integer, String> hoursClose = new Hashtable<Integer, String>();

                for (Attribute attribute : lot.getAttributes()) {

                  if (attribute.getName().equalsIgnoreCase("location"))
                    internalLotLocation.setLocation(attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("rating"))
                    internalLotLocation.setRating(Float.parseFloat(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("business"))
                    internalLotLocation.setBusiness(attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("description"))
                    internalLotLocation.setDescription(attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("amex"))
                    internalLotLocation.setAcceptsAmex(
                        com.experiment.trax.utils.Boolean.valueOf(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("visa"))
                    internalLotLocation.setAcceptsVisa(
                        com.experiment.trax.utils.Boolean.valueOf(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("mastercard"))
                    internalLotLocation.setAcceptsMastercard(
                        com.experiment.trax.utils.Boolean.valueOf(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("discover"))
                    internalLotLocation.setAcceptsDiscover(
                        com.experiment.trax.utils.Boolean.valueOf(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("phone"))
                    internalLotLocation.setPhone(attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("verified"))
                    internalLotLocation.setVerified(
                        com.experiment.trax.utils.Boolean.valueOf(attribute.getValue()));

                  // create a key -> value to day of week and time opened or closed
                  if (attribute.getName().equalsIgnoreCase("1_open"))
                    hoursOpen.put(1, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("1_close"))
                    hoursClose.put(1, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("2_open"))
                    hoursOpen.put(2, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("2_close"))
                    hoursClose.put(2, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("3_open"))
                    hoursOpen.put(3, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("3_close"))
                    hoursClose.put(3, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("4_open"))
                    hoursOpen.put(4, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("4_close"))
                    hoursClose.put(4, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("5_open"))
                    hoursOpen.put(5, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("5_close"))
                    hoursClose.put(5, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("6_open"))
                    hoursOpen.put(6, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("6_close"))
                    hoursClose.put(6, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("7_open"))
                    hoursOpen.put(7, attribute.getValue());
                  if (attribute.getName().equalsIgnoreCase("7_close"))
                    hoursClose.put(7, attribute.getValue());

                  if (attribute.getName().equalsIgnoreCase("lat"))
                    lotLocation.setLatitude(Double.parseDouble(attribute.getValue()));
                  if (attribute.getName().equalsIgnoreCase("lng"))
                    lotLocation.setLongitude(Double.parseDouble(attribute.getValue()));
                }

                // store the times the lot is opened and closed
                internalLotLocation.setHoursOpen(hoursOpen);
                internalLotLocation.setHoursClose(hoursClose);

                // store the location of the lot
                internalLotLocation.setPoint(
                    new LatLng(lotLocation.getLatitude(), lotLocation.getLongitude()));

                // save it to our locations listing to return back to the consumer
                locations.put(currentLocation.distanceTo(lotLocation), internalLotLocation);
              }
            }
          }
        }
      } catch (Exception e) {
        Log.e("GetLocationsTask", "Failure attempting to get locations", e);
      }

      return locations;
    }