예제 #1
0
 public Geometry decodeGeometry(JsonNode node) throws GeoJSONException {
   if (node == null || node.isNull() || node.isMissingNode()) {
     return null;
   } else {
     return decodeGeometry(node, DEFAULT_GEOMETRY_FACTORY);
   }
 }
 List<FolderServerGroup> findGroups() {
   List<FolderServerGroup> groupList = new ArrayList<>();
   String cypher = CypherQueryBuilder.findGroups();
   CypherQuery q = new CypherQueryLiteral(cypher);
   JsonNode jsonNode = executeCypherQueryAndCommit(q);
   JsonNode userListJsonNode = jsonNode.at("/results/0/data");
   if (userListJsonNode != null && !userListJsonNode.isMissingNode()) {
     userListJsonNode.forEach(
         f -> {
           JsonNode groupNode = f.at("/row/0");
           if (groupNode != null && !groupNode.isMissingNode()) {
             FolderServerGroup cg = buildGroup(groupNode);
             groupList.add(cg);
           }
         });
   }
   return groupList;
 }
예제 #3
0
  private ObjectNode getNodeByFieldName(ArrayNode nodes, String fieldName) {
    if (fieldName.length() == 0) return null;

    for (JsonNode output : nodes) {
      JsonNode node = output.path(fieldName);
      if (!node.isMissingNode()) {
        return (ObjectNode) output.path(fieldName);
      }
    }

    return null;
  }
예제 #4
0
 protected boolean isEqualToCurrentLocalizationValue(
     String language, String id, String propertyName, String propertyValue, ObjectNode infoNode) {
   boolean isEqual = false;
   JsonNode localizationNode =
       infoNode.path("localization").path(language).path(id).path(propertyName);
   if (localizationNode.isMissingNode() == false
       && localizationNode.isNull() == false
       && localizationNode.asText().equals(propertyValue)) {
     isEqual = true;
   }
   return isEqual;
 }
  @Override
  public void receiveLoop() {
    log.debug("receiveLoop starts");
    ObjectReader reader = this.mapper.reader();

    while (true) {
      try {
        JsonNode root = reader.readTree(this.istream);
        String type = root.path(TYPE).asText();
        JsonNode data = root.path(DATA);
        log.debug("Processing {} with {}", type, data);
        if (type.equals(GOODBYE)) {
          log.info("Connection closing from server.");
          break;
        } else if (type.equals(HELLO)) {
          this.receiveHello(data);
        } else if (type.equals(LOCALE)) {
          this.receiveHello(data);
        } else if (type.equals(PONG)) {
          // silently ignore
        } else if (!data.isMissingNode() || (root.isArray() && ((ArrayNode) root).size() > 0)) {
          // process replies with a data node or non-empty arrays
          JsonClientReply reply = new JsonClientReply(root);
          Runnable r = new RcvNotifier(reply, mLastSender, this);
          try {
            SwingUtilities.invokeAndWait(r);
          } catch (InterruptedException e) {
            log.error("Exception notifying listeners of reply: {}", e.getMessage(), e);
          } catch (InvocationTargetException e) {
            log.error("Exception notifying listeners of reply: {}", e.getMessage(), e);
          }
        }
      } catch (IOException e) {
        this.rcvException = true;
        reportReceiveLoopException(e);
        break;
      } catch (NoSuchElementException nse) {
        // we get an NSE when we are finished with this client
        // so break out of the loop
        break;
      }
    }
    ConnectionStatus.instance()
        .setConnectionState(this.controller.getCurrentPortName(), ConnectionStatus.CONNECTION_DOWN);
    log.error("Exit from rcv loop");
    this.recovery();
  }
