public Item unmarshall(StaxUnmarshallerContext context) throws Exception {
    Item item = new Item();
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) targetDepth += 2;

    while (true) {
      XMLEvent xmlEvent = context.nextEvent();
      if (xmlEvent.isEndDocument()) return item;

      if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
        if (context.testExpression("Name", targetDepth)) {
          item.setName(StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("Name/@encoding", targetDepth)) {
          item.setAlternateNameEncoding(StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("Attribute", targetDepth)) {
          item.getAttributes().add(AttributeStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
      } else if (xmlEvent.isEndElement()) {
        if (context.getCurrentDepth() < originalDepth) {
          return item;
        }
      }
    }
  }
  /*
   * (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;
  }
  /*
   * (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;
  }
  /*
   * (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;
  }
    @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;
    }
 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;
 }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Item == false) return false;
    Item other = (Item) obj;

    if (other.getName() == null ^ this.getName() == null) return false;
    if (other.getName() != null && other.getName().equals(this.getName()) == false) return false;
    if (other.getAlternateNameEncoding() == null ^ this.getAlternateNameEncoding() == null)
      return false;
    if (other.getAlternateNameEncoding() != null
        && other.getAlternateNameEncoding().equals(this.getAlternateNameEncoding()) == false)
      return false;
    if (other.getAttributes() == null ^ this.getAttributes() == null) return false;
    if (other.getAttributes() != null
        && other.getAttributes().equals(this.getAttributes()) == false) return false;
    return true;
  }
 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());
     }
   }
 }
  /*
   * (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;
  }
  /*
   * (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;
  }
 @Override
 protected List<?> buildRow(Item item) throws TranslatorException {
   Map<String, List<String>> valueMap = createAttributeMap(item.getAttributes());
   List row = new ArrayList();
   Object[] results = new Object[valueMap.size()];
   int i = 0;
   for (String attributeName : valueMap.keySet()) {
     if (SimpleDBMetadataProcessor.isItemName(attributeName)) {
       results[i++] = item.getName();
       continue;
     }
     List<String> value = valueMap.get(attributeName);
     results[i++] = (value.size() == 1) ? value.get(0) : value.toString();
   }
   row.add(results);
   return row;
 }
Exemple #12
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;
 }
  /*
   * (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;
  }
  /**
   * 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;
  }
 /*
  * Extracts the 'player' attribute from the SimpleDB Item.
  */
 protected String getPlayerForItem(Item item) {
   return this.getStringValueForAttributeFromList(PLAYER_ATTRIBUTE, item.getAttributes());
 }
 /*
  * Extracts the 'score' attribute from the SimpleDB Item.
  */
 protected int getScoreForItem(Item item) {
   return this.getIntValueForAttributeFromList(SCORE_ATTRIBUTE, item.getAttributes());
 }
Exemple #17
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;
    }