org.sonatype.nexus.common.collect.NestedAttributesMap Java Examples

The following examples show how to use org.sonatype.nexus.common.collect.NestedAttributesMap. 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
/**
 * Parses the package root, which is the starting point of the parsing process for the incoming request.
 */
private NestedAttributesMap parsePackageRoot() throws IOException {
  Map<String, Object> backing = new LinkedHashMap<>();
  consumeToken();
  consumeToken();
  while (!END_OBJECT.equals(currentToken())) {
    String key = parseFieldName();
    final Object value;
    if (ATTACHMENTS_KEY.equals(key)) {
      value = parseAttachments();
    } else {
      value = parseValue();
    }
    backing.put(key, value);
  }
  return new NestedAttributesMap(String.valueOf(backing.get(NpmMetadataUtils.NAME)), backing);
}
 
Example #2
Source File: NpmMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #3
Source File: BlobStoreConfigurationData.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public NestedAttributesMap attributes(final String key) {
  checkNotNull(key);

  if (attributes == null) {
    attributes = Maps.newHashMap();
  }

  Map<String,Object> map = attributes.get(key);
  if (map == null) {
    map = Maps.newHashMap();
    attributes.put(key, map);
  }

  return new NestedAttributesMap(key, map);
}
 
Example #4
Source File: MockBlobStoreConfiguration.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public NestedAttributesMap attributes(final String key) {
  checkNotNull(key);

  if (attributes == null) {
    attributes = Maps.newHashMap();
  }

  Map<String,Object> map = attributes.get(key);
  if (map == null) {
    map = Maps.newHashMap();
    attributes.put(key, map);
  }

  return new NestedAttributesMap(key, map);
}
 
Example #5
Source File: OrientNpmProxyFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Content maybeHandleMissingBlob(final RuntimeException e,
                                       final NpmPackageId packageId,
                                       final NestedAttributesMap packageRoot,
                                       final Content payload) throws IOException
{
  BlobRef blobRef = null;

  if (e instanceof MissingBlobException) {
    blobRef = ((MissingBlobException) e).getBlobRef();
  }
  else if (e.getCause() instanceof MissingBlobException) {
    blobRef = ((MissingBlobException) e.getCause()).getBlobRef();
  }

  if (nonNull(blobRef)) {
    log.warn("Unable to find blob {} for {}, skipping merge of package root", blobRef, packageId);
    return doPutPackageRoot(packageId, packageRoot, payload, false);
  }

  // when we have no blob ref, just throw the original runtime exception
  throw e;
}
 
Example #6
Source File: GoogleCloudBlobStoreITSupport.java    From nexus-blobstore-google-cloud with Eclipse Public License 1.0 6 votes vote down vote up
public BlobStoreConfiguration newConfiguration(final String name, final String bucketName,
                                               @Nullable final File credentialFile) {
  BlobStoreConfiguration configuration = blobStoreManager.newConfiguration();
  configuration.setName(name);
  configuration.setType("Google Cloud Storage");
  NestedAttributesMap configMap = configuration.attributes("google cloud storage");
  configMap.set("bucket", bucketName);
  configMap.set("location", "us-central1");
  if (credentialFile != null) {
    configMap.set("credential_file", credentialFile.getAbsolutePath());
  }
  NestedAttributesMap quotaMap = configuration.attributes(BlobStoreQuotaSupport.ROOT_KEY);
  quotaMap.set(BlobStoreQuotaSupport.TYPE_KEY, SpaceUsedQuota.ID);
  quotaMap.set(BlobStoreQuotaSupport.LIMIT_KEY, 512000L);

  return configuration;
}
 
Example #7
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves the package root JSON content by persisting content into root asset's blob. It also removes some transient
 * fields from JSON document.
 */
static void savePackageRoot(final StorageTx tx,
                            final Asset packageRootAsset,
                            final NestedAttributesMap packageRoot) throws IOException
{
  packageRoot.remove(NpmMetadataUtils.META_ID);
  packageRoot.remove("_attachments");
  packageRootAsset.formatAttributes().set(
      NpmAttributes.P_NPM_LAST_MODIFIED, NpmMetadataUtils.maintainTime(packageRoot).toDate()
  );
  storeContent(
      tx,
      packageRootAsset,
      new StreamCopier<Supplier<InputStream>>(
          outputStream -> serialize(new OutputStreamWriter(outputStream, UTF_8), packageRoot),
          inputStream -> () -> inputStream).read(),
      AssetKind.PACKAGE_ROOT
  );
  tx.saveAsset(packageRootAsset);
}
 
