예제 #1
0
 public static List<String> collectAttributeValues(Item item, String attributeName) {
   List<String> ids = new LinkedList<String>();
   for (Attribute attribute : item.getAttributes()) {
     if (attributeName.equals(attribute.getName())) {
       ids.add(attribute.getValue());
     }
   }
   return ids;
 }
  /*
   * Extracts the value for the given attribute from the list of attributes.
   * Extracted value is returned as an int.
   */
  protected int getIntValueForAttributeFromList(String attributeName, List<Attribute> attributes) {
    for (Attribute attribute : attributes) {
      if (attribute.getName().equals(attributeName)) {
        return Integer.parseInt(attribute.getValue());
      }
    }

    return 0;
  }
  /*
   * Extracts the value for the given attribute from the list of attributes.
   * Extracted value is returned as a String.
   */
  protected String getStringValueForAttributeFromList(
      String attributeName, List<Attribute> attributes) {
    for (Attribute attribute : attributes) {
      if (attribute.getName().equals(attributeName)) {
        return attribute.getValue();
      }
    }

    return "";
  }
예제 #4
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getParticipantById(java.lang.String)
   */
  public Participant getParticipantById(String participantId) {
    logger.debug(LOGPRE + "getParticipantById() start" + LOGPRE);

    Participant participant = new Participant();
    String selectRequest = "select * from `" + DOMAIN_PARTICIPANT + "`";
    List<Item> items = this.getDataFromDomain(selectRequest);
    Item findItem = new Item();

    if (!items.isEmpty()) {
      for (Item item : items) {
        if (item.getName().equals(participantId)) {
          findItem = item;
          break;
        }
      }
    }

    if (findItem != null) {
      participant.setId(findItem.getName());
      for (Attribute attribute : findItem.getAttributes()) {
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_NAME))
          participant.setName(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_EMAIL))
          participant.setEmail(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_COLLABORATION_ID))
          participant.setCollaborationId(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_IS_REG))
          participant.setIsReg(attribute.getValue());
      }
    }

    logger.debug(LOGPRE + "getParticipantById() end" + LOGPRE);
    return participant;
  }
예제 #5
0
 private static Collection<String> getValuesToSet(
     List<Attribute> atts, String propertyName, String columnName) {
   Collection<String> values = new ArrayList<String>();
   if (columnName != null) propertyName = columnName;
   for (Attribute att : atts) {
     String attName = att.getName();
     if (attName.equals(propertyName)) {
       values.add(att.getValue());
     }
   }
   return values;
 }
예제 #6
0
 private static String getValueToSet(
     List<Attribute> atts, String propertyName, String columnName) {
   if (columnName != null) propertyName = columnName;
   for (Attribute att : atts) {
     String attName = att.getName();
     if (attName.equals(propertyName)) {
       String val = att.getValue();
       return val;
     }
   }
   return null;
 }
  /*
   * Method returns the number of items in the High Scores Domain.
   */
  public int getCount() {
    if (count < 0) {
      SelectRequest selectRequest = new SelectRequest(COUNT_QUERY).withConsistentRead(true);
      List<Item> items = this.sdbClient.select(selectRequest).getItems();

      Item countItem = (Item) items.get(0);
      Attribute countAttribute =
          (Attribute)
              (((com.amazonaws.services.simpledb.model.Item) countItem).getAttributes().get(0));
      this.count = Integer.parseInt(countAttribute.getValue());
    }

    return this.count;
  }
예제 #8
0
 private static Set<String> getForeignKeys(
     EntityManagerSimpleJPA em,
     PersistentProperty getter,
     String columnName,
     List<Attribute> atts) {
   String fkAttName =
       columnName != null ? columnName : NamingHelper.foreignKey(getter.getFieldName());
   HashSet<String> keys = new HashSet<String>(atts.size());
   for (Attribute att : atts) {
     if (att.getName().equals(fkAttName)) {
       keys.add(att.getValue());
     }
   }
   return keys;
 }
예제 #9
0
 public TransactionSnapshot(Item item) {
   this.snapshotId = Long.valueOf(item.getName());
   for (Attribute attr : item.getAttributes()) {
     if (attr.getName().equals(TICKER)) {
       this.ticker = attr.getValue();
     } else if (attr.getName().equals(STOCK_PRICE)) {
       this.stockPrice = Double.parseDouble(attr.getValue());
     } else if (attr.getName().equals(NUM_OF_STOCKS)) {
       this.numOfStocks = Integer.parseInt(attr.getValue());
     } else if (attr.getName().equals(SP_500_PRICE)) {
       this.sp500Price = Double.parseDouble(attr.getValue());
     }
   }
 }
