Changeset 1733 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager
- Timestamp:
- 09/05/14 19:33:12 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/ComponentManager.java
r1189 r1733 23 23 /** 24 24 * <p> 25 * The component manager is the central reference for the distinct submodules required for 26 * task tree generation. Such include the temporal relationship rule manager, the task equality 27 * rule manager, the default task builder, as well as the default task factory. 25 * The component manager is the central reference for the distinct submodules 26 * required for task tree generation. Such include the temporal relationship 27 * rule manager, the task equality rule manager, the default task builder, as 28 * well as the default task factory. 28 29 * </p> 29 30 * … … 32 33 */ 33 34 public class ComponentManager { 34 35 /**36 * <p>37 * singleton instance of this class38 * </p>39 */40 private static ComponentManager instance;41 35 42 /** 43 * <p> 44 * the default temporal relationship rule manager 45 * </p> 46 */ 47 private TemporalRelationshipRuleManager temporalRelationshipRuleManager; 36 /** 37 * <p> 38 * clears the singleton instance. Needed for test purposes to ensure 39 * statelessness between tests. 40 * </p> 41 */ 42 public static synchronized void clearInstance() { 43 instance = null; 44 } 48 45 49 /** 50 * <p> 51 * the default task builder 52 * </p> 53 */ 54 private ITaskBuilder taskBuilder; 46 /** 47 * <p> 48 * returns the default task builder 49 * </p> 50 * 51 * @return as described 52 */ 53 public static ITaskBuilder getDefaultTaskBuilder() { 54 return getInstance().taskBuilder; 55 } 55 56 56 /** 57 * <p> 58 * the default task factory 59 * </p> 60 */ 61 private ITaskFactory taskFactory; 57 /** 58 * <p> 59 * returns the default task factory 60 * </p> 61 * 62 * @return as described 63 */ 64 public static ITaskFactory getDefaultTaskFactory() { 65 return getInstance().taskFactory; 66 } 62 67 63 /** 64 * <p> 65 * returns the default temporal relationship rule manager 66 * </p> 67 * 68 * @return as described 69 */ 70 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() { 71 return getInstance().temporalRelationshipRuleManager; 72 } 68 /** 69 * <p> 70 * returns the singleton instance of this class 71 * </p> 72 * 73 * @return as described 74 */ 75 private static synchronized ComponentManager getInstance() { 76 if (instance == null) { 77 instance = new ComponentManager(); 78 instance.init(); 79 } 80 return instance; 81 } 73 82 74 75 76 * returns the default task builder77 78 79 80 81 public static ITaskBuilder getDefaultTaskBuilder() {82 return getInstance().taskBuilder;83 83 /** 84 * <p> 85 * returns the default temporal relationship rule manager 86 * </p> 87 * 88 * @return as described 89 */ 90 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() { 91 return getInstance().temporalRelationshipRuleManager; 92 } 84 93 85 /** 86 * <p> 87 * returns the default task factory 88 * </p> 89 * 90 * @return as described 91 */ 92 public static ITaskFactory getDefaultTaskFactory() { 93 return getInstance().taskFactory; 94 } 94 /** 95 * <p> 96 * singleton instance of this class 97 * </p> 98 */ 99 private static ComponentManager instance; 95 100 96 /** 97 * <p> 98 * clears the singleton instance. Needed for test purposes to ensure statelessness between 99 * tests. 100 * </p> 101 */ 102 public static synchronized void clearInstance() { 103 instance = null; 104 } 101 /** 102 * <p> 103 * the default temporal relationship rule manager 104 * </p> 105 */ 106 private TemporalRelationshipRuleManager temporalRelationshipRuleManager; 105 107 106 /** 107 * <p> 108 * returns the singleton instance of this class 109 * </p> 110 * 111 * @return as described 112 */ 113 private static synchronized ComponentManager getInstance() { 114 if (instance == null) { 115 instance = new ComponentManager(); 116 instance.init(); 117 } 118 return instance; 119 } 108 /** 109 * <p> 110 * the default task builder 111 * </p> 112 */ 113 private ITaskBuilder taskBuilder; 120 114 121 /** 122 * <p> 123 * initialized the component manager with all it default components which are the temporal 124 * relationship rule manager, the task equality rule manager, the default task builder, as 125 * well as the default task factory. 126 * </p> 127 */ 128 private void init() { 129 taskBuilder = new TaskBuilder(); 130 taskFactory = new TaskFactory(); 115 /** 116 * <p> 117 * the default task factory 118 * </p> 119 */ 120 private ITaskFactory taskFactory; 131 121 132 temporalRelationshipRuleManager = 133 new TemporalRelationshipRuleManager(taskFactory, taskBuilder); 134 temporalRelationshipRuleManager.init(); 135 } 122 /** 123 * <p> 124 * initialized the component manager with all it default components which 125 * are the temporal relationship rule manager, the task equality rule 126 * manager, the default task builder, as well as the default task factory. 127 * </p> 128 */ 129 private void init() { 130 taskBuilder = new TaskBuilder(); 131 taskFactory = new TaskFactory(); 132 133 temporalRelationshipRuleManager = new TemporalRelationshipRuleManager( 134 taskFactory, taskBuilder); 135 temporalRelationshipRuleManager.init(); 136 } 136 137 137 138 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java
r1397 r1733 30 30 /** 31 31 * <p> 32 * The task tree manager is responsible for transforming one or more user sessions into a task 33 * model. It can be called by providing a collection of user sessions where the result 34 * will be a task model. Furthermore, it can be used by providing single events in their respective 35 * order including notifications about where a user session ends. The result is a task model, 36 * as well. 32 * The task tree manager is responsible for transforming one or more user 33 * sessions into a task model. It can be called by providing a collection of 34 * user sessions where the result will be a task model. Furthermore, it can be 35 * used by providing single events in their respective order including 36 * notifications about where a user session ends. The result is a task model, as 37 * well. 37 38 * </p> 38 39 * … … 41 42 */ 42 43 public class TaskTreeManager { 43 44 /**45 * <p>46 * the internally used task builder47 * </p>48 */49 private ITaskBuilder taskBuilder = ComponentManager.getDefaultTaskBuilder();50 44 51 /** 52 * <p> 53 * the internally used task factory 54 * </p> 55 */ 56 private ITaskFactory taskFactory = ComponentManager.getDefaultTaskFactory(); 45 /** 46 * <p> 47 * the internally used task builder 48 * </p> 49 */ 50 private final ITaskBuilder taskBuilder = ComponentManager 51 .getDefaultTaskBuilder(); 57 52 58 /** 59 * <p> 60 * if single events are provided, the user sessions collected so far 61 * </p> 62 */ 63 private List<IUserSession> sessions = null; 53 /** 54 * <p> 55 * the internally used task factory 56 * </p> 57 */ 58 private final ITaskFactory taskFactory = ComponentManager 59 .getDefaultTaskFactory(); 64 60 65 66 67 * if single events are provided, the currently collected user session 68 69 70 private IUserSession currentSession= null;61 /** 62 * <p> 63 * if single events are provided, the user sessions collected so far 64 * </p> 65 */ 66 private List<IUserSession> sessions = null; 71 67 72 /** 73 * <p> 74 * initializes the task tree manager 75 * </p> 76 */ 77 public TaskTreeManager() { 78 sessions = new LinkedList<IUserSession>(); 79 } 68 /** 69 * <p> 70 * if single events are provided, the currently collected user session 71 * </p> 72 */ 73 private IUserSession currentSession = null; 80 74 81 /** 82 * <p> 83 * creates a task model based on the provided user sessions. Yet, the user sessions are 84 * list of events. Such will be transformed in into task instances of event tasks assigned 85 * to {@link IUserSession}s. The {@link IUserSession}s will then be restructured using 86 * the temporal relationship rule manager to detect tasks and respective instances. The 87 * results of this transformation is stored in a task model which is the return value of 88 * this method. 89 * </p> 90 * 91 * @param newSessions the user sessions of which the task model shall be created 92 * 93 * @return the task model created from the user sessions 94 * 95 * @throws IllegalStateException if the task manager is already used by providing it with 96 * single events 97 */ 98 public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 99 if ((currentSession != null) || (sessions.size() > 0)) { 100 throw new IllegalStateException("do not mix calls to this method with calls to the " + 101 "other methods for handling tasks. Use only one " + 102 "variant instead."); 103 } 104 105 for (List<Event> newSession : newSessions) { 106 if (newSession.size() > 0) { 107 for (Event event : newSession) { 108 handleNewEvent(event); 109 } 110 finishSession(); 111 } 112 } 113 114 return getTaskModel(); 115 } 75 /** 76 * <p> 77 * initializes the task tree manager 78 * </p> 79 */ 80 public TaskTreeManager() { 81 sessions = new LinkedList<IUserSession>(); 82 } 116 83 117 /** 118 * <p> 119 * handles a single event that occurred in a user session. 120 * </p> 121 * 122 * @param event the event to handle 123 */ 124 public void handleNewEvent(Event event) { 125 assertSessionSequence(); 126 String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 127 IEventTask eventTask = taskFactory.createNewEventTask(description); 128 taskBuilder.addExecutedTask 129 (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 130 } 84 /** 85 * <p> 86 * internally asserts that there is a current session to add new events to 87 * </p> 88 */ 89 private void assertSessionSequence() { 90 if (currentSession == null) { 91 currentSession = taskFactory.createUserSession(); 92 } 93 } 131 94 132 /** 133 * <p> 134 * used to denote, that all previously added events using {@link #handleNewEvent(Event)} 135 * belong to the same session and that this session is now complete. All further events 136 * will be added to a new session which may be ended using this method, as well. 137 * </p> 138 */ 139 public void finishSession() { 140 if ((currentSession != null) && (currentSession.size() > 0)) { 141 sessions.add(currentSession); 142 currentSession = null; 143 } 144 } 95 /** 96 * <p> 97 * creates a task model based on the provided user sessions. Yet, the user 98 * sessions are list of events. Such will be transformed in into task 99 * instances of event tasks assigned to {@link IUserSession}s. The 100 * {@link IUserSession}s will then be restructured using the temporal 101 * relationship rule manager to detect tasks and respective instances. The 102 * results of this transformation is stored in a task model which is the 103 * return value of this method. 104 * </p> 105 * 106 * @param newSessions 107 * the user sessions of which the task model shall be created 108 * 109 * @return the task model created from the user sessions 110 * 111 * @throws IllegalStateException 112 * if the task manager is already used by providing it with 113 * single events 114 */ 115 public synchronized ITaskModel createTaskModel( 116 Collection<List<Event>> newSessions) { 117 if ((currentSession != null) || (sessions.size() > 0)) { 118 throw new IllegalStateException( 119 "do not mix calls to this method with calls to the " 120 + "other methods for handling tasks. Use only one " 121 + "variant instead."); 122 } 145 123 146 /** 147 * <p> 148 * returns the task model, that belongs to the events in the user sessions collected so far. 149 * </p> 150 * 151 * @return the task model 152 */ 153 public synchronized ITaskModel getTaskModel() { 154 finishSession(); 155 156 Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 157 158 ComponentManager.getTemporalRelationshipRuleManager().applyRules(sessions); 124 for (final List<Event> newSession : newSessions) { 125 if (newSession.size() > 0) { 126 for (final Event event : newSession) { 127 handleNewEvent(event); 128 } 129 finishSession(); 130 } 131 } 159 132 160 return taskFactory.createTaskModel(sessions);161 133 return getTaskModel(); 134 } 162 135 163 /** 164 * <p> 165 * internally asserts that there is a current session to add new events to 166 * </p> 167 */ 168 private void assertSessionSequence() { 169 if (currentSession == null) { 170 currentSession = taskFactory.createUserSession(); 171 } 172 } 136 /** 137 * <p> 138 * used to denote, that all previously added events using 139 * {@link #handleNewEvent(Event)} belong to the same session and that this 140 * session is now complete. All further events will be added to a new 141 * session which may be ended using this method, as well. 142 * </p> 143 */ 144 public void finishSession() { 145 if ((currentSession != null) && (currentSession.size() > 0)) { 146 sessions.add(currentSession); 147 currentSession = null; 148 } 149 } 150 151 /** 152 * <p> 153 * returns the task model, that belongs to the events in the user sessions 154 * collected so far. 155 * </p> 156 * 157 * @return the task model 158 */ 159 public synchronized ITaskModel getTaskModel() { 160 finishSession(); 161 162 Console.traceln(Level.INFO, 163 "applying temporal relationship generation rules"); 164 165 ComponentManager.getTemporalRelationshipRuleManager().applyRules( 166 sessions); 167 168 return taskFactory.createTaskModel(sessions); 169 } 170 171 /** 172 * <p> 173 * handles a single event that occurred in a user session. 174 * </p> 175 * 176 * @param event 177 * the event to handle 178 */ 179 public void handleNewEvent(Event event) { 180 assertSessionSequence(); 181 final String description = event.getType().getName() + " \u21D2 " 182 + event.getTarget(); 183 final IEventTask eventTask = taskFactory 184 .createNewEventTask(description); 185 taskBuilder.addExecutedTask(currentSession, 186 taskFactory.createNewTaskInstance(eventTask, event)); 187 } 173 188 174 189 }
Note: See TracChangeset
for help on using the changeset viewer.