source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/CMDperformUsabilityEvaluation.java @ 1152

Last change on this file since 1152 was 1152, checked in by pharms, 11 years ago
  • complete refactoring of task tree model with a separation of task models and task instances
  • Property svn:mime-type set to text/plain
File size: 4.8 KB
Line 
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
15package de.ugoe.cs.autoquest.usability;
16
17import java.util.List;
18
19import com.google.common.base.Optional;
20
21import de.ugoe.cs.autoquest.CommandHelpers;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
23import de.ugoe.cs.autoquest.usability.rules.EmptyRuleset;
24import de.ugoe.cs.autoquest.usability.rules.UsabilityResult;
25import de.ugoe.cs.autoquest.usability.rules.UsabilityRuleset;
26import de.ugoe.cs.util.console.Command;
27import de.ugoe.cs.util.console.GlobalDataContainer;
28
29/**
30 * <p>
31 * TODO comment
32 * </p>
33 *
34 * @author Alexander Deicke
35 */
36public class CMDperformUsabilityEvaluation implements Command {
37
38    private final int taskTreeParamaterIndex = 0;
39   
40    private final int evaluationResultParameterIndex = 1;
41   
42    private final String defaultEvaluationResultParameterName = "usabilityEvaluationResult";
43   
44    private final UsabilityRuleset defaultUsabilityRuleset = new EmptyRuleset();
45   
46    /* (non-Javadoc)
47     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
48     */
49    @Override
50    public void run(List<Object> parameters) {
51        String nameOfTaskTree = getTaskTreeParameter(parameters);
52        Optional<ITaskModel> taskModel = getTaskModelFromDataContainer(nameOfTaskTree);
53        if (taskModel.isPresent()) {
54            UsabilityRuleset ruleset = getUsabilityRuleset();
55            UsabilityResult result = UsabilityEvaluator.evaluate(taskModel.get()).using(ruleset);
56            String evaluationResultParameterName = getEvaluationResultParameter(parameters);
57            storeUsabilityResultInDataContainer(evaluationResultParameterName, result);
58        }
59        return;
60    }
61
62    /**
63     * <p>
64     * TODO: comment
65     * </p>
66     *
67     * @param parameters
68     * @return
69     */
70    private String getTaskTreeParameter(List<Object> parameters) {
71        try {
72            return (String) parameters.get(taskTreeParamaterIndex);
73        } catch (Exception e) {
74            throw new IllegalArgumentException("must provide a task tree name");
75        }
76    }
77
78    /**
79     * <p>
80     * TODO: comment
81     * </p>
82     *
83     * @param parameters
84     * @return
85     */
86    private String getEvaluationResultParameter(List<Object> parameters) {
87        if(parameters.size() == 2) {
88            return (String) parameters.get(evaluationResultParameterIndex);
89        }
90        return defaultEvaluationResultParameterName;
91    }
92   
93    /**
94     * <p>
95     * TODO: comment
96     * </p>
97     *
98     * @param nameOfTaskTree
99     * @return
100     */
101    private Optional<ITaskModel> getTaskModelFromDataContainer(String nameOfTaskTree) {
102        Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskTree);
103        if(dataObject != null) {
104            if(dataObject instanceof ITaskModel) {
105                ITaskModel taskTree = (ITaskModel) dataObject;
106                return Optional.of(taskTree);
107            } else {
108                CommandHelpers.objectNotType(nameOfTaskTree, "ITaskModel");
109                return Optional.absent();
110            }
111        }
112        CommandHelpers.objectNotFoundMessage(nameOfTaskTree);
113        return Optional.absent();
114    }
115   
116    /**
117     * <p>
118     * TODO: comment
119     * </p>
120     *
121     * @return
122     */
123    private UsabilityRuleset getUsabilityRuleset() {
124        // TODO Auto-generated method stub
125        System.out.println("TODO: implement CMDperformUsabilityEvaluation.getUsabilityRuleset ");
126        return this.defaultUsabilityRuleset;
127    }
128   
129    /**
130     * <p>
131     * TODO: comment
132     * </p>
133     * @param evaluationResultParameterName
134     *
135     */
136    private void storeUsabilityResultInDataContainer(String evaluationResultParameterName, UsabilityResult result) {
137        if (GlobalDataContainer.getInstance().addData(evaluationResultParameterName, result)) {
138            CommandHelpers.dataOverwritten(evaluationResultParameterName);
139        }   
140    }
141
142    /* (non-Javadoc)
143     * @see de.ugoe.cs.util.console.Command#help()
144     */
145    @Override
146    public String help() {
147        return "peformUsabilityEvaluation <taskTree> {evaluationResult}";
148    }
149
150}
Note: See TracBrowser for help on using the repository browser.