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 #include <U2Core/BaseDocumentFormats.h>
23 
24 #include <U2Lang/BaseTypes.h>
25 #include <U2Lang/ExternalToolCfg.h>
26 
27 namespace U2 {
28 
29 const DocumentFormatId DataConfig::STRING_VALUE = DocumentFormatId("string-value");
30 const DocumentFormatId DataConfig::OUTPUT_FILE_URL = DocumentFormatId("output-file-url");
31 
isStringValue() const32 bool DataConfig::isStringValue() const {
33     return (BaseTypes::STRING_TYPE()->getId() == type) && (STRING_VALUE == format);
34 }
35 
isFileUrl() const36 bool DataConfig::isFileUrl() const {
37     return (OUTPUT_FILE_URL == format);
38 }
39 
isSequence() const40 bool DataConfig::isSequence() const {
41     return (BaseTypes::DNA_SEQUENCE_TYPE()->getId() == type);
42 }
43 
isAnnotations() const44 bool DataConfig::isAnnotations() const {
45     return (BaseTypes::ANNOTATION_TABLE_TYPE()->getId() == type);
46 }
47 
isAnnotatedSequence() const48 bool DataConfig::isAnnotatedSequence() const {
49     return (SEQ_WITH_ANNS == type);
50 }
51 
isAlignment() const52 bool DataConfig::isAlignment() const {
53     return (BaseTypes::MULTIPLE_ALIGNMENT_TYPE()->getId() == type);
54 }
55 
isText() const56 bool DataConfig::isText() const {
57     return (BaseTypes::STRING_TYPE()->getId() == type) && (BaseDocumentFormats::PLAIN_TEXT == format);
58 }
59 
operator ==(const DataConfig & other) const60 bool DataConfig::operator==(const DataConfig &other) const {
61     return attributeId == other.attributeId && attrName == other.attrName && type == other.type && format == other.format && description == other.description;
62 }
63 
64 const QString AttributeConfig::NUMBER_DEPRECATED_TYPE = "Number";
65 const QString AttributeConfig::URL_DEPRECATED_TYPE = "URL";
66 
67 const QString AttributeConfig::BOOLEAN_TYPE = "Boolean";
68 const QString AttributeConfig::STRING_TYPE = "String";
69 const QString AttributeConfig::INTEGER_TYPE = "Integer";
70 const QString AttributeConfig::DOUBLE_TYPE = "Double";
71 const QString AttributeConfig::INPUT_FILE_URL_TYPE = "Input_file_URL";
72 const QString AttributeConfig::OUTPUT_FILE_URL_TYPE = "Output_file_URL";
73 const QString AttributeConfig::INPUT_FOLDER_URL_TYPE = "Input_dir_URL";
74 const QString AttributeConfig::OUTPUT_FOLDER_URL_TYPE = "Output_dir_URL";
75 
AttributeConfig()76 AttributeConfig::AttributeConfig()
77     : flags(None) {
78 }
79 
fixTypes()80 void AttributeConfig::fixTypes() {
81     if (type == URL_DEPRECATED_TYPE) {
82         type = INPUT_FILE_URL_TYPE;
83     } else if (type == NUMBER_DEPRECATED_TYPE) {
84         type = STRING_TYPE;
85     }
86 }
87 
isOutputUrl() const88 bool AttributeConfig::isOutputUrl() const {
89     return type == OUTPUT_FILE_URL_TYPE || type == OUTPUT_FOLDER_URL_TYPE;
90 }
91 
isFile() const92 bool AttributeConfig::isFile() const {
93     return type == INPUT_FILE_URL_TYPE || type == OUTPUT_FILE_URL_TYPE;
94 }
95 
isFolder() const96 bool AttributeConfig::isFolder() const {
97     return type == INPUT_FOLDER_URL_TYPE || type == OUTPUT_FOLDER_URL_TYPE;
98 }
99 
operator ==(const AttributeConfig & other) const100 bool AttributeConfig::operator==(const AttributeConfig &other) const {
101     return attributeId == other.attributeId && attrName == other.attrName && type == other.type && defaultValue == other.defaultValue && description == other.description && flags == other.flags;
102 }
103 
ExternalProcessConfig()104 ExternalProcessConfig::ExternalProcessConfig()
105     : useIntegratedTool(false) {
106 }
107 
108 #define CHECK_EQ(expr1, expr2) \
109     if (!(expr1 == expr2)) { \
110         return false; \
111     }
112 
operator ==(const ExternalProcessConfig & other) const113 bool ExternalProcessConfig::operator==(const ExternalProcessConfig &other) const {
114     CHECK_EQ(inputs.size(), other.inputs.size());
115     CHECK_EQ(outputs.size(), other.outputs.size());
116     CHECK_EQ(attrs.size(), other.attrs.size());
117     CHECK_EQ(cmdLine, other.cmdLine);
118     CHECK_EQ(id, other.id);
119     CHECK_EQ(name, other.name);
120     CHECK_EQ(description, other.description);
121     CHECK_EQ(templateDescription, other.templateDescription);
122     CHECK_EQ(useIntegratedTool, other.useIntegratedTool);
123     CHECK_EQ(customToolPath, other.customToolPath);
124     CHECK_EQ(integratedToolId, other.integratedToolId);
125 
126     foreach (const DataConfig &in, inputs) {
127         CHECK_EQ(other.inputs.contains(in), true);
128     }
129     foreach (const DataConfig &out, outputs) {
130         CHECK_EQ(other.outputs.contains(out), true);
131     }
132     foreach (const AttributeConfig &at, attrs) {
133         CHECK_EQ(other.attrs.contains(at), true);
134     }
135 
136     return true;
137 }
138 
operator !=(const ExternalProcessConfig & other) const139 bool ExternalProcessConfig::operator!=(const ExternalProcessConfig &other) const {
140     return !operator==(other);
141 }
142 
ExternalToolCfgRegistry(QObject * _parent)143 ExternalToolCfgRegistry::ExternalToolCfgRegistry(QObject *_parent)
144     : QObject(_parent) {
145 }
146 
registerExternalTool(ExternalProcessConfig * cfg)147 bool ExternalToolCfgRegistry::registerExternalTool(ExternalProcessConfig *cfg) {
148     if (configs.contains(cfg->id)) {
149         return false;
150     } else {
151         configs.insert(cfg->id, cfg);
152         return true;
153     }
154 }
155 
unregisterConfig(const QString & id)156 void ExternalToolCfgRegistry::unregisterConfig(const QString &id) {
157     // TODO: UTI-294
158     configs.remove(id);
159 }
160 
getConfigById(const QString & id) const161 ExternalProcessConfig *ExternalToolCfgRegistry::getConfigById(const QString &id) const {
162     return configs.value(id, nullptr);
163 }
164 
getConfigs() const165 QList<ExternalProcessConfig *> ExternalToolCfgRegistry::getConfigs() const {
166     return configs.values();
167 }
168 
169 }  // namespace U2
170