Skip to content

Commit

Permalink
feature: merging AE-800; supporting assets in reports
Browse files Browse the repository at this point in the history
  • Loading branch information
karsten-klein committed Nov 10, 2024
1 parent 4021907 commit 9c7a87c
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,38 @@ protected static void removeAttributes(Inventory inventory, Collection<String> k
}
}

/**
* Maps all assets which contain the artifact.
*
* @param inventory the inventory
* @param artifacts artifacts for which to get all assets
*
* @return a map containing the artifact and a set of assets.
*/
public static Set<AssetMetaData> getAssetsForArtifacts(Inventory inventory, Set<Artifact> artifacts) {
Set<AssetMetaData> setOfAssets = new HashSet<>();
for (AssetMetaData assetMetaData : inventory.getAssetMetaData()) {
String assetId = assetMetaData.get(AssetMetaData.Attribute.ASSET_ID);
for (Artifact artifact : artifacts) {
if (StringUtils.isNotBlank(artifact.get(assetId)) && artifact.get(assetId).equals(Constants.MARKER_CONTAINS)) {
setOfAssets.add(assetMetaData);
}
}
}
return setOfAssets;
}

public static Set<Artifact> getArtifactsForAsset(Inventory inventory, AssetMetaData assetMetaData) {
Set<Artifact> setOfArtifacts = new HashSet<>();
String assetId = assetMetaData.get(Constants.KEY_ASSET_ID);
for (Artifact artifact : inventory.getArtifacts()) {
if (StringUtils.isNotBlank(artifact.get(assetId))) {
if (artifact.get(assetId).equals(Constants.MARKER_CONTAINS)) {
setOfArtifacts.add(artifact);
}
}
}
return setOfArtifacts;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class Constants {
public static final String KEY_ARCHIVE = "Archive";
public static final String KEY_STRUCTURED = "Structured";
public static final String KEY_EXECUTABLE = "Executable";
public static final String KEY_PRIMARY = "Primary";

/**
* Organization key. We stick to the terminology of maven; in other context this is the vendor (CVE) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public Inventory mergeInventories() throws IOException {
final Inventory outputInventory = new Inventory();

final Map<Inventory, File> collectedInventories = new LinkedHashMap<>();
inputInventories.forEach(i -> collectedInventories.put(i, null));

if (inputInventories != null && !inputInventories.isEmpty()) {
inputInventories.forEach(i -> collectedInventories.put(i, null));
}

final List<File> inventoryFiles = collectInventoryFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.metaeffekt.core.inventory.InventoryUtils;
import org.metaeffekt.core.inventory.processor.model.Artifact;
import org.metaeffekt.core.inventory.processor.model.AssetMetaData;
import org.metaeffekt.core.inventory.processor.model.Constants;
import org.metaeffekt.core.inventory.processor.model.Inventory;
Expand All @@ -41,6 +43,10 @@ public List<AssetMetaData> listAssets() {
return assetMetaData;
}

public List<Artifact> getRelatedArtifacts(AssetMetaData assetMetaData) {
return new ArrayList<>(InventoryUtils.getArtifactsForAsset(inventory, assetMetaData));
}

final Pair<String, String>[] containerKeyList = new Pair[]{
Pair.of("Type", "Type"),
Pair.of("Name", "Name"),
Expand Down
Loading

0 comments on commit 9c7a87c

Please sign in to comment.