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

The following examples show how to use org.sonatype.nexus.common.collect.AttributesMap. 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: RFacetUtils.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset && create blob.
 *
 * @return blob content
 */
public static Content saveAsset(final StorageTx tx,
                                final Asset asset,
                                final Supplier<InputStream> contentSupplier,
                                final String contentType,
                                @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );

  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example #2
Source File: Request.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Request(final AttributesMap attributes,
                final Headers headers,
                final String action,
                final String path,
                final Parameters parameters,
                @Nullable final Payload payload,
                final boolean multipart,
                @Nullable final Iterable<PartPayload> multiPayloads)
{
  this.attributes = checkNotNull(attributes);
  this.headers = checkNotNull(headers);
  this.action = checkNotNull(action);
  this.path = checkNotNull(path);
  this.parameters = checkNotNull(parameters);
  this.payload = payload;
  this.multipart = multipart;
  this.multiPayloads = multiPayloads;
}
 
Example #3
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutContent(final String path, final TempBlob tempBlob, final Payload payload)
    throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();

  Asset asset = getOrCreateAsset(getRepository(), path, RawCoordinatesHelper.getGroup(path), path);

  AttributesMap contentAttributes = null;
  if (payload instanceof Content) {
    contentAttributes = ((Content) payload).getAttributes();
  }
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset,
      path,
      tempBlob,
      null,
      payload.getContentType(),
      false
  );

  tx.saveAsset(asset);

  return toContent(asset, assetBlob.getBlob());
}
 
Example #4
Source File: AptRestoreFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content restore(final AssetBlob assetBlob, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset;
  AptFacet aptFacet = facet(AptFacet.class);
  if (isDebPackageContentType(path)) {
    ControlFile controlFile = AptPackageParser.getDebControlFile(assetBlob.getBlob());
    asset = aptFacet.findOrCreateDebAsset(tx, path, new PackageInfo(controlFile));
  }
  else {
    asset = aptFacet.findOrCreateMetadataAsset(tx, path);
  }

  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
  tx.saveAsset(asset);
  return FacetHelper.toContent(asset, assetBlob.getBlob());
}
 
Example #5
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 #6
Source File: ConanHashVerifier.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Retrieves the hash maps which are stored as key, value pairs within the conanmanifest file
 * @param tx
 * @param bucket
 * @param assetPath
 * @return hashcode of the file
 */
public HashCode lookupHashFromAsset(final StorageTx tx, final Bucket bucket, final String assetPath) {
  checkNotNull(tx);
  checkNotNull(bucket);
  checkNotNull(assetPath);

  AttributesMap attributes = getConanmanifestHashes(tx, bucket, assetPath);

  if(attributes != null) {
    String filename = getFilenameFromPath(assetPath);
    if (attributes.contains(filename)) {
      return HashCode.fromString((String) attributes.get(filename));
    }
  }
  return null;
}
 
Example #7
Source File: FluentAssetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Record external cache details provided by upstream content.
 *
 * @see ProxyFacetSupport#fetch
 */
private void cacheContentHeaders(final AttributesMap contentAttributes) {
  ImmutableMap.Builder<String, String> headerBuilder = ImmutableMap.builder();
  if (contentAttributes.contains(CONTENT_LAST_MODIFIED)) {
    headerBuilder.put(CONTENT_LAST_MODIFIED, contentAttributes.get(CONTENT_LAST_MODIFIED).toString());
  }
  if (contentAttributes.contains(CONTENT_ETAG)) {
    headerBuilder.put(CONTENT_ETAG, contentAttributes.get(CONTENT_ETAG, String.class));
  }
  Map<String, String> contentHeaders = headerBuilder.build();
  if (!contentHeaders.isEmpty()) {
    withAttribute(CONTENT, contentHeaders);
  }
  else {
    withoutAttribute(CONTENT);
  }
}
 
Example #8
Source File: ConanManifest.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Extract all the md5 for conan files
 * @param conanManifestContentStream
 * @return Returns {AttributesMap} of file path keys to file md5 hash values
 */