예제 #10
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCreatorById(java.lang.String)
   */
  public Creator getCreatorById(String id) {
    logger.debug(LOGPRE + "getCreatorById() start" + LOGPRE);

    Creator creator = new Creator();
    String selectRequest = "select * from `" + DOMAIN_CREATOR + "`";
    List<Item> items = this.getDataFromDomain(selectRequest);
    Item findItem = new Item();

    if (!items.isEmpty()) {
      for (Item item : items) {
        if (item.getName().equals(id)) {
          findItem = item;
          break;
        }
      }
    }

    if (findItem != null) {
      creator.setId(findItem.getName());
      for (Attribute attribute : findItem.getAttributes()) {
        if (attribute.getName().equals(CREATOR_ATTRIBUTE_NAME))
          creator.setName(attribute.getValue());
        if (attribute.getName().equals(CREATOR_ATTRIBUTE_PASSWORD))
          creator.setPassword(attribute.getValue());
        if (attribute.getName().equals(CREATOR_ATTRIBUTE_EMAIL))
          creator.setEmail(attribute.getValue());
      }
    }

    logger.debug(LOGPRE + "getCreatorById() end" + LOGPRE);
    return creator;
  }
예제 #11
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCreatorByName(java.lang.String)
   */
  public Creator getCreatorByName(String userName) {
    logger.debug(LOGPRE + "getCreatorByName() start" + LOGPRE);

    Creator creator = new Creator();
    String selectRequest =
        "select * from `"
            + DOMAIN_CREATOR
            + "` where "
            + CREATOR_ATTRIBUTE_NAME
            + " = '"
            + userName
            + "'";
    Item item = this.getDataFromDomain(selectRequest).get(0);

    creator.setId(item.getName());
    for (Attribute attribute : item.getAttributes()) {
      if (attribute.getName().equals(CREATOR_ATTRIBUTE_NAME)) creator.setName(attribute.getValue());
      if (attribute.getName().equals(CREATOR_ATTRIBUTE_PASSWORD))
        creator.setPassword(attribute.getValue());
      if (attribute.getName().equals(CREATOR_ATTRIBUTE_EMAIL))
        creator.setEmail(attribute.getValue());
    }

    logger.debug(LOGPRE + "getCreatorByName() end" + LOGPRE);
    return creator;
  }
예제 #12
0
 public UserComicImpl(
     String userComicId, List<Attribute> comicAttributes, List<Attribute> userComicAttributes) {
   this.userComicItemId = userComicId;
   this.fields = new TreeMap<String, String>();
   for (Attribute attribute : comicAttributes) {
     this.fields.put(attribute.getName(), attribute.getValue());
   }
   for (Attribute attribute : userComicAttributes) {
     this.fields.put(attribute.getName(), attribute.getValue());
   }
 }
예제 #13
0
  /**
   * Get a participant record from the data base by name and collaboration id.
   *
   * @param participantName
   * @param collaborationId
   * @return a participant
   */
  private Participant getParticipantByNameAndCollaborationId(
      String participantName, String collaborationId) {
    logger.debug(LOGPRE + "getParticipantByNameAndCollaborationId() start" + LOGPRE);

    Participant participant = new Participant();
    String selectRequest =
        "select * from `"
            + DOMAIN_PARTICIPANT
            + "` where "
            + PARTICIPANT_ATTRIBUTE_NAME
            + " = '"
            + participantName
            + "' AND "
            + PARTICIPANT_ATTRIBUTE_COLLABORATION_ID
            + "='"
            + collaborationId
            + "'";
    List<Item> items = this.getDataFromDomain(selectRequest);

    if (items != null) {
      Item item = items.get(0);
      participant.setId(item.getName());
      for (Attribute attribute : item.getAttributes()) {
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_NAME))
          participant.setName(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_EMAIL))
          participant.setEmail(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_COLLABORATION_ID))
          participant.setCollaborationId(attribute.getValue());
        if (attribute.getName().equals(PARTICIPANT_ATTRIBUTE_IS_REG))
          participant.setIsReg(attribute.getValue());
      }
    }

    logger.debug(LOGPRE + "getParticipantByNameAndCollaborationId() end" + LOGPRE);
    return participant;
  }
예제 #14
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;
    }
