[927] | 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.
|
---|
[727] | 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.usability;
|
---|
[727] | 16 |
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 21 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
| 22 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 23 | import de.ugoe.cs.autoquest.tasktrees.manager.TaskTreeManager;
|
---|
[1146] | 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
[727] | 25 | import de.ugoe.cs.util.console.Command;
|
---|
| 26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * <p>
|
---|
[730] | 30 | * This command generates a task tree based on the provided sequences. It uses the
|
---|
| 31 | * {@link TaskTreeManager} for this purpose. Please consult the documentation of the task tree
|
---|
| 32 | * manager for more details.
|
---|
[727] | 33 | * </p>
|
---|
| 34 | *
|
---|
| 35 | * @author Patrick Harms
|
---|
| 36 | * @version 1.0
|
---|
| 37 | */
|
---|
| 38 | public class CMDgenerateTaskTree implements Command {
|
---|
| 39 |
|
---|
| 40 | /*
|
---|
| 41 | * (non-Javadoc)
|
---|
| 42 | *
|
---|
| 43 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 44 | */
|
---|
| 45 | @Override
|
---|
| 46 | public String help() {
|
---|
[2132] | 47 | return "generateTaskTree <sequences> {<tasktree>} {-considerEventEquality} " +
|
---|
| 48 | "{-minimumSequenceCoverage=<some integer>}";
|
---|
[727] | 49 | }
|
---|
| 50 |
|
---|
| 51 | /*
|
---|
| 52 | * (non-Javadoc)
|
---|
| 53 | *
|
---|
| 54 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 55 | */
|
---|
| 56 | @SuppressWarnings("unchecked")
|
---|
| 57 | @Override
|
---|
| 58 | public void run(List<Object> parameters) {
|
---|
[2132] | 59 | String sequencesName = null;
|
---|
| 60 | String tasktreeName = null;
|
---|
| 61 | boolean useEventEqualityForTaskComparison = false;
|
---|
| 62 | int minimumSequenceCoverage = 0;
|
---|
| 63 |
|
---|
[727] | 64 | try {
|
---|
[2132] | 65 | for (int i = 0; i < parameters.size(); i++) {
|
---|
| 66 | String parameter = (String) parameters.get(i);
|
---|
| 67 | if (!parameter.startsWith("-")) {
|
---|
| 68 | if (sequencesName == null) {
|
---|
| 69 | sequencesName = parameter;
|
---|
| 70 | }
|
---|
| 71 | else if (tasktreeName == null) {
|
---|
| 72 | tasktreeName = parameter;
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | throw new IllegalArgumentException("unrecognized parameter: " + parameter);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | else {
|
---|
| 79 | if ("-considerEventEquality".equals(parameter)) {
|
---|
| 80 | useEventEqualityForTaskComparison = true;
|
---|
| 81 | }
|
---|
| 82 | else if (parameter.startsWith("-minimumSequenceCoverage=")) {
|
---|
| 83 | try {
|
---|
| 84 | minimumSequenceCoverage = Integer.parseInt
|
---|
| 85 | (parameter.substring("-minimumSequenceCoverage=".length()));
|
---|
| 86 | }
|
---|
| 87 | catch (Exception e) {
|
---|
| 88 | throw new IllegalArgumentException
|
---|
| 89 | ("invalid value for parameter minimumSequenceCoverage: " +
|
---|
| 90 | parameter.substring("-minimumSequenceCoverage=".length()));
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | throw new IllegalArgumentException("unrecognized parameter: " + parameter);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
[727] | 97 | }
|
---|
| 98 | }
|
---|
[2132] | 99 | catch (IllegalArgumentException e) {
|
---|
| 100 | throw e;
|
---|
| 101 | }
|
---|
[727] | 102 | catch (Exception e) {
|
---|
[2132] | 103 | throw new IllegalArgumentException("could not process parameters", e);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | if (sequencesName == null) {
|
---|
[766] | 107 | throw new IllegalArgumentException("must provide a sequences name");
|
---|
[727] | 108 | }
|
---|
[2132] | 109 |
|
---|
| 110 | if (tasktreeName == null) {
|
---|
| 111 | tasktreeName = "tasktree";
|
---|
| 112 | }
|
---|
[727] | 113 |
|
---|
| 114 | Collection<List<Event>> sequences = null;
|
---|
| 115 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
| 116 | if (dataObject == null) {
|
---|
| 117 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
| 118 | return;
|
---|
| 119 | }
|
---|
| 120 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
| 121 | CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | sequences = (Collection<List<Event>>) dataObject;
|
---|
| 126 |
|
---|
[2132] | 127 | ITaskModel taskModel = new TaskTreeManager().createTaskModel
|
---|
| 128 | (sequences, useEventEqualityForTaskComparison, minimumSequenceCoverage);
|
---|
[727] | 129 |
|
---|
[1146] | 130 | if (GlobalDataContainer.getInstance().addData(tasktreeName, taskModel)) {
|
---|
[1844] | 131 | CommandHelpers.dataOverwritten(tasktreeName);
|
---|
[727] | 132 | }
|
---|
| 133 |
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | }
|
---|