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

io.bdeploy.bhive.op.ManifestRefLoadOperation Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
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;
import io.bdeploy.common.ActivityReporter.Activity;

/**
 * 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");

        try (Activity activity = getActivityReporter().start("Loading Relations", -1)) {
            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