예제 #15
0
 /**
  * Convert a simpledb item to PriamInstance
  *
  * @param item
  * @return
  */
 public PriamInstance transform(Item item) {
   PriamInstance ins = new PriamInstance();
   Iterator<Attribute> attrs = item.getAttributes().iterator();
   while (attrs.hasNext()) {
     Attribute att = attrs.next();
     if (att.getName().equals(Attributes.INSTANCE_ID)) ins.setInstanceId(att.getValue());
     else if (att.getName().equals(Attributes.TOKEN)) ins.setToken(att.getValue());
     else if (att.getName().equals(Attributes.APP_ID)) ins.setApp(att.getValue());
     else if (att.getName().equals(Attributes.ID)) ins.setId(Integer.parseInt(att.getValue()));
     else if (att.getName().equals(Attributes.AVAILABILITY_ZONE)) ins.setRac(att.getValue());
     else if (att.getName().equals(Attributes.ELASTIC_IP)) ins.setHostIP(att.getValue());
     else if (att.getName().equals(Attributes.HOSTNAME)) ins.setHost(att.getValue());
     else if (att.getName().equals(Attributes.LOCATION)) ins.setDC(att.getValue());
     else if (att.getName().equals(Attributes.UPDATE_TS))
       ins.setUpdatetime(Long.parseLong(att.getValue()));
   }
   return ins;
 }
예제 #16
0
  public static <T> T buildObject(
      EntityManagerSimpleJPA em, Class<T> tClass, Object id, List<Attribute> atts) {
    T newInstance;
    /*
    Why was this here?  Should we merge if it exists though?
    newInstance = em.cacheGet(tClass, id);
    if (newInstance != null) {
        return newInstance;
    }*/
    AnnotationInfo ai = em.getFactory().getAnnotationManager().getAnnotationInfo(tClass);
    try {
      //            newInstance = tClass.newInstance();
      // check for DTYPE to see if it's a subclass, must be a faster way to do this you'd think?
      for (Attribute att : atts) {
        if (att.getName().equals(EntityManagerFactoryImpl.DTYPE)) {
          logger.finest("dtype=" + att.getValue());
          ai =
              em.getFactory()
                  .getAnnotationManager()
                  .getAnnotationInfoByDiscriminator(att.getValue());
          if (ai == null) {
            throw new PersistenceException(
                new ClassNotFoundException(
                    "Could not build object with dtype = "
                        + att.getValue()
                        + ". Class not found or is not an @Entity."));
          }
          tClass = ai.getMainClass();
          // check cache again with new class
          newInstance = em.cacheGet(tClass, id);
          if (newInstance != null) return newInstance;
          break;
        }
      }
      ObjectWithInterceptor owi = newEnancedInstance(em, tClass);
      newInstance = (T) owi.getBean();
      for (PersistentProperty field : ai.getPersistentProperties()) {
        String attName = field.getFieldName();
        String columnName = field.getColumnName();
        if (field.isForeignKeyRelationship()) {
          // lazy it up
          Set<String> keys = getForeignKeys(em, field, columnName, atts);
          logger.finest("keys=" + keys);
          if (keys == null || keys.isEmpty()) {
            continue;
          }
          // todo: stick a cache in here and check the cache for the instance before creating the
          // lazy loader.
          logger.finest(
              "creating new lazy loading instance for field "
                  + field.getFieldName()
                  + " of class "
                  + tClass.getSimpleName()
                  + " with id "
                  + id);
          //                    Object toSet = newLazyLoadingInstance(retType, keys);
          owi.getInterceptor().putForeignKey(attName, keys);
        } else if (field.isInverseRelationship()) {
          Class typeInList = field.getPropertyClass();
          // todo: should this return null if there are no elements??
          //                    LazyList lazyList = new LazyList(this, newInstance,
          // annotation.mappedBy(), id, typeInList,
          // factory.getAnnotationManager().getAnnotationInfo(typeInList));

          List<PersistentProperty.OrderClause> orderBy = null;
          if (List.class.isAssignableFrom(field.getRawClass())) {
            orderBy = field.getOrderClauses();
          }

          LazyList lazyList =
              new LazyList(
                  em,
                  typeInList,
                  oneToManyQuery(em, attName, field.getMappedBy(), id, typeInList, orderBy));
          //                    Class retType = field.getReturnType();
          // todo: assuming List for now, handle other collection types
          field.setProperty(newInstance, lazyList);
        } else if (field.isLob() || field.isJsonLob()) {
          // handled in Proxy
          String lobKeyAttributeName = field.getColumnName();
          String lobKeyVal = getValueToSet(atts, lobKeyAttributeName, columnName);
          logger.finest(
              "lobkeyval to set on interceptor=" + lobKeyVal + " - fromatt=" + lobKeyAttributeName);
          // TODO add multivalue support for LOB keys
          if (lobKeyVal != null)
            owi.getInterceptor().putForeignKey(attName, Collections.singleton(lobKeyVal));
        } else if (field.getEnumType() != null) {
          String val = getValueToSet(atts, attName, columnName);
          if (val != null) {
            Object enumVal = getEnumValue(field, val);
            field.setProperty(newInstance, enumVal);
          }
        } else if (field.isId()) {
          field.setProperty(newInstance, id);
        } else {
          Collection<String> val = getValuesToSet(atts, attName, columnName);
          if (val != null && !val.isEmpty()) {
            em.setFieldValue(tClass, newInstance, field, val);
          }
        }
      }
    } catch (Exception e) {
      throw new PersistenceException(e);
    }
    em.cachePut(id, newInstance);
    return newInstance;
  }
