14 #define LICENSE_REF_TABLE "ONLY license_ref"
17 long left,
long right,
long groupId,
18 bool ignoreIrre,
bool scanFindings) {
24 char* distinctPfile =
"SELECT DISTINCT pfile_fk FROM %s"
25 " WHERE upload_fk = $1 AND (ufile_mode&x'3C000000'::int) = 0 "
26 " AND (lft BETWEEN $2 AND $3) AND pfile_fk != 0";
27 char* distinctPfileNoDec =
"SELECT DISTINCT pfile_fk FROM ("
28 "SELECT distinct ON(ut.uploadtree_pk, ut.pfile_fk, scopesort) ut.pfile_fk pfile_fk, ut.uploadtree_pk, decision_type,"
29 " CASE cd.scope WHEN 1 THEN 1 ELSE 0 END AS scopesort"
31 " LEFT JOIN clearing_decision cd ON ("
32 " (ut.uploadtree_pk = cd.uploadtree_fk AND cd.scope = 0 AND cd.group_fk = $5)"
34 " SELECT 1 FROM report_info ri WHERE ri.upload_fk=$1 AND ri.ri_globaldecision=1"
35 " ) AND ut.pfile_fk = cd.pfile_fk AND cd.scope = 1)"
37 " WHERE upload_fk=$1 AND (ufile_mode&x'3C000000'::int)=0 AND (lft BETWEEN $2 AND $3) AND ut.pfile_fk != 0"
38 " ORDER BY ut.uploadtree_pk, scopesort, ut.pfile_fk, clearing_decision_pk DESC"
39 ") itemView WHERE decision_type!=$4 OR decision_type IS NULL";
40 char* nonVoidPfile =
", realFindings AS ("
41 " SELECT DISTINCT lf.pfile_fk"
42 " FROM license_file lf"
43 " INNER JOIN ars_master am ON lf.agent_fk = am.agent_fk AND am.upload_fk = $1"
44 " INNER JOIN " LICENSE_REF_TABLE
" lr ON lf.rf_fk = lr.rf_pk"
45 " WHERE lr.rf_shortname NOT IN ('No_license_found', 'Void')"
47 " SELECT pfile_fk FROM allPfileData"
48 " WHERE pfile_fk IN (SELECT pfile_fk FROM realFindings)";
50 if (!ignoreIrre && !scanFindings)
52 sql = g_strdup_printf(distinctPfile, tablename);
53 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s", tablename);
55 fo_dbManager_PrepareStamement(
63 else if(!ignoreIrre && scanFindings)
65 sql = g_strdup_printf(
66 g_strconcat(
"WITH allPfileData AS (", distinctPfile,
") ", nonVoidPfile,
68 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimitswithlicensefinding.%s", tablename);
70 fo_dbManager_PrepareStamement(
78 else if(ignoreIrre && scanFindings)
80 sql = g_strdup_printf(
81 g_strconcat(
"WITH allPfileData AS (", distinctPfileNoDec,
") ",
82 nonVoidPfile, NULL), tablename);
83 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirreandscanFindings", tablename);
85 fo_dbManager_PrepareStamement(
89 int,
long,
long,
int,
long),
90 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
95 sql = g_strdup_printf(distinctPfileNoDec, tablename);
96 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirre", tablename);
98 fo_dbManager_PrepareStamement(
102 int,
long,
long,
int,
long),
103 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
112 return fo_dbManager_Exec_printf(
114 "select rf_pk, rf_shortname from " LICENSE_REF_TABLE
" where rf_detector_type = 1 and rf_active = 'true'"
120 fo_dbManager_PrepareStamement(
122 "getLicenseTextForLicenseRefId",
123 "select rf_text from " LICENSE_REF_TABLE
" where rf_pk = $1",
128 if (PQntuples(licenseTextResult) != 1) {
129 printf(
"cannot find license text!\n");
130 PQclear(licenseTextResult);
134 char* result = g_strdup(PQgetvalue(licenseTextResult, 0, 0));
135 PQclear(licenseTextResult);
141 fo_dbManager_PrepareStamement(
143 "hasAlreadyResultsFor",
144 "SELECT 1 WHERE EXISTS (SELECT 1"
145 " FROM license_file WHERE agent_fk = $1 AND pfile_fk = $2"
153 exists = (PQntuples(insertResult) == 1);
154 PQclear(insertResult);
162 fo_dbManager_PrepareStamement(
165 "insert into license_file(agent_fk, pfile_fk) values($1,$2)",
173 PQclear(insertResult);
181 fo_dbManager_PrepareStamement(
184 "insert into license_file(rf_fk, agent_fk, pfile_fk, rf_match_pct) values($1,$2,$3,$4) RETURNING fl_pk",
185 long,
int,
long,
unsigned),
186 refId, agentId, pFileId, percent
189 long licenseFilePk = -1;
191 if (PQntuples(insertResult) == 1) {
192 licenseFilePk = atol(PQgetvalue(insertResult, 0, 0));
194 PQclear(insertResult);
197 return licenseFilePk;
202 fo_dbManager_PrepareStamement(
204 "saveDiffHighlightToDb",
205 "insert into highlight(fl_fk, type, start, len, rf_start, rf_len) values($1,$2,$3,$4,$5,$6)",
206 long,
char*,
size_t,
size_t,
size_t,
size_t),
209 diffInfo->text.start, diffInfo->text.length,
210 diffInfo->search.start, diffInfo->search.length
216 PQclear(insertResult);
222 size_t matchedInfoLen = matchedInfo->len ;
223 for (
size_t i = 0; i < matchedInfoLen; i++) {
225 if (!saveDiffHighlightToDb(
dbManager, diffMatchInfo, licenseFileId))
240 fo_dbManager_PrepareStamement(
242 "queryActiveCustomPhrasesWithMappings",
243 "SELECT cp.cp_pk, cp.text, cp.acknowledgement, cp.comments,"
244 " cplm.rf_fk, cplm.removing,"
245 " cplm.comment, cplm.reportinfo, cplm.acknowledgement"
246 " FROM custom_phrase cp"
247 " LEFT JOIN custom_phrase_license_map cplm ON cp.cp_pk = cplm.cp_fk"
248 " WHERE cp.is_active = true"
253 GArray* phrases = g_array_new(FALSE, FALSE,
sizeof(
Phrase*));
258 int numRows = PQntuples(result);
261 for (
int i = 0; i < numRows; i++) {
262 long cpId = atol(PQgetvalue(result, i, 0));
264 if (!current || current->cpId != cpId) {
267 phrase->text = g_strdup(PQgetvalue(result, i, 1));
268 phrase->acknowledgement = PQgetisnull(result, i, 2) ? NULL : g_strdup(PQgetvalue(result, i, 2));
269 phrase->comments = PQgetisnull(result, i, 3) ? NULL : g_strdup(PQgetvalue(result, i, 3));
270 phrase->licenseMappings = g_array_new(FALSE, FALSE,
sizeof(
LicenseMapping));
271 phrase->stmtName = NULL;
272 g_array_append_val(phrases, phrase);
277 if (!PQgetisnull(result, i, 4)) {
279 mapping.
rfPk = atol(PQgetvalue(result, i, 4));
280 mapping.
removing = (strcmp(PQgetvalue(result, i, 5),
"t") == 0) ? 1 : 0;
281 mapping.
comment = PQgetisnull(result, i, 6) ? NULL : g_strdup(PQgetvalue(result, i, 6));
282 mapping.
reportinfo = PQgetisnull(result, i, 7) ? NULL : g_strdup(PQgetvalue(result, i, 7));
283 mapping.
acknowledgement = PQgetisnull(result, i, 8) ? NULL : g_strdup(PQgetvalue(result, i, 8));
284 g_array_append_val(current->licenseMappings, mapping);
296 void phrase_free(
Phrase* phrase) {
299 g_free(phrase->text);
300 g_free(phrase->acknowledgement);
301 g_free(phrase->comments);
302 g_free(phrase->stmtName);
304 if (phrase->licenseMappings) {
305 for (guint i = 0; i < phrase->licenseMappings->len; i++) {
311 g_array_free(phrase->licenseMappings, TRUE);
321 void phrases_free(GArray* phrases) {
322 if (!phrases)
return;
324 for (guint i = 0; i < phrases->len; i++) {
329 g_array_free(phrases, TRUE);
char * getUploadTreeTableName(fo_dbManager *dbManager, int uploadId)
Get the upload tree table name for a given upload.
fo_dbManager * dbManager
fo_dbManager object
PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement.
License mapping entry with per-mapping report metadata.
int removing
0 = add license, 1 = remove license
char * acknowledgement
nullable
long rfPk
rf_pk from license_ref table
char * reportinfo
nullable
Structure to hold a custom phrase and its mapped licenses.
int exists
Default not exists.