public static AttributesMap parse(InputStream conanManifestContentStream) {
  AttributesMap attributesMap = new AttributesMap();
  try(BufferedReader reader = new BufferedReader(new InputStreamReader(conanManifestContentStream))) {
    String line;
    while ((line = reader.readLine()) != null) {
      String[] split = line.split(":");
      if (split.length == 2) {
        attributesMap.set(split[0].trim(), split[1].trim());
      }
    }
  } catch (IOException e) {
    LOGGER.warn("Unable to convertKeys manifest file");
  }
  return attributesMap;
}
 
Example #9
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset and create a blob
 *
 * @return blob content
 */
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final String contentType,
                          final AttributesMap contentAttributes,
                          final HashCode hash) throws IOException
{
  Content.applyToAsset(asset, maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );

  if (!hashVerifier.verify(hash, assetBlob.getHashes().get(MD5))) {
    return null;
  }
  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example #10
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPut(final MavenPath path,
                        final Payload payload,
                        final TempBlob tempBlob)
    throws IOException
{
  final StorageTx tx = UnitOfWork.currentTx();

  final AssetBlob assetBlob = tx.createBlob(
      path.getPath(),
      tempBlob,
      null,
      payload.getContentType(),
      false
  );
  AttributesMap contentAttributes = null;
  if (payload instanceof Content) {
    contentAttributes = ((Content) payload).getAttributes();
  }

  return doPutAssetBlob(path, contentAttributes, tx, assetBlob);
}
 
Example #11
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPut(final MavenPath path,
                        final Path sourceFile,
                        final String contentType,
                        final AttributesMap contentAttributes,
                        final Map<HashAlgorithm, HashCode> hashes,
                        final long size)
    throws IOException
{
  final StorageTx tx = UnitOfWork.currentTx();

  final AssetBlob assetBlob = tx.createBlob(
      path.getPath(),
      sourceFile,
      hashes,
      null,
      contentType,
      size
  );

  return doPutAssetBlob(path, contentAttributes, tx, assetBlob);
}
 
Example #12
Source File: ContentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void lastModifiedAndEtagApply() {
  final DateTime now = DateTime.now();
  final String etag = "foo-bar";
  final NestedAttributesMap attributes = nestedAttributesMap();
  attributes.child(Content.CONTENT).set(Content.P_LAST_MODIFIED, now.toDate());
  attributes.child(Content.CONTENT).set(Content.P_ETAG, etag);
  Asset asset = mock(Asset.class);
  when(asset.attributes()).thenReturn(attributes);
  AttributesMap contentAttributes = new AttributesMap();
  contentAttributes.set(Content.CONTENT_LAST_MODIFIED, now);
  contentAttributes.set(Content.CONTENT_ETAG, etag);
  Content.applyToAsset(asset, contentAttributes);
  assertThat(asset.attributes().child(Content.CONTENT).get(Content.P_LAST_MODIFIED, Date.class),
      equalTo(now.toDate()));
  assertThat(asset.attributes().child(Content.CONTENT).get(Content.P_ETAG, String.class), equalTo(
      etag));
}
 
Example #13
Source File: RRestoreFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalTouchBlob
public void restore(final AssetBlob assetBlob, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  RFacet facet = facet(RFacet.class);

  Asset asset;
  if (componentRequired(path)) {
    Map<String, String> attributes;

    try (InputStream is = assetBlob.getBlob().getInputStream()) {
      attributes = extractDescriptionFromArchive(path, is);
    }

    Component component = facet.findOrCreateComponent(tx, path, attributes);
    asset = facet.findOrCreateAsset(tx, component, path, attributes);
  }
  else {
    asset = facet.findOrCreateAsset(tx, path);
  }
  tx.attachBlob(asset, assetBlob);

  Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
  tx.saveAsset(asset);
}
 
Example #14
Source File: OrientPyPiGroupFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
public Content saveToCache(final String name, final Content content) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();

  Asset asset = getAsset(tx, name);
  AttributesMap contentAttributes = Content.maintainLastModified(asset, null);
  contentAttributes.set(CacheInfo.class, cacheController.current());
  Content.applyToAsset(asset, contentAttributes);

  AssetBlob blob = updateAsset(tx, asset, content);

  Content response = new Content(new BlobPayload(blob.getBlob(), ContentTypes.TEXT_HTML));
  Content.extractFromAsset(asset, HASH_ALGORITHMS, response.getAttributes());

  return response;
}
 
