197 lines
6.3 KiB
C++
Executable File
197 lines
6.3 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ISM Custom functions (extends flm_db_impl.cpp/.h)
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Iuliana Ojog, SLSE, 2016-11-26
|
|
*/
|
|
|
|
#include "flm_dtc_impl_custom.h"
|
|
|
|
#include <DDS/DTC/generic_dtc.h>
|
|
#include <DDS/Generic/generic_data_reader.h>
|
|
|
|
#include <QSet>
|
|
#include <QVector>
|
|
#include <unordered_map>
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
namespace FileManagement
|
|
{
|
|
namespace Interface
|
|
{
|
|
DtcImplCustom::DtcImplCustom(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
|
|
: DtcImpl(ddsConnector)
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
bool DtcImplCustom::getAllTemplates(QList<FileContent> &allTemplates)
|
|
{
|
|
if(!isFileContentEnabled())
|
|
{
|
|
enableFileContent();
|
|
waitForHistoricalDataFileContent(4000);
|
|
}
|
|
for (const auto &fc : m_dtcFileContent->readAlive())
|
|
if (fc.data().isTemplate())
|
|
allTemplates.append(fc);
|
|
return true;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
bool DtcImplCustom::getAllFiles(const FileType &fileType, int folderId, QStringList &allFiles, bool showHidden)
|
|
{
|
|
if(!isFileContentEnabled())
|
|
{
|
|
enableFileContent();
|
|
waitForHistoricalDataFileContent(4000);
|
|
}
|
|
for (const auto &fc : m_dtcFileContent->readAlive())
|
|
if (fc.data().fileType() == fileType && fc.data().folderId() == folderId)
|
|
{
|
|
if (showHidden || !fc.data().isHidden())
|
|
allFiles << QString::fromStdString(fc.data().name());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
bool DtcImplCustom::getFilesOperator(const FileType &fileType, int folderId, int operatorId, QStringList &allFiles)
|
|
{
|
|
if(!isFileContentEnabled())
|
|
{
|
|
enableFileContent();
|
|
waitForHistoricalDataFileContent(4000);
|
|
}
|
|
for (const auto &fc : m_dtcFileContent->readAlive())
|
|
if (fc.data().fileType() == fileType && fc.data().folderId() == folderId && fc.data().operatorId() == operatorId)
|
|
allFiles << QString::fromStdString(fc.data().name());
|
|
return true;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
bool DtcImplCustom::getFile(const FileType &fileType, int folderId, const QString &fileName, FileContent &fileMetadata)
|
|
{
|
|
if(!isFileContentEnabled())
|
|
{
|
|
enableFileContent();
|
|
waitForHistoricalDataFileContent(4000);
|
|
}
|
|
const auto stdFileName = fileName.toStdString();
|
|
for (const auto &fc : m_dtcFileContent->readAlive())
|
|
{
|
|
if (fc.data().fileType() == fileType && fc.data().folderId() == folderId && fc.data().name() == stdFileName)
|
|
{
|
|
fileMetadata = fc;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::findFolder(int parentId, const QString &name) const
|
|
{
|
|
QVector<int> foldersVec;
|
|
|
|
std::string stdName = name.toStdString();
|
|
for (const auto &fld : m_dtcFolder->readAlive())
|
|
{
|
|
if (fld.data().parentId() == parentId)
|
|
{
|
|
if (fld.data().name() == stdName)
|
|
return fld.data().id();
|
|
else
|
|
foldersVec.append(fld.data().id());
|
|
}
|
|
}
|
|
|
|
int folderId = 0;
|
|
for (int subParentId : foldersVec)
|
|
{
|
|
folderId = findFolder(subParentId, name);
|
|
if (folderId > 0)
|
|
return folderId;
|
|
}
|
|
|
|
return folderId;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::getExerciseFolderId(int exerciseId) const
|
|
{
|
|
const QString exerciseFolder = getExerciseFolderName(exerciseId);
|
|
return findFolder(0, exerciseFolder);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::getPhaseFolderId(int exerciseId, int phaseId) const
|
|
{
|
|
const QString phaseFolder = getPhaseFolderName(phaseId);
|
|
int exerciseFolderId = getExerciseFolderId(exerciseId);
|
|
return findFolder(exerciseFolderId, phaseFolder);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::getPartyFolderId(int exerciseId, int partyId) const
|
|
{
|
|
const QString partyFolder = getPartyFolderName(partyId);
|
|
int exerciseFolderId = getExerciseFolderId(exerciseId);
|
|
return findFolder(exerciseFolderId, partyFolder);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::getExerciseId(int folderId)
|
|
{
|
|
if (!isFolderEnabled())
|
|
{
|
|
enableFolder();
|
|
waitForHistoricalDataFolder(4000);
|
|
}
|
|
for (const auto &fld : m_dtcFolder->readAlive())
|
|
{
|
|
if (fld.data().id() == folderId)
|
|
{
|
|
int exId = QString::fromStdString(fld.data().name()).remove(0,4).toInt();
|
|
// can be "$EX_" or "$PH_"
|
|
if (exId > 0)
|
|
return exId;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------------------
|
|
int DtcImplCustom::getFileId(const FileType &fileType, const QString &fileName, int exerciseId, int phaseId)
|
|
{
|
|
ERROR_LOG(m_logger) << "fileName: " << fileName;
|
|
|
|
if (fileName.size() <= 0)
|
|
return 0;
|
|
|
|
const auto strFileName = fileName.toStdString();
|
|
DEBUG_LOG(m_logger) << "Searching for " << fileName << ", " << exerciseId << ", " << phaseId << ", " << fileType;
|
|
for (const auto &fc : m_dtcFileContent->readAlive())
|
|
{
|
|
const FileContent &content = fc.data();
|
|
bool cond = (content.fileType() == fileType && content.name() == strFileName);
|
|
if (content.exerciseId().is_set())
|
|
cond &= (content.exerciseId() == exerciseId);
|
|
if (content.phaseId().is_set())
|
|
cond &= (content.phaseId() == phaseId);
|
|
|
|
if (cond)
|
|
{
|
|
DEBUG_LOG(m_logger) << "Found file content id = " << content.id();
|
|
return content.id();
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
} // namespace Interface
|
|
} // namespace FileManagement
|