All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.metaeffekt.artifact.enrichment.configurations.CpeDerivationEnrichmentConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2021-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.metaeffekt.artifact.enrichment.configurations;

import com.metaeffekt.mirror.query.NvdCpeApiVendorProductIndexQuery;
import lombok.Getter;
import org.json.JSONArray;
import org.json.JSONObject;
import org.metaeffekt.core.inventory.processor.configuration.ProcessConfiguration;
import org.metaeffekt.core.inventory.processor.configuration.ProcessMisconfiguration;

import java.util.*;
import java.util.stream.Collectors;

public class CpeDerivationEnrichmentConfiguration extends ProcessConfiguration {

    @Getter
    private int maxCorrelatedCpePerArtifact = Integer.MAX_VALUE;

    /**
     * The list of terms limiters to be used for determining the secondary indication terms.
     * If multiple are provided, they will be applied in the order they are provided.
     * 

* Default value is: [{"type":"MinTermsLimiter","minTerms":60}] which uses the {@link NvdCpeApiVendorProductIndexQuery.MinTermsLimiter} with a minimum of 60 terms. *

* Available types can be found next to {@link NvdCpeApiVendorProductIndexQuery.TermsLimiter} and include: *

    *
  • {@link NvdCpeApiVendorProductIndexQuery.MinTermsLimiter}
  • *
  • {@link NvdCpeApiVendorProductIndexQuery.MaxTermsLimiter}
  • *
  • {@link NvdCpeApiVendorProductIndexQuery.TopPTermsLimiter}
  • *
  • {@link NvdCpeApiVendorProductIndexQuery.TopNTermsLimiter}
  • */ private List> requireSecondaryIndicationTermsLimiters = new ArrayList<>(Collections.singletonList(new NvdCpeApiVendorProductIndexQuery.MinTermsLimiter(60).toJson().toMap())); @Getter private boolean addDetailedMatchingInformation = false; public CpeDerivationEnrichmentConfiguration setMaxCorrelatedCpePerArtifact(int maxCorrelatedCpePerArtifact) { this.maxCorrelatedCpePerArtifact = maxCorrelatedCpePerArtifact; return this; } public CpeDerivationEnrichmentConfiguration setRequireSecondaryIndicationTermsLimitersBySerialized(List> requireSecondaryIndicationTermsLimiters) { this.requireSecondaryIndicationTermsLimiters = requireSecondaryIndicationTermsLimiters; return this; } public CpeDerivationEnrichmentConfiguration setRequireSecondaryIndicationTermsLimiters(List limiters) { this.requireSecondaryIndicationTermsLimiters = limiters.stream().map(NvdCpeApiVendorProductIndexQuery.TermsLimiter::toJson).map(JSONObject::toMap).collect(Collectors.toList()); return this; } public List getRequireSecondaryIndicationTermsLimiters() { return NvdCpeApiVendorProductIndexQuery.TermsLimiter.fromJson(new JSONArray(requireSecondaryIndicationTermsLimiters)); } public CpeDerivationEnrichmentConfiguration setAddDetailedMatchingInformation(boolean addDetailedMatchingInformation) { this.addDetailedMatchingInformation = addDetailedMatchingInformation; return this; } @Override public LinkedHashMap getProperties() { final LinkedHashMap properties = new LinkedHashMap<>(); properties.put("maxCorrelatedCpePerArtifact", maxCorrelatedCpePerArtifact); properties.put("requireSecondaryIndicationTermsLimiters", requireSecondaryIndicationTermsLimiters); properties.put("addDetailedMatchingInformation", addDetailedMatchingInformation); return properties; } @Override public void setProperties(LinkedHashMap properties) { super.loadIntegerProperty(properties, "maxCorrelatedCpePerArtifact", this::setMaxCorrelatedCpePerArtifact); if (properties.containsKey("requireSecondaryIndicationTermsLimiters") && properties.get("requireSecondaryIndicationTermsLimiters") instanceof List) { if (((List) properties.get("requireSecondaryIndicationTermsLimiters")).stream().allMatch(o -> o instanceof Map)) { this.requireSecondaryIndicationTermsLimiters = (List>) properties.get("requireSecondaryIndicationTermsLimiters"); } } super.loadBooleanProperty(properties, "addDetailedMatchingInformation", this::setAddDetailedMatchingInformation); } @Override protected void collectMisconfigurations(List misconfigurations) { if (maxCorrelatedCpePerArtifact < -1) { misconfigurations.add(new ProcessMisconfiguration("maxCorrelatedCpePerArtifact", "Must be greater or equal to -1")); } try { NvdCpeApiVendorProductIndexQuery.TermsLimiter.fromJson(new JSONArray(requireSecondaryIndicationTermsLimiters)); } catch (Exception e) { misconfigurations.add(new ProcessMisconfiguration("requireSecondaryIndicationTermsLimiters", "Must be a list of valid terms limiters: " + e.getMessage())); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy