Java Code Examples for org.sonatype.nexus.common.collect.NestedAttributesMap#child()
The following examples show how to use
org.sonatype.nexus.common.collect.NestedAttributesMap#child() .
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: NpmPublishParser.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private void updateMaintainer(final NestedAttributesMap packageRoot, final String currentUserId) { String distVersion = getDistTagVersion(packageRoot); if (distVersion != null && packageRoot.contains(VERSIONS_KEY)) { NestedAttributesMap versionsMap = packageRoot.child(VERSIONS_KEY); if (versionsMap.contains(distVersion)) { NestedAttributesMap versionToUpdate = versionsMap.child(distVersion); String npmUser = getNpmUser(versionToUpdate); if (isUserTokenBasedPublish(currentUserId, npmUser)) { updateNpmUser(packageRoot, currentUserId); updateMaintainerList(packageRoot, currentUserId); updateNpmUser(versionToUpdate, currentUserId); updateMaintainerList(versionToUpdate, currentUserId); } } } else { log.warn("Version(s) attribute not found in package root"); } }
Example 2
Source File: NestedAttributesMapJsonParser.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Attempt to retrieve the {@link NestedAttributesMap} that is associated with * the current path, if parts of the path are not existing they will * be manually created by the {@link NestedAttributesMap#child(String)} for that path part. * * @return NestedAttributesMap or null if we are mapping inside an array or no child was found. */ @Nullable public NestedAttributesMap getChildFromRoot() { // if we are inside an array we don't have a map value to return if (isMappingInsideArray()) { return null; } // we start with the root as initial existing child to go down it's path NestedAttributesMap existingChild = root; // remove the first "/" and then split on any leftover for (String part : currentPathInParts()) { Object o = existingChild.get(part); // only create and/or retrieve other child json objects, if (isNull(o) || o instanceof Map) { existingChild = existingChild.child(part); } } return existingChild.equals(root) ? null : existingChild; }
Example 3
Source File: NpmMetadataUtilsTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void shrinkSimple() { NestedAttributesMap packageRoot = new NestedAttributesMap("metadata", new HashMap<String, Object>()); packageRoot.child("dist-tags").set("alpha", "1.0.0"); packageRoot.child("dist-tags").set("gamma", "1.0.2"); packageRoot.child("dist-tags").set("latest", "1.0.3"); NestedAttributesMap versions = packageRoot.child("versions"); versions.child("1.0.0").set("version", "1.0.0"); versions.child("1.0.1").set("version", "1.0.1"); versions.child("1.0.2").set("version", "1.0.2"); versions.child("1.0.3").set("version", "1.0.3"); NpmMetadataUtils.shrink(packageRoot); // dist tags untouched assertThat(packageRoot.child("dist-tags").backing().entrySet(), hasSize(3)); // versions shrinked assertThat(versions.get("1.0.0").toString(), equalTo("alpha")); assertThat(versions.get("1.0.1").toString(), equalTo("1.0.1")); assertThat(versions.get("1.0.2").toString(), equalTo("gamma")); assertThat(versions.get("1.0.3").toString(), equalTo("latest")); }
Example 4
Source File: NpmPackageRootMetadataUtils.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private static void copy(final NestedAttributesMap map, final NestedAttributesMap src, final String field) { Object object = src.get(field); if (object instanceof Map) { NestedAttributesMap destChild = map.child(field); NestedAttributesMap srcChild = src.child(field); for (String key : srcChild.keys()) { if (srcChild.get(field) instanceof Map) { copy(destChild, srcChild, key); } else { destChild.set(key, srcChild.get(key)); } } } else if (object != null) { map.set(field, object); } }
Example 5
Source File: OrientNpmProxyFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalTouchMetadata protected Content getDistTags(final NpmPackageId packageId) { checkNotNull(packageId); StorageTx tx = UnitOfWork.currentTx(); Asset packageRootAsset = NpmFacetUtils.findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId); if (packageRootAsset != null) { try { final NestedAttributesMap attributesMap = NpmFacetUtils.loadPackageRoot(tx, packageRootAsset); final NestedAttributesMap distTags = attributesMap.child(DIST_TAGS); return NpmFacetUtils.distTagsToContent(distTags); } catch (IOException e) { log.error("Unable to read packageRoot {}", packageId.id(), e); } } return null; }
Example 6
Source File: OrientNpmHostedFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected void putPublishRequest(final NpmPackageId packageId, @Nullable final String revision, final NpmPublishRequest request) throws IOException { log.debug("Storing package: {}", packageId); StorageTx tx = UnitOfWork.currentTx(); NestedAttributesMap packageRoot = request.getPackageRoot(); // process attachments, if any NestedAttributesMap attachments = packageRoot.child("_attachments"); if (!attachments.isEmpty()) { for (String name : attachments.keys()) { NestedAttributesMap attachment = attachments.child(name); NestedAttributesMap packageVersion = selectVersionByTarballName(packageRoot, name); putTarball(tx, packageId, packageVersion, attachment, request); } } putPackageRoot(packageId, revision, packageRoot); }
Example 7
Source File: OrientNpmHostedFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Nullable @Override @TransactionalTouchBlob public Content getDistTags(final NpmPackageId packageId) { checkNotNull(packageId); log.debug("Getting package: {}", packageId); StorageTx tx = UnitOfWork.currentTx(); Asset packageRootAsset = findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId); if (packageRootAsset == null) { return null; } try { final NestedAttributesMap packageRoot = NpmFacetUtils.loadPackageRoot(tx, packageRootAsset); final NestedAttributesMap distTags = packageRoot.child(DIST_TAGS); return NpmFacetUtils.distTagsToContent(distTags); } catch (IOException e) { log.info("Unable to obtain dist-tags for {}", packageId.id(), e); } return null; }
Example 8
Source File: NpmMetadataUtils.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Rewrites dist/tarball entry URLs to point back to this Nexus instance and given repository. */ public static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot) { if (BaseUrlHolder.isSet()) { NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { if (versions.get(v) instanceof Map) { // only if not incomplete NestedAttributesMap version = versions.child(v); NestedAttributesMap dist = version.child(DIST); String tarballName = extractTarballName(dist.get(TARBALL, String.class)); dist.set( TARBALL, String.format( "%s/repository/%s/%s/-/%s", BaseUrlHolder.get(), repositoryName, version.get(NAME), tarballName ) ); } } } }
Example 9
Source File: NpmMetadataUtils.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Selects and returns version metadata object based on tarball name. */ @Nullable public static NestedAttributesMap selectVersionByTarballName( final NestedAttributesMap packageRoot, final String tarballName) { String extractedTarballName = extractTarballName(tarballName); NestedAttributesMap versions = packageRoot.child(VERSIONS); for (String v : versions.keys()) { NestedAttributesMap version = versions.child(v); String versionTarballUrl = version.child(DIST).get(TARBALL, String.class); if (extractedTarballName.equals(extractTarballName(versionTarballUrl))) { return version; } } return null; }
Example 10
Source File: NpmPublishParserTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void assertMaintainers(final NpmPublishRequest request, final String name) { NestedAttributesMap packageRoot = request.getPackageRoot(); NestedAttributesMap versions = packageRoot.child("versions"); assertMaintainer(name, packageRoot); assertMaintainer(name, versions.child("1.0")); }
Example 11
Source File: NpmClientITSupport.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
protected void verifyMerged(final String repository, final String name, final String...versions) { NpmClient npmClient = getNpmClient(repository); NestedAttributesMap fetchedPackageRoot = npmClient.fetch(name); NestedAttributesMap versionsMap = fetchedPackageRoot.child("versions"); assertThat(versionsMap.backing().keySet(), equalTo(ImmutableSet.copyOf(versions))); }
Example 12
Source File: NpmMetadataUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Resolves version to a corresponding tag in "dist-tags" section, if any, or the version itself if no tag assigned. */ private static String resolveVersionToTag(final NestedAttributesMap packageRoot, final String version) { final NestedAttributesMap distTags = packageRoot.child(DIST_TAGS); if (!distTags.isEmpty()) { for (Entry<String, Object> distTag : distTags) { if (version.equals(distTag.getValue())) { return distTag.getKey(); } } } return version; }
Example 13
Source File: NpmMetadataUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Shrinks the package root JSON object as required for npm search operations (basically shaves off version entry * values replacing them with tags. Package roots transformed like this must NOT be persisted back into storage * of Nexus, they are meant only by npm CLI downstream consumption. */ @Nonnull public static NestedAttributesMap shrink(final NestedAttributesMap packageRoot) { final NestedAttributesMap versions = packageRoot.child(VERSIONS); for (Entry<String, Object> version : versions) { version.setValue(resolveVersionToTag(packageRoot, version.getKey())); } return packageRoot; }
Example 14
Source File: NpmFacetUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Deletes the {@param tag} from the packageRoot */ public static void deleteDistTags(final StorageTx tx, final Asset packageRootAsset, final String tag) throws IOException { NestedAttributesMap packageRoot = NpmFacetUtils.loadPackageRoot(tx, packageRootAsset); if (packageRoot.contains(DIST_TAGS)) { NestedAttributesMap distTags = packageRoot.child(DIST_TAGS); distTags.remove(tag); NpmFacetUtils.savePackageRoot(tx, packageRootAsset, packageRoot); } }
Example 15
Source File: NpmFacetUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Updates the packageRoot with this set of dist-tags */ public static void updateDistTags(final StorageTx tx, final Asset packageRootAsset, final String tag, final Object version) throws IOException { NestedAttributesMap packageRoot = loadPackageRoot(tx, packageRootAsset); NestedAttributesMap distTags = packageRoot.child(DIST_TAGS); distTags.set(tag, version); savePackageRoot(tx, packageRootAsset, packageRoot); }
Example 16
Source File: ProxyRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void convertAuthentication( final HttpClientAttributes httpClient, final NestedAttributesMap httpClientConfiguration) { HttpClientConnectionAuthenticationAttributes authentication = httpClient.getAuthentication(); if (nonNull(authentication)) { NestedAttributesMap authenticationConfiguration = httpClientConfiguration.child("authentication"); authenticationConfiguration.set("type", authentication.getType()); authenticationConfiguration.set("username", authentication.getUsername()); authenticationConfiguration.set("password", authentication.getPassword()); authenticationConfiguration.set("ntlmHost", authentication.getNtlmHost()); authenticationConfiguration.set("ntlmDomain", authentication.getNtlmDomain()); } }
Example 17
Source File: NpmMergeObjectMapperTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private void verifyMergingMultipleContentsWithMultiDepthJsonResult(final NestedAttributesMap result) { assertThat(result.size(), equalTo(11)); // checks it has all the merged tags + the dist_tags assertThat(result.get("name"), equalTo("third")); List maintainers = (List) result.get("maintainers"); assertThat(((Map) maintainers.get(0)).get("email"), equalTo("[email protected]")); assertThat(((Map) maintainers.get(0)).get("name"), equalTo("third")); List keywords = (List) result.get("keywords"); assertThat(keywords.get(0), equalTo("array")); assertThat(keywords.get(1), equalTo("third")); assertThat(result.get("readme"), is(nullValue())); assertThat(result.get("multi-null-field"), equalTo("not so null in third")); NestedAttributesMap mulitDepth = result.child("multi-depth"); NestedAttributesMap first = mulitDepth.child("first"); NestedAttributesMap second = first.child("second"); NestedAttributesMap third = second.child("third"); assertThat(first.get("title"), equalTo("This is the first depth")); assertThat(second.get("title"), equalTo("This is the second depth")); assertThat(third.get("title"), equalTo("This is the third depth")); NestedAttributesMap reverseMulitDepth = result.child("reverse-multi-depth"); first = reverseMulitDepth.child("first"); second = first.child("second"); third = second.child("third"); assertThat(first.get("title"), equalTo("This is the first depth")); assertThat(second.get("title"), equalTo("This is the second depth")); assertThat(third.get("title"), equalTo("This is the third depth")); NestedAttributesMap mulitDepthMerge = result.child("multi-depth-merge"); first = mulitDepthMerge.child("first"); assertThat(first.get("title"), equalTo("This is the first depth")); assertThat(first.get("description"), equalTo("We have here the first depth from the second response")); assertThat(first.get("summary"), equalTo("We have here the first depth from the third response")); NestedAttributesMap dependencies = result.child("dependencies"); assertThat(dependencies.get("equire(\"orchestrator\""), equalTo("*")); assertThat(dependencies.get("@types/node"), equalTo("*")); assertThat(dependencies.get("@types/orchestrator"), equalTo("*")); NestedAttributesMap funckyFieldName = dependencies.child("funcky(\"fieldname\""); assertThat(funckyFieldName.get("test"), equalTo("value")); verifyWhatGoesInMustComeOut(result); }
Example 18
Source File: MergeObjectMapperTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private void verifyReadFirstJson(final NestedAttributesMap result) { assertThat(result.size(), equalTo(9)); assertThat(result.get("name"), equalTo("first")); List maintainers = (List) result.get("maintainers"); assertThat(((Map) maintainers.get(0)).get("email"), equalTo("[email protected]")); assertThat(((Map) maintainers.get(0)).get("name"), equalTo("first")); assertThat(((Map) maintainers.get(1)).get("email"), equalTo("[email protected]")); assertThat(((Map) maintainers.get(1)).get("name"), equalTo("first2")); List keywords = (List) result.get("keywords"); assertThat(keywords.get(0), equalTo("array")); assertThat(keywords.get(1), equalTo("first")); assertThat(result.get("readme"), is(nullValue())); assertThat(result.get("multi-null-field"), is(nullValue())); NestedAttributesMap mulitDepth = result.child("multi-depth"); NestedAttributesMap first = mulitDepth.child("first"); assertThat(first.get("title"), equalTo("This is the first depth")); NestedAttributesMap reverseMulitDepth = result.child("reverse-multi-depth"); first = reverseMulitDepth.child("first"); NestedAttributesMap second = first.child("second"); NestedAttributesMap third = second.child("third"); assertThat(first.get("title"), equalTo("This is the first depth")); assertThat(second.get("title"), equalTo("This is the second depth")); assertThat(third.get("title"), equalTo("This is the third depth")); NestedAttributesMap mulitDepthMerge = result.child("multi-depth-merge"); first = mulitDepthMerge.child("first"); assertThat(first.get("title"), equalTo("This is the first depth")); NestedAttributesMap dependencies = result.child("dependencies"); assertThat(dependencies.get("equire(\"orchestrator\""), equalTo("*")); assertThat(dependencies.get("@types/node"), equalTo("*")); assertThat(dependencies.get("@types/orchestrator"), equalTo("*")); NestedAttributesMap funckyFieldName = dependencies.child("funcky(\"fieldname\""); NestedAttributesMap godeep = funckyFieldName.child("godeep"); first = godeep.child("first"); assertThat(first.get("title"), equalTo("This is the first depth")); }
Example 19
Source File: MergeObjectMapperTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private void verifyMergingMultipleContentsWithMultiDepthJsonResult(final NestedAttributesMap result) { assertThat(result.size(), equalTo(9)); assertThat(result.get("name"), equalTo("third")); List maintainers = (List) result.get("maintainers"); assertThat(((Map) maintainers.get(0)).get("email"), equalTo("[email protected]")); assertThat(((Map) maintainers.get(0)).get("name"), equalTo("third")); List keywords = (List) result.get("keywords"); assertThat(keywords.get(0), equalTo("array")); assertThat(keywords.get(1), equalTo("third")); assertThat(result.get("readme"), is(nullValue())); assertThat(result.get("multi-null-field"), equalTo("not so null in third")); NestedAttributesMap mulitDepth = result.child("multi-depth"); NestedAttributesMap first = mulitDepth.child("first"); NestedAttributesMap second = first.child("second"); NestedAttributesMap third = second.child("third"); assertThat(first.get("title"), equalTo("This is the first depth")); assertThat(second.get("title"), equalTo("This is the second depth")); assertThat(third.get("title"), equalTo("This is the third depth")); NestedAttributesMap reverseMulitDepth = result.child("reverse-multi-depth"); first = reverseMulitDepth.child("first"); assertThat(first.get("title"), equalTo("This is the first depth")); NestedAttributesMap mulitDepthMerge = result.child("multi-depth-merge"); first = mulitDepthMerge.child("first"); assertThat(first.get("summary"), equalTo("We have here the first depth from the third response")); NestedAttributesMap dependencies = result.child("dependencies"); assertThat(dependencies.get("equire(\"orchestrator\""), equalTo("*")); assertThat(dependencies.get("@types/node"), equalTo("*")); assertThat(dependencies.get("@types/orchestrator"), equalTo("*")); NestedAttributesMap funckyFieldName = dependencies.child("funcky(\"fieldname\""); assertThat(funckyFieldName.get("test"), equalTo("value")); }
Example 20
Source File: NpmPublishParser.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private void updateNpmUser(final NestedAttributesMap packageEntry, final String currentUserId) { if (packageEntry.contains(NPM_USER)) { NestedAttributesMap npmUser = packageEntry.child(NPM_USER); npmUser.set(NAME, currentUserId); } }