Ejemplo n.º 1
0
  @Override
  public List<FeedValue> getFeed(final int count, final String relationshipEntityKey)
      throws NimbitsException {

    final User loggedInUser = getUser();
    final User feedUser = getFeedUser(relationshipEntityKey, loggedInUser);

    if (feedUser != null) {

      final Point point = getFeedPoint(feedUser);
      if (point == null) {
        return new ArrayList<FeedValue>(0);
      } else {
        final List<Value> values =
            RecordedValueServiceFactory.getInstance().getTopDataSeries(point, count, new Date());
        final List<FeedValue> retObj = new ArrayList<FeedValue>(values.size());

        for (final Value v : values) {
          if (!Utils.isEmptyString(v.getData())) {
            try {
              retObj.add(GsonFactory.getInstance().fromJson(v.getData(), FeedValueModel.class));
            } catch (JsonSyntaxException ignored) {

            }
          }
        }
        return retObj;
      }
    } else {
      return new ArrayList<FeedValue>(0);
    }
  }
Ejemplo n.º 2
0
  private String valueToHtml(final Entity entity, final Entity point, final Value value) {
    final StringBuilder sb = new StringBuilder(SIZE);
    if (!(Double.compare(value.getDoubleValue(), Const.CONST_IGNORED_NUMBER_VALUE) == 0)) {
      sb.append("<img style=\"float:left\" src=\"")
          .append(ServerInfoImpl.getFullServerURL(this.getThreadLocalRequest()));

      switch (value.getAlertState()) {
        case LowAlert:
          sb.append("/resources/images/point_low.png\">");
          break;
        case HighAlert:
          sb.append("/resources/images/point_high.png\">");
          break;
        case IdleAlert:
          sb.append("/resources/images/point_idle.png\">");
          break;
        case OK:
          sb.append("/resources/images/point_ok.png\">");
          break;
      }
    }

    if (entity != null && point != null) {

      sb.append("&nbsp;");

      if (!(Double.compare(value.getDoubleValue(), Const.CONST_IGNORED_NUMBER_VALUE) == 0)) {
        sb.append("Alert&nbsp;Status:").append(value.getAlertState().name());
        sb.append("<br>Value:").append(value.getDoubleValue());
      }

      if (!Utils.isEmptyString(value.getNote())) {
        sb.append("<br>Note:").append(value.getNote());
      }

      sb.append("<a href=\"#\" onclick=\"window.open('report.html?uuid=")
          .append(point.getKey())
          .append("', 'Report',")
          .append("'height=800,width=800,toolbar=0,status=0,location=0' );\" >")
          .append("&nbsp;[more]</a>");
    }

    return sb.toString();
  }
Ejemplo n.º 3
0
  protected void serializePrettyHtml(
      final TagNode tagNode,
      final Writer writer,
      final int level,
      final boolean isPreserveWhitespaces,
      final boolean isLastNewLine)
      throws IOException {
    final List tagChildren = tagNode.getChildren();
    final String tagName = tagNode.getName();
    final boolean isHeadlessNode = Utils.isEmptyString(tagName);
    final String indent = isHeadlessNode ? "" : getIndent(level);

    if (!isPreserveWhitespaces) {
      if (!isLastNewLine) {
        writer.write("\n");
      }
      writer.write(indent);
    }
    serializeOpenTag(tagNode, writer, true);

    final boolean preserveWhitespaces = isPreserveWhitespaces || "pre".equalsIgnoreCase(tagName);

    boolean lastWasNewLine = false;

    if (!isMinimizedTagSyntax(tagNode)) {
      final String singleLine = getSingleLineOfChildren(tagChildren);
      final boolean dontEscape = dontEscape(tagNode);
      if (!preserveWhitespaces && singleLine != null) {
        writer.write(!dontEscape(tagNode) ? escapeText(singleLine) : singleLine);
      } else {
        final Iterator childIterator = tagChildren.iterator();
        while (childIterator.hasNext()) {
          final Object child = childIterator.next();
          if (child instanceof TagNode) {
            serializePrettyHtml(
                (TagNode) child,
                writer,
                isHeadlessNode ? level : level + 1,
                preserveWhitespaces,
                lastWasNewLine);
            lastWasNewLine = false;
          } else if (child instanceof ContentNode) {
            final String content = dontEscape ? child.toString() : escapeText(child.toString());
            if (content.length() > 0) {
              if (dontEscape || preserveWhitespaces) {
                writer.write(content);
              } else if (Character.isWhitespace(content.charAt(0))) {
                if (!lastWasNewLine) {
                  writer.write("\n");
                  lastWasNewLine = false;
                }
                if (content.trim().length() > 0) {
                  writer.write(
                      getIndentedText(Utils.rtrim(content), isHeadlessNode ? level : level + 1));
                } else {
                  lastWasNewLine = true;
                }
              } else {
                if (content.trim().length() > 0) {
                  writer.write(Utils.rtrim(content));
                }
                if (!childIterator.hasNext()) {
                  writer.write("\n");
                  lastWasNewLine = true;
                }
              }
            }
          } else if (child instanceof CommentNode) {
            if (!lastWasNewLine && !preserveWhitespaces) {
              writer.write("\n");
              lastWasNewLine = false;
            }
            final CommentNode commentNode = (CommentNode) child;
            final String content = commentNode.getCommentedContent();
            writer.write(
                dontEscape
                    ? content
                    : getIndentedText(content, isHeadlessNode ? level : level + 1));
          }
        }
      }

      if (singleLine == null && !preserveWhitespaces) {
        if (!lastWasNewLine) {
          writer.write("\n");
        }
        writer.write(indent);
      }

      serializeEndTag(tagNode, writer, false);
    }
  }
  @Override
  public Value solveEquation(final User user, final Calculation calculation)
      throws NimbitsException {

    final MathEvaluator m = new MathEvaluatorImpl(calculation.getFormula());
    log.info(calculation.getFormula());

    if (!Utils.isEmptyString(calculation.getX()) && calculation.getFormula().contains("x")) {
      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getX());
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getX(), EntityType.point)
              .get(0);

      if (p != null) {
        log.info("calc has an x car and i found " + p.getName());
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);

        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();

        m.addVariable("x", d);
      } else {
        log.severe("calc has an x car and x not found");
      }
    }
    if (!Utils.isEmptyString(calculation.getY()) && calculation.getFormula().contains("y")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getY(), EntityType.point)
              .get(0);

      // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getY());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("y", d);
      }
    }
    if (!Utils.isEmptyString(calculation.getZ()) && calculation.getFormula().contains("z")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getZ(), EntityType.point)
              .get(0);

      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getZ());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("z", d);
      }
    }

    final Double retVal = m.getValue();

    if (retVal == null) {

      throw new NimbitsException("Formula returned a null value: " + calculation.getFormula());
    }

    return ValueFactory.createValueModel(retVal, "CV");
  }