コード例 #1
0
 public List<NotificationEntry> getNotifications(String username, String startId) {
   try {
     byte[] timeUUIDAsBytes = EMPTY_BYTE_ARRAY;
     if (startId != null && startId.length() > 0) {
       UUID uuid = UUIDUtil.fromString(startId);
       final byte[] idAsBytes = UUIDUtil.toBytes(uuid);
       timeUUIDAsBytes = getTimeUUIDFromID(username, idAsBytes);
       if (timeUUIDAsBytes == null) {
         timeUUIDAsBytes = EMPTY_BYTE_ARRAY;
       }
     }
     Selector selector = Pelops.createSelector(TRENDOCEAN_POOL, TRENDOCEAN_KEYSPACE);
     SlicePredicate columnPredicate =
         Selector.newColumnsPredicate(timeUUIDAsBytes, EMPTY_BYTE_ARRAY, true, PAGE_SIZE);
     List<SuperColumn> columns =
         selector.getSuperColumnsFromRow(username, WALL_CF, columnPredicate, ConsistencyLevel.ONE);
     List<NotificationEntry> notificationList = new ArrayList<NotificationEntry>(columns.size());
     for (SuperColumn superColumn : columns) {
       List<Column> wallEntryColumns = superColumn.getColumns();
       String notificationId = null;
       NotificationType notificationType = null;
       String questionId = null;
       String relatedUser = null;
       long answerCount = -1L;
       long time = 0;
       for (Column notificationColumn : wallEntryColumns) {
         String notificationColumnName = toString(notificationColumn.getName());
         if (notificationColumnName.equals("_id")) {
           notificationId = UUIDUtil.toUUID(notificationColumn.getValue()).toString();
           long timeInMicroSeconds = notificationColumn.getTimestamp();
           time = timeInMicroSeconds / 1000L;
         } else if (notificationColumnName.equals("_type")) {
           notificationType = NotificationType.fromId(toByte(notificationColumn));
         } else if (notificationColumnName.equals("questionId")) {
           questionId = toString(notificationColumn);
         } else if (notificationColumnName.equals("relatedUser")) {
           relatedUser = toString(notificationColumn);
         } else if (notificationColumnName.equals("answerCount")) {
           answerCount = toLong(notificationColumn);
         } else {
           logger.warn("Invalid notification column:{}", notificationColumnName);
         }
       }
       NotificationEntry notificationEntry = new NotificationEntry();
       notificationEntry.setId(notificationId);
       notificationEntry.setTime(time);
       notificationEntry.setNotificationType(notificationType);
       notificationEntry.setQuestionId(questionId);
       notificationList.add(notificationEntry);
       notificationEntry.setUsername(relatedUser);
       notificationEntry.setAnswerCount(answerCount);
     }
     return notificationList;
   } catch (NotFoundException ex) {
     return Collections.EMPTY_LIST;
   } catch (Exception ex) {
     logger.error("Can not get time uuid", ex);
     throw new TrendOceanException(ex);
   }
 }
コード例 #2
0
  /**
   * Delete the entry from wall.
   *
   * @param followEntry
   */
  public void deleteEntry(String username, String id) {
    try {
      // find name of super column using reverse mapping from id to time
      UUID uuid = UUIDUtil.fromString(id);
      final byte[] idAsBytes = UUIDUtil.toBytes(uuid);
      byte[] timeUUIDAsBytes = getTimeUUIDFromID(username, idAsBytes);
      if (timeUUIDAsBytes == null) {
        throw new TrendOceanException("Can not find time uuid " + username + ":" + id);
      }

      // delete super column from wall cf
      Mutator mutator = Pelops.createMutator(TRENDOCEAN_POOL, TRENDOCEAN_KEYSPACE);
      mutator.deleteColumn(username, WALL_CF, timeUUIDAsBytes);

      // also delete from reverse mapping from id to time
      mutator.deleteColumn(username, ID_TO_TIMEUUID_CF, idAsBytes);

      mutator.execute(ConsistencyLevel.QUORUM);
    } catch (Exception ex) {
      logger.error("Can not delete follow entry", username + ":" + id, ex);
      throw new TrendOceanException(ex);
    }
  }