Search in sources :

Example 1 with CveSearchGuesser

use of org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser in project sw360portal by sw360.

the class SearchLevels method guessForRelease.

private List<NeedleWithMeta> guessForRelease(CveSearchGuesser cveSearchGuesser, Release release, boolean useVersionInformation) throws IOException {
    if (useVersionInformation && !release.isSetVersion()) {
        return Collections.emptyList();
    }
    List<Match> vendorProductList;
    String productHaystack = release.getName();
    if (release.isSetVendor() && (release.getVendor().isSetShortname() || release.getVendor().isSetFullname())) {
        String vendorHaystack = nullToEmptyString(release.getVendor().getShortname()) + " " + nullToEmptyString(release.getVendor().getFullname());
        vendorProductList = cveSearchGuesser.guessVendorAndProducts(vendorHaystack, productHaystack);
    } else {
        vendorProductList = cveSearchGuesser.guessVendorAndProducts(productHaystack);
    }
    String cpeNeedlePostfix = ":" + (useVersionInformation ? release.getVersion() : "") + CPE_WILDCARD;
    Function<String, String> cpeBuilder = cpeNeedle -> CPE_NEEDLE_PREFIX + cpeNeedle + cpeNeedlePostfix;
    return vendorProductList.stream().map(match -> new NeedleWithMeta(cpeBuilder.apply(match.getNeedle()), "heuristic (dist. " + (useVersionInformation ? "0" : "1") + match.getDistance() + ")")).collect(Collectors.toList());
}
Also used : Properties(java.util.Properties) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Predicate(java.util.function.Predicate) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match) CveSearchApi(org.eclipse.sw360.cvesearch.datasource.CveSearchApi) IOException(java.io.IOException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Logger(org.apache.log4j.Logger) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) List(java.util.List) Stream(java.util.stream.Stream) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) CveSearchGuesser(org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser) Collections(java.util.Collections) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match)

Example 2 with CveSearchGuesser

use of org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser in project sw360portal by sw360.

the class SearchLevels method addGuessingSearchLevels.

private void addGuessingSearchLevels(CveSearchApi cveSearchApi, int vendorThreshold, int productThreshold, int cutoff) {
    CveSearchGuesser cveSearchGuesser = new CveSearchGuesser(cveSearchApi);
    cveSearchGuesser.setVendorThreshold(vendorThreshold);
    cveSearchGuesser.setProductThreshold(productThreshold);
    cveSearchGuesser.setCutoff(cutoff);
    // Level 2. search by guessed vendors and products with version
    searchLevels.add(release -> guessForRelease(cveSearchGuesser, release, true));
    // Level 3. search by guessed vendors and products without version
    searchLevels.add(release -> guessForRelease(cveSearchGuesser, release, false));
}
Also used : CveSearchGuesser(org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser)

Aggregations

CveSearchGuesser (org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Logger (org.apache.log4j.Logger)1 CveSearchApi (org.eclipse.sw360.cvesearch.datasource.CveSearchApi)1 Match (org.eclipse.sw360.cvesearch.datasource.matcher.Match)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1