[1889] | 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.commands.usability;
|
---|
| 16 |
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
| 19 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 20 | import de.ugoe.cs.autoquest.tasktrees.manager.TaskTreeManager;
|
---|
| 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 22 | import de.ugoe.cs.util.console.Command;
|
---|
[2031] | 23 | import de.ugoe.cs.util.console.Console;
|
---|
[1889] | 24 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * <p>
|
---|
| 28 | * This command merges similar tasks in a given task tree. It uses the {@link TaskTreeManager} for
|
---|
| 29 | * this purpose. Please consult the documentation of the task tree manager for more details.
|
---|
| 30 | * </p>
|
---|
| 31 | *
|
---|
| 32 | * @author Patrick Harms
|
---|
| 33 | * @version 1.0
|
---|
| 34 | */
|
---|
| 35 | public class CMDmergeSimilarTasks implements Command {
|
---|
| 36 |
|
---|
| 37 | /*
|
---|
| 38 | * (non-Javadoc)
|
---|
| 39 | *
|
---|
| 40 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 41 | */
|
---|
| 42 | @Override
|
---|
| 43 | public String help() {
|
---|
[1952] | 44 | return "mergeSimilarTasks <inputTaskTree>";
|
---|
[1889] | 45 | }
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | * (non-Javadoc)
|
---|
| 49 | *
|
---|
| 50 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 51 | */
|
---|
| 52 | @Override
|
---|
| 53 | public void run(List<Object> parameters) {
|
---|
| 54 | String inputTaskTreeName;
|
---|
| 55 | try {
|
---|
| 56 | inputTaskTreeName = (String) parameters.get(0);
|
---|
| 57 | }
|
---|
| 58 | catch (Exception e) {
|
---|
| 59 | throw new IllegalArgumentException("must provide an input task tree name");
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | ITaskModel inputTaskModel = null;
|
---|
| 63 | Object dataObject = GlobalDataContainer.getInstance().getData(inputTaskTreeName);
|
---|
| 64 | if (dataObject == null) {
|
---|
| 65 | CommandHelpers.objectNotFoundMessage(inputTaskTreeName);
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 | if (!(dataObject instanceof ITaskModel)) {
|
---|
| 69 | CommandHelpers.objectNotType(inputTaskTreeName, "ITaskModel");
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | inputTaskModel = (ITaskModel) dataObject;
|
---|
| 74 |
|
---|
[2031] | 75 | try {
|
---|
| 76 | ITaskModel taskModel = new TaskTreeManager().mergeSimilarTasks(inputTaskModel);
|
---|
| 77 |
|
---|
| 78 | if (GlobalDataContainer.getInstance().addData(inputTaskTreeName, taskModel)) {
|
---|
| 79 | CommandHelpers.dataOverwritten(inputTaskTreeName);
|
---|
| 80 | }
|
---|
[1889] | 81 | }
|
---|
[2031] | 82 | catch (Exception e) {
|
---|
| 83 | Console.logException(e);
|
---|
| 84 | }
|
---|
[1889] | 85 |
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | }
|
---|