Package com.fasterxml.jackson.databind.node

Examples of com.fasterxml.jackson.databind.node.ObjectNode


   * Retrieve calendar event from calendaragent
   * @param agent
   * @return event   Calendar event, or null if not found
   */
  private ObjectNode getEvent (String agent) {
    ObjectNode event = null;
    String eventId = getAgentData(agent).eventId;
    if (eventId != null) {
      ObjectNode params = JOM.createObjectNode();
      params.put("eventId", eventId);
      try {
        event = send(agent, "getEvent", params, ObjectNode.class);
      } catch (JSONRPCException e) {
        if (e.getCode() == 404) {
          // event was deleted by the user.
View Full Code Here


  private void syncEvent(@Name("agent") String agent) {
    logger.info("syncEvent started for agent " + agent);
    State state = getState();

    // retrieve event from calendar agent
    ObjectNode event = getEvent(agent);
    if (event == null) {
      event = JOM.createObjectNode();
    }
    Activity eventActivity = convertEventToActivity(event);
   
    // verify all kind of stuff
    Activity activity = (Activity) state.get("activity");
    if (activity == null) {
      return; // oops no activity at all
    }
    if (activity.withStatus().getStart() == null ||
        activity.withStatus().getEnd() == null) {
      return; // activity is not yet planned. cancel synchronization
    }
    Attendee attendee = activity.withConstraints().getAttendee(agent);
    if (attendee == null) {
      return; // unknown attendee
    }
    if (attendee.getResponseStatus() == Attendee.RESPONSE_STATUS.declined) {
      // attendee does not want to attend
      clearAttendee(agent);
      return;
    }
   
    // check if the activity or the retrieved event is changed since the
    // last synchronization
    AgentData agentData = getAgentData(agent);
    boolean activityChanged = !equalsDateTime(agentData.activityUpdated,
        activity.withStatus().getUpdated());
    boolean eventChanged = !equalsDateTime(agentData.eventUpdated,
        eventActivity.withStatus().getUpdated());
    boolean changed = activityChanged || eventChanged;   
    if (changed && activity.isNewerThan(eventActivity)) {
      // activity is updated (event is out-dated or not yet existing)

      // merge the activity into the event
      mergeActivityIntoEvent(event, activity);
     
      // TODO: if attendee cannot attend (=optional or declined), show this somehow in the event
     
      // save the event
      ObjectNode params = JOM.createObjectNode();
      params.put("event", event);
      try {
        // TODO: only update/create the event when the attendee
        // is not optional or is available at the planned time
        String method = event.has("id") ? "updateEvent" : "createEvent";
        ObjectNode updatedEvent = send(agent, method, params,
            ObjectNode.class);

        // update the agent data
        agentData.eventId = updatedEvent.get("id").asText();
        agentData.eventUpdated = updatedEvent.get("updated").asText();
        agentData.activityUpdated = activity.withStatus().getUpdated();
        putAgentData(agent, agentData);
      } catch (JSONRPCException e) {
        addIssue(TYPE.warning, Issue.JSONRPCEXCEPTION, e.getMessage());
        e.printStackTrace(); // TODO remove printing stacktrace
View Full Code Here

   * @return
   */
  // TODO: remove this temporary method
  @SuppressWarnings("unchecked")
  public ObjectNode getIntervals() {
    ObjectNode intervals = JOM.createObjectNode();

    List<Interval> infeasible = (List<Interval>) getState().get("infeasible");
    List<Weight> preferred = (List<Weight>) getState().get("preferred");
    List<Weight> solutions = calculateSolutions();

    // merge the intervals
    List<Interval> mergedInfeasible = null;
    List<Weight> mergedPreferred = null;
    if (infeasible != null) {
      mergedInfeasible = IntervalsUtil.merge(infeasible);
    }
    if (preferred != null) {
      mergedPreferred = WeightsUtil.merge(preferred);
    }

    if (infeasible != null) {
      ArrayNode arr = JOM.createArrayNode();
      for (Interval interval : infeasible) {
        ObjectNode o = JOM.createObjectNode();
        o.put("start", interval.getStart().toString());
        o.put("end", interval.getEnd().toString());
        arr.add(o);
      }
      intervals.put("infeasible", arr);
    }

    if (preferred != null) {
      ArrayNode arr = JOM.createArrayNode();
      for (Weight weight : preferred) {
        ObjectNode o = JOM.createObjectNode();
        o.put("start", weight.getStart().toString());
        o.put("end", weight.getEnd().toString());
        o.put("weight", weight.getWeight());
        arr.add(o);
      }
      intervals.put("preferred", arr);
    }

    if (solutions != null) {
      ArrayNode arr = JOM.createArrayNode();
      for (Weight weight : solutions) {
        ObjectNode o = JOM.createObjectNode();
        o.put("start", weight.getStart().toString());
        o.put("end", weight.getEnd().toString());
        o.put("weight", weight.getWeight());
        arr.add(o);
      }
      intervals.put("solutions", arr);
    }

    if (mergedInfeasible != null) {
      ArrayNode arr = JOM.createArrayNode();
      for (Interval i : mergedInfeasible) {
        ObjectNode o = JOM.createObjectNode();
        o.put("start", i.getStart().toString());
        o.put("end", i.getEnd().toString());
        arr.add(o);
      }
      intervals.put("mergedInfeasible", arr);
    }

    if (mergedPreferred != null) {
      ArrayNode arr = JOM.createArrayNode();
      for (Weight wi : mergedPreferred) {
        ObjectNode o = JOM.createObjectNode();
        o.put("start", wi.getStart().toString());
        o.put("end", wi.getEnd().toString());
        o.put("weight", wi.getWeight());
        arr.add(o);
      }
      intervals.put("mergedPreferred", arr);
    }   

View Full Code Here

   */
  private void updateBusyInterval(@Name("agent") String agent) {
    try {
      // create parameters with the boundaries of the interval to be
      // retrieved
      ObjectNode params = JOM.createObjectNode();
      DateTime timeMin = DateTime.now();
      DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS);
      params.put("timeMin", timeMin.toString());
      params.put("timeMax", timeMax.toString());

      // exclude the event managed by this agent from the busy intervals
      String eventId = getAgentData(agent).eventId;
      if (eventId != null) {
        ArrayNode excludeEventIds = JOM.createArrayNode();
        excludeEventIds.add(eventId);
        params.put("excludeEventIds", excludeEventIds);
      }

      // get the busy intervals from the agent
      ArrayNode array = send(agent, "getBusy", params, ArrayNode.class);

      // convert from ArrayNode to List
      List<Interval> busy = new ArrayList<Interval>();
      for (int i = 0; i < array.size(); i++) {
        ObjectNode obj = (ObjectNode) array.get(i);
        String start = obj.has("start") ? obj.get("start").asText()
            : null;
        String end = obj.has("end") ? obj.get("end").asText() : null;
        busy.add(new Interval(new DateTime(start), new DateTime(end)));
      }

      // store the interval in the state
      putAgentBusy(agent, busy);
View Full Code Here

  private void clearAttendee(@Name("agent") String agent) {
    AgentData data = getAgentData(agent);
    if (data != null) {
      try {
        if (data.eventId != null) {
          ObjectNode params = JOM.createObjectNode();
          params.put("eventId", data.eventId);
          send(agent, "deleteEvent", params);
          data.eventId = null;
        }
      } catch (JSONRPCException e) {
        if (e.getCode() == 404) {
View Full Code Here

        timeMin), new DateTime(timeMax));

    // convert to JSON array
    ArrayNode array = JOM.createArrayNode();
    for (Interval interval : available) {
      ObjectNode obj = JOM.createObjectNode();
      obj.put("start", interval.getStart().toString());
      obj.put("end", interval.getEnd().toString());
      array.add(obj);
    }
    return array;
  }
View Full Code Here

   
    @Override
    public JsonNode getSchema(SerializerProvider provider, Type typeHint)
        throws JsonMappingException
    {
        ObjectNode o = createSchemaNode("object", true);
        // [JACKSON-813]: Add optional JSON Schema id attribute, if found
        // NOTE: not optimal, does NOT go through AnnotationIntrospector etc:
        JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class);
        if (ann != null) {
            String id = ann.id();
            if (id != null && id.length() > 0) {
                o.put("id", id);
            }
        }       
        //todo: should the classname go in the title?
        //o.put("title", _className);
        ObjectNode propertiesNode = o.objectNode();
        for (int i = 0; i < _props.length; i++) {
            BeanPropertyWriter prop = _props[i];
            JavaType propType = prop.getSerializationType();
            // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't...
            Type hint = (propType == null) ? prop.getGenericPropertyType() : propType.getRawClass();
            // Maybe it already has annotated/statically configured serializer?
            JsonSerializer<Object> ser = prop.getSerializer();
            if (ser == null) { // nope
                Class<?> serType = prop.getRawSerializationType();
                if (serType == null) {
                    serType = prop.getPropertyType();
                }
                ser = provider.findValueSerializer(serType, prop);
            }
            JsonNode schemaNode = (ser instanceof SchemaAware) ?
                    ((SchemaAware) ser).getSchema(provider, hint) :
                    JsonSchema.getDefaultSchemaNode();
            propertiesNode.put(prop.getName(), schemaNode);
        }
        o.put("properties", propertiesNode);
        return o;
    }
View Full Code Here

        }

        private Object readObject(ObjectMapper mapper, JsonNode rootNode) throws IOException,
                JsonParseException, JsonMappingException {
            Class<?> clazz = Object.class;
            ObjectNode root = (ObjectNode) rootNode;
            JsonNode node = root.remove(configuration.getJsonTypeFieldName());
            if (node != null) {
                try {
                    String typeName = node.asText();
                    if (configuration.getPackagePrefix() != null) {
                        typeName = configuration.getPackagePrefix() + "." + typeName;
View Full Code Here

        @Override
        public Event deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
                JsonProcessingException {
            ObjectMapper mapper = (ObjectMapper) jp.getCodec();
            ObjectNode root = (ObjectNode) mapper.readTree(jp);
            String eventName = root.get("name").asText();
            if (!eventMapping.containsKey(eventName)) {
                return new Event(eventName, Collections.emptyList());
            }

            List eventArgs = new ArrayList();
            Event event = new Event(eventName, eventArgs);
            JsonNode args = root.get("args");
            if (args != null) {
                Iterator<JsonNode> iterator = args.elements();
                if (iterator.hasNext()) {
                    JsonNode node = iterator.next();
                    Class<?> eventClass = eventMapping.get(eventName);
View Full Code Here

    @SuppressWarnings("deprecation")
    @Override
    public JsonNode getSchema(SerializerProvider provider, Type typeHint)
        throws JsonMappingException
    {
        ObjectNode o = createSchemaNode("array", true);
        JavaType contentType = _elementType;
        if (contentType != null) {
            JsonNode schemaNode = null;
            // 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
            if (contentType.getRawClass() != Object.class) {
                JsonSerializer<Object> ser = provider.findValueSerializer(contentType, _property);
                if (ser instanceof SchemaAware) {
                    schemaNode = ((SchemaAware) ser).getSchema(provider, null);
                }
            }
            if (schemaNode == null) {
                schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
            }
            o.put("items", schemaNode);
        }
        return o;
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.node.ObjectNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.