예제 #17
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCollaborationById(java.lang.String)
   */
  public Collaboration getCollaborationById(String collaborationId) {
    logger.debug(LOGPRE + "getCollaborationById() start" + LOGPRE);

    Collaboration collaboration = new Collaboration();
    String selectRequest = "select * from `" + DOMAIN_COLLABORATION + "`";
    List<Item> items = this.getDataFromDomain(selectRequest);
    Item findItem = new Item();

    if (!items.isEmpty()) {
      for (Item item : items) {
        if (item.getName().equals(collaborationId)) {
          findItem = item;
          break;
        }
      }
    }

    if (findItem != null) {
      List<String> participantNames = new ArrayList<String>();
      List<Participant> participants = new ArrayList<Participant>();

      collaboration.setId(findItem.getName());
      for (Attribute attribute : findItem.getAttributes()) {
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
          collaboration.setName(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
          collaboration.setCreatorId(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
          collaboration.setCurrentState(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
          participantNames.add(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
          collaboration.setWorkflowModel(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PROCESS_DEFINITION_ID))
          collaboration.setProcessDefId(attribute.getValue());
      }

      for (String s : participantNames) {
        Participant p = this.getParticipantByNameAndCollaborationId(s, findItem.getName());
        participants.add(p);
      }

      collaboration.setParticipants(participants);
    }

    logger.debug(LOGPRE + "getCollaborationById() end" + LOGPRE);
    return collaboration;
  }
예제 #18
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.PcsfSimpleDBAccess#getCollaborationByName(java.lang.String)
   */
  @Override
  public Collaboration getCollaborationByName(String collaborationName) {
    logger.debug(LOGPRE + "getCollaborationByName() start" + LOGPRE);

    Collaboration collaboration = new Collaboration();
    String selectExpression =
        "select * from `"
            + DOMAIN_COLLABORATION
            + "` where "
            + COLLABORATION_ATTRIBUTE_NAME
            + "='"
            + collaborationName
            + "'";
    Item findItem = this.getDataFromDomain(selectExpression).get(0);

    List<String> participantNames = new ArrayList<String>();
    List<Participant> participants = new ArrayList<Participant>();

    collaboration.setId(findItem.getName());
    for (Attribute attribute : findItem.getAttributes()) {
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
        collaboration.setName(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
        collaboration.setCreatorId(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
        collaboration.setCurrentState(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
        participantNames.add(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
        collaboration.setWorkflowModel(attribute.getValue());
    }

    for (String s : participantNames) {
      Participant p = this.getParticipantByNameAndCollaborationId(s, findItem.getName());
      participants.add(p);
    }

    collaboration.setParticipants(participants);

    logger.debug(LOGPRE + "getCollaborationByName() end" + LOGPRE);
    return collaboration;
  }
예제 #19
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;
    }
예제 #20
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCollaborationsByCreatorId(java.lang.String)
   */
  public List<Collaboration> getCollaborationsByCreatorId(String creatorId) {
    logger.debug(LOGPRE + "getCollaborationsByCreatorId() start" + LOGPRE);

    List<Collaboration> collaborations = new ArrayList<Collaboration>();
    String selectExpression =
        "select * from `"
            + DOMAIN_COLLABORATION
            + "` where "
            + COLLABORATION_ATTRIBUTE_CREATOR_ID
            + "='"
            + creatorId
            + "'";
    List<Item> items = this.getDataFromDomain(selectExpression);

    if (!items.isEmpty()) {
      for (Item item : items) {
        Collaboration collaboration = new Collaboration();
        List<String> users = new ArrayList<String>();
        List<Participant> participants = new ArrayList<Participant>();
        collaboration.setId(item.getName());
        for (Attribute attribute : item.getAttributes()) {
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
            collaboration.setName(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
            collaboration.setCreatorId(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
            collaboration.setCurrentState(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
            users.add(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
            collaboration.setWorkflowModel(attribute.getValue());
        }

        for (String user : users) {
          Participant p = this.getParticipantByNameAndCollaborationId(user, collaboration.getId());
          participants.add(p);
        }

        collaboration.setParticipants(participants);
        collaborations.add(collaboration);
      }
    }

    logger.debug(LOGPRE + "getCollaborationsByCreatorId() end" + LOGPRE);
    return collaborations;
  }