1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_GALAXY_CONFIG_TASK_H_
23 #define _U2_GALAXY_CONFIG_TASK_H_
24 
25 #include <QXmlStreamWriter>
26 
27 #include <U2Core/Task.h>
28 
29 #include <U2Lang/ActorContext.h>
30 #include <U2Lang/ActorPrototypeRegistry.h>
31 
32 namespace U2 {
33 
34 class GalaxyConfigTask : public Task {
35     Q_OBJECT
36 public:
37     static const QString UGENE_PATH_OPTION;
38     static const QString GALAXY_PATH_OPTION;
39     static const QString GALAXY_CONFIG_OPTION;
40 
41     GalaxyConfigTask(const QString &_schemePath, const QString &_ugenePath, const QString &_galaxyPath, const QString &_destinationPath);
42     ~GalaxyConfigTask();
43 
44     void fillGObjectTypeMap();
45     void prepare();
46     void run();
47 
48 private:
49     QString appDirPath;
50     QString schemeName;
51     QString schemePath;
52     QString ugenePath;
53     QString galaxyPath;
54     QString destinationPath;
55     QString schemeContent;
56     QString galaxyToolName;
57     QString galaxyHelpMessage;
58     QString schemeConfigName;
59     QString schemeConfigPath;
60 
61     QMap<QString, QString> portGObjectTypeMap;
62 
63     QList<QMap<QString, QStringList>> elemAliases;
64     QList<int> inputElementsPositions;
65     QList<int> outputElementsPositions;
66     QList<int> optionElementsPositions;
67     QXmlStreamWriter galaxyConfigOutput;
68 
69     /* Preparation to generating */
70     /* BEGIN */
71     void tryToFindInPath(const QString &objectName, QString &objectPath);
72     void tryToFindByLocate(const QString &objectName, QString &objectPath);
73     bool fileExists(const QString &objectPath, const QString &suffix);
74     bool findPathToObject(const QString &objectName, QString &objectPath);
75     bool getGalaxyPath();
76 
77     bool getSchemeName();
78 
79     bool getSchemeContent();
80     void setError(const QString &keyword);
81     bool getHelpMessage();
82     bool getWorkflowName();
83 
84     bool getParameterValue(const QString &keyword, const int searchFrom, QString &parameterValue, int &nextSearchFrom);
85     bool defineAliases();
86     /* END */
87 
88     /* Tool config generation */
89     /* BEGIN */
90     void writeToolUnit();
91 
92     ActorPrototype *getElementFromActorPrototypeRegistry(const QString &elementName);
93 
94     void fillPositionsList(const QString &elementAttribute, const int elementPosition);
95     bool divideElementsByType();
96     void writeRunUgeneCommand(const QString &ugeneExecutable);
97     void writeOutputFilesChecks();
98     bool writeCommandUnit();
99 
100     void getConstraint(const QString &typeName, QString &resultType);
101     bool getResultType(const ActorPrototype &currElement, QString &resultType);
102     void writeFormatAttribute(const QString &resultType);
103     void writeLabelAttribute(const QStringList &elementParameters, const ActorPrototype &element);
104     bool writeInputElements();
105     bool isDelegateComboBox(PropertyDelegate *pd);
106     bool isDelegateComboBoxWithChecks(PropertyDelegate *pd);
107     bool isDelegateSpinBox(PropertyDelegate *pd);
108     bool isDelegateStringList(PropertyDelegate *pd);
109     bool convertAttributeType(QString &attributeType, PropertyDelegate *pd);
110     bool tryToWriteSimpleType(const PropertyDelegate *pd, QString &attributeType);
111     void writeSelectAttribute(const PropertyDelegate &pd);
112     void writeDrillDownAttribute(const PropertyDelegate &pd);
113     void writeMinAndMaxAttributes(const PropertyDelegate &pd);
114     bool tryToWriteComplexType(PropertyDelegate *pd, const QString &attributeName);
115     bool writeTypeForOptionElement(const QStringList &elementParameters, const ActorPrototype &element);
116     bool writeOptionElements();
117     bool writeInputsUnit();
118 
119     void writeFormatAttributeForOutputElement(const QString &resultType);
120     bool checkDocumentFormatAttribute(const ActorPrototype &element);
121     void writeChangeFormatAttribute(const QString &aliasName, const ActorPrototype &element);
122     void tryToWriteChangeFormatAttribute(const ActorPrototype &element, QList<int> &usedOptionElements);
123     bool writeOutputsUnit();
124 
125     void writeHelpUnit();
126 
127     bool createConfigForGalaxy();
128     /* END */
129 
130     bool tryToCopySchemeConfigFile();
131 
132     bool rewriteFile(const QString &sourceFileName, const QString &targetDirectory);
133     bool doCopyCommands(const QString &pathToCopy);
134     void doDeleteCommands();
135     bool prepareToolDirectory();
136 
137     bool makeCopyOfGalaxyToolConfig();
138     void addNewTool();
139     void writeNewSection(const QString &config);
140     void modifyToolConfig();
141 
142     void addToolToGalaxy();
143 
144 };  // GalaxyConfigTask
145 
146 }  // namespace U2
147 
148 #endif  // _U2_GALAXY_CONFIG_TASK_H_
149