예제 #6
0
  private StationMeasurements parseMeasurements(Station station, JsonNode data) {
    StationMeasurements.Builder builder = new StationMeasurements.Builder(station);

    // current measurement
    JsonNode currentMeasurement = data.path("currentMeasurement");
    if (!currentMeasurement.isMissingNode()) {
      builder.setLevel(
          new Measurement(
              (float) currentMeasurement.path("value").asDouble(),
              currentMeasurement.path("unit").asText()));
      builder.setLevelTimestamp(
          PegelOnlineUtils.parseStringTimestamp(currentMeasurement.path("timestamp").asText()));
    }

    // characteristic values
    for (JsonNode charValue : currentMeasurement.path("characteristicValues")) {
      Measurement measurement =
          new Measurement(
              (float) charValue.path("value").asDouble(), charValue.path("unit").asText());
      String charType = charValue.path("shortname").asText();

      if ("MNW".equalsIgnoreCase(charType)) {
        builder.setMnw(measurement);
      } else if ("MW".equalsIgnoreCase(charType)) {
        builder.setMw(measurement);
      } else if ("MHW".equalsIgnoreCase(charType)) {
        builder.setMhw(measurement);
      } else if ("HThw".equalsIgnoreCase(charType)) {
        builder.setHthw(measurement);
      } else if ("NTnw".equalsIgnoreCase(charType)) {
        builder.setNtnw(measurement);
      } else if ("MTnw".equalsIgnoreCase(charType)) {
        builder.setMtnw(measurement);
      } else if ("MThw".equalsIgnoreCase(charType)) {
        builder.setMthw(measurement);
      }
    }

    return builder.build();
  }
예제 #7
0
 private boolean isNull(JsonNode node) {
   return node == null || node.isNull() || node.isMissingNode();
 }
예제 #8
0
 public boolean isDeleted() {
   JsonNode deleted = node.findPath(DELETED_FIELD_NAME);
   return !deleted.isMissingNode() && deleted.booleanValue();
 }
