Package com.almende.eve.entity.activity

Examples of com.almende.eve.entity.activity.Activity


   
    State state = getState();
    List<Weight> solutions = new ArrayList<Weight>();
   
    // get the activity
    Activity activity = state.get("activity",Activity.class);
    if (activity == null) {
      return solutions;
    }
   
    // get infeasible intervals
    ArrayList<Interval> infeasible = state.get("infeasible",new TypeUtil<ArrayList<Interval>>(){});
    if (infeasible == null) {
      infeasible = new ArrayList<Interval>();
    }
   
    // get preferred intervals
    List<Weight> preferred = state.get("preferred",new TypeUtil<ArrayList<Weight>>(){});
    if (preferred == null) {
      preferred = new ArrayList<Weight>();
    }
   
    // get the duration of the activity
    Long durationLong = activity.withConstraints().withTime().getDuration();
    Duration duration = null;
    if (durationLong != null) {
      duration = new Duration(durationLong);
    } else {
      // TODO: give error when duration is not defined?
View Full Code Here


   * @throws JsonMappingException
   * @throws JsonParseException
   */
  public void startAutoUpdate() {
    State state = getState();
    Activity activity = getActivity();
   
    // determine the interval (1 hour by default)
    long TEN_SECONDS = 10 * 1000;
    long ONE_HOUR = 60 * 60 * 1000;
    long interval = ONE_HOUR; // default is 1 hour
    if (activity != null) {
      String updated = activity.withStatus().getUpdated();
      if (updated != null) {
        DateTime dateUpdated = new DateTime(updated);
        DateTime now = DateTime.now();
        interval = new Interval(dateUpdated, now).toDurationMillis();
      }
View Full Code Here

   * Convert a calendar event into an activity
   * @param event
   * @return activity
   */
  private Activity convertEventToActivity(ObjectNode event) {
    Activity activity = new Activity();
   
    // agent
    URI agent = null;
    if (event.has("agent")) {
      agent = URI.create(event.get("agent").asText());
    }
    activity.setAgent(agent);

    // summary
    String summary = null;
    if (event.has("summary")) {
      summary = event.get("summary").asText();
    }
    activity.setSummary(summary);

    // description
    String description = null;
    if (event.has("description")) {
      description = event.get("description").asText();
    }
    activity.setDescription(description);
   
    // updated
    String updated = null;
    if (event.has("updated")) {
      updated = event.get("updated").asText();
    }
    activity.withStatus().setUpdated(updated);

    // start
    String start = null;
    if (event.with("start").has("dateTime")) {
      start = event.with("start").get("dateTime").asText();
    }
    activity.withStatus().setStart(start);

    // end
    String end = null;
    if (event.with("end").has("dateTime")) {
      end = event.with("end").get("dateTime").asText();
    }
    activity.withStatus().setEnd(end);

    // duration
    if (start != null && end != null) {
      Interval interval = new Interval(new DateTime(start), new DateTime(
          end));
      Long duration = interval.toDurationMillis();
      activity.withConstraints().withTime().setDuration(duration);
    }

    // location
    String location = null;
    if (event.has("location")) {
      location = event.get("location").asText();
    }
    activity.withConstraints().withLocation().setSummary(location);
   
    return activity;
  }
View Full Code Here

      } catch (JSONRPCException e) {
        if (e.getCode() == 404) {
          // event was deleted by the user.

          //e.printStackTrace();
          Activity activity = getState().get("activity",Activity.class);
          Attendee attendee = activity.withConstraints().withAttendee(agent);
          attendee.setResponseStatus(RESPONSE_STATUS.declined);
          getState().put("activity", activity);
         
          clearAttendee(agent); // TODO: seems not to work
        } else {
View Full Code Here

    // 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 = state.get("activity",Activity.class);
    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(URI.create(agent), method, params,
            JOM.getSimpleType(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
      } catch (Exception e) {
        addIssue(TYPE.warning, Issue.EXCEPTION, e.getMessage());
        e.printStackTrace(); // TODO remove printing stacktrace
      }
    } else if (changed) {
      // event is updated (activity is out-dated or both have the same
      // updated timestamp)
     
      // if start is changed, add this as preferences to the constraints
      if (!equalsDateTime(activity.withStatus().getStart(),
          eventActivity.withStatus().getStart())) {
        /* TODO: store the old interval as undesired?
        String oldStart = activity.withStatus().getStart();
        String oldEnd = activity.withStatus().getEnd();
        if (oldStart != null && oldEnd != null) {
          Preference undesired = new Preference ();
          undesired.setStart(oldStart);
          undesired.setEnd(oldEnd);
          undesired.setWeight(WEIGHT_UNDESIRED_INTERVAL);
          activity.getConstraints().getTime().addPreference(undesired); 
        }
        */
       
        // store the new interval as preferred
        String newStart = eventActivity.withStatus().getStart();
        String newEnd = eventActivity.withStatus().getEnd();
        if (newStart != null && newEnd != null) {
          Preference preferred = new Preference ();
          preferred.setStart(newStart);
          preferred.setEnd(newEnd);
          preferred.setWeight(WEIGHT_PREFERRED_INTERVAL);

          // overwrite other preferences with this new preference
          // TODO: all preferences are overwritten for now. Behavior should be changed.
          List<Preference> preferences = new ArrayList<Preference>();
          preferences.add(preferred);
          activity.getConstraints().getTime().setPreferences(preferences);       
         
          //activity.getConstraints().getTime().addPreference(preferred);
        }
      }
      else {
        // events are in sync, nothing to do
      }
     
      // update the activity
      activity.merge(eventActivity);
      state.put("activity", activity);

      // update the agent data
      agentData.eventId = event.get("id").asText();
      agentData.eventUpdated = event.get("updated").asText();
      agentData.activityUpdated = activity.withStatus().getUpdated();
      putAgentData(agent, agentData);
    }
    else {
      // activity and eventActivity have the same updated timestamp
      // nothing to do.
View Full Code Here

  /**
   * Update the busy intervals of all attendees, and merge the results
   */
  private void updateBusyIntervals() {
    Activity activity = getActivity();
    if (activity != null) {
      List<Attendee> attendees = activity.withConstraints().withAttendees();
      for (Attendee attendee : attendees) {
        String agent = attendee.getAgent();
        if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) {
          updateBusyInterval(agent);
        }
View Full Code Here

   */
  private void mergeTimeConstraints() {
    ArrayList<Interval> infeasibleIntervals = new ArrayList<Interval>();
    ArrayList<Weight> preferredIntervals = new ArrayList<Weight>();

    Activity activity = getActivity();
    if (activity != null) {
      // read and merge the stored busy intervals of all attendees
      for (Attendee attendee : activity.withConstraints().withAttendees()) {
        String agent = attendee.getAgent();
        if (attendee.getResponseStatus() == RESPONSE_STATUS.declined) {
          // This attendee declined.
          // Ignore this attendees busy interval
        }
        else if (new Boolean(true).equals(attendee.getOptional())) {
          // This attendee is optional.
          // Add its busy intervals to the soft constraints
          List<Interval> attendeeBusy = getAgentBusy(agent);
          if (attendeeBusy != null) {
            for (Interval i : attendeeBusy) {
              Weight wi = new Weight(
                  i.getStart(), i.getEnd(),
                  WEIGHT_BUSY_OPTIONAL_ATTENDEE);

              preferredIntervals.add(wi);
            }
          }         
        }
        else {
          // this attendee is required.
          // Add its busy intervals to the hard constraints
          List<Interval> attendeeBusy = getAgentBusy(agent);
          if (attendeeBusy != null) {
            infeasibleIntervals.addAll(attendeeBusy);
          }
        }       
      }

      // read the time preferences and add them to the soft constraints
      List<Preference> preferences = activity.withConstraints()
        .withTime().withPreferences();
      for (Preference p : preferences) {
        if (p != null) {
          Weight wi = new Weight(
              new DateTime(p.getStart()),
View Full Code Here

  /**
   * Clear the stored activity, and remove events from attendees.
   */
  @Access(AccessType.UNAVAILABLE)
  public void clear () {
    Activity activity = getActivity();

    if (activity != null) {
      List<Attendee> attendees = activity.withConstraints().withAttendees();
      for (Attendee attendee : attendees) {
        String agent = attendee.getAgent();
        if (agent != null) {
          clearAttendee(agent);
        }
View Full Code Here

   */
  public void setActivityQuick(@Name("summary") String summary,
      @Required(false) @Name("location") String location,
      @Name("duration") Integer duration,
      @Name("agents") List<String> agents) {
    Activity activity = new Activity();
    activity.setSummary(summary);
    activity.withConstraints().withLocation().setSummary(location);
    for (String agent : agents) {
      Attendee attendee = new Attendee();
      attendee.setAgent(agent);
      activity.withConstraints().withAttendees().add(attendee);
    }

    update();
  }
View Full Code Here

   * @param activity
   * @throws Exception
   */
  public Activity updateActivity(@Name("activity") Activity updatedActivity)
      throws Exception {
    Activity activity = getState().get("activity",Activity.class);
    if (activity == null) {
      activity = new Activity();
    }

    Set<String> prevAttendees = getAgents(activity);

    // if no updated timestamp is provided, set the timestamp to now
    if (updatedActivity.withStatus().getUpdated() == null) {
      updatedActivity.withStatus().setUpdated(DateTime.now().toString());
    }

    // synchronize with the stored activity
    activity = Activity.sync(activity, updatedActivity);

    // ensure the url of the meeting agent is filled in
    String myUrl = getFirstUrl("http");
    activity.setAgent(new URI(myUrl));

    // create duration when missing
    Long duration = activity.withConstraints().withTime().getDuration();
    if (duration == null) {
      duration = Duration.standardHours(1).getMillis(); // 1 hour in ms
      activity.withConstraints().withTime().setDuration(duration);
    }

    // remove calendar events from removed attendees
    Set<String> currentAttendees = getAgents(activity);
    Set<String> removedAttendees = new TreeSet<String>(prevAttendees);
View Full Code Here

TOP

Related Classes of com.almende.eve.entity.activity.Activity

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.