13 #include "libfossagentref.h"
52 int uploadId,
int agentId)
57 fo_dbManager_PrepareStamement(
59 (
"pfileForUploadFilterAgent" + uploadtreeTableName).c_str(),
60 (
"SELECT distinct(ut.pfile_fk) FROM " + uploadtreeTableName +
62 "INNER JOIN license_file AS lf ON ut.pfile_fk = lf.pfile_fk "
63 "LEFT JOIN comp_result AS cr ON ut.pfile_fk = cr.pfile_fk "
64 "AND cr.agent_fk = $2 WHERE cr.pfile_fk IS NULL "
65 "AND ut.upload_fk = $1 AND (ut.ufile_mode&x'3C000000'::int)=0;")
78 unsigned long pFileId,
79 vector<unsigned long> agentIds)
84 for (
size_t i = 0; i < agentIds.size() - 1; i++)
86 ss << agentIds[i] <<
",";
88 ss << agentIds[agentIds.size() - 1] <<
"}";
91 fo_dbManager_PrepareStamement(
93 (
"SELECT DISTINCT rf_fk FROM license_file INNER JOIN license_ref "
94 "ON rf_fk = rf_pk AND rf_shortname NOT IN"
95 "('Dual-license', 'No_license_found', 'Void') WHERE pfile_fk = $1 "
96 "AND agent_fk = ANY($2::int[])"),
97 unsigned long,
char*),
98 pFileId, ss.str().c_str());
112 vector<tuple<unsigned long, string>> vec;
116 fo_dbManager_PrepareStamement(
118 (
"SELECT rf_licensetype FROM license_ref WHERE rf_pk = $1"),
121 vector<string> vec2 = queryResult.
getRow(0);
122 vec.emplace_back(i, vec2[0]);
134 tuple<unsigned long, string> lic1, tuple<unsigned long, string> lic2)
const
137 fo_dbManager_PrepareStamement(
139 (
"SELECT compatibility FROM license_rules WHERE (first_rf_fk = $1 AND "
141 "$2) OR (second_rf_fk = $1 AND first_rf_fk = $2)"),
142 unsigned long,
unsigned long),
143 get<0>(lic1), get<0>(lic2));
157 return NOTCOMPATIBLE;
170 std::tuple<unsigned long, std::string> lic1,
171 std::tuple<unsigned long, std::string> lic2)
const
175 "getCompatibilityOnLicenseType",
176 (
"SELECT compatibility FROM license_rules "
177 "WHERE (first_type = $1 AND second_type = $2) "
178 "OR (second_type = $1 AND first_type = $2)"),
180 get<1>(lic1).c_str(), get<1>(lic2).c_str());
194 return NOTCOMPATIBLE;
206 std::tuple<unsigned long, std::string> lic1,
207 std::tuple<unsigned long, std::string> lic2)
const
209 unsigned long licenseId1, licenseId2;
211 licenseId1 = get<0>(lic1);
212 licenseId2 = get<0>(lic2);
213 const char* licenseType1 = get<1>(lic1).c_str();
214 const char* licenseType2 = get<1>(lic2).c_str();
217 fo_dbManager_PrepareStamement(
219 (
"SELECT compatibility FROM license_rules WHERE (first_rf_fk = $1 AND "
220 "second_type = $2) OR (first_rf_fk = $3 AND second_type = $4)"),
221 unsigned long,
char*,
unsigned long,
char*),
222 licenseId1, licenseType2, licenseId2, licenseType1);
237 return NOTCOMPATIBLE;
250 unsigned long pFileId)
253 fo_dbManager_PrepareStamement(
255 (
"SELECT exists(SELECT 1 FROM comp_result WHERE ((first_rf_fk= $1 "
257 "second_rf_fk= $2) OR (second_rf_fk= $1 AND first_rf_fk= $2)) AND "
259 unsigned long,
unsigned long,
unsigned long),
280 fo_dbManager_PrepareStamement(
282 "INSERT INTO comp_result"
283 "(pfile_fk, agent_fk, first_rf_fk, second_rf_fk, result)"
284 "VALUES($1, $2, $3, $4, $5)",
285 unsigned long,
int,
unsigned long,
unsigned long,
char*),
286 pFileId, a_id, id1, id2, comp.c_str());
308 fo_dbManager_PrepareStamement(
310 "SELECT compatibility FROM license_rules "
311 "WHERE first_rf_fk IS NULL AND second_rf_fk IS NULL AND "
312 "first_type IS NULL AND second_type IS NULL;"));
322 return NOTCOMPATIBLE;
334 fo_dbManager_PrepareStamement(
336 (
"SELECT DISTINCT ON (agent_name) agent_pk FROM agent AS ag "
337 "INNER JOIN ars_master AS am "
338 " ON ag.agent_pk = am.agent_fk AND am.upload_fk = $1"
339 " AND am.ars_success = true "
340 "WHERE agent_name IN (" FOSSOLOGY_SCANNER_AGENT_NAME_ARRAY
") "
341 "ORDER BY agent_name, agent_ts DESC;"),
356 fo_dbManager_PrepareStamement(
358 (
"SELECT DISTINCT rf_fk FROM "
359 "upload_clearing_license "
360 "WHERE upload_fk = $1 AND group_fk = $2;"),
361 unsigned long,
unsigned long),
Database handler for COMPATIBILITY.
std::vector< unsigned long > queryScannerIdsForUpload(int uploadId)
Get the agent id of latest scanners run on the upload.
std::vector< unsigned long > queryMainLicenseForUpload(int uploadId, int groupId)
Get the main licenses for the upload.
bool queryInsertResult(unsigned long pFileId, int a_id, unsigned long id1, unsigned long id2, const string &comp)
insert the compatibility result in the comp_result table
bool check(unsigned long id1, unsigned long id2, unsigned long pFileId)
Checking whether the data is already present in database or not, to prevent redundancy.
std::vector< unsigned long > queryLicIdsFromPfile(unsigned long pFileId, vector< unsigned long > agentIds)
to get the license id from the file id
CompatibilityDatabaseHandler(fo::DbManager dbManager)
CompatibilityStatus queryRule3(std::tuple< unsigned long, std::string > lic1, std::tuple< unsigned long, std::string > lic2) const
This rule uses license id and license type to find the compatibility.
std::vector< std::tuple< unsigned long, std::string > > queryLicDetails(const std::vector< unsigned long > &licId)
store the id and type of that respective license in vector of tuple for all the licenses
CompatibilityStatus queryRule2(std::tuple< unsigned long, std::string > lic1, std::tuple< unsigned long, std::string > lic2) const
This rule uses license type of both the licenses to find the compatibility.
std::vector< unsigned long > queryFileIdsForScan(int uploadId, int agentId)
CompatibilityStatus queryRule1(tuple< unsigned long, string > lic1, tuple< unsigned long, string > lic2) const
This rule uses id of both the licenses to find the compatibility.
std::vector< unsigned long > queryFileIdsForUpload(int uploadId)
CompatibilityDatabaseHandler spawn() const
CompatibilityStatus getDefaultRule() const
Get the default rule from DB as CompatibilityStatus.
Database handler for agents.
std::vector< unsigned long > queryFileIdsVectorForUpload(int uploadId, bool ignoreFilesWithMimeType) const
Get pfile ids for a given upload id.
std::string queryUploadTreeTableName(int uploadId)
Get the upload tree table name for a given upload id.
DbManager dbManager
DbManager to use.
QueryResult execPrepared(fo_dbManager_PreparedStatement *stmt,...) const
Execute a prepared statement with new parameters.
fo_dbManager * getStruct_dbManager() const
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.
bool isFailed() const
Check if the query failed.
std::vector< std::string > getRow(int i) const
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
bool stringToBool(const char *string)
unsigned long stringToUnsignedLong(const char *string)