예제 #9
0
 /**
  * Process a JSON node and handle appropriately.
  *
  * <p>See {@link #onMessage(java.lang.String) } for expected JSON objects.
  *
  * @see #onMessage(java.lang.String)
  * @param root
  * @throws IOException
  */
 public void onMessage(JsonNode root) throws IOException {
   try {
     String type = root.path(TYPE).asText();
     if (root.path(TYPE).isMissingNode() && root.path(LIST).isValueNode()) {
       type = LIST;
     }
     JsonNode data = root.path(DATA);
     if (data.path(METHOD).isMissingNode() && root.path(METHOD).isValueNode()) {
       ((ObjectNode) data).put(METHOD, root.path(METHOD).asText());
     }
     log.debug("Processing {} with {}", type, data);
     if (type.equals(PING)) {
       this.connection.sendMessage(
           this.connection.getObjectMapper().createObjectNode().put(TYPE, PONG));
     } else if (type.equals(GOODBYE)) {
       this.connection.sendMessage(
           this.connection.getObjectMapper().createObjectNode().put(TYPE, GOODBYE));
       this.connection.close();
     } else if (type.equals(HELLO)) {
       this.receiveHello(data);
       this.sendHello(JsonServerPreferences.getDefault().getHeartbeatInterval());
     } else if (type.equals(LOCALE)) {
       this.receiveHello(data);
     } else if (type.equals(LIST)) {
       JsonNode reply;
       String list = root.path(LIST).asText();
       switch (list) {
         case CARS:
           reply = JsonUtil.getCars(this.connection.getLocale());
           break;
         case CONSISTS:
           reply = JsonUtil.getConsists(this.connection.getLocale());
           break;
         case ENGINES:
           reply = JsonUtil.getEngines(this.connection.getLocale());
           break;
         case LIGHTS:
           reply = JsonUtil.getLights(this.connection.getLocale());
           break;
         case LOCATIONS:
           reply = JsonUtil.getLocations(this.connection.getLocale());
           break;
         case METADATA:
           reply = JsonUtil.getMetadata(this.connection.getLocale());
           break;
         case PANELS:
           reply =
               JsonUtil.getPanels(
                   this.connection.getLocale(),
                   (data.path(FORMAT).isMissingNode()) ? XML : data.path(FORMAT).asText());
           break;
         case REPORTERS:
           reply = JsonUtil.getReporters(this.connection.getLocale());
           break;
         case SENSORS:
           reply = JsonUtil.getSensors(this.connection.getLocale());
           break;
         case SIGNAL_HEADS:
           reply = JsonUtil.getSignalHeads(this.connection.getLocale());
           break;
         case SIGNAL_MASTS:
           reply = JsonUtil.getSignalMasts(this.connection.getLocale());
           break;
         case TRAINS:
           reply = JsonUtil.getTrains(this.connection.getLocale());
           break;
         case NETWORK_SERVICES:
           reply = JsonUtil.getNetworkServices(this.connection.getLocale());
           break;
         case SYSTEM_CONNECTIONS:
           reply = JsonUtil.getSystemConnections(this.connection.getLocale());
           break;
         default:
           if (this.services.get(list) != null) {
             for (JsonSocketService service : this.services.get(list)) {
               service.onList(list, data, this.connection.getLocale());
             }
             return;
           } else {
             this.sendErrorMessage(
                 404, Bundle.getMessage(this.connection.getLocale(), "ErrorUnknownType", list));
             return;
           }
       }
       this.connection.sendMessage(this.connection.getObjectMapper().writeValueAsString(reply));
     } else if (!data.isMissingNode()) {
       switch (type) {
         case CONSIST:
           this.consistServer.parseRequest(this.connection.getLocale(), data);
           break;
         case METADATA:
           this.connection.sendMessage(
               JsonUtil.getMetadata(this.connection.getLocale(), data.path(NAME).asText()));
           break;
         case PROGRAMMER:
           this.programmerServer.parseRequest(this.connection.getLocale(), data);
           break;
         case SENSOR:
           this.sensorServer.parseRequest(this.connection.getLocale(), data);
           break;
         case SIGNAL_HEAD:
           this.signalHeadServer.parseRequest(this.connection.getLocale(), data);
           break;
         case SIGNAL_MAST:
           this.signalMastServer.parseRequest(this.connection.getLocale(), data);
           break;
         case REPORTER:
           this.reporterServer.parseRequest(this.connection.getLocale(), data);
           break;
         case THROTTLE:
           this.throttleServer.parseRequest(this.connection.getLocale(), data);
           break;
         case TRAIN:
           this.operationsServer.parseTrainRequest(this.connection.getLocale(), data);
           break;
         default:
           if (this.services.get(type) != null) {
             for (JsonSocketService service : this.services.get(type)) {
               service.onMessage(type, data, this.connection.getLocale());
             }
           } else {
             this.sendErrorMessage(
                 404, Bundle.getMessage(this.connection.getLocale(), "ErrorUnknownType", type));
           }
           break;
       }
     } else {
       this.sendErrorMessage(
           400, Bundle.getMessage(this.connection.getLocale(), "ErrorMissingData"));
     }
   } catch (JmriException je) {
     this.sendErrorMessage(
         500,
         Bundle.getMessage(
             this.connection.getLocale(), "ErrorUnsupportedOperation", je.getLocalizedMessage()));
   } catch (JsonException je) {
     this.sendErrorMessage(je);
   }
 }
예제 #10
0
 private Float parseFloat(JsonNode value) {
   if (value.isMissingNode()) return null;
   return (float) value.asDouble();
 }
 /** Adds a variable to the current scope. */
 private void addVariable(String name) {
   JsonNode node = currentNode.path(name);
   if (node.isMissingNode()) {
     currentNode.put(name, NullNode.getInstance());
   }
 }
 List<FolderServerUser> findGroupMembers(String groupURL) {
   List<FolderServerUser> memberList = new ArrayList<>();
   String cypher = CypherQueryBuilder.getGroupUsersWithRelation(RelationLabel.MEMBEROF);
   Map<String, Object> params = CypherParamBuilder.matchGroupId(groupURL);
   CypherQuery q = new CypherQueryWithParameters(cypher, params);
   JsonNode jsonNode = executeCypherQueryAndCommit(q);
   JsonNode userListJsonNode = jsonNode.at("/results/0/data");
   if (userListJsonNode != null && !userListJsonNode.isMissingNode()) {
     userListJsonNode.forEach(
         f -> {
           JsonNode userNode = f.at("/row/0");
           if (userNode != null && !userNode.isMissingNode()) {
             FolderServerUser u = buildUser(userNode);
             memberList.add(u);
           }
         });
   }
   return memberList;
 }