public List process()

in streams-contrib/streams-provider-facebook/src/main/java/org/apache/streams/facebook/processor/FacebookTypeConverter.java [154:215]


  public List<StreamsDatum> process(StreamsDatum entry) {

    StreamsDatum result = null;

    try {
      Object item = entry.getDocument();
      ObjectNode node;

      LOGGER.debug("{} processing {}", STREAMS_ID, item.getClass());

      if ( item instanceof String ) {

        // if the target is string, just pass-through
        if ( String.class.equals(outClass)) {
          result = entry;
        } else {
          // first check for valid json
          node = (ObjectNode)mapper.readTree((String)item);

          // since data is coming from outside provider, we don't know what type the events are
          // for now we'll assume post
          Class inClass = FacebookEventClassifier.detectClass((String) item);

          Object out = convert(node, inClass, outClass);

          if ( out != null && validate(out, outClass)) {
            result = new StreamsDatum(out);
          }
        }

      } else if ( item instanceof ObjectNode) {

        // first check for valid json
        node = mapper.valueToTree(item);

        Class inClass = FacebookEventClassifier.detectClass(mapper.writeValueAsString(item));

        Object out = convert(node, inClass, outClass);

        if ( out != null && validate(out, outClass)) {
          result = new StreamsDatum(out);
        }
      } else if (item instanceof Post || item instanceof Page) {
        Object out = convert(mapper.convertValue(item, ObjectNode.class), inClass, outClass);

        if ( out != null && validate(out, outClass)) {
          result = new StreamsDatum(out);
        }
      }
    } catch (Exception ex) {
      LOGGER.error("Exception switching types : {}", ex);
      if (ex instanceof InterruptedException) {
        Thread.currentThread().interrupt();
      }
    }

    if ( result != null ) {
      return Stream.of(result).collect(Collectors.toList());
    } else {
      return new ArrayList<>();
    }
  }