Exemple #1
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;
  }
  @Override
  public void updateSystemPoint(
      final String pointName,
      final double value,
      final boolean incrementAsCounter,
      final PointType type)
      throws NimbitsException {

    EntityName name = CommonFactory.createName(pointName, EntityType.point);
    User admin = userService.getAdmin();
    List<Entity> e = entityService.getEntityByName(admin, name, EntityType.point);
    Point p;
    if (e.isEmpty()) {
      String ownerKey = admin.getKey();
      Entity ep =
          EntityModelFactory.createEntity(
              name,
              "",
              EntityType.point,
              ProtectionLevel.onlyMe,
              ownerKey,
              ownerKey,
              UUID.randomUUID().toString());
      Point pm =
          PointModelFactory.createPointModel(
              ep,
              0.0,
              EXPIRE,
              "",
              0.0,
              false,
              false,
              false,
              0,
              false,
              FilterType.none,
              0.0,
              false,
              type,
              0,
              false,
              0.0);
      p = (Point) entityService.addUpdateEntity(admin, pm);
    } else {
      p = (Point) e.get(0);
    }
    Value vx;
    if (incrementAsCounter) {
      List<Value> c = valueService.getCurrentValue(p);
      double cd = !c.isEmpty() ? c.get(0).getDoubleValue() : 0.0;
      vx = ValueFactory.createValueModel(cd + value);
    } else {
      vx = ValueFactory.createValueModel(value);
    }
    valueService.recordValue(admin, p, vx);
  }
    @Override
    public void handleEvent(final MessageBoxEvent be) {
      final String newEntityName = be.getValue();
      if (!Utils.isEmptyString(newEntityName)) {
        final EntityName categoryName;
        try {
          categoryName =
              CommonFactoryLocator.getInstance().createName(newEntityName, EntityType.category);
        } catch (NimbitsException e) {
          FeedbackHelper.showError(e);
          return;
        }

        final EntityServiceAsync service = GWT.create(EntityService.class);
        Entity entity = EntityModelFactory.createEntity(categoryName, EntityType.category);

        service.addUpdateEntity(entity, new AddUpdateEntityAsyncCallback());
      }
    }