Exemplo n.º 1
1
 protected static boolean checkIdle(final Point p) throws NimbitsException {
   final Calendar c = Calendar.getInstance();
   c.add(Calendar.SECOND, p.getIdleSeconds() * -1);
   boolean retVal = false;
   final List<Entity> result =
       EntityServiceFactory.getInstance()
           .getEntityByKey(
               UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user);
   if (!result.isEmpty()) {
     final User u = (User) result.get(0);
     final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p);
     if (p.getIdleSeconds() > 0
         && !v.isEmpty()
         && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis()
         && !p.getIdleAlarmSent()) {
       p.setIdleAlarmSent(true);
       EntityServiceFactory.getInstance().addUpdateEntity(u, p);
       // PointServiceFactory.getInstance().updatePoint(u, p);
       final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert);
       SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va);
       retVal = true;
     }
   }
   return retVal;
 }
Exemplo n.º 2
0
  private Point createFeedPoint(final User user) throws NimbitsException {

    final EntityName name =
        CommonFactoryLocator.getInstance().createName(Const.TEXT_DATA_FEED, EntityType.point);

    final Entity entity =
        EntityModelFactory.createEntity(
            name,
            "",
            EntityType.feed,
            ProtectionLevel.onlyConnection,
            user.getKey(),
            user.getKey(),
            UUID.randomUUID().toString());
    // final Entity r = EntityServiceFactory.getInstance().addUpdateEntity(user, entity);

    Point point = PointModelFactory.createPointModel(entity);

    final Point result = (Point) EntityServiceFactory.getInstance().addUpdateEntity(point);

    postToFeed(
        user,
        "A new data point has been created for your data feed. Your data feed is just "
            + "a data point. Points are capable of storing numbers, text, json and xml data. Nimbits uses "
            + "a single data point to drive this feed.",
        FeedType.info);
    return result;
  }
Exemplo n.º 3
0
  private Point getFeedPoint(final User user) throws NimbitsException {
    final Point point;
    final Map<String, Entity> map =
        EntityServiceFactory.getInstance().getEntityMap(user, EntityType.feed, 1);

    if (map.isEmpty()) {
      point = createFeedPoint(user);
    } else {
      return (Point) map.values().iterator().next();
    }
    return point;
  }
Exemplo n.º 4
0
  protected static int processGet() throws NimbitsException {
    final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities();
    log.info("Processing " + points.size() + " potentially idle points");
    for (final Entity p : points) {
      try {
        checkIdle((Point) p);
      } catch (NimbitsException e) {

        LogHelper.logException(IdlePointCron.class, e);
      }
    }
    return points.size();
  }