use of org.sonatype.nexus.repository.storage.Bucket 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;
}
use of org.sonatype.nexus.repository.storage.Bucket in project nexus-repository-r by sonatype-nexus-community.
the class RepositoryFacetTestSupport method initialiseFacetMocksAndSetupTransaction.
@Before
public void initialiseFacetMocksAndSetupTransaction() throws Exception {
assets = new ArrayList<>();
UnitOfWork.beginBatch(storageTx);
when(storageTx.browseAssets(any(Bucket.class))).thenReturn(assets);
when(storageTx.browseAssets(any(), any(Bucket.class))).thenReturn(assets);
when(storageTx.findAssetWithProperty(anyString(), anyString(), any(Bucket.class))).thenReturn(asset);
when(storageTx.findBucket(repository)).thenReturn(bucket);
when(storageTx.requireBlob(any())).thenReturn(blob);
when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
when(asset.formatAttributes()).thenReturn(formatAttributes);
when(asset.attributes()).thenReturn(attributes);
when(attributes.get("last_modified", Date.class)).thenReturn(new Date());
when(attributes.get("last_verified", Date.class)).thenReturn(new Date());
when(attributes.get("cache_token", String.class)).thenReturn("test");
when(attributes.child("content")).thenReturn(attributes);
when(attributes.child("cache")).thenReturn(attributes);
underTest = initialiseSystemUnderTest();
underTest.attach(repository);
}
use of org.sonatype.nexus.repository.storage.Bucket in project nexus-repository-r by sonatype-nexus-community.
the class RFacetImpl method findOrCreateAsset.
@Override
public Asset findOrCreateAsset(final StorageTx tx, final Component component, final String path, final Map<String, String> attributes) {
Bucket bucket = tx.findBucket(getRepository());
Asset asset = findAsset(tx, bucket, path);
if (asset == null) {
asset = tx.createAsset(bucket, component);
asset.name(path);
// 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> attribute : attributes.entrySet()) {
asset.formatAttributes().set(attribute.getKey(), attribute.getValue());
}
asset.formatAttributes().set(P_ASSET_KIND, getAssetKind(path).name());
tx.saveAsset(asset);
}
return asset;
}
Aggregations