| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude 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 (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "COWLlinkBatchFileLoader.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Loader { |
| 29 |
|
| 30 |
|
| 31 |
COWLlinkBatchFileLoader::COWLlinkBatchFileLoader() { |
| 32 |
owllinkInterpreter = 0; |
| 33 |
loaderConfig = 0; |
| 34 |
mConfLogProcessingTimes = false; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
COWLlinkBatchFileLoader::~COWLlinkBatchFileLoader() { |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CLoader *COWLlinkBatchFileLoader::init(CLoaderFactory *loaderFactory, CConfiguration *config) { |
| 44 |
loaderConfig = config; |
| 45 |
CConfigData *data = config->getLastConfigChange("Konclude.OWLlink.RequestFile"); |
| 46 |
if (data) { |
| 47 |
reqFileString = data->getString(); |
| 48 |
} |
| 49 |
|
| 50 |
data = config->getLastConfigChange("Konclude.OWLlink.ResponseFile"); |
| 51 |
if (data) { |
| 52 |
resFileString = data->getString(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
directConsoleOutput = false; |
| 57 |
data = config->getLastConfigChange("Konclude.OWLlink.WriteResponseToStandardOutput"); |
| 58 |
if (data) { |
| 59 |
directConsoleOutput = data->getBoolean(); |
| 60 |
} |
| 61 |
directErrorOutput = false; |
| 62 |
data = config->getLastConfigChange("Konclude.OWLlink.WriteResponseToStandardError"); |
| 63 |
if (data) { |
| 64 |
directErrorOutput = data->getBoolean(); |
| 65 |
} |
| 66 |
closeAfterOutput = false; |
| 67 |
data = config->getLastConfigChange("Konclude.OWLlink.CloseAfterProcessedRequest"); |
| 68 |
if (data) { |
| 69 |
closeAfterOutput = data->getBoolean(); |
| 70 |
} |
| 71 |
blockUntilProcessed = false; |
| 72 |
data = config->getLastConfigChange("Konclude.OWLlink.BlockUntilProcessedRequest"); |
| 73 |
if (data) { |
| 74 |
blockUntilProcessed = data->getBoolean(); |
| 75 |
} |
| 76 |
mConfLogProcessingTimes = false; |
| 77 |
data = config->getLastConfigChange("Konclude.OWLlink.LoggingExtendedProcessingTimes"); |
| 78 |
if (data) { |
| 79 |
mConfLogProcessingTimes = data->getBoolean(); |
| 80 |
} |
| 81 |
data = config->getLastConfigChange("Konclude.OWLlink.SAXBasedLoadOntologiesParsing"); |
| 82 |
if (data) { |
| 83 |
mConfLoadOntologiesSAXParsing = data->getBoolean(); |
| 84 |
} |
| 85 |
|
| 86 |
reasonerCommander = CConfigManagerReader::readCommanderManagerConfig(config); |
| 87 |
|
| 88 |
return this; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
CLoader *COWLlinkBatchFileLoader::load() { |
| 94 |
startProcessing(); |
| 95 |
if (blockUntilProcessed) { |
| 96 |
blockingSem.acquire(); |
| 97 |
} |
| 98 |
return this; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
CConfiguration *COWLlinkBatchFileLoader::getConfiguration() { |
| 104 |
if (!reasonerCommander) { |
| 105 |
return loaderConfig; |
| 106 |
} else { |
| 107 |
CGetDescriptionCommand *getDesComm = new CGetDescriptionCommand(); |
| 108 |
reasonerCommander->delegateCommand(getDesComm); |
| 109 |
CCommandExecutedBlocker commExeBlocker; |
| 110 |
commExeBlocker.waitExecutedCommand(getDesComm); |
| 111 |
CConfiguration *config = getDesComm->getConfiguration(); |
| 112 |
return config; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
COWLlinkProcessor *COWLlinkBatchFileLoader::initializeOWLlinkContent() { |
| 119 |
mResponseTime.start(); |
| 120 |
if (!reqFileString.isEmpty()) { |
| 121 |
QFile file(reqFileString); |
| 122 |
LOG(INFO,getLogDomain(),logTr("Processing OWLlink request from file '%1'.").arg(reqFileString),this); |
| 123 |
if (file.open(QIODevice::ReadOnly)) { |
| 124 |
fileContent = file.readAll(); |
| 125 |
COWLlinkQtXMLCommandParser *owllinkCommandParser = new COWLlinkQtXMLCommandParser(loaderConfig); |
| 126 |
owllinkInterpreter = nullptr; |
| 127 |
if (!resFileString.isEmpty()) { |
| 128 |
owllinkInterpreter = new COWLLinkRecordInterpreter(preSynchronizer,loaderConfig); |
| 129 |
defaultCommandDelegater = owllinkInterpreter; |
| 130 |
} else { |
| 131 |
defaultCommandDelegater = preSynchronizer; |
| 132 |
} |
| 133 |
|
| 134 |
CParseOWLlinkCommandsCommand *parseCommand = new CParseOWLlinkCommandsCommand(&fileContent,reqFileString); |
| 135 |
parseCommand->setRecorder(owllinkInterpreter); |
| 136 |
parseCommand->setReportErrorFromSubCommands(false); |
| 137 |
|
| 138 |
CCommandProcessedCallbackEvent *proComm = new CCommandProcessedCallbackEvent(this,parseCommand); |
| 139 |
parseCommand->addProcessedCallback(proComm); |
| 140 |
|
| 141 |
|
| 142 |
owllinkCommandParser->realizeCommand(parseCommand,defaultCommandDelegater); |
| 143 |
|
| 144 |
delete owllinkCommandParser; |
| 145 |
|
| 146 |
if (mConfLogProcessingTimes) { |
| 147 |
cint64 readMilliSeconds = mResponseTime.elapsed(); |
| 148 |
LOG(INFO,getLogDomain(),logTr("Read XML content in %1 ms.").arg(readMilliSeconds),this); |
| 149 |
} |
| 150 |
|
| 151 |
} else { |
| 152 |
LOG(ERROR,getLogDomain(),logTr("OWLlink request file '%1' not found.").arg(reqFileString),this); |
| 153 |
concludeOWLlinkContent(); |
| 154 |
} |
| 155 |
} |
| 156 |
return this; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
COWLlinkProcessor *COWLlinkBatchFileLoader::concludeOWLlinkContent() { |
| 162 |
if (owllinkInterpreter) { |
| 163 |
QByteArray fileContent(owllinkInterpreter->getByteArray()); |
| 164 |
if (!resFileString.isEmpty()) { |
| 165 |
QFile file(resFileString); |
| 166 |
if (file.open(QIODevice::WriteOnly)) { |
| 167 |
file.write(fileContent); |
| 168 |
file.close(); |
| 169 |
} |
| 170 |
} |
| 171 |
if (directConsoleOutput) { |
| 172 |
std::cout<<fileContent.data(); |
| 173 |
} |
| 174 |
if (directErrorOutput) { |
| 175 |
std::cerr<<fileContent.data(); |
| 176 |
} |
| 177 |
} |
| 178 |
if (mConfLogProcessingTimes) { |
| 179 |
cint64 responseMilliSeconds = mResponseTime.elapsed(); |
| 180 |
LOG(INFO,getLogDomain(),logTr("OWLlink request processed in %1 ms.").arg(responseMilliSeconds),this); |
| 181 |
} |
| 182 |
if (blockUntilProcessed) { |
| 183 |
blockingSem.release(); |
| 184 |
} |
| 185 |
if (closeAfterOutput) { |
| 186 |
CLogger::getInstance()->waitSynchronization(); |
| 187 |
//qSleep(10); |
| 188 |
//qWait(); |
| 189 |
QCoreApplication::exit(); |
| 190 |
} |
| 191 |
return this; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
CLoader *COWLlinkBatchFileLoader::exit() { |
| 196 |
|
| 197 |
stopThread(); |
| 198 |
|
| 199 |
return this; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
}; // end namespace Loader |
| 205 |
|
| 206 |
}; // end namespace Control |
| 207 |
|
| 208 |
}; // end namespace Konclude |