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

Last change on this file since 1217 was 1217, checked in by adeicke, 11 years ago
  • Added proper formating and JavaDoc?.
  • Several renaming refactorings.
  • Property svn:mime-type set to text/plain
File size: 5.6 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.PatternRuleset;
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 * Command to perform a automatic usability evaluation for a given task model.
32 * </p>
33 *
34 * @author Alexander Deicke
35 */
36public class CMDperformUsabilityEvaluation implements Command {
37
38    /**
39     * <p>
40     * index for name of task model under which it could be retrieved from
41     * {@link GlobalDataContainer}
42     * </p>
43     */
44    private final int taskModelParamaterIndex = 0;
45
46    /**
47     * <p>
48     * index for name under which evaluation result should be stored in {@link GlobalDataContainer}
49     * </p>
50     */
51    private final int evaluationResultParameterIndex = 1;
52
53    /**
54     * <p>
55     * default name for evaluation result, which is used to store it in {@link GlobalDataContainer}
56     * </p>
57     */
58    private final String defaultEvaluationResultParameterName = "usabilityEvaluationResult";
59
60    /*
61     * (non-Javadoc)
62     *
63     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
64     */
65    @Override
66    public void run(List<Object> parameters) {
67        String nameOfTaskModel = getTaskModelParameter(parameters);
68        Optional<ITaskModel> taskModel = getTaskModelFromDataContainer(nameOfTaskModel);
69        if (taskModel.isPresent()) {
70            UsabilityRuleset ruleset = new PatternRuleset(taskModel.get());
71            UsabilityResult result = UsabilityEvaluator.evaluate(taskModel.get()).using(ruleset);
72            String evaluationResultParameterName = getEvaluationResultParameter(parameters);
73            storeUsabilityResultInDataContainer(evaluationResultParameterName, result);
74        }
75    }
76
77    /**
78     * <p>
79     * Gets name of task model from list of parameters.
80     * </p>
81     *
82     * @param parameters
83     *            parameters for the command
84     * @return name of task model
85     */
86    private String getTaskModelParameter(List<Object> parameters) {
87        try {
88            return (String) parameters.get(taskModelParamaterIndex);
89        }
90        catch (Exception e) {
91            throw new IllegalArgumentException("must provide a task model name");
92        }
93    }
94
95    /**
96     * <p>
97     * Gets name under which evaluation result should be stored in {@link GlobalDataContainer} from
98     * list of parameters. If not present, the default value {@code usabilityEvaluationResult} is
99     * used!
100     * </p>
101     *
102     * @param parameters
103     *            parameters for the command
104     * @return name under which evaluation result should be stored
105     */
106    private String getEvaluationResultParameter(List<Object> parameters) {
107        if (parameters.size() == 2) {
108            return (String) parameters.get(evaluationResultParameterIndex);
109        }
110        return defaultEvaluationResultParameterName;
111    }
112
113    /**
114     * <p>
115     * Retrieves task model from {@link GlobalDataContainer}.
116     * </p>
117     *
118     * @param nameOfTaskModel
119     *            name of task model, under which it is stored in {@link GlobalDataContainer}
120     * @return if present, task model
121     */
122    private Optional<ITaskModel> getTaskModelFromDataContainer(String nameOfTaskModel) {
123        Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskModel);
124        if (dataObject != null) {
125            if (dataObject instanceof ITaskModel) {
126                ITaskModel taskModel = (ITaskModel) dataObject;
127                return Optional.of(taskModel);
128            }
129            else {
130                CommandHelpers.objectNotType(nameOfTaskModel, "ITaskModel");
131                return Optional.absent();
132            }
133        }
134        CommandHelpers.objectNotFoundMessage(nameOfTaskModel);
135        return Optional.absent();
136    }
137
138    /**
139     * <p>
140     * Stores usability evaluation in {@link GlobalDataContainer}.
141     * </p>
142     *
143     * @param evaluationResultParameterName
144     *            name under which usability result should be stored in {@link GlobalDataContainer}
145     *
146     */
147    private void storeUsabilityResultInDataContainer(String evaluationResultParameterName,
148                                                     UsabilityResult result)
149    {
150        if (GlobalDataContainer.getInstance().addData(evaluationResultParameterName, result)) {
151            CommandHelpers.dataOverwritten(evaluationResultParameterName);
152        }
153    }
154
155    /*
156     * (non-Javadoc)
157     *
158     * @see de.ugoe.cs.util.console.Command#help()
159     */
160    @Override
161    public String help() {
162        return "peformUsabilityEvaluation <taskModel> {evaluationResult}";
163    }
164
165}
Note: See TracBrowser for help on using the repository browser.