Search in sources :

Example 1 with Continuation

use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.

the class AptHostedFacet method buildPackageIndexes.

private CompressingTempFileStore buildPackageIndexes(final List<AssetChange> changes) throws IOException {
    CompressingTempFileStore result = new CompressingTempFileStore();
    Map<String, Writer> streams = new HashMap<>();
    boolean ok = false;
    try {
        Set<String> architectures = changes.stream().map(change -> getArchitecture(change.getAsset())).collect(Collectors.toSet());
        final Continuation<FluentAsset> allAssets = getRepository().facet(ContentFacet.class).assets().byKind(DEB).browse(Integer.MAX_VALUE, null);
        allAssets.stream().map(this::getArchitecture).collect(Collectors.toCollection(() -> architectures));
        Map<String, List<FluentAsset>> assetsPerArch = new HashMap<>();
        for (String architecture : architectures) {
            List<FluentAsset> assets = allAssets.stream().filter(asset -> getArchitecture(asset).equals(architecture)).collect(Collectors.toList());
            assetsPerArch.put(architecture, assets);
        }
        for (List<FluentAsset> assets : assetsPerArch.values()) {
            Optional<AssetChange> removeAssetChange = changes.stream().filter(change -> change.getAsset().kind().equals(DEB)).filter(change -> change.getAction() == AssetAction.REMOVED).findAny();
            if (assets.isEmpty() && removeAssetChange.isPresent()) {
                createEmptyMetadataFile(result, streams, removeAssetChange.get());
            } else {
                createMetadataFileWithData(changes, result, streams, assets);
            }
        }
        ok = true;
    } finally {
        for (Writer writer : streams.values()) {
            IOUtils.closeQuietly(writer);
        }
        if (!ok) {
            result.close();
        }
    }
    return result;
}
Also used : GZ(org.sonatype.nexus.repository.apt.internal.AptProperties.GZ) Arrays(java.util.Arrays) ControlFile(org.sonatype.nexus.repository.apt.internal.debian.ControlFile) Date(java.util.Date) FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) StringUtils(org.apache.commons.lang3.StringUtils) AptContentFacet(org.sonatype.nexus.repository.apt.datastore.AptContentFacet) RELEASE(org.sonatype.nexus.repository.apt.internal.ReleaseName.RELEASE) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) Map(java.util.Map) FormatAttributesUtils(org.sonatype.nexus.repository.content.utils.FormatAttributesUtils) AssetAction(org.sonatype.nexus.repository.apt.internal.hosted.AssetAction) TimeZone(java.util.TimeZone) Collection(java.util.Collection) FacetSupport(org.sonatype.nexus.repository.FacetSupport) Set(java.util.Set) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Writer(java.io.Writer) Optional(java.util.Optional) P_INDEX_SECTION(org.sonatype.nexus.repository.apt.internal.AptProperties.P_INDEX_SECTION) INRELEASE(org.sonatype.nexus.repository.apt.internal.ReleaseName.INRELEASE) Continuation(org.sonatype.nexus.common.entity.Continuation) Paragraph(org.sonatype.nexus.repository.apt.internal.debian.ControlFile.Paragraph) MD5(org.sonatype.nexus.common.hash.HashAlgorithm.MD5) RELEASE_GPG(org.sonatype.nexus.repository.apt.internal.ReleaseName.RELEASE_GPG) HashMap(java.util.HashMap) CompressingTempFileStore(org.sonatype.nexus.repository.apt.internal.hosted.CompressingTempFileStore) BZ2(org.sonatype.nexus.repository.apt.internal.AptProperties.BZ2) Payload(org.sonatype.nexus.repository.view.Payload) DEB(org.sonatype.nexus.repository.apt.internal.AptProperties.DEB) Named(javax.inject.Named) PackageInfo(org.sonatype.nexus.repository.apt.internal.debian.PackageInfo) PATTERN_RFC1123(org.apache.http.protocol.HttpDateGenerator.PATTERN_RFC1123) Charsets(com.google.common.base.Charsets) ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) Facet(org.sonatype.nexus.repository.Facet) AptSigningFacet(org.sonatype.nexus.repository.apt.internal.gpg.AptSigningFacet) SHA256(org.sonatype.nexus.common.hash.HashAlgorithm.SHA256) P_ARCHITECTURE(org.sonatype.nexus.repository.apt.internal.AptProperties.P_ARCHITECTURE) AptMimeTypes(org.sonatype.nexus.repository.apt.internal.AptMimeTypes) AssetBlob(org.sonatype.nexus.repository.content.AssetBlob) HashAlgorithm(org.sonatype.nexus.common.hash.HashAlgorithm) Collections(java.util.Collections) DateFormatUtils(org.apache.commons.lang3.time.DateFormatUtils) HashMap(java.util.HashMap) AptContentFacet(org.sonatype.nexus.repository.apt.datastore.AptContentFacet) ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) CompressingTempFileStore(org.sonatype.nexus.repository.apt.internal.hosted.CompressingTempFileStore) List(java.util.List) Writer(java.io.Writer) FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset)

