[1326] | 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 |
|
---|
| 15 | package de.ugoe.cs.autoquest.plugin.usability2.commands;
|
---|
| 16 |
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
| 19 | import com.google.common.base.Optional;
|
---|
| 20 |
|
---|
| 21 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 22 | import de.ugoe.cs.autoquest.usability.UsabilityEvaluator;
|
---|
| 23 | import de.ugoe.cs.autoquest.usability.rules.UsabilityResult;
|
---|
| 24 | import de.ugoe.cs.autoquest.plugin.usability2.rules.CombinedRuleset;
|
---|
| 25 | import de.ugoe.cs.autoquest.plugin.usability2.rules.patterns.InputMethodSwitching;
|
---|
| 26 | import de.ugoe.cs.autoquest.plugin.usability2.rules.patterns.TestProblem;
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 28 | import de.ugoe.cs.util.console.Command;
|
---|
| 29 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * <p>
|
---|
| 33 | * Command to perform a series of tests
|
---|
| 34 | * </p>
|
---|
| 35 | *
|
---|
| 36 | * @author Alexander Deicke
|
---|
| 37 | */
|
---|
| 38 | public class CMDperformTest implements Command {
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * <p>
|
---|
| 42 | * index for name of task model under which it could be retrieved from
|
---|
| 43 | * {@link GlobalDataContainer}
|
---|
| 44 | * </p>
|
---|
| 45 | */
|
---|
| 46 | private final int taskModelParamaterIndex = 0;
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * <p>
|
---|
| 50 | * index for name under which evaluation result should be stored in {@link GlobalDataContainer}
|
---|
| 51 | * </p>
|
---|
| 52 | */
|
---|
| 53 | private final int evaluationResultParameterIndex = 1;
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * <p>
|
---|
| 57 | * default name for evaluation result, which is used to store it in {@link GlobalDataContainer}
|
---|
| 58 | * </p>
|
---|
| 59 | */
|
---|
| 60 | private final String defaultEvaluationResultParameterName = "usabilityEvaluationResult";
|
---|
| 61 |
|
---|
| 62 | /*
|
---|
| 63 | * (non-Javadoc)
|
---|
| 64 | *
|
---|
| 65 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 66 | */
|
---|
| 67 | @Override
|
---|
| 68 | public void run(List<Object> parameters) {
|
---|
| 69 | String nameOfTaskModel = getTaskModelParameter(parameters);
|
---|
| 70 | Optional<ITaskModel> taskModel = getTaskModelFromDataContainer(nameOfTaskModel);
|
---|
| 71 |
|
---|
| 72 | if (taskModel.isPresent()) {
|
---|
| 73 | // UsabilityRuleset ruleset = new PatternRuleset(taskModel.get());
|
---|
| 74 | CombinedRuleset ruleset = new CombinedRuleset();
|
---|
| 75 | ruleset.add(new TestProblem(taskModel.get()));
|
---|
| 76 | ruleset.add(new InputMethodSwitching(taskModel.get()));
|
---|
| 77 | UsabilityResult result = UsabilityEvaluator.evaluate(taskModel.get()).using(ruleset);
|
---|
| 78 | String evaluationResultParameterName = getEvaluationResultParameter(parameters);
|
---|
| 79 | storeUsabilityResultInDataContainer(evaluationResultParameterName, result);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * <p>
|
---|
| 85 | * Gets name of task model from list of parameters.
|
---|
| 86 | * </p>
|
---|
| 87 | *
|
---|
| 88 | * @param parameters
|
---|
| 89 | * parameters for the command
|
---|
| 90 | * @return name of task model
|
---|
| 91 | */
|
---|
| 92 | private String getTaskModelParameter(List<Object> parameters) {
|
---|
| 93 | try {
|
---|
| 94 | return (String) parameters.get(taskModelParamaterIndex);
|
---|
| 95 | }
|
---|
| 96 | catch (Exception e) {
|
---|
| 97 | throw new IllegalArgumentException("must provide a task model name");
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | /**
|
---|
| 102 | * <p>
|
---|
| 103 | * Gets name under which evaluation result should be stored in {@link GlobalDataContainer} from
|
---|
| 104 | * list of parameters. If not present, the default value {@code usabilityEvaluationResult} is
|
---|
| 105 | * used!
|
---|
| 106 | * </p>
|
---|
| 107 | *
|
---|
| 108 | * @param parameters
|
---|
| 109 | * parameters for the command
|
---|
| 110 | * @return name under which evaluation result should be stored
|
---|
| 111 | */
|
---|
| 112 | private String getEvaluationResultParameter(List<Object> parameters) {
|
---|
| 113 | if (parameters.size() == 2) {
|
---|
| 114 | return (String) parameters.get(evaluationResultParameterIndex);
|
---|
| 115 | }
|
---|
| 116 | return defaultEvaluationResultParameterName;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
| 120 | * <p>
|
---|
| 121 | * Retrieves task model from {@link GlobalDataContainer}.
|
---|
| 122 | * </p>
|
---|
| 123 | *
|
---|
| 124 | * @param nameOfTaskModel
|
---|
| 125 | * name of task model, under which it is stored in {@link GlobalDataContainer}
|
---|
| 126 | * @return if present, task model
|
---|
| 127 | */
|
---|
| 128 | private Optional<ITaskModel> getTaskModelFromDataContainer(String nameOfTaskModel) {
|
---|
| 129 | Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskModel);
|
---|
| 130 | if (dataObject != null) {
|
---|
| 131 | if (dataObject instanceof ITaskModel) {
|
---|
| 132 | ITaskModel taskModel = (ITaskModel) dataObject;
|
---|
| 133 | return Optional.of(taskModel);
|
---|
| 134 | }
|
---|
| 135 | else {
|
---|
| 136 | CommandHelpers.objectNotType(nameOfTaskModel, "ITaskModel");
|
---|
| 137 | return Optional.absent();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | CommandHelpers.objectNotFoundMessage(nameOfTaskModel);
|
---|
| 141 | return Optional.absent();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /**
|
---|
| 145 | * <p>
|
---|
| 146 | * Stores usability evaluation in {@link GlobalDataContainer}.
|
---|
| 147 | * </p>
|
---|
| 148 | *
|
---|
| 149 | * @param evaluationResultParameterName
|
---|
| 150 | * name under which usability result should be stored in {@link GlobalDataContainer}
|
---|
| 151 | *
|
---|
| 152 | */
|
---|
| 153 | private void storeUsabilityResultInDataContainer(String evaluationResultParameterName,
|
---|
| 154 | UsabilityResult result)
|
---|
| 155 | {
|
---|
| 156 | if (GlobalDataContainer.getInstance().addData(evaluationResultParameterName, result)) {
|
---|
| 157 | CommandHelpers.dataOverwritten(evaluationResultParameterName);
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /*
|
---|
| 162 | * (non-Javadoc)
|
---|
| 163 | *
|
---|
| 164 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 165 | */
|
---|
| 166 | @Override
|
---|
| 167 | public String help() {
|
---|
| 168 | return "performTest <taskModel> {evaluationResult}";
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | }
|
---|