FOSSology  4.4.0
Open Source License Compliance by Open Source Software
OjosDatabaseHandler Class Reference

#include <OjosDatabaseHandler.hpp>

Inheritance diagram for OjosDatabaseHandler:
Inheritance graph
Collaboration diagram for OjosDatabaseHandler:
Collaboration graph

Public Member Functions

 OjosDatabaseHandler (fo::DbManager dbManager)
 
 OjosDatabaseHandler (OjosDatabaseHandler &&other)
 
OjosDatabaseHandler spawn () const
 
std::vector< unsigned long > queryFileIdsForUpload (int uploadId, int agentId, bool ignoreFilesWithMimeType)
 
unsigned long saveLicenseToDatabase (OjoDatabaseEntry &entry) const
 Save findings to the database if agent was called by scheduler. More...
 
bool insertNoResultInDatabase (OjoDatabaseEntry &entry) const
 Save no result to the database. More...
 
bool saveHighlightToDatabase (const ojomatch &match, const unsigned long fl_fk) const
 
unsigned long getLicenseIdForName (std::string const &rfShortName, const int groupId, const int userId)
 Get the license id for a given short name. More...
 
- Public Member Functions inherited from fo::AgentDatabaseHandler
 AgentDatabaseHandler (DbManager dbManager)
 
 AgentDatabaseHandler (AgentDatabaseHandler &&other)
 
 AgentDatabaseHandler (const AgentDatabaseHandler &)=delete
 
virtual ~AgentDatabaseHandler ()
 
AgentDatabaseHandler operator= (const AgentDatabaseHandler &)=delete
 
bool begin () const
 BEGIN a transaction block in DB. More...
 
bool commit () const
 COMMIT a transaction block in DB. More...
 
bool rollback () const
 ROLLBACK a transaction block in DB. More...
 
char * getPFileNameForFileId (unsigned long pfileId) const
 Get the file name of a give pfile id. More...
 
std::string queryUploadTreeTableName (int uploadId)
 Get the upload tree table name for a given upload id. More...
 
std::vector< unsigned long > queryFileIdsVectorForUpload (int uploadId, bool ignoreFilesWithMimeType) const
 Get pfile ids for a given upload id. More...
 
std::vector< unsigned long > queryFileIdsVectorForUpload (int uploadId, int agentId, bool ignoreFilesWithMimeType) const
 Get pfile ids for a given upload id which agent has not scanned. More...
 

Private Member Functions

unsigned long getCachedLicenseIdForName (std::string const &rfShortName) const
 
unsigned long selectOrInsertLicenseIdForName (std::string rfShortname, const int groupId, const int userId)
 

Private Attributes

std::unordered_map< std::string, long > licenseRefCache
 

Additional Inherited Members

- Protected Attributes inherited from fo::AgentDatabaseHandler
DbManager dbManager
 DbManager to use.
 

Detailed Description

Database handler for OJO agent

Definition at line 60 of file OjosDatabaseHandler.hpp.

Constructor & Destructor Documentation

◆ OjosDatabaseHandler()

OjosDatabaseHandler::OjosDatabaseHandler ( fo::DbManager  dbManager)

Default constructor for OjosDatabaseHandler

Parameters
dbManagerDBManager to be used

Definition at line 20 of file OjosDatabaseHandler.cc.

Member Function Documentation

◆ getCachedLicenseIdForName()

unsigned long OjosDatabaseHandler::getCachedLicenseIdForName ( std::string const &  rfShortName) const
private

Get the license id from the cached license list.

Parameters
rfShortNameName of the license
Returns
License id if found, 0 otherwise

Definition at line 347 of file OjosDatabaseHandler.cc.

◆ getLicenseIdForName()

unsigned long OjosDatabaseHandler::getLicenseIdForName ( std::string const &  rfShortName,
const int  groupId,
const int  userId 
)

Get the license id for a given short name.

The function first checks if the license exists in the cache list. If the license is not cached, it checks in DB and store in the cache.

Parameters
rfShortNameShort name to be searched
groupIdGroup running the agent
userIdUserRunning the agent
Returns
License ID if found, 0 otherwise
See also
OjosDatabaseHandler::getCachedLicenseIdForName()

Definition at line 330 of file OjosDatabaseHandler.cc.

◆ insertNoResultInDatabase()

bool OjosDatabaseHandler::insertNoResultInDatabase ( OjoDatabaseEntry entry) const

Save no result to the database.

Parameters
entryEntry containing the agent id and file id
Returns
True of successful insertion, false otherwise

Definition at line 108 of file OjosDatabaseHandler.cc.

◆ queryFileIdsForUpload()

vector< unsigned long > OjosDatabaseHandler::queryFileIdsForUpload ( int  uploadId,
int  agentId,
bool  ignoreFilesWithMimeType 
)

Get a vector of all file id for a given upload id.

Parameters
uploadIdUpload ID to be queried
agentIdCurrent agent ID
ignoreFilesWithMimeTypeTo ignore files with particular mimetype
Returns
List of all pfiles for the given upload

Definition at line 32 of file OjosDatabaseHandler.cc.

◆ saveHighlightToDatabase()

bool OjosDatabaseHandler::saveHighlightToDatabase ( const ojomatch match,
const unsigned long  fl_fk 
) const

Save findings highlights to DB

Parameters
matchMatch to be saved
fl_fkfl_pk from license_file table
Returns
True on success, false otherwise

Definition at line 84 of file OjosDatabaseHandler.cc.

◆ saveLicenseToDatabase()

unsigned long OjosDatabaseHandler::saveLicenseToDatabase ( OjoDatabaseEntry entry) const

Save findings to the database if agent was called by scheduler.

Parameters
entryThe entry to be made
Returns
fl_pk on success, -1 on failure

Definition at line 55 of file OjosDatabaseHandler.cc.

◆ selectOrInsertLicenseIdForName()

unsigned long OjosDatabaseHandler::selectOrInsertLicenseIdForName ( std::string  rfShortname,
const int  groupId,
const int  userId 
)
private

Get the license id for a given short name or create a new entry.

Note
The following rules are also applied on name matching:
  1. All matches are case in-sensitive.
  2. GPL-2.0 and GPL-2.0-only are treated as same
  3. GPL-2.0+ and GPL-2.0-or-later are treated as same
If the agent could not find license in main license, it will create a new one as candidate license.
Parameters
rfShortNameShort name to be searched.
groupIdGroup id for candidate license
userIdUser who is running the agent
Returns
License id, 0 on failure

Definition at line 160 of file OjosDatabaseHandler.cc.

◆ spawn()

OjosDatabaseHandler OjosDatabaseHandler::spawn ( ) const

Spawn a new DbManager object.

Used to create new objects for threads.

Returns
DbManager object for threads.

Definition at line 44 of file OjosDatabaseHandler.cc.

Member Data Documentation

◆ licenseRefCache

std::unordered_map<std::string, long> OjosDatabaseHandler::licenseRefCache
private

Cached license pairs

Definition at line 91 of file OjosDatabaseHandler.hpp.


The documentation for this class was generated from the following files: