[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() {
|
---|
| 47 | return "generateTaskTree <sequences> {<tasktree>}";
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /*
|
---|
| 51 | * (non-Javadoc)
|
---|
| 52 | *
|
---|
| 53 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 54 | */
|
---|
| 55 | @SuppressWarnings("unchecked")
|
---|
| 56 | @Override
|
---|
| 57 | public void run(List<Object> parameters) {
|
---|
| 58 | String sequencesName;
|
---|
| 59 | String tasktreeName;
|
---|
| 60 | try {
|
---|
| 61 | sequencesName = (String) parameters.get(0);
|
---|
| 62 | if (parameters.size() > 1) {
|
---|
| 63 | tasktreeName = (String) parameters.get(1);
|
---|
| 64 | }
|
---|
| 65 | else {
|
---|
| 66 | tasktreeName = "tasktree";
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | catch (Exception e) {
|
---|
[766] | 70 | throw new IllegalArgumentException("must provide a sequences name");
|
---|
[727] | 71 | }
|
---|
| 72 |
|
---|
| 73 | Collection<List<Event>> sequences = null;
|
---|
| 74 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
| 75 | if (dataObject == null) {
|
---|
| 76 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
| 77 | return;
|
---|
| 78 | }
|
---|
| 79 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
| 80 | CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
|
---|
| 81 | return;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | sequences = (Collection<List<Event>>) dataObject;
|
---|
| 85 |
|
---|
[1146] | 86 | ITaskModel taskModel = new TaskTreeManager().createTaskModel(sequences);
|
---|
[727] | 87 |
|
---|
[1146] | 88 | if (GlobalDataContainer.getInstance().addData(tasktreeName, taskModel)) {
|
---|
[1844] | 89 | CommandHelpers.dataOverwritten(tasktreeName);
|
---|
[727] | 90 | }
|
---|
| 91 |
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | }
|
---|