Example #8
Source File: Content.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Extracts non-format specific content attributes into the passed in {@link AttributesMap} (usually originating from
 * {@link Content#getAttributes()}) from passed in {@link Asset} and format required hashes.
 */
public static void extractFromAsset(final Asset asset,
                                    final Iterable<HashAlgorithm> hashAlgorithms,
                                    final AttributesMap contentAttributes)
{
  checkNotNull(asset);
  checkNotNull(hashAlgorithms);
  final NestedAttributesMap assetAttributes = asset.attributes().child(CONTENT);
  final DateTime lastModified = toDateTime(assetAttributes.get(P_LAST_MODIFIED, Date.class));
  final String etag = assetAttributes.get(P_ETAG, String.class);

  final Map<HashAlgorithm, HashCode> checksums = asset.getChecksums(hashAlgorithms);

  contentAttributes.set(Asset.class, asset);
  contentAttributes.set(Content.CONTENT_LAST_MODIFIED, lastModified);
  contentAttributes.set(Content.CONTENT_ETAG, etag);
  contentAttributes.set(Content.CONTENT_HASH_CODES_MAP, checksums);
  contentAttributes.set(CacheInfo.class, CacheInfo.extractFromAsset(asset));
}
 
Example #9
Source File: NpmMetadataUtilsTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@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));
}
 
Example #10
Source File: GroupFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testLeafMembers() throws Exception {
  Repository hosted1 = hostedRepository("hosted1");
  Repository hosted2 = hostedRepository("hosted2");
  Repository group1 = groupRepository("group1", hosted1);
  Config config = new Config();
  config.memberNames = ImmutableSet.of(hosted1.getName(), hosted2.getName(), group1.getName());
  Configuration configuration = mock(Configuration.class);
  when(configuration.attributes(CONFIG_KEY)).thenReturn(new NestedAttributesMap(
      "dummy",
      ImmutableMap.of("memberNames", config.memberNames)
  ));
  when(configurationFacet.readSection(configuration, CONFIG_KEY, Config.class)).thenReturn(config);
  underTest.doConfigure(configuration);
  assertThat(underTest.leafMembers(), contains(hosted1, hosted2));
}
 
Example #11
Source File: OrientNpmProxyFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Content putPackageRoot(final NpmPackageId packageId,
                               final TempBlob tempBlob,
                               final Content payload) throws IOException
{
  checkNotNull(packageId);
  checkNotNull(payload);
  checkNotNull(tempBlob);

  NestedAttributesMap packageRoot = NpmFacetUtils.parse(tempBlob);
  try {
    return doPutPackageRoot(packageId, packageRoot, payload, true);
  }
  catch (RetryDeniedException | MissingBlobException e) {
    return maybeHandleMissingBlob(e, packageId, packageRoot, payload);
  }
}
 
Example #12
Source File: ComponentComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testReadAsset() {
  Asset asset = mock(Asset.class);
  Bucket bucket = mock(Bucket.class);
  EntityId bucketId = mock(EntityId.class);
  EntityMetadata entityMetadata = mock(EntityMetadata.class);
  when(asset.getEntityMetadata()).thenReturn(entityMetadata);
  when(asset.bucketId()).thenReturn(bucketId);
  when(asset.attributes()).thenReturn(new NestedAttributesMap("attributes", new HashMap<>()));
  when(entityMetadata.getId()).thenReturn(new DetachedEntityId("someid"));
  when(contentPermissionChecker.isPermitted(anyString(),any(), eq(BreadActions.BROWSE), any())).thenReturn(true);

  when(browseService.getAssetById(new DetachedEntityId("someid"), repository)).thenReturn(asset);
  when(bucketStore.getById(bucketId)).thenReturn(bucket);
  when(bucket.getRepositoryName()).thenReturn("testRepositoryName");
  AssetXO assetXO = underTest.readAsset("someid", "testRepositoryName");

  assertThat(assetXO, is(notNullValue()));
  assertThat(assetXO.getId(), is("someid"));
  assertThat(assetXO.getRepositoryName(), is("testRepositoryName"));
  assertThat(assetXO.getContainingRepositoryName(), is("testRepositoryName"));
}
 
