source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java @ 1146

Last change on this file since 1146 was 1146, checked in by pharms, 11 years ago
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
  • Property svn:executable set to *
File size: 3.6 KB
RevLine 
[1113]1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
[922]15package de.ugoe.cs.autoquest.tasktrees.manager;
[439]16
[727]17import java.util.Collection;
[1109]18import java.util.LinkedList;
[727]19import java.util.List;
[725]20import java.util.logging.Level;
[439]21
[922]22import de.ugoe.cs.autoquest.eventcore.Event;
[1146]23import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
[725]28import de.ugoe.cs.util.console.Console;
[439]29
30/**
31 * TODO comment
[557]32 *
[439]33 * @version $Revision: $ $Date: $
[557]34 * @author 2011, last modified by $Author: $
[439]35 */
[557]36public class TaskTreeManager {
37   
38    /** */
[1146]39    private ITaskBuilder taskBuilder = ComponentManager.getDefaultTaskBuilder();
[439]40
[557]41    /** */
[1146]42    private ITaskFactory taskFactory = ComponentManager.getDefaultTaskFactory();
[557]43
44    /** */
[1146]45    private List<IUserSession> sessions = null;
[557]46
47    /** */
[1146]48    private IUserSession currentSession = null;
[557]49
50    /**
[1109]51     *
[557]52     */
53    public TaskTreeManager() {
[1146]54        sessions = new LinkedList<IUserSession>();
[439]55    }
[557]56
57    /**
58     *
59     */
[1146]60    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) {
[1109]61        if ((currentSession != null) || (sessions.size() > 0)) {
62            throw new IllegalStateException("do not mix calls to this method with calls to the " +
63                                            "other methods for handling tasks. Use only one " +
64                                            "variant instead.");
65        }
[727]66       
[1109]67        for (List<Event> newSession : newSessions) {
68            if (newSession.size() > 0) {
69                for (Event event : newSession) {
70                    handleNewEvent(event);
71                }
72                finishSession();
[727]73            }
74        }
75       
[1146]76        return getTaskModel();
[727]77    }
78
79    /**
80     *
81     */
[557]82    public void handleNewEvent(Event event) {
[1146]83        assertSessionSequence();
84        ITask eventTask = taskFactory.createNewEventTask(event.getType(), event.getTarget());
85        taskBuilder.addExecutedTask(currentSession, taskFactory.createNewTaskInstance(eventTask));
[439]86    }
87
[557]88    /**
[1109]89     *
[557]90     */
[1109]91    public void finishSession() {
[1146]92        if ((currentSession != null) && (currentSession.getExecutedTasks().size() > 0)) {
[1109]93            sessions.add(currentSession);
94            currentSession = null;
95        }
[439]96    }
[557]97
98    /**
[1109]99     *
[557]100     */
[1146]101    public synchronized ITaskModel getTaskModel() {
[1109]102        finishSession();
103       
104        Console.traceln(Level.INFO, "applying temporal relationship generation rules");
105       
[1146]106        ComponentManager.getTemporalRelationshipRuleManager().applyRules(sessions);
[1109]107
[1146]108        return taskFactory.createTaskModel(sessions);
[439]109    }
[557]110
111    /**
112     *
113     */
[1109]114    private void assertSessionSequence() {
115        if (currentSession == null) {
[1146]116            currentSession = taskFactory.createUserSession();
[557]117        }
[439]118    }
119
120}
Note: See TracBrowser for help on using the repository browser.