Search in sources :

Example 1 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected Content doPutArchive(final String path, final String filename, final TempBlob archiveContent, final Payload payload) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    String assetPath = path(path, filename);
    Map<String, String> attributes;
    try (InputStream is = archiveContent.get()) {
        attributes = extractDescriptionFromArchive(filename, is);
    }
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    Component component = findComponent(tx, getRepository(), name, version);
    if (component == null) {
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
    }
    tx.saveComponent(component);
    Asset asset = findAsset(tx, bucket, assetPath);
    if (asset == null) {
        asset = tx.createAsset(bucket, component);
        asset.name(assetPath);
        asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
    }
    // TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
    for (Entry<String, String> entry : attributes.entrySet()) {
        asset.formatAttributes().set(entry.getKey(), entry.getValue());
    }
    return saveAsset(tx, asset, archiveContent, payload);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Bucket(org.sonatype.nexus.repository.storage.Bucket) InputStream(java.io.InputStream) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 2 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RFacetUtilsTest method returnFirstComponent.

@Test
public void returnFirstComponent() throws Exception {
    Component component = findComponent(tx, repository, "name", "version");
    assertThat(component, is(notNullValue()));
}
Also used : RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 3 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected void doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException {
    checkNotNull(path);
    checkNotNull(archiveContent);
    checkNotNull(payload);
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    Map<String, String> attributes;
    try (InputStream is = archiveContent.get()) {
        attributes = extractDescriptionFromArchive(path, is);
    }
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    Component component = findComponent(tx, getRepository(), name, version);
    if (component == null) {
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
    }
    tx.saveComponent(component);
    Asset asset = findAsset(tx, bucket, path);
    if (asset == null) {
        asset = tx.createAsset(bucket, component);
        asset.name(path);
        asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
    }
    // TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
    for (Entry<String, String> entry : attributes.entrySet()) {
        asset.formatAttributes().set(entry.getKey(), entry.getValue());
    }
    saveAsset(tx, asset, archiveContent, payload);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Bucket(org.sonatype.nexus.repository.storage.Bucket) InputStream(java.io.InputStream) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 4 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RBrowseNodeGeneratorTest method shouldComputeAssetAndComponentPathWithoutNameDuplication.

@Test
public void shouldComputeAssetAndComponentPathWithoutNameDuplication() {
    final String commonPath = "src/contrib/Archive/ggplot2";
    final String lastSegment = "ggplot2_0.9.0.tar.gz";
    final String assetPath = commonPath + "/" + lastSegment;
    final String componentName = "ggplot2";
    final String componentVersion = "0.9.0";
    // Browse path should not have name duplicates
    final String componentBrowsePath = commonPath + "/" + componentVersion;
    final String assetBrowsePath = componentBrowsePath + "/" + lastSegment;
    Component component = createComponent(componentName, commonPath, componentVersion);
    Asset asset = createAsset(assetPath);
    List<BrowsePaths> pathsAsset = generator.computeAssetPaths(asset, component);
    List<BrowsePaths> pathsComponent = generator.computeComponentPaths(asset, component);
    assertPaths(Arrays.asList(assetBrowsePath.split("/")), pathsAsset);
    assertPaths(Arrays.asList(componentBrowsePath.split("/")), pathsComponent, true);
}
Also used : Asset(org.sonatype.nexus.repository.storage.Asset) BrowsePaths(org.sonatype.nexus.repository.browse.BrowsePaths) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 5 with Component

use of org.sonatype.nexus.repository.storage.Component in project nexus-repository-r by sonatype-nexus-community.

the class RFacetImpl method findOrCreateComponent.

@Override
public Component findOrCreateComponent(final StorageTx tx, final String path, final Map<String, String> attributes) {
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    String group = getBasePath(path);
    Component component = findComponent(tx, getRepository(), name, version, group);
    if (component == null) {
        Bucket bucket = tx.findBucket(getRepository());
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version).group(group);
        tx.saveComponent(component);
    }
    return component;
}
Also used : Bucket(org.sonatype.nexus.repository.storage.Bucket) Component(org.sonatype.nexus.repository.storage.Component) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)

Aggregations

Component (org.sonatype.nexus.repository.storage.Component)19 Test (org.junit.Test)12 Asset (org.sonatype.nexus.repository.storage.Asset)12 InputStream (java.io.InputStream)6 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)6 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)4 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)4 RFacet (org.sonatype.nexus.repository.r.RFacet)3 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)3 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ComponentMaintenance (org.sonatype.nexus.repository.storage.ComponentMaintenance)3 BrowsePaths (org.sonatype.nexus.repository.browse.BrowsePaths)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)1 EntityId (org.sonatype.nexus.common.entity.EntityId)1 TransactionalDeleteBlob (org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)1