Java Code Examples for org.sonatype.nexus.common.collect.NestedAttributesMap#contains()

The following examples show how to use org.sonatype.nexus.common.collect.NestedAttributesMap#contains() . 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 vote down vote up
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: NpmMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Maintains the time fields of npm package root. Sets created time if it doesn't exist, updates the modified time.
 */
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;
}
 
Example 3
Source File: NpmPublishParser.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String getNpmUser(final NestedAttributesMap packageEntry) {
  if (packageEntry.contains(NPM_USER)) {
    NestedAttributesMap npmUser = packageEntry.child(NPM_USER);
    return npmUser.get(NAME, String.class);
  }
  return null;
}
 
Example 4
Source File: NpmPublishParser.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String getDistTagVersion(final NestedAttributesMap packageRoot) {
  if (packageRoot.contains(DIST_TAGS)) {
    NestedAttributesMap distTag = packageRoot.child(DIST_TAGS);
    return (String) distTag.iterator().next().getValue();
  }
  return null;
}
 
Example 5
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void updateRevision(final NestedAttributesMap packageRoot,
                            final Asset packageRootAsset,
                            final boolean createdPackageRoot)
{
  String newRevision = "1";

  if (!createdPackageRoot) {
    if (packageRoot.contains(META_REV)) {
      String rev = packageRoot.get(META_REV, String.class);
      newRevision = Integer.toString(Integer.parseInt(rev) + 1);
    }
    else {
      /*
        This is covering the edge case when a new package is uploaded to a repository where the packageRoot already 
        exists.
        
        If that packageRoot was created using an earlier version of NXRM where we didn't store the rev then we need
        to add it in. We also add the rev in on download but it is possible that someone is uploading a package where
        the packageRoot has never been downloaded before.
       */
      newRevision = EntityHelper.version(packageRootAsset).getValue();
    }
  }

  packageRoot.set(META_ID, packageRootAsset.name());
  packageRoot.set(META_REV, newRevision);
}
 
Example 6
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 7
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static BiConsumer<String, Object> populateLatestVersion(final NestedAttributesMap merged) {
  return (k, v) -> {
    if (!merged.contains(k)) {
      merged.set(k, v);
    }
    else {
      final String newestVersion = extractNewestVersion.apply(merged.get(k, String.class), (String) v);
      merged.set(k, newestVersion);
    }
  };
}
 
Example 8
Source File: StorageTxImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns {@code true} when at least one incoming hash has the same algorithm as an existing checksum.
 */
private boolean checksumExists(final NestedAttributesMap checksums, final AssetBlob assetBlob) {
  if (!checksums.isEmpty()) {
    for (HashAlgorithm algorithm : assetBlob.getHashes().keySet()) {
      if (checksums.contains(algorithm.name())) {
        return true;
      }
    }
  }
  return false;
}
 
Example 9
Source File: NpmPublishParser.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private void updateNpmUser(final NestedAttributesMap packageEntry, final String currentUserId) {
  if (packageEntry.contains(NPM_USER)) {
    NestedAttributesMap npmUser = packageEntry.child(NPM_USER);
    npmUser.set(NAME, currentUserId);
  }
}
 
Example 10
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Removes all tags that are associated with a given {@param version}. If that version is also set as the
 * latest, the new latest is also populated from the remaining package versions stored
 */
public static void removeDistTagsFromTagsWithVersion(final NestedAttributesMap packageRoot, final String version) {
  if (packageRoot.contains(DIST_TAGS)) {
    packageRoot.child(NpmMetadataUtils.DIST_TAGS).entries().removeIf(e -> version.equals(e.getValue()));
  }
}