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