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);
}
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()));
}
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);
}
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);
}
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;
}
Aggregations