Java Code Examples for org.sonatype.nexus.common.collect.AttributesMap#get()

The following examples show how to use org.sonatype.nexus.common.collect.AttributesMap#get() . 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: NpmAuditTarballFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static Optional<String> getHashsum(final AttributesMap attributes) {
  Map<HashAlgorithm, HashCode> hashMap = attributes.get(CONTENT_HASH_CODES_MAP, T_CONTENT_HASH_CODES_MAP);
  if (hashMap != null) {
    HashCode hashCode = hashMap.get(SHA1);
    return Optional.ofNullable(hashCode.toString());
  }
  return Optional.empty();
}
 
Example 2
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 3
Source File: Content.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Applies non-format specific content attributes onto passed in {@link Asset} from passed in {@link AttributesMap}
 * (usually originating from {@link Content#getAttributes()}).
 */
public static void applyToAsset(final Asset asset, final AttributesMap contentAttributes) {
  checkNotNull(asset);
  checkNotNull(contentAttributes);
  final NestedAttributesMap assetAttributes = asset.attributes().child(CONTENT);
  assetAttributes.set(P_LAST_MODIFIED, toDate(contentAttributes.get(Content.CONTENT_LAST_MODIFIED, DateTime.class)));
  assetAttributes.set(P_ETAG, contentAttributes.get(Content.CONTENT_ETAG, String.class));
  final CacheInfo cacheInfo = contentAttributes.get(CacheInfo.class);
  if (cacheInfo != null) {
    CacheInfo.applyToAsset(asset, cacheInfo);
  }
}
 
Example 4
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 5
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;
}
 
Example 6
Source File: CacheInfo.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @since 3.24
 */
@Nullable
public static CacheInfo fromMap(final AttributesMap map) {
  if (map != null) {
    return new CacheInfo(new DateTime(map.get(LAST_VERIFIED)), map.get(CACHE_TOKEN, String.class));
  }
  return null;
}
 
Example 7
Source File: DeconflictAssetMetadataTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private DateTime getLastModified(final Asset asset) {
  AttributesMap contentAttributes = new AttributesMap();
  Content.extractFromAsset(asset, ImmutableList.of(), contentAttributes);
  return contentAttributes.get(CONTENT_LAST_MODIFIED, DateTime.class);
}