NpmMetadataUtils { public static DateTime maintainTime(final NestedAttributesMap packageRoot) { final NestedAttributesMap time = packageRoot.child(TIME); final DateTime now = DateTime.now(); final String nowString = NPM_TIMESTAMP_FORMAT.print(now); if (!time.contains(CREATED)) { time.set(CREATED, nowString); } time.set(MODIFIED, nowString); for (String version : packageRoot.child(VERSIONS).keys()) { if (!time.contains(version)) { time.set(version, nowString); } } return now; } 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 maintainTimeTest() { NestedAttributesMap package1 = new NestedAttributesMap("package1", Maps.newHashMap()); package1.child("versions").set("1.0", "incomplete"); String createdTimestamp = "2016-10-17T00:00:00.000Z"; NestedAttributesMap package2 = new NestedAttributesMap("package2", Maps.newHashMap()); package2.child("time").set("created", createdTimestamp); package2.child("time").set("1.0", createdTimestamp); package2.child("versions").set("1.0", "incomplete"); package2.child("versions").set("2.0", "incomplete"); DateTime package1Modified = NpmMetadataUtils.maintainTime(package1); DateTime package2Modified = NpmMetadataUtils.maintainTime(package2); String package1ModifiedTimestamp = NpmMetadataUtils.NPM_TIMESTAMP_FORMAT.print(package1Modified); assertThat(package1.child("time").get("created"), equalTo(package1ModifiedTimestamp)); assertThat(package1.child("time").get("modified"), equalTo(package1ModifiedTimestamp)); assertThat(package1.child("time").get("1.0"), equalTo(package1ModifiedTimestamp)); String package2ModifiedTimestamp = NpmMetadataUtils.NPM_TIMESTAMP_FORMAT.print(package2Modified); assertThat(package2.child("time").get("created"), equalTo(createdTimestamp)); assertThat(package2.child("time").get("modified"), equalTo(package2ModifiedTimestamp)); assertThat(package2.child("time").get("1.0"), equalTo(createdTimestamp)); assertThat(package2.child("time").get("2.0"), equalTo(package2ModifiedTimestamp)); }