예제 #1
0
  @Override
  public Status createStatus(
      String login,
      String username,
      String domain,
      String content,
      String replyTo,
      String replyToUsername,
      List<String> tags)
      throws ConstraintViolationException {

    Status status = new Status();
    String statusId = TimeUUIDUtils.getUniqueTimeUUIDinMillis().toString();
    status.setStatusId(statusId);
    status.setLogin(login);
    status.setUsername(username);
    status.setDomain(domain);
    status.setContent(content);
    status.setStatusDate(Calendar.getInstance().getTime());
    status.setReplyTo(replyTo);
    status.setReplyToUsername(replyToUsername);
    status.setRemoved(false);
    status.setTags(tags);
    if (log.isDebugEnabled()) {
      log.debug("Persisting Status : " + status);
    }
    Set<ConstraintViolation<Status>> constraintViolations = validator.validate(status);
    if (!constraintViolations.isEmpty()) {
      throw new ConstraintViolationException(
          new HashSet<ConstraintViolation<?>>(constraintViolations));
    }
    em.persist(status);

    // Persist tags
    addTags(keyspaceOperator, STATUS_CF, statusId, tags);

    return status;
  }
예제 #2
0
  @Override
  @Cacheable("status-cache")
  public Status findStatusById(String statusId) {
    if (statusId == null || statusId.equals("")) {
      return null;
    }
    if (log.isDebugEnabled()) {
      log.debug("Finding status : " + statusId);
    }
    Status status = em.find(Status.class, statusId);

    if (status != null) {
      // Find status's tags
      List<String> tags =
          getTags(keyspaceOperator, STATUS_CF, statusId, TAG_COLUMN_MIN_NAME, TAG_COLUMN_MAX_NAME);

      status.setTags(tags);

      status = Boolean.TRUE.equals(status.getRemoved()) ? null : status;
    }

    return status;
  }