@Test public void testGetMetadata() throws IOException { Bucket bucket = createBucket(REPO_NAME); Component component = createDetachedComponent(bucket, GROUP, NAME, VERSION); Iterable<Asset> assets = newArrayList(createDetachedAsset(bucket, NAME, component)); Map<String, Object> additional = ImmutableMap.of("foo", "bar"); String result = underTest.getMetadata(component, assets, additional); JsonNode json = mapper.readTree(result); assertValue(json, DefaultComponentMetadataProducer.FORMAT, "format-id"); assertValue(json, DefaultComponentMetadataProducer.NAME, NAME); assertValue(json, DefaultComponentMetadataProducer.GROUP, GROUP); assertValue(json, DefaultComponentMetadataProducer.VERSION, VERSION); assertValue(json, DefaultComponentMetadataProducer.IS_PRERELEASE_KEY, "false"); assertThat(json.get(DefaultComponentMetadataProducer.LAST_BLOB_UPDATED_KEY), equalTo(null)); assertThat(json.get(DefaultComponentMetadataProducer.LAST_DOWNLOADED_KEY), equalTo(null)); assertValue(json, "foo", "bar"); JsonNode jsonAssets = json.get(DefaultComponentMetadataProducer.ASSETS); assertTrue(jsonAssets.isArray()); assertThat(jsonAssets.size(), equalTo(1)); JsonNode jsonAsset = jsonAssets.get(0); assertValue(jsonAsset, DefaultComponentMetadataProducer.NAME, NAME); verify(componentMetadataProducerExtension).getComponentMetadata(any(Component.class)); }
@Override public String getMetadata(final Component component, final Iterable<Asset> assets, final Map<String, Object> additional) { checkNotNull(component); checkNotNull(assets); checkNotNull(additional); Map<String, Object> metadata = new HashMap<>(); put(metadata, FORMAT, component.format()); put(metadata, GROUP, component.group()); put(metadata, NAME, component.name()); put(metadata, VERSION, component.version()); put(metadata, ATTRIBUTES, component.attributes().backing()); String normalizedVersion = getNormalizedVersion(component); put(metadata, NORMALIZED_VERSION, normalizedVersion); put(metadata, IS_PRERELEASE_KEY, isPrerelease(component, assets)); lastBlobUpdated(assets) .ifPresent(dateTime -> put(metadata, LAST_BLOB_UPDATED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); lastDownloaded(assets) .ifPresent(dateTime -> put(metadata, LAST_DOWNLOADED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); List<Map<String, Object>> allAssetMetadata = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetMetadata = new HashMap<>(); put(assetMetadata, ID, documentId(asset)); put(assetMetadata, NAME, asset.name()); put(assetMetadata, CONTENT_TYPE, asset.contentType()); put(assetMetadata, ATTRIBUTES, asset.attributes().backing()); allAssetMetadata.add(assetMetadata); } if (!allAssetMetadata.isEmpty()) { metadata.put(ASSETS, allAssetMetadata); } for (ComponentMetadataProducerExtension componentMetadataProducerExtension : componentMetadataProducerExtensions) { metadata.putAll(componentMetadataProducerExtension.getComponentMetadata(component)); } metadata.putAll(additional); try { return JsonUtils.from(metadata); } catch (IOException e) { throw new RuntimeException(e); } }
DefaultComponentMetadataProducer implements ComponentMetadataProducer { @Override public String getMetadata(final Component component, final Iterable<Asset> assets, final Map<String, Object> additional) { checkNotNull(component); checkNotNull(assets); checkNotNull(additional); Map<String, Object> metadata = new HashMap<>(); put(metadata, FORMAT, component.format()); put(metadata, GROUP, component.group()); put(metadata, NAME, component.name()); put(metadata, VERSION, component.version()); put(metadata, ATTRIBUTES, component.attributes().backing()); String normalizedVersion = getNormalizedVersion(component); put(metadata, NORMALIZED_VERSION, normalizedVersion); put(metadata, IS_PRERELEASE_KEY, isPrerelease(component, assets)); lastBlobUpdated(assets) .ifPresent(dateTime -> put(metadata, LAST_BLOB_UPDATED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); lastDownloaded(assets) .ifPresent(dateTime -> put(metadata, LAST_DOWNLOADED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); List<Map<String, Object>> allAssetMetadata = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetMetadata = new HashMap<>(); put(assetMetadata, ID, documentId(asset)); put(assetMetadata, NAME, asset.name()); put(assetMetadata, CONTENT_TYPE, asset.contentType()); put(assetMetadata, ATTRIBUTES, asset.attributes().backing()); allAssetMetadata.add(assetMetadata); } if (!allAssetMetadata.isEmpty()) { metadata.put(ASSETS, allAssetMetadata); } for (ComponentMetadataProducerExtension componentMetadataProducerExtension : componentMetadataProducerExtensions) { metadata.putAll(componentMetadataProducerExtension.getComponentMetadata(component)); } metadata.putAll(additional); try { return JsonUtils.from(metadata); } catch (IOException e) { throw new RuntimeException(e); } } }
DefaultComponentMetadataProducer implements ComponentMetadataProducer { @Override public String getMetadata(final Component component, final Iterable<Asset> assets, final Map<String, Object> additional) { checkNotNull(component); checkNotNull(assets); checkNotNull(additional); Map<String, Object> metadata = new HashMap<>(); put(metadata, FORMAT, component.format()); put(metadata, GROUP, component.group()); put(metadata, NAME, component.name()); put(metadata, VERSION, component.version()); put(metadata, ATTRIBUTES, component.attributes().backing()); String normalizedVersion = getNormalizedVersion(component); put(metadata, NORMALIZED_VERSION, normalizedVersion); put(metadata, IS_PRERELEASE_KEY, isPrerelease(component, assets)); lastBlobUpdated(assets) .ifPresent(dateTime -> put(metadata, LAST_BLOB_UPDATED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); lastDownloaded(assets) .ifPresent(dateTime -> put(metadata, LAST_DOWNLOADED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); List<Map<String, Object>> allAssetMetadata = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetMetadata = new HashMap<>(); put(assetMetadata, ID, documentId(asset)); put(assetMetadata, NAME, asset.name()); put(assetMetadata, CONTENT_TYPE, asset.contentType()); put(assetMetadata, ATTRIBUTES, asset.attributes().backing()); allAssetMetadata.add(assetMetadata); } if (!allAssetMetadata.isEmpty()) { metadata.put(ASSETS, allAssetMetadata); } for (ComponentMetadataProducerExtension componentMetadataProducerExtension : componentMetadataProducerExtensions) { metadata.putAll(componentMetadataProducerExtension.getComponentMetadata(component)); } metadata.putAll(additional); try { return JsonUtils.from(metadata); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  DefaultComponentMetadataProducer(final Set<ComponentMetadataProducerExtension> componentMetadataProducerExtensions); }
DefaultComponentMetadataProducer implements ComponentMetadataProducer { @Override public String getMetadata(final Component component, final Iterable<Asset> assets, final Map<String, Object> additional) { checkNotNull(component); checkNotNull(assets); checkNotNull(additional); Map<String, Object> metadata = new HashMap<>(); put(metadata, FORMAT, component.format()); put(metadata, GROUP, component.group()); put(metadata, NAME, component.name()); put(metadata, VERSION, component.version()); put(metadata, ATTRIBUTES, component.attributes().backing()); String normalizedVersion = getNormalizedVersion(component); put(metadata, NORMALIZED_VERSION, normalizedVersion); put(metadata, IS_PRERELEASE_KEY, isPrerelease(component, assets)); lastBlobUpdated(assets) .ifPresent(dateTime -> put(metadata, LAST_BLOB_UPDATED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); lastDownloaded(assets) .ifPresent(dateTime -> put(metadata, LAST_DOWNLOADED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); List<Map<String, Object>> allAssetMetadata = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetMetadata = new HashMap<>(); put(assetMetadata, ID, documentId(asset)); put(assetMetadata, NAME, asset.name()); put(assetMetadata, CONTENT_TYPE, asset.contentType()); put(assetMetadata, ATTRIBUTES, asset.attributes().backing()); allAssetMetadata.add(assetMetadata); } if (!allAssetMetadata.isEmpty()) { metadata.put(ASSETS, allAssetMetadata); } for (ComponentMetadataProducerExtension componentMetadataProducerExtension : componentMetadataProducerExtensions) { metadata.putAll(componentMetadataProducerExtension.getComponentMetadata(component)); } metadata.putAll(additional); try { return JsonUtils.from(metadata); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  DefaultComponentMetadataProducer(final Set<ComponentMetadataProducerExtension> componentMetadataProducerExtensions); @Override String getMetadata(final Component component,
                            final Iterable<Asset> assets,
                            final Map<String, Object> additional); @VisibleForTesting Optional<DateTime> lastDownloaded(final Iterable<Asset> assets); @VisibleForTesting Optional<DateTime> lastBlobUpdated(final Iterable<Asset> assets); String getNormalizedVersion(Component component); }
DefaultComponentMetadataProducer implements ComponentMetadataProducer { @Override public String getMetadata(final Component component, final Iterable<Asset> assets, final Map<String, Object> additional) { checkNotNull(component); checkNotNull(assets); checkNotNull(additional); Map<String, Object> metadata = new HashMap<>(); put(metadata, FORMAT, component.format()); put(metadata, GROUP, component.group()); put(metadata, NAME, component.name()); put(metadata, VERSION, component.version()); put(metadata, ATTRIBUTES, component.attributes().backing()); String normalizedVersion = getNormalizedVersion(component); put(metadata, NORMALIZED_VERSION, normalizedVersion); put(metadata, IS_PRERELEASE_KEY, isPrerelease(component, assets)); lastBlobUpdated(assets) .ifPresent(dateTime -> put(metadata, LAST_BLOB_UPDATED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); lastDownloaded(assets) .ifPresent(dateTime -> put(metadata, LAST_DOWNLOADED_KEY, dateTime.toString(DATE_TIME_FORMATTER))); List<Map<String, Object>> allAssetMetadata = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetMetadata = new HashMap<>(); put(assetMetadata, ID, documentId(asset)); put(assetMetadata, NAME, asset.name()); put(assetMetadata, CONTENT_TYPE, asset.contentType()); put(assetMetadata, ATTRIBUTES, asset.attributes().backing()); allAssetMetadata.add(assetMetadata); } if (!allAssetMetadata.isEmpty()) { metadata.put(ASSETS, allAssetMetadata); } for (ComponentMetadataProducerExtension componentMetadataProducerExtension : componentMetadataProducerExtensions) { metadata.putAll(componentMetadataProducerExtension.getComponentMetadata(component)); } metadata.putAll(additional); try { return JsonUtils.from(metadata); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  DefaultComponentMetadataProducer(final Set<ComponentMetadataProducerExtension> componentMetadataProducerExtensions); @Override String getMetadata(final Component component,
                            final Iterable<Asset> assets,
                            final Map<String, Object> additional); @VisibleForTesting Optional<DateTime> lastDownloaded(final Iterable<Asset> assets); @VisibleForTesting Optional<DateTime> lastBlobUpdated(final Iterable<Asset> assets); String getNormalizedVersion(Component component); static final String ATTRIBUTES; static final String CONTENT_TYPE; static final String FORMAT; static final String NAME; static final String GROUP; static final String REPOSITORY_NAME; static final String VERSION; static final String NORMALIZED_VERSION; static final String ASSETS; static final String ID; static final String IS_PRERELEASE_KEY; static final String LAST_BLOB_UPDATED_KEY; static final String LAST_DOWNLOADED_KEY; static final String REGEX_KEY; }