Class LPVSLicenseService

java.lang.Object
com.lpvs.service.LPVSLicenseService

@Service public class LPVSLicenseService extends Object
Service class for managing licenses and license conflicts. It provides methods to retrieve licenses from a database, check for license conflicts, and handle license-related operations.
  • Field Details

    • licenseConflictsSource

      public String licenseConflictsSource
      Source of license conflicts.
  • Constructor Details

    • LPVSLicenseService

      @Autowired public LPVSLicenseService(@Value("${license_conflict:db}") String licenseConflictsSource, LPVSExitHandler exitHandler)
      Constructs an instance of LPVSLicenseService with the specified license conflicts source and exit handler.
      Parameters:
      licenseConflictsSource - Source of license conflicts.
      exitHandler - Handler for exiting the application.
  • Method Details

    • reloadFromTables

      public void reloadFromTables()
      This method reloads licenses and license conflicts from database tables if the licenses list in case of single scan triggered and used in memory database.
    • findLicenseBySPDX

      protected LPVSLicense findLicenseBySPDX(String name)
      Finds a license by SPDX identifier.
      Parameters:
      name - SPDX identifier of the license.
      Returns:
      LPVSLicense object if found, otherwise null.
    • addLicenseToList

      protected void addLicenseToList(LPVSLicense license)
      Adds a license to the list of licenses.
      Parameters:
      license - The license to add.
    • findLicenseByName

      protected LPVSLicense findLicenseByName(String name)
      Finds a license by its name.
      Parameters:
      name - The name of the license.
      Returns:
      LPVSLicense object if found, otherwise null.
    • getLicenseBySpdxIdAndName

      public LPVSLicense getLicenseBySpdxIdAndName(String licenseSpdxId, Optional<String> licenseName)
      Gets a license object from the database using the specified license SPDX ID and license name.
      Parameters:
      licenseSpdxId - The license SPDX ID to search for
      licenseName - The license name to use if the license is not found in the database
      Returns:
      The license object that was found or created
    • findLicenseInOsoriDB

      public LPVSLicense findLicenseInOsoriDB(String licenseSpdxId)
      Search for a license with the given SPDX identifier in the OSORI database.
      Parameters:
      licenseSpdxId - The SPDX identifier of the license to search for.
      Returns:
      The LPVSLicense object if the license is found in the OSORI database, otherwise null.
    • findLicense

      public LPVSLicense findLicense(String licenseSpdxId, String licenseName)
      Search for a license using the given SPDX identifier and license name. It first tries to find the license by its SPDX identifier, and if that fails, it checks by the license name and alternative names.
      Parameters:
      licenseSpdxId - The SPDX identifier of the license to search for.
      licenseName - The name or alternative name of the license to search for.
      Returns:
      The LPVSLicense object if the license is found, otherwise null.
    • addLicenseConflict

      public void addLicenseConflict(String license1, String license2)
      Adds a license conflict to the list of conflicts.
      Parameters:
      license1 - The first license in conflict.
      license2 - The second license in conflict.
    • findConflicts

      public List<LPVSLicenseService.Conflict<String,String>> findConflicts(LPVSQueue webhookConfig, List<LPVSFile> scanResults)
      Finds license conflicts based on the provided scan results and repository information.
      Parameters:
      webhookConfig - Configuration related to the repository and webhook.
      scanResults - List of scanned files.
      Returns:
      List of license conflicts found.