Example #13
Source File: NpmPackageRootMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private static String getPackageRootLatestVersion(final NestedAttributesMap packageJson,
                                                  final Repository repository)
{
  StorageTx tx = UnitOfWork.currentTx();
  NpmPackageId packageId = NpmPackageId.parse((String) packageJson.get(P_NAME));

  try {
    NestedAttributesMap packageRoot = getPackageRoot(tx, repository, packageId);
    if(nonNull(packageRoot)) {

      String latestVersion = getLatestVersionFromPackageRoot(packageRoot);
      if (nonNull(latestVersion)) {
        return latestVersion;
      }
    }
  }
  catch (IOException ignored) { // NOSONAR
  }
  return "";
}
 
Example #14
Source File: Maven2BrowseNodeGeneratorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void computeAssetPathForSnapshotAssetWithComponent() {
  String baseVersion = "1.0-SNAPSHOT";
  NestedAttributesMap attributes = new NestedAttributesMap("attributes",
      singletonMap("maven2", singletonMap("baseVersion", baseVersion)));

  Asset asset = createAsset("org/foo/bar/example/1.0-SNAPSHOT/example-1.0-20171213.212030-158.jar");
  Component component = new DefaultComponent();
  component.group("org.foo.bar");
  component.name("example");
  component.version("1.0-20171213.212030-158");
  component.attributes(attributes);

  List<BrowsePaths> paths = generator.computeAssetPaths(asset, component);

  assertSNAPSHOTPaths(asList("org", "foo", "bar", "example", "1.0-SNAPSHOT", "1.0-20171213.212030-158",
      "example-1.0-20171213.212030-158.jar"), paths, false);
}
 
Example #15
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalDeleteBlob
public Set<String> deletePackage(final NpmPackageId packageId,
                                 @Nullable final String revision,
                                 final boolean deleteBlobs)
    throws IOException
{
  checkNotNull(packageId);
  StorageTx tx = UnitOfWork.currentTx();
  if (revision != null) {
    Asset packageRootAsset = findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId);
    if (packageRootAsset != null) {
      NestedAttributesMap oldPackageRoot = NpmFacetUtils.loadPackageRoot(tx, packageRootAsset);
      checkArgument(revision.equals(oldPackageRoot.get(META_REV, String.class)));
    }
  }

  return NpmFacetUtils.deletePackageRoot(tx, getRepository(), packageId, deleteBlobs);
}
 
Example #16
Source File: ConfigurationData.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public NestedAttributesMap attributes(final String key) {
  checkNotNull(key);

  if (attributes == null) {
    attributes = Maps.newHashMap();
  }

  Map<String, Object> map = attributes.get(key);
  if (map == null) {
    map = Maps.newHashMap();
    attributes.put(key, map);
  }

  return new NestedAttributesMap(key, map);
}
 
Example #17
Source File: NpmComponentDirector.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional
protected void updatePackageRoot(final NpmHostedFacet npmHostedFacet,
                                 final Component component,
                                 final Repository destination)
{
  final StorageTx tx = UnitOfWork.currentTx();
  tx.browseAssets(component).forEach(asset -> {
    Blob blob = checkNotNull(tx.getBlob(asset.blobRef()));
    final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(blob::getInputStream);
    final NpmPackageId packageId = NpmPackageId.parse((String) packageJson.get(P_NAME));

    try {
      final NestedAttributesMap updatedMetadata = createFullPackageMetadata(
          new NestedAttributesMap("metadata", packageJson),
          destination.getName(),
          blob.getMetrics().getSha1Hash(),
          destination,
          extractNewestVersion);
      npmHostedFacet.putPackageRoot(packageId, null, updatedMetadata);
    }
    catch (IOException e) {
      log.error("Failed to update package root, packageId: {}", packageId, e);
    }
  });
}
 
Example #18
Source File: NpmPublishParser.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parses the {@code JsonParser}'s content into a {@code NpmPublishOrDeleteRequest}. Temp blobs will be created if
 * necessary using the {@code StorageFacet} and with the provided {@code HashAlgorithm}s.
 *
 * This method will manage the temp blobs for the lifetime of the parse operation (and will dispose accordingly in
 * event of a failure). After returning, the parsed result must be managed carefully so as not to leak temp blobs.
 * @param currentUserId currently logged in userId
 */
public NpmPublishRequest parse(@Nullable final String currentUserId) throws IOException {
  try {
    NestedAttributesMap packageRoot = parsePackageRoot();

    if(currentUserId != null && !currentUserId.isEmpty()) {
      updateMaintainer(packageRoot, currentUserId);
    }
    return new NpmPublishRequest(packageRoot, tempBlobs);
  }
  catch (Throwable t) { //NOSONAR
    for (TempBlob tempBlob : tempBlobs.values()) {
      tempBlob.close();
    }
    throw t;
  }
}
 
