* 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);