@Override
  public Collection<TatamibotConfiguration> findTatamibotConfigurationsByDomain(String domain) {

    Set<TatamibotConfiguration> configurations = new HashSet<TatamibotConfiguration>();

    ColumnSlice<UUID, String> results =
        HFactory.createSliceQuery(
                keyspaceOperator,
                StringSerializer.get(),
                UUIDSerializer.get(),
                StringSerializer.get())
            .setColumnFamily(ColumnFamilyKeys.DOMAIN_TATAMIBOT_CF)
            .setKey(domain)
            .setRange(null, null, false, Integer.MAX_VALUE)
            .execute()
            .get();

    for (HColumn<UUID, String> column : results.getColumns()) {
      String tatamibotConfigurationId = column.getName().toString();
      TatamibotConfiguration configuration =
          em.find(TatamibotConfiguration.class, tatamibotConfigurationId);
      configurations.add(configuration);
    }
    return configurations;
  }
Exemplo n.º 2
0
 @Override
 @CacheEvict(value = "status-cache", key = "#status.statusId")
 public void removeStatus(Status status) {
   status.setRemoved(true);
   if (log.isDebugEnabled()) {
     log.debug("Updating Status : " + status);
   }
   em.persist(status);
 }
Exemplo n.º 3
0
 @Override
 @CacheEvict(value = "user-cache", key = "#user.login", beforeInvocation = true)
 public void updateUser(User user) throws ConstraintViolationException, IllegalArgumentException {
   if (log.isDebugEnabled()) {
     log.debug("Updating user : " + user);
   }
   Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
   if (!constraintViolations.isEmpty()) {
     throw new ConstraintViolationException(
         new HashSet<ConstraintViolation<?>>(constraintViolations));
   }
   em.persist(user);
 }
  @Override
  public void insertTatamibotConfiguration(TatamibotConfiguration tatamibotConfiguration) {
    UUID tatamibotConfigurationId = TimeUUIDUtils.getUniqueTimeUUIDinMillis();
    Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, StringSerializer.get());
    mutator.insert(
        tatamibotConfiguration.getDomain(),
        ColumnFamilyKeys.DOMAIN_TATAMIBOT_CF,
        HFactory.createColumn(
            tatamibotConfigurationId, "", UUIDSerializer.get(), StringSerializer.get()));

    tatamibotConfiguration.setTatamibotConfigurationId(tatamibotConfigurationId.toString());
    em.persist(tatamibotConfiguration);
  }
Exemplo n.º 5
0
 @Override
 @CacheEvict(value = "user-cache", key = "#user.login")
 public void createUser(User user) {
   if (log.isDebugEnabled()) {
     log.debug("Creating user : " + user);
   }
   Set<ConstraintViolation<User>> constraintViolations =
       validator.validate(user, ContraintsUserCreation.class);
   if (!constraintViolations.isEmpty()) {
     throw new ConstraintViolationException(
         new HashSet<ConstraintViolation<?>>(constraintViolations));
   }
   em.persist(user);
 }
Exemplo n.º 6
0
 @Override
 @Cacheable("user-cache")
 public User findUserByLogin(String login) {
   User user = null;
   try {
     user = em.find(User.class, login);
   } catch (Exception e) {
     if (log.isDebugEnabled()) {
       log.debug("Exception while looking for user " + login + " : " + e.toString());
     }
     return null;
   }
   if (user != null) {
     user.setStatusCount(counterRepository.getStatusCounter(login));
     user.setFollowersCount(counterRepository.getFollowersCounter(login));
     user.setFriendsCount(counterRepository.getFriendsCounter(login));
   }
   return user;
 }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
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;
  }
 @Override
 public TatamibotConfiguration findTatamibotConfigurationById(String tatamibotConfigurationId) {
   return em.find(TatamibotConfiguration.class, tatamibotConfigurationId);
 }
 @Override
 public void updateTatamibotConfiguration(TatamibotConfiguration tatamibotConfiguration) {
   em.persist(tatamibotConfiguration);
 }