Example #19
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalTouchBlob
protected void upgradeRevisionOnPackageRoot(final Asset packageRootAsset, final String revision) {
  StorageTx tx = UnitOfWork.currentTx();

  NpmPackageId packageId = NpmPackageId.parse(packageRootAsset.name());
  Asset asset = findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId);

  if (asset == null) {
    log.error("Failed to update revision on package root. Asset for id '{}' didn't exist", packageId.id());
    return;
  }

  // if there is a transaction failure and we fail to upgrade the package root with _rev
  // then the user who fetched the package root will not be able to run a delete command
  try {
    NestedAttributesMap packageRoot = NpmFacetUtils.loadPackageRoot(tx, asset);
    packageRoot.set(META_REV, revision);
    savePackageRoot(UnitOfWork.currentTx(), packageRootAsset, packageRoot);
  }
  catch (IOException e) {
    log.warn("Failed to update revision in package root. Revision '{}' was not set" +
            " and might cause delete for that revision to fail for Asset {}",
        revision, packageRootAsset, e);
  }
}
 
Example #20
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 #21
Source File: NpmPublishParser.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void updateMaintainerList(final NestedAttributesMap versionToUpdate, final String currentUserId) {
  Object maintainersObject = versionToUpdate.get(MAINTAINERS_KEY);

  if (nonNull(maintainersObject)) {
    if(maintainersObject instanceof List) {
      List maintainers = (List) maintainersObject;

      Object maintainer = maintainers.get(0);
      if (maintainer instanceof Map) {
        updateMaintainerAsMap(maintainers, currentUserId);
      }
      else if (maintainer instanceof String) {
        updateMaintainerAsString(maintainers, currentUserId);
      }
    }
    else if (maintainersObject instanceof String) {
      versionToUpdate.set(MAINTAINERS_KEY, currentUserId);
    }
  }
}
 
Example #22
Source File: Maven2BrowseNodeGeneratorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void computeComponentPathNoGroup() {
  String baseVersion = "1.0.0";
  NestedAttributesMap attributes = new NestedAttributesMap("attributes",
      singletonMap("maven2", singletonMap("baseVersion", baseVersion)));

  Asset asset = createAsset("name/1.0.0/name-1.0.0.jar");
  Component component = new DefaultComponent();
  component.name("name");
  component.version("1.0.0");
  component.attributes(attributes);

  List<BrowsePaths> paths = generator.computeComponentPaths(asset, component);

  assertPaths(asList(component.name(), component.version()), paths, true);
}
 
Example #23
Source File: MavenFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Asset createMetadataAsset(String name, String cacheToken) {
  Asset asset = new Asset();
  asset.contentType(TEXT_XML);
  asset.name(name);
  asset.format(Maven2Format.NAME);
  asset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
  asset.formatAttributes().set(P_ASSET_KIND, REPOSITORY_METADATA.name());
  asset.attributes().child(CHECKSUM).set(HashType.SHA1.getExt(),
      HashAlgorithm.SHA1.function().hashString("foobar", StandardCharsets.UTF_8).toString());
  asset.attributes().child(CHECKSUM).set(HashType.MD5.getExt(),
      HashAlgorithm.MD5.function().hashString("foobar", StandardCharsets.UTF_8).toString());
  asset.attributes().child(CONTENT).set(P_LAST_MODIFIED, new Date());
  asset.attributes().child(CONTENT).set(P_ETAG, "ETAG");
  asset.attributes().child(CACHE).set(LAST_VERIFIED, new Date());
  asset.attributes().child(CACHE).set(CACHE_TOKEN, cacheToken);
  asset.blobRef(new BlobRef("node", "store", "blobid"));
  return asset;
}
 