Example #15
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Asset putPackage(final NpmPackageId packageId,
                           final NestedAttributesMap requestPackageRoot,
                           final TempBlob tarballTempBlob)
    throws IOException
{
  checkNotNull(packageId);
  checkNotNull(requestPackageRoot);
  checkNotNull(tarballTempBlob);

  log.debug("Storing package: {}", packageId);

  StorageTx tx = UnitOfWork.currentTx();

  String tarballName = NpmMetadataUtils.extractTarballName(requestPackageRoot);
  AssetBlob assetBlob = NpmFacetUtils.createTarballAssetBlob(tx, packageId, tarballName, tarballTempBlob);

  NpmFacet npmFacet = facet(NpmFacet.class);
  Asset asset = npmFacet.putTarball(packageId.id(), tarballName, assetBlob, new AttributesMap());

  putPackageRoot(packageId, null, requestPackageRoot);

  return asset;
}
 
Example #16
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void putTarball(final StorageTx tx,
                        final NpmPackageId packageId,
                        final NestedAttributesMap packageVersion,
                        final NestedAttributesMap attachment,
                        final NpmPublishRequest request) throws IOException
{
  String tarballName = NpmMetadataUtils.extractTarballName(attachment.getKey());
  log.debug("Storing tarball: {}@{} ({})",
      packageId,
      packageVersion.get(NpmMetadataUtils.VERSION, String.class),
      tarballName);

  TempBlob tempBlob = request.requireBlob(attachment.require("data", String.class));
  AssetBlob assetBlob = NpmFacetUtils.createTarballAssetBlob(tx, packageId, tarballName, tempBlob);

  NpmFacet npmFacet = facet(NpmFacet.class);
  npmFacet.putTarball(packageId.id(), tarballName, assetBlob, new AttributesMap());
}
 
Example #17
Source File: NpmFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nullable
@Override
public Asset putRepositoryRoot(final AssetBlob assetBlob, @Nullable final AttributesMap contentAttributes)
    throws IOException
{
  final Repository repository = getRepository();
  final StorageTx tx = UnitOfWork.currentTx();
  final Bucket bucket = tx.findBucket(repository);
  Asset asset = NpmFacetUtils.findRepositoryRootAsset(tx, bucket);

  if (asset == null) {
    asset = tx.createAsset(bucket, repository.getFormat()).name(REPOSITORY_ROOT_ASSET);
    getEventManager().post(new NpmSearchIndexInvalidatedEvent(repository));
    saveAsset(tx, asset, assetBlob, REPOSITORY_ROOT, contentAttributes);
  }

  return asset;
}
 
Example #18
Source File: NpmFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nullable
@Override
public Asset putPackageRoot(final String packageId,
                            final AssetBlob assetBlob,
                            @Nullable final AttributesMap contentAttributes)
    throws IOException
{
  final Repository repository = getRepository();
  final StorageTx tx = UnitOfWork.currentTx();
  final Bucket bucket = tx.findBucket(repository);
  Asset asset = NpmFacetUtils.findPackageRootAsset(tx, bucket, NpmPackageId.parse(packageId));

  if (asset == null) {
    asset = tx.createAsset(bucket, repository.getFormat()).name(packageId);
    saveAsset(tx, asset, assetBlob, PACKAGE_ROOT, contentAttributes);
  }

  return asset;
}
 
Example #19
Source File: OrientPyPiGroupFacetTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  AttributesMap attributesMap = new AttributesMap();
  attributesMap.set(CONTENT_LAST_MODIFIED, DateTime.now());

  when(originalContent.getAttributes()).thenReturn(attributesMap);

  underTest = new OrientPyPiGroupFacet(repositoryManager, constraintViolationFactory, new GroupType()) {
    @Override
    public boolean isStale(@Nullable final Content content) {
      return false;
    }
  };

  responses = ImmutableMap.of(repository, response);
}
 
Example #20
Source File: OrientArchetypeCatalogHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tries to get the catalog from hosted repository, and generate it if not present.
 */
private Response doGet(final MavenPath path, final Repository repository) throws IOException {
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  Content content = mavenFacet.get(path);
  if (content == null) {
    // try to generate it
    repository.facet(MavenHostedFacet.class).rebuildArchetypeCatalog();
    content = mavenFacet.get(path);
    if (content == null) {
      return HttpResponses.notFound(path.getPath());
    }
  }
  AttributesMap attributesMap = content.getAttributes();
  MavenFacetUtils.mayAddETag(attributesMap, getHashAlgorithmFromContent(attributesMap));
  return HttpResponses.ok(content);
}
 
Example #21
Source File: OrientPyPiGroupFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected AssetBlob updateAsset(final StorageTx tx, final Asset asset, final Content content) throws IOException {
  AttributesMap contentAttributes = Content.maintainLastModified(asset, content.getAttributes());
  Content.applyToAsset(asset, contentAttributes);

  InputStream inputStream = content.openInputStream();
  AssetBlob blob = tx.setBlob(asset,
      asset.name(),
      () -> inputStream,
      HASH_ALGORITHMS,
      null,
      ContentTypes.TEXT_HTML,
      true);

  tx.saveAsset(asset);

  return blob;
}
 
Example #22
Source File: MavenFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds {@link Content#CONTENT_ETAG} content attribute if not present. In case of hosted repositories, this is safe
 * and even good thing to do, as the content is hosted here only and NX is content authority.
 */
public static void mayAddETag(final AttributesMap attributesMap,
                              final Map<HashAlgorithm, HashCode> hashCodes) {
  if (attributesMap.contains(Content.CONTENT_ETAG)) {
    return;
  }
  HashCode sha1HashCode = hashCodes.get(HashAlgorithm.SHA1);
  if (sha1HashCode != null) {
    attributesMap.set(Content.CONTENT_ETAG, "{SHA1{" + sha1HashCode + "}}");
  }
}
 
Example #23
Source File: ContentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void etagOnlyExtract() {
  final String etag = "foo-bar";
  final NestedAttributesMap attributes = nestedAttributesMap();
  attributes.child(Content.CONTENT).set(Content.P_ETAG, etag);
  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.get(Content.CONTENT_ETAG, String.class), equalTo(etag));
  assertThat(contentAttributes.contains(Content.CONTENT_HASH_CODES_MAP), is(true));
}
 
Example #24
Source File: LastDownloadedHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void configureHappyPath() throws Exception {
  when(asset.lastDownloaded()).thenReturn(empty());

  attributes = new AttributesMap();
  attributes.set(Asset.class, asset);

  when(context.proceed()).thenReturn(response);
  when(context.getRepository()).thenReturn(repository);
  when(context.getRequest()).thenReturn(request);
  when(request.getAction()).thenReturn(GET);
  when(response.getPayload()).thenReturn(payload);
  when(response.getStatus()).thenReturn(new Status(true, 200));
  when(payload.getAttributes()).thenReturn(attributes);
}
 
Example #25
Source File: OrientPyPiHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String buildIndex(final String name, final StorageTx tx) {
  List<PyPiLink> links = new ArrayList<>();
  for (Asset asset : findAssetsByComponentName(tx, getRepository(), name)) {
    AttributesMap pypiAttributes = asset.attributes().child(PyPiFormat.NAME);
    String path = asset.name();
    String file = path.substring(path.lastIndexOf('/') + 1);
    String link = String.format("../../%s#md5=%s", path, asset.getChecksum(MD5));
    String dataRequiresPython = (String) pypiAttributes.get(PyPiAttributes.P_REQUIRES_PYTHON, "");
    links.add(new PyPiLink(file, link, dataRequiresPython));
  }

  return buildIndexPage(templateHelper, name, links);
}
 
Example #26
Source File: OrientPyPiDataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset and create a blob with the specified content attributes.
 *
 * @return blob content
 */
static Content saveAsset(
    final StorageTx tx,
    final Asset asset,
    final TempBlob tempBlob,
    @Nullable final String contentType,
    @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(asset, asset.name(), tempBlob, null, contentType, false);

  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example #27
Source File: OrientPyPiDataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset and create blob.
 *
 * @return blob content
 */
static Content saveAsset(
    final StorageTx tx,
    final Asset asset,
    final TempBlob tempBlob,
    final Payload payload) throws IOException
{
  AttributesMap contentAttributes = null;
  String contentType = null;
  if (payload instanceof Content) {
    contentAttributes = ((Content) payload).getAttributes();
    contentType = payload.getContentType();
  }
  return saveAsset(tx, asset, tempBlob, contentType, contentAttributes);
}
 
Example #28
Source File: FluentAttributesHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Apply a change request to the given {@link AttributesMap}.
 */
public static boolean applyAttributeChange(final AttributesMap attributes,
                                           final AttributeChange change,
                                           final String key,
                                           @Nullable final Object value)
{
  switch (change) {
    case SET:
      return !value.equals(attributes.set(key, checkNotNull(value)));
    case REMOVE:
      return attributes.remove(key) != null; // value is ignored
    case APPEND:
      attributes.compute(key, v -> append(v, checkNotNull(value)));
      return true;
    case PREPEND:
      attributes.compute(key, v -> prepend(v, checkNotNull(value)));
      return true;
    case OVERLAY:
      Object oldMap = attributes.get(key);
      Object newMap = overlay(oldMap, checkNotNull(value));
      if (!newMap.equals(oldMap)) {
        attributes.set(key, newMap);
        return true;
      }
      return false;
    default:
      throw new IllegalArgumentException("Unknown request");
  }
}
 
Example #29
Source File: OrientNpmGroupPackageHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
  underTest = new OrientNpmGroupPackageHandler();

  AttributesMap attributesMap = new AttributesMap();
  attributesMap.set(TokenMatcher.State.class, state);
  when(context.getAttributes()).thenReturn(attributesMap);
  when(context.getRepository()).thenReturn(group);
  when(context.getRequest()).thenReturn(request);

  when(group.getName()).thenReturn(OrientNpmGroupFacetTest.class.getSimpleName() + "-group");
  when(group.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(group.facet(StorageFacet.class)).thenReturn(storageFacet);

  when(groupFacet.buildPackageRoot(anyMap(), eq(context)))
      .thenReturn(new Content(new BytesPayload("test".getBytes(), "")));

  when(viewFacet.dispatch(request, context))
      .thenReturn(new Response.Builder().status(success(OK)).build());

  when(proxy.facet(ViewFacet.class)).thenReturn(viewFacet);
  when(hosted.facet(ViewFacet.class)).thenReturn(viewFacet);

  when(request.getHeaders()).thenReturn(new Headers());
  when(request.getAttributes()).thenReturn(new AttributesMap());

  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);

  UnitOfWork.beginBatch(storageTx);
}
 
Example #30
Source File: FluentAssetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FluentAsset markAsCached(final Payload content) {
  if (content instanceof Content) {
    AttributesMap contentAttributes = ((Content) content).getAttributes();
    CacheInfo cacheInfo = contentAttributes.get(CacheInfo.class);
    if (cacheInfo != null) {
      markAsCached(cacheInfo);
    }
    cacheContentHeaders(contentAttributes);
  }
  return this;
}