FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
OjosDatabaseHandler.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019, Siemens AG
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
22 #ifndef OJOS_AGENT_DATABASE_HANDLER_HPP
23 #define OJOS_AGENT_DATABASE_HANDLER_HPP
24 
25 #include <unordered_map>
26 #include <algorithm>
27 #include <string>
28 #include <iostream>
29 
30 #include "libfossUtils.hpp"
33 #include "ojomatch.hpp"
34 
35 extern "C" {
36 #include "libfossology.h"
37 }
38 
44 {
53  const unsigned long int license_fk, agent_fk, pfile_fk;
60  OjoDatabaseEntry(const unsigned long int l, const unsigned long int a,
61  const unsigned long int p) :
62  license_fk(l), agent_fk(a), pfile_fk(p)
63  {
64  }
65 };
66 
72 {
73  public:
76  fo::AgentDatabaseHandler(std::move(other))
77  {
78  }
79  ;
80  OjosDatabaseHandler spawn() const;
81 
82  std::vector<unsigned long> queryFileIdsForUpload(int uploadId, bool ignoreFilesWithMimeType);
83  std::vector<unsigned long> queryFileIdsForScan(int uploadId, int agentId, bool ignoreFilesWithMimeType);
84  unsigned long saveLicenseToDatabase(OjoDatabaseEntry &entry) const;
85  bool insertNoResultInDatabase(OjoDatabaseEntry &entry) const;
86  bool saveHighlightToDatabase(const ojomatch &match,
87  const unsigned long fl_fk) const;
88 
89  unsigned long getLicenseIdForName(std::string const &rfShortName);
90 
91  private:
92  unsigned long getCachedLicenseIdForName(
93  std::string const &rfShortName) const;
94  unsigned long selectOrInsertLicenseIdForName(std::string rfShortname);
98  std::unordered_map<std::string, long> licenseRefCache;
99 };
100 
101 #endif // OJOS_AGENT_DATABASE_HANDLER_HPP
DB wrapper for agents.
Store the results of a regex match.
Definition: scanners.hpp:39
DB wrapper for agents.
Database handler for agents.
std::unordered_map< std::string, long > licenseRefCache
The main FOSSology C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
General utility functions for CPP.
const unsigned long int agent_fk
OjoDatabaseEntry(const unsigned long int l, const unsigned long int a, const unsigned long int p)
PGresult * queryFileIdsForUpload(fo_dbManager *dbManager, int uploadId, bool ignoreFilesWithMimeType)
Get all file IDs (pfile_fk) for a given upload.
Definition: libfossagent.c:73
const unsigned long int license_fk
DB utility functions for agents.
const unsigned long int pfile_fk
Store the results of a regex match.
Definition: ojomatch.hpp:27