Example #24
Source File: NpmSearchIndexFacetCachingTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  when(repository.getName()).thenReturn("npm-test");
  when(repository.getFormat()).thenReturn(new NpmFormat());

  underTest = Guice.createInjector(new TransactionModule(), new AbstractModule()
  {
    @Override
    protected void configure() {
      bind(EventManager.class).toInstance(eventManager);
    }
  }).getInstance(NpmSearchIndexFacetCachingImpl.class);
  underTest.attach(repository);

  frozenException = mockOrientException(OModificationOperationProhibitedException.class);

  assetAttributes = new NestedAttributesMap(MetadataNodeEntityAdapter.P_ATTRIBUTES, new HashMap<>());
  assetAttributes.child(Asset.CHECKSUM).set(HashAlgorithm.SHA1.name(), "1234567890123456789012345678901234567890");

  doReturn(blobRef).when(asset).requireBlobRef();
  doReturn(NpmFormat.NAME).when(asset).format();
  doReturn(assetAttributes).when(asset).attributes();
  asset.contentType(ContentTypes.APPLICATION_JSON);

  when(assetBlob.getBlob()).thenReturn(blob);

  when(storageTx.findBucket(repository)).thenReturn(bucket);
  when(storageTx.requireBlob(blobRef)).thenReturn(blob);
  UnitOfWork.begin(() -> storageTx);
}
 
Example #25
Source File: StorageTxImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns {@code true} when incoming hashes all match existing checksums.
 */
private boolean compareChecksums(final NestedAttributesMap checksums, final AssetBlob assetBlob) {
  for (Entry<HashAlgorithm, HashCode> entry : assetBlob.getHashes().entrySet()) {
    HashAlgorithm algorithm = entry.getKey();
    HashCode checksum = entry.getValue();
    if (!checksum.toString().equals(checksums.get(algorithm.name()))) {
      return false;
    }
  }
  return true;
}
 
Example #26
Source File: ProxyRepositoryApiRequestToConfigurationConverter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void convertHttpClient(final T request, final Configuration configuration) {
  HttpClientAttributes httpClient = request.getHttpClient();
  if (nonNull(httpClient)) {
    NestedAttributesMap httpClientConfiguration = configuration.attributes("httpclient");
    httpClientConfiguration.set("blocked", httpClient.getBlocked());
    httpClientConfiguration.set("autoBlock", httpClient.getAutoBlock());
    HttpClientConnectionAttributes connection = httpClient.getConnection();
    NestedAttributesMap connectionConfiguration = httpClientConfiguration.child("connection");
    convertConnection(connection, connectionConfiguration);
    convertAuthentication(httpClient, httpClientConfiguration);
  }
}
 
Example #27
Source File: S3BlobStoreApiModelMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static void copyGeneralS3BucketSettings(
    final S3BlobStoreApiBucket bucket,
    final NestedAttributesMap s3BucketAttributes)
{
  s3BucketAttributes.set(REGION_KEY, checkNotNull(bucket.getRegion()));
  s3BucketAttributes.set(BUCKET_KEY, checkNotNull(bucket.getName()));
  setAttribute(s3BucketAttributes, BUCKET_PREFIX_KEY, bucket.getPrefix());
  setAttribute(s3BucketAttributes, EXPIRATION_KEY, String.valueOf(bucket.getExpiration()));
}
 
Example #28
Source File: ContentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void nothingToExtract() {
  final NestedAttributesMap attributes = nestedAttributesMap();
  Asset asset = mock(Asset.class);
  when(asset.attributes()).thenReturn(attributes);
  AttributesMap contentAttributes = new AttributesMap();
  Content.extractFromAsset(asset, ALGORITHMS, contentAttributes);
  assertThat(contentAttributes.contains(Content.CONTENT_LAST_MODIFIED), is(false));
  assertThat(contentAttributes.contains(Content.CONTENT_ETAG), is(false));
  assertThat(contentAttributes.contains(Content.CONTENT_HASH_CODES_MAP), is(true));
}
 
Example #29
Source File: S3BlobStoreApiModelMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static void copyAdvancedBucketConnectionSettings(
    final S3BlobStoreApiAdvancedBucketConnection advancedBucketConnection,
    final NestedAttributesMap s3BucketAttributes)
{
  if (nonNull(advancedBucketConnection)) {
    setAttribute(s3BucketAttributes, ENDPOINT_KEY, advancedBucketConnection.getEndpoint());
    setAttribute(s3BucketAttributes, SIGNERTYPE_KEY, advancedBucketConnection.getSignerType());
    setForcePathStyleIfTrue(advancedBucketConnection.getForcePathStyle(), s3BucketAttributes);
  }
}
 
Example #30
Source File: NpmMergeObjectMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String updateLatestVersion(final NestedAttributesMap result, final String latestVersion) {
  String pkgLatestVersion = result.child(DIST_TAGS).get(LATEST, String.class);

  if (nonNull(pkgLatestVersion) && (isNull(latestVersion) ||
      versionComparator.compare(pkgLatestVersion, latestVersion) > 0)) {
    return pkgLatestVersion;
  }

  return latestVersion;
}