io.bdeploy.bhive.op.ManifestRefLoadOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
package io.bdeploy.bhive.op;
import static io.bdeploy.common.util.RuntimeAssert.assertFalse;
import java.io.InputStream;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import io.bdeploy.bhive.BHive;
import io.bdeploy.bhive.ReadOnlyOperation;
import io.bdeploy.bhive.audit.AuditParameterExtractor.AuditStrategy;
import io.bdeploy.bhive.audit.AuditParameterExtractor.AuditWith;
import io.bdeploy.bhive.model.Manifest;
import io.bdeploy.bhive.model.Manifest.Key;
import io.bdeploy.bhive.model.ObjectId;
import io.bdeploy.bhive.model.Tree;
import io.bdeploy.bhive.util.StorageHelper;
/**
* Resolve {@link Manifest}s referenced in a {@link Tree} by the given
* {@link ObjectId}s.
*/
@ReadOnlyOperation
public class ManifestRefLoadOperation extends BHive.Operation> {
@AuditWith(AuditStrategy.COLLECTION_PEEK)
private final SortedSet ids = new TreeSet<>();
@Override
public SortedMap call() throws Exception {
assertFalse(ids.isEmpty(), "Nothing to load");
SortedMap refs = new TreeMap<>();
for (ObjectId id : ids) {
try (InputStream is = getObjectManager().db(x -> x.getStream(id))) {
refs.put(id, StorageHelper.fromStream(is, Manifest.Key.class));
}
}
return refs;
}
public ManifestRefLoadOperation addManifestRef(ObjectId manifest) {
ids.add(manifest);
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy