Package com.almende.eve.entity.activity

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


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

          //e.printStackTrace();
          Activity activity = (Activity) getState().get("activity");
          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 = (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
      } 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 = (Activity) getState().get("activity");
    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();
    activity.setAgent(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

   * Get meeting summary
   *
   * @return
   */
  public String getSummary() {
    Activity activity = (Activity) getState().get("activity");
    return (activity != null) ? activity.getSummary() : null;
  }
View Full Code Here

   *
   * @param activity
   * @return changed    Returns true if the activity is changed
   */
  private boolean applyConstraints() {
    Activity activity = (Activity) getState().get("activity");
    boolean changed = false;
    if (activity == null) {
      return false;
    }

    // constraints on attendees/resources
    /* TODO: copy actual attendees to status.attendees
    List<Attendee> constraintsAttendees = activity.withConstraints().withAttendees();
    List<Attendee> attendees = new ArrayList<Attendee>();
    for (Attendee attendee : constraintsAttendees) {
      attendees.add(attendee.clone());
    }
    activity.withStatus().setAttendees(attendees);
    // TODO: is it needed to check if the attendees are changed?
    */
   
    // check time constraints
    Long duration = activity.withConstraints().withTime().getDuration();
    if (duration != null) {
      String start = activity.withStatus().getStart();
      String end = activity.withStatus().getEnd();
      if (start != null && end != null) {
        DateTime startTime = new DateTime(start);
        DateTime endTime = new DateTime(end);
        Interval interval = new Interval(startTime, endTime);
        if (interval.toDurationMillis() != duration) {
          logger.info("status did not match constraints. "
              + "Changed end time to match the duration of "
              + duration + " ms");

          // duration does not match. adjust the end time
          endTime = startTime.plus(duration);
          activity.withStatus().setEnd(endTime.toString());
          activity.withStatus().setUpdated(DateTime.now().toString());

          changed = true;
        }
      }
    }
   
    // location constraints
    String newLocation = activity.withConstraints().withLocation().getSummary();
    String oldLocation = activity.withStatus().withLocation().getSummary();
    if (newLocation != null && !newLocation.equals(oldLocation)) {
      activity.withStatus().withLocation().setSummary(newLocation);
      changed = true;
    }
   
    if (changed) {
      // store the updated activity
View Full Code Here

  /**
   * synchronize the meeting in all attendees calendars
   */
  private boolean syncEvents() {
    logger.info("syncEvents started");
    Activity activity = getActivity();

    boolean changed = false;
    if (activity != null) {
      String updatedBefore = activity.withStatus().getUpdated();

      for (Attendee attendee : activity.withConstraints().withAttendees()) {
        String agent = attendee.getAgent();
        if (agent != null) {
          if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) {
            syncEvent(agent);
          }
          else {
            clearAttendee(agent);
          }
        }
      }

      activity = getActivity();
      String updatedAfter = activity.withStatus().getUpdated();

      changed = !updatedBefore.equals(updatedAfter);
    }
   
    return changed;
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.