Java Code Examples for org.sonatype.nexus.repository.storage.Asset#name()
The following examples show how to use
org.sonatype.nexus.repository.storage.Asset#name() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComposerContentFacetImpl.java From nexus-repository-composer with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreMetadata public Asset getOrCreateAsset(final String path, final String group, final String name, final String version) { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Component component = findComponent(tx, group, name, version); if (component == null) { component = tx.createComponent(bucket, format).group(group).name(name).version(version); tx.saveComponent(component); } Asset asset = findAsset(tx, path); if (asset == null) { asset = tx.createAsset(bucket, component); asset.name(path); } asset.markAsDownloaded(); return asset; }
Example 2
Source File: RebuildBrowseNodesManagerTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Asset createAsset(final String name, final String format, final Bucket bucket) throws Exception { Asset asset = new Asset(); asset.name(name); Method m = MetadataNode.class.getDeclaredMethod("format", String.class); m.setAccessible(true); m.invoke(asset, format); m = MetadataNode.class.getDeclaredMethod("bucketId", EntityId.class); m.setAccessible(true); m.invoke(asset, EntityHelper.id(bucket)); m = MetadataNode.class.getDeclaredMethod("attributes", NestedAttributesMap.class); m.setAccessible(true); m.invoke(asset, new NestedAttributesMap("attributes", new HashMap<>())); return asset; }
Example 3
Source File: MavenFacetImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Asset createMetadataAsset(String name, String cacheToken) { Asset asset = new Asset(); asset.contentType(TEXT_XML); asset.name(name); asset.format(Maven2Format.NAME); asset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); asset.formatAttributes().set(P_ASSET_KIND, REPOSITORY_METADATA.name()); asset.attributes().child(CHECKSUM).set(HashType.SHA1.getExt(), HashAlgorithm.SHA1.function().hashString("foobar", StandardCharsets.UTF_8).toString()); asset.attributes().child(CHECKSUM).set(HashType.MD5.getExt(), HashAlgorithm.MD5.function().hashString("foobar", StandardCharsets.UTF_8).toString()); asset.attributes().child(CONTENT).set(P_LAST_MODIFIED, new Date()); asset.attributes().child(CONTENT).set(P_ETAG, "ETAG"); asset.attributes().child(CACHE).set(LAST_VERIFIED, new Date()); asset.attributes().child(CACHE).set(CACHE_TOKEN, cacheToken); asset.blobRef(new BlobRef("node", "store", "blobid")); return asset; }
Example 4
Source File: GolangDataAccess.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Save an asset and create blob. * * @return blob content */ @TransactionalStoreBlob public Content maybeCreateAndSaveAsset(final Repository repository, final String assetPath, final AssetKind assetKind, final TempBlob tempBlob, final Payload payload) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(repository); Asset asset = findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, repository.getFormat()); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return saveAsset(tx, asset, tempBlob, payload); }
Example 5
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Asset putFile(final StorageTx tx, final MavenPath path, final AssetBlob assetBlob, @Nullable final AttributesMap contentAttributes) throws IOException { final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(path.getPath()); asset.formatAttributes().set(P_ASSET_KIND, fileAssetKindFor(path)); } putAssetPayload(tx, asset, assetBlob, contentAttributes); tx.saveAsset(asset); return asset; }
Example 6
Source File: OrientPyPiProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPutIndex(final String name, final TempBlob tempBlob, final Payload payload, final Map<String, Object> attributes) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, name); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(name); } if (attributes != null) { for (Entry<String, Object> entry : attributes.entrySet()) { asset.formatAttributes().set(entry.getKey(), entry.getValue()); } } return saveAsset(tx, asset, tempBlob, payload); }
Example 7
Source File: HelmFacetImpl.java From nexus-repository-helm with Eclipse Public License 1.0 | 6 votes |
private Asset createAsset( final StorageTx tx, final String assetPath, final HelmAttributes helmAttributes, final AssetKind assetKind) { checkNotNull(assetKind); Bucket bucket = tx.findBucket(getRepository()); Asset asset = CacheControllerHolder.METADATA.equals(assetKind.getCacheType()) ? tx.createAsset(bucket, getRepository().getFormat()) : tx.createAsset(bucket, findOrCreateComponent(tx, bucket, helmAttributes.getName(), helmAttributes.getVersion())); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); helmAttributes.populate(asset.formatAttributes()); asset.name(assetPath); tx.saveAsset(asset); return asset; }
Example 8
Source File: P2ProxyFacetImpl.java From nexus-repository-p2 with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content saveMetadataAsAsset(final String assetPath, final TempBlob metadataContent, final Payload payload, final AssetKind assetKind) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = facet(P2Facet.class).findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return facet(P2Facet.class).saveAsset(tx, asset, metadataContent, payload); }
Example 9
Source File: BrowseNodeEntityAdapterTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private void createEntities(final ODatabaseDocumentTx db) { bucket = new Bucket(); bucket.setRepositoryName(REPOSITORY_NAME); bucket.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); bucketEntityAdapter.addEntity(db, bucket); component = new DefaultComponent(); component.bucketId(EntityHelper.id(bucket)); component.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); component.format(FORMAT_NAME); component.group("org").name("foo").version("1.0"); componentEntityAdapter.addEntity(db, component); asset = new Asset(); asset.bucketId(EntityHelper.id(bucket)); asset.componentId(EntityHelper.id(component)); asset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); asset.format(FORMAT_NAME); asset.name("/org/foo/1.0/foo-1.0.jar"); assetEntityAdapter.addEntity(db, asset); }
Example 10
Source File: PurgeUnusedSnapshotsFacetImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Asset createMetadataAsset(String name, String cacheToken) { Asset asset = new Asset(); asset.contentType(TEXT_XML); asset.name(name); asset.format(Maven2Format.NAME); asset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); asset.formatAttributes().set(P_ASSET_KIND, REPOSITORY_METADATA.name()); asset.attributes().child(CHECKSUM).set(HashType.SHA1.getExt(), HashAlgorithm.SHA1.function().hashString("foobar", StandardCharsets.UTF_8).toString()); asset.attributes().child(CHECKSUM).set(HashType.MD5.getExt(), HashAlgorithm.MD5.function().hashString("foobar", StandardCharsets.UTF_8).toString()); asset.attributes().child(CONTENT).set(P_LAST_MODIFIED, new Date()); asset.attributes().child(CONTENT).set(P_ETAG, "ETAG"); asset.attributes().child(CACHE).set(LAST_VERIFIED, new Date()); asset.attributes().child(CACHE).set(CACHE_TOKEN, cacheToken); asset.blobRef(new BlobRef("node", "store", "blobid")); return asset; }
Example 11
Source File: RFacetImpl.java From nexus-repository-r with Eclipse Public License 1.0 | 5 votes |
@Override public Asset findOrCreateAsset(final StorageTx tx, final String path) { Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(path); asset.formatAttributes().set(P_ASSET_KIND, getAssetKind(path).name()); tx.saveAsset(asset); } return asset; }
Example 12
Source File: ConanHostedFacet.java From nexus-repository-conan with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreBlob protected void doPutArchive(final ConanCoords coord, final String path, final TempBlob tempBlob, final AssetKind assetKind) throws IOException { checkNotNull(path); checkNotNull(tempBlob); StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Map<String, String> attributes = new HashMap<>(); attributes.put(GROUP, coord.getGroup()); attributes.put(PROJECT, coord.getProject()); attributes.put(VERSION, coord.getVersion()); attributes.put(STATE, coord.getChannel()); Component component = findComponent(tx, getRepository(), coord); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()) .group(coord.getGroup()) .name(coord.getProject()) .version(getComponentVersion(coord)); } 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, assetKind); } saveAsset(tx, asset, tempBlob); }
Example 13
Source File: P2FacetImpl.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
@Override public Asset findOrCreateAsset(final StorageTx tx, final String path) { Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(path); asset.formatAttributes().set(P_ASSET_KIND, getAssetKind(path).name()); tx.saveAsset(asset); } return asset; }
Example 14
Source File: OrientPyPiFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Asset putIndex(final String path, final AssetBlob assetBlob) { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(path); saveAsset(tx, asset, assetBlob, AssetKind.INDEX); } return asset; }
Example 15
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreMetadata protected Asset createRootIndexAsset(final Bucket bucket) { StorageTx tx = UnitOfWork.currentTx(); Asset asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(INDEX_PATH_PREFIX); asset.formatAttributes().set(P_ASSET_KIND, ROOT_INDEX.name()); return asset; }
Example 16
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private String buildIndex(final String name, final StorageTx tx) { List<PyPiLink> links = new ArrayList<>(); for (Asset asset : findAssetsByComponentName(tx, getRepository(), name)) { AttributesMap pypiAttributes = asset.attributes().child(PyPiFormat.NAME); String path = asset.name(); String file = path.substring(path.lastIndexOf('/') + 1); String link = String.format("../../%s#md5=%s", path, asset.getChecksum(MD5)); String dataRequiresPython = (String) pypiAttributes.get(PyPiAttributes.P_REQUIRES_PYTHON, ""); links.add(new PyPiLink(file, link, dataRequiresPython)); } return buildIndexPage(templateHelper, name, links); }
Example 17
Source File: ComposerContentFacetImpl.java From nexus-repository-composer with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreMetadata public Asset getOrCreateAsset(final String path) { final StorageTx tx = UnitOfWork.currentTx(); final Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, path); if (asset == null) { asset = tx.createAsset(bucket, format); asset.name(path); } asset.markAsDownloaded(); return asset; }
Example 18
Source File: DefaultIntegrityCheckStrategy.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
/** * Get the name from the {@link Asset} */ protected String getAssetName(final Asset asset) { return asset.name(); }
Example 19
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Asset putArtifact(final StorageTx tx, final MavenPath path, final AssetBlob assetBlob, @Nullable final AttributesMap contentAttributes) throws IOException { final Coordinates coordinates = checkNotNull(path.getCoordinates()); final Bucket bucket = tx.findBucket(getRepository()); Component component = findComponent(tx, getRepository(), path); boolean updatePomModel = false; if (component == null) { // Create and set top-level properties component = tx.createComponent(bucket, getRepository().getFormat()) .group(coordinates.getGroupId()) .name(coordinates.getArtifactId()) .version(coordinates.getVersion()); // Set format specific attributes final NestedAttributesMap componentAttributes = component.formatAttributes(); componentAttributes.set(P_GROUP_ID, coordinates.getGroupId()); componentAttributes.set(P_ARTIFACT_ID, coordinates.getArtifactId()); componentAttributes.set(P_VERSION, coordinates.getVersion()); componentAttributes.set(P_BASE_VERSION, coordinates.getBaseVersion()); if (path.isPom()) { fillInFromModel(path, assetBlob, component.formatAttributes()); } tx.saveComponent(component); } else if (path.isPom()) { // reduce copying by deferring update of pom.xml attributes (which involves reading the blob) // until after putAssetPayload, in case the blob is a duplicate and the model has not changed updatePomModel = true; } Asset asset = findAsset(tx, bucket, path); if (asset == null) { asset = tx.createAsset(bucket, component); asset.name(path.getPath()); final NestedAttributesMap assetAttributes = asset.formatAttributes(); assetAttributes.set(P_GROUP_ID, coordinates.getGroupId()); assetAttributes.set(P_ARTIFACT_ID, coordinates.getArtifactId()); assetAttributes.set(P_VERSION, coordinates.getVersion()); assetAttributes.set(P_BASE_VERSION, coordinates.getBaseVersion()); assetAttributes.set(P_CLASSIFIER, coordinates.getClassifier()); assetAttributes.set(P_EXTENSION, coordinates.getExtension()); assetAttributes.set( P_ASSET_KIND, path.isSubordinate() ? AssetKind.ARTIFACT_SUBORDINATE.name() : AssetKind.ARTIFACT.name() ); } putAssetPayload(tx, asset, assetBlob, contentAttributes); tx.saveAsset(asset); // avoid re-reading pom.xml if it's a duplicate of the old asset if (updatePomModel && !assetBlob.isDuplicate()) { fillInFromModel(path, assetBlob, component.formatAttributes()); tx.saveComponent(component); } return asset; }
Example 20
Source File: BrowseNodeEntityAdapterTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void browseNestedAssets() throws Exception { List<String> path = Splitter.on('/').omitEmptyStrings().splitToList(asset.name()); try (ODatabaseDocumentTx db = database.getInstance().acquire()) { Asset parentAsset = new Asset(); parentAsset.bucketId(EntityHelper.id(bucket)); parentAsset.componentId(EntityHelper.id(component)); parentAsset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>())); parentAsset.format(FORMAT_NAME); parentAsset.name("/org/foo"); assetEntityAdapter.addEntity(db, parentAsset); underTest.createAssetNode(db, REPOSITORY_NAME, FORMAT_NAME, toBrowsePaths(path.subList(0, 2)), parentAsset); underTest.createAssetNode(db, REPOSITORY_NAME, FORMAT_NAME, toBrowsePaths(path), asset); assertThat(underTest.getByPath(db, REPOSITORY_NAME, path.subList(0, 0), 1, "", emptyMap()), contains( allOf( hasProperty("repositoryName", is(REPOSITORY_NAME)), hasProperty("parentPath", is("/")), hasProperty("name", is("org")), hasProperty("leaf", is(false)), hasProperty("componentId", nullValue()), hasProperty("assetId", nullValue()), hasProperty("path", is("org/"))) )); assertThat(underTest.getByPath(db, REPOSITORY_NAME, path.subList(0, 1), 1, "", emptyMap()), contains( allOf( hasProperty("repositoryName", is(REPOSITORY_NAME)), hasProperty("parentPath", is("/org/")), hasProperty("name", is("foo")), hasProperty("leaf", is(false)), hasProperty("componentId", nullValue()), hasProperty("assetId", is(EntityHelper.id(parentAsset))), hasProperty("path", is("org/foo/"))) )); assertThat(underTest.getByPath(db, REPOSITORY_NAME, path.subList(0, 2), 1, "", emptyMap()), contains( allOf( hasProperty("repositoryName", is(REPOSITORY_NAME)), hasProperty("parentPath", is("/org/foo/")), hasProperty("name", is("1.0")), hasProperty("leaf", is(false)), hasProperty("componentId", nullValue()), hasProperty("assetId", nullValue()), hasProperty("path", is("org/foo/1.0/"))) )); assertThat(underTest.getByPath(db, REPOSITORY_NAME, path.subList(0, 3), 1, "", emptyMap()), contains( allOf( hasProperty("repositoryName", is(REPOSITORY_NAME)), hasProperty("parentPath", is("/org/foo/1.0/")), hasProperty("name", is("foo-1.0.jar")), hasProperty("leaf", is(true)), hasProperty("componentId", nullValue()), hasProperty("assetId", is(EntityHelper.id(asset))), hasProperty("path", is("org/foo/1.0/foo-1.0.jar"))) )); assertThat(underTest.getByPath(db, REPOSITORY_NAME, path, 1, "", emptyMap()), is(empty())); } }