NpmMetadataUtils { @Nonnull public static NestedAttributesMap overlay(final NestedAttributesMap recessive, final NestedAttributesMap dominant) { overlay(recessive.backing(), dominant.backing(), true); return recessive; } private  NpmMetadataUtils(); @Nonnull static String extractTarballName(final String tarballUrl); @Nullable static String extractTarballName(final NestedAttributesMap packageMetadata); @Nullable static NestedAttributesMap selectVersionByTarballName(
      final NestedAttributesMap packageRoot,
      final String tarballName); static DateTime maintainTime(final NestedAttributesMap packageRoot); @Nullable static DateTime lastModified(final NestedAttributesMap packageRoot); static void rewriteTarballUrl(final String repositoryName, final NestedAttributesMap packageRoot); static String createRepositoryPath(final String name, final String version); static String createTarballName(final String name, final String version); @Nonnull static NestedAttributesMap shrink(final NestedAttributesMap packageRoot); @Nonnull static NestedAttributesMap overlay(final NestedAttributesMap recessive, final NestedAttributesMap dominant); @Nonnull static NestedAttributesMap merge(final String key, final List<NestedAttributesMap> packages); static NestedAttributesMap mergeContents(final List<Content> contents); static NestedAttributesMap parseContent(final Content content); static Map<String, Object> overlay(
      final Map<String, Object> recessive,
      final Map<String, Object> dominant,
      final boolean mergeVersionDocuments); static String getLatestVersionFromPackageRoot(final NestedAttributesMap pkg); static NestedAttributesMap retrievePackageRoot(
      final NpmPackageId packageId,
      final Context context,
      final Repository repository); static List<String> findCachedVersionsRemovedFromRemote(
      final NestedAttributesMap cachedRoot,
      final NestedAttributesMap newPackageRoot,
      final BiFunction<NpmPackageId, String, Boolean> componentExists); static NestedAttributesMap mergePackageRoots(
      final NestedAttributesMap newPackageRoot,
      final NestedAttributesMap existingPackageRoot, final List<String> cachedVersions); static void removeVersionsNotCachedAndNotInNewRoot(final NestedAttributesMap newPackageRoot,
                                                             final NestedAttributesMap existingPackageRoot,
                                                             final List<String> cachedVersions); @VisibleForTesting
  static final DateTimeFormatter NPM_TIMESTAMP_FORMAT; static final String NAME; static final String DIST_TAGS; static final String VERSIONS; static final String VERSION; static final String DEPRECATED; static final String TIME; static final String DIST; static final String TARBALL; static final String META_ID; static final String META_REV; static final String META_UPDATED; }
@Test public void overlayTest() { NestedAttributesMap recessive = new NestedAttributesMap("recessive", Maps.newHashMap()); recessive.set("_id", "id"); recessive.set("name", "recessive"); recessive.child("versions").child("1.0").set("version", "1.0"); recessive.child("versions").child("1.0").set("foo", "bar"); recessive.child("versions").child("1.0").set("foo1", "bar1"); recessive.child("versions").child("1.0").child("author").set("url", "http: recessive.child("versions").child("1.0").child("dependencies").set("a", "1.0"); recessive.child("versions").child("1.0").child("devDependencies").set("m", "2.0"); recessive.child("versions").child("1.0").child("publishConfig").set("a", "m"); recessive.child("versions").child("1.0").child("scripts").set("cmd1", "command1"); NestedAttributesMap dominant = new NestedAttributesMap("dominant", Maps.newHashMap()); dominant.set("_id", "id"); dominant.set("name", "dominant"); dominant.child("versions").child("1.0").set("version", "1.0"); dominant.child("versions").child("1.0").set("foo", "baz"); dominant.child("versions").child("1.0").child("author").set("email", "none@example.com"); dominant.child("versions").child("1.0").child("dependencies").set("b", "2.0"); dominant.child("versions").child("1.0").child("devDependencies").set("n", "3.0"); dominant.child("versions").child("1.0").child("publishConfig").set("b", "n"); dominant.child("versions").child("1.0").child("scripts").set("cmd2", "command2"); NestedAttributesMap result = NpmMetadataUtils.overlay(recessive, dominant); assertThat(result, equalTo(recessive)); assertThat(result.backing(), hasEntry("_id", "id")); assertThat(result.backing(), hasEntry("name", "dominant")); assertThat(result.child("versions").child("1.0").backing(), hasEntry("foo", "baz")); assertThat(result.child("versions").child("1.0").backing(), hasEntry("foo1", "bar1")); assertThat(result.child("versions").child("1.0").child("author").backing(), not(hasEntry("url", "http: assertThat(result.child("versions").child("1.0").child("author").backing(), hasEntry("email", "none@example.com")); assertThat(result.child("versions").child("1.0").child("dependencies").backing(), not(hasEntry("a", "1.0"))); assertThat(result.child("versions").child("1.0").child("dependencies").backing(), hasEntry("b", "2.0")); assertThat(result.child("versions").child("1.0").child("devDependencies").backing(), not(hasEntry("m", "2.0"))); assertThat(result.child("versions").child("1.0").child("devDependencies").backing(), hasEntry("n", "3.0")); assertThat(result.child("versions").child("1.0").child("publishConfig").backing(), not(hasEntry("a", "m"))); assertThat(result.child("versions").child("1.0").child("publishConfig").backing(), hasEntry("b", "n")); assertThat(result.child("versions").child("1.0").child("scripts").backing(), not(hasEntry("cmd1", "command1"))); assertThat(result.child("versions").child("1.0").child("scripts").backing(), hasEntry("cmd2", "command2")); }