Package com.almende.eve.entity.activity

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


   */
  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

      syncEvents();
    }

    // Check if the activity is finished
    // If not, schedule a new update task. Else we are done
    Activity activity = getActivity();
    String start =   (activity != null) ? activity.withStatus().getStart() : null;
    String updated = (activity != null) ? activity.withStatus().getUpdated() : null;
    boolean isFinished = false;
    if (start != null && (new DateTime(start)).isBefore(DateTime.now())) {
      // start of the event is in the past
      isFinished = true;
      if (updated != null && (new DateTime(updated)).isAfter(new DateTime(start))) {
        // if changed after the last planned start time, then it is
        // updated afterwards, so do not mark as finished
        isFinished = false;
      }
    }
    if (activity != null && !isFinished) {
      // not yet finished. Reschedule the activity
      updateBusyIntervals();

      boolean changedConstraints = applyConstraints();
      boolean rescheduled = scheduleActivity();
     
      if (changedConstraints || rescheduled) {
        changedEvent = syncEvents();
        if (changedEvent) {
          syncEvents();
        }
      }

      // TODO: not so nice adjusting the activityStatus here this way
      activity = getActivity();
      if (activity.withStatus().getActivityStatus() != Status.ACTIVITY_STATUS.error) {
        // store status of a activity as "planned"
        activity.withStatus().setActivityStatus(Status.ACTIVITY_STATUS.planned);
        getState().put("activity", activity);
      }

      startAutoUpdate();
    } else {
      // store status of a activity as "executed"
      activity.withStatus().setActivityStatus(Status.ACTIVITY_STATUS.executed);
      getState().put("activity", activity);

      logger.info("The activity is over, my work is done. Goodbye world.");
    }
  }
View Full Code Here

   *         syncEvents.
   */
  private boolean scheduleActivity() {
    logger.info("scheduleActivity started"); // TODO: cleanup
    State state = getState();
    Activity activity = (Activity) state.get("activity");
    if (activity == null) {
      return false;
    }
   
    // read planned start and end from the activity
    DateTime activityStart = null;
    if (activity.withStatus().getStart() != null) {
      activityStart = new DateTime(activity.withStatus().getStart());
    }
    DateTime activityEnd = null;
    if (activity.withStatus().getEnd() != null) {
      activityEnd = new DateTime(activity.withStatus().getEnd());
    }
    Interval activityInterval = null;
    if (activityStart != null && activityEnd != null) {
      activityInterval = new Interval(activityStart, activityEnd);
    }

    // calculate solutions
    List<Weight> solutions = calculateSolutions();
    if (solutions.size() > 0) {
      // there are solutions. yippie!
      Weight solution = solutions.get(0);
      if (activityInterval == null ||
          !solution.getInterval().equals(activityInterval)) {
        // interval is changed, save new interval
        Status status = activity.withStatus();
        status.setStart(solution.getStart().toString());
        status.setEnd(solution.getEnd().toString());
        status.setActivityStatus(Status.ACTIVITY_STATUS.planned);
        status.setUpdated(DateTime.now().toString());
        state.put("activity", activity);
        logger.info("Activity replanned at " + solution.toString()); // TODO: cleanup logging
        try {
          // TODO: cleanup
          logger.info("Replanned activity: " + JOM.getInstance().writeValueAsString(activity));
        } catch (Exception e) {}
        return true;
      }
      else {
        // planning did not change. nothing to do.
      }
    }
    else {
      if (activityStart != null || activityEnd != null) {
        // no solution
        Issue issue = new Issue();
        issue.setCode(Issue.NO_PLANNING);
        issue.setType(Issue.TYPE.error);
        issue.setMessage("No free interval found for the meeting");
        issue.setTimestamp(DateTime.now().toString());
        // TODO: generate hints
        addIssue(issue);
 
        Status status = activity.withStatus();
        status.setStart(null);
        status.setEnd(null);
        status.setActivityStatus(Status.ACTIVITY_STATUS.error);
        status.setUpdated(DateTime.now().toString());
        state.put("activity", activity);
View Full Code Here

   
    State state = getState();
    List<Weight> solutions = new ArrayList<Weight>();
   
    // get the activity
    Activity activity = (Activity) state.get("activity");
    if (activity == null) {
      return solutions;
    }
   
    // get infeasible intervals
    List<Interval> infeasible = (List<Interval>) state.get("infeasible");
    if (infeasible == null) {
      infeasible = new ArrayList<Interval>();
    }
   
    // get preferred intervals
    List<Weight> preferred = (List<Weight>) state.get("preferred");
    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
    String agent = null;
    if (event.has("agent")) {
      agent = 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

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.