Example 2 with Continuation

use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.

the class DatastoreMetadataRebuilderTest method infiniteContinuation.

private Continuation infiniteContinuation(Object returnItem) {
    Continuation continuation = mock(Continuation.class);
    Iterator iterator = mock(Iterator.class);
    Spliterator spliterator = mock(Spliterator.class);
    when(continuation.spliterator()).thenReturn(spliterator);
    when(continuation.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(true);
    when(iterator.next()).thenReturn(returnItem);
    return continuation;
}
Also used : Continuation(org.sonatype.nexus.common.entity.Continuation) Iterator(java.util.Iterator) Spliterator(java.util.Spliterator)

Example 3 with Continuation

use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.

the class AssetDAOTest method testReadPathTest.

@Test
public void testReadPathTest() {
    TestAssetData asset1 = randomAsset(repositoryId);
    TestAssetData asset2 = randomAsset(repositoryId);
    // make sure paths are different
    asset2.setPath(asset1.path() + "/2");
    try (DataSession<?> session = sessionRule.openSession(DEFAULT_DATASTORE_NAME)) {
        TestAssetDAO dao = session.access(TestAssetDAO.class);
        // our bespoke schema will be applied automatically via 'extendSchema'...
        dao.createAsset(asset1);
        dao.createAsset(asset2);
        asset2.setTestFlag(true);
        dao.updateAssetFlag(asset2);
        TestAssetData test1 = dao.readPathTest(repositoryId, asset1.path()).orElse(null);
        TestAssetData test2 = dao.readPathTest(repositoryId, asset2.path()).orElse(null);
        assertThat(test1, notNullValue());
        assertThat(test1.getTestFlag(), equalTo(false));
        assertThat(test2, notNullValue());
        assertThat(test2.getTestFlag(), equalTo(true));
        Continuation<Asset> continuation = dao.browseFlaggedAssets(repositoryId, 10, null);
        assertThat(continuation.size(), equalTo(1));
        TestAssetData test3 = continuation.stream().filter(obj -> obj instanceof TestAssetData).map(obj -> (TestAssetData) obj).findFirst().orElseThrow(() -> new IllegalStateException("Expect asset not found"));
        assertThat(test3.getTestFlag(), equalTo(true));
    }
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) IsIterableContainingInOrder(org.hamcrest.collection.IsIterableContainingInOrder) AssetInfo(org.sonatype.nexus.repository.content.AssetInfo) EntityId(org.sonatype.nexus.common.entity.EntityId) TestContentRepositoryDAO(org.sonatype.nexus.repository.content.store.example.TestContentRepositoryDAO) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DEFAULT_DATASTORE_NAME(org.sonatype.nexus.datastore.api.DataStoreManager.DEFAULT_DATASTORE_NAME) Before(org.junit.Before) ImmutableSet.of(com.google.common.collect.ImmutableSet.of) UTC(org.sonatype.nexus.common.time.UTC) DataSession(org.sonatype.nexus.datastore.api.DataSession) Collections.emptyMap(java.util.Collections.emptyMap) TestComponentDAO(org.sonatype.nexus.repository.content.store.example.TestComponentDAO) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Matchers.allOf(org.hamcrest.Matchers.allOf) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Asset(org.sonatype.nexus.repository.content.Asset) TestAssetBlobDAO(org.sonatype.nexus.repository.content.store.example.TestAssetBlobDAO) List(java.util.List) TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) ComponentDAOTest.browseComponents(org.sonatype.nexus.repository.content.store.ComponentDAOTest.browseComponents) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) AssetBlob(org.sonatype.nexus.repository.content.AssetBlob) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) DuplicateKeyException(org.sonatype.nexus.datastore.api.DuplicateKeyException) Matchers.is(org.hamcrest.Matchers.is) ComponentDAOTest.countComponents(org.sonatype.nexus.repository.content.store.ComponentDAOTest.countComponents) Collections(java.util.Collections) Continuation(org.sonatype.nexus.common.entity.Continuation) Arrays.stream(java.util.Arrays.stream) IsIterableContainingInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder) Collectors.summingInt(java.util.stream.Collectors.summingInt) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Asset(org.sonatype.nexus.repository.content.Asset) Test(org.junit.Test)

Aggregations

Continuation (org.sonatype.nexus.common.entity.Continuation)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Charsets (com.google.common.base.Charsets)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet.of (com.google.common.collect.ImmutableSet.of)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneOffset (java.time.ZoneOffset)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.emptyMap (java.util.Collections.emptyMap)1