This commit is contained in:
@@ -30,6 +30,24 @@ public class Composite implements Asset {
|
||||
addAsset(asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the composite asset as a specific type.
|
||||
* @param assetType The type of asset to return, e.g., CpuAsset.class.
|
||||
* @return The asset cast to the specified type.
|
||||
* @param <T> The type of asset to return, must extend Asset.
|
||||
*/
|
||||
public <T extends Asset> T getAsset(Class<T> assetType) {
|
||||
if (assetType.equals(Composite.class)) {
|
||||
return assetType.cast(this);
|
||||
}
|
||||
for (Asset asset : assets) {
|
||||
if (assetType.isInstance(asset)) {
|
||||
return assetType.cast(asset);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No asset of type " + assetType.getSimpleName() + " found in composite.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an asset to the composite.
|
||||
*
|
||||
|
||||
@@ -213,6 +213,7 @@ public class AssetService {
|
||||
var genericAsset = new GenericAsset();
|
||||
genericAsset.setType("composite");
|
||||
fillIn(genericAsset, genericDescriptor, formData);
|
||||
genericAsset = genericRepository.saveAndFlush(genericAsset);
|
||||
|
||||
for (var assetType : type) {
|
||||
var assetDescriptor = getAssetDescriptor(assetType);
|
||||
@@ -222,7 +223,7 @@ public class AssetService {
|
||||
getRepositoryFor(assetType).saveAndFlushAsset(asset);
|
||||
}
|
||||
|
||||
return genericRepository.saveAndFlush(genericAsset);
|
||||
return genericAsset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user