class NpmMetadataUtils {

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

  private  NpmMetadataUtils();

}