@Test public void testGetMetadata() throws IOException { FluentAsset asset = mockAsset(NAME, 1); when(component.assets()).thenReturn(ImmutableList.of(asset)); String result = underTest.getDocument(component, commonFields); JsonNode json = mapper.readTree(result); assertValue(json, SearchConstants.FORMAT, "format-id"); assertValue(json, SearchConstants.NAME, NAME); assertValue(json, SearchConstants.GROUP, GROUP); assertValue(json, SearchConstants.VERSION, VERSION); assertValue(json, SearchConstants.IS_PRERELEASE_KEY, "false"); assertThat(json.get(SearchConstants.LAST_BLOB_UPDATED_KEY), equalTo(null)); assertThat(json.get(SearchConstants.LAST_DOWNLOADED_KEY), equalTo(null)); assertValue(json, "foo", "bar"); JsonNode jsonAssets = json.get(SearchConstants.ASSETS); assertTrue(jsonAssets.isArray()); assertThat(jsonAssets.size(), equalTo(1)); JsonNode jsonAsset = jsonAssets.get(0); assertValue(jsonAsset, SearchConstants.NAME, NAME); verify(searchDocumentExtension).getFields(any(FluentComponent.class)); }
@Override public String getDocument(final FluentComponent component, final Map<String, Object> commonFields) { checkNotNull(component); checkNotNull(commonFields); Map<String, Object> componentDoc = new HashMap<>(); componentDoc.put(GROUP, component.namespace()); componentDoc.put(NAME, component.name()); componentDoc.put(VERSION, component.version()); componentDoc.put(ATTRIBUTES, component.attributes().backing()); componentDoc.put(NORMALIZED_VERSION, getNormalizedVersion(component)); componentDoc.put(IS_PRERELEASE_KEY, isPrerelease(component)); Collection<FluentAsset> assets = component.assets(); lastBlobUpdated(assets).ifPresent(dateTime -> componentDoc.put(LAST_BLOB_UPDATED_KEY, format(dateTime))); lastDownloaded(assets).ifPresent(dateTime -> componentDoc.put(LAST_DOWNLOADED_KEY, format(dateTime))); List<Map<String, Object>> assetDocs = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetDoc = new HashMap<>(); assetDoc.put(ID, internalAssetId(asset)); assetDoc.put(NAME, asset.path()); Map<String, Object> attributes = new HashMap<>(asset.attributes().backing()); assetDoc.put(CONTENT_TYPE, ""); asset.blob().ifPresent(blob -> { assetDoc.put(CONTENT_TYPE, blob.contentType()); attributes.put("checksum", blob.checksums()); }); assetDoc.put(ATTRIBUTES, attributes); assetDocs.add(assetDoc); } if (!assetDocs.isEmpty()) { componentDoc.put(ASSETS, assetDocs); } for (SearchDocumentExtension extension : documentExtensions) { componentDoc.putAll(extension.getFields(component)); } componentDoc.putAll(commonFields); try { return WRITER.writeValueAsString(componentDoc); } catch (IOException e) { throw new UncheckedIOException(e); } }
DefaultSearchDocumentProducer extends ComponentSupport implements SearchDocumentProducer { @Override public String getDocument(final FluentComponent component, final Map<String, Object> commonFields) { checkNotNull(component); checkNotNull(commonFields); Map<String, Object> componentDoc = new HashMap<>(); componentDoc.put(GROUP, component.namespace()); componentDoc.put(NAME, component.name()); componentDoc.put(VERSION, component.version()); componentDoc.put(ATTRIBUTES, component.attributes().backing()); componentDoc.put(NORMALIZED_VERSION, getNormalizedVersion(component)); componentDoc.put(IS_PRERELEASE_KEY, isPrerelease(component)); Collection<FluentAsset> assets = component.assets(); lastBlobUpdated(assets).ifPresent(dateTime -> componentDoc.put(LAST_BLOB_UPDATED_KEY, format(dateTime))); lastDownloaded(assets).ifPresent(dateTime -> componentDoc.put(LAST_DOWNLOADED_KEY, format(dateTime))); List<Map<String, Object>> assetDocs = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetDoc = new HashMap<>(); assetDoc.put(ID, internalAssetId(asset)); assetDoc.put(NAME, asset.path()); Map<String, Object> attributes = new HashMap<>(asset.attributes().backing()); assetDoc.put(CONTENT_TYPE, ""); asset.blob().ifPresent(blob -> { assetDoc.put(CONTENT_TYPE, blob.contentType()); attributes.put("checksum", blob.checksums()); }); assetDoc.put(ATTRIBUTES, attributes); assetDocs.add(assetDoc); } if (!assetDocs.isEmpty()) { componentDoc.put(ASSETS, assetDocs); } for (SearchDocumentExtension extension : documentExtensions) { componentDoc.putAll(extension.getFields(component)); } componentDoc.putAll(commonFields); try { return WRITER.writeValueAsString(componentDoc); } catch (IOException e) { throw new UncheckedIOException(e); } } }
DefaultSearchDocumentProducer extends ComponentSupport implements SearchDocumentProducer { @Override public String getDocument(final FluentComponent component, final Map<String, Object> commonFields) { checkNotNull(component); checkNotNull(commonFields); Map<String, Object> componentDoc = new HashMap<>(); componentDoc.put(GROUP, component.namespace()); componentDoc.put(NAME, component.name()); componentDoc.put(VERSION, component.version()); componentDoc.put(ATTRIBUTES, component.attributes().backing()); componentDoc.put(NORMALIZED_VERSION, getNormalizedVersion(component)); componentDoc.put(IS_PRERELEASE_KEY, isPrerelease(component)); Collection<FluentAsset> assets = component.assets(); lastBlobUpdated(assets).ifPresent(dateTime -> componentDoc.put(LAST_BLOB_UPDATED_KEY, format(dateTime))); lastDownloaded(assets).ifPresent(dateTime -> componentDoc.put(LAST_DOWNLOADED_KEY, format(dateTime))); List<Map<String, Object>> assetDocs = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetDoc = new HashMap<>(); assetDoc.put(ID, internalAssetId(asset)); assetDoc.put(NAME, asset.path()); Map<String, Object> attributes = new HashMap<>(asset.attributes().backing()); assetDoc.put(CONTENT_TYPE, ""); asset.blob().ifPresent(blob -> { assetDoc.put(CONTENT_TYPE, blob.contentType()); attributes.put("checksum", blob.checksums()); }); assetDoc.put(ATTRIBUTES, attributes); assetDocs.add(assetDoc); } if (!assetDocs.isEmpty()) { componentDoc.put(ASSETS, assetDocs); } for (SearchDocumentExtension extension : documentExtensions) { componentDoc.putAll(extension.getFields(component)); } componentDoc.putAll(commonFields); try { return WRITER.writeValueAsString(componentDoc); } catch (IOException e) { throw new UncheckedIOException(e); } } @Inject  DefaultSearchDocumentProducer(final Set<SearchDocumentExtension> documentExtensions); }
DefaultSearchDocumentProducer extends ComponentSupport implements SearchDocumentProducer { @Override public String getDocument(final FluentComponent component, final Map<String, Object> commonFields) { checkNotNull(component); checkNotNull(commonFields); Map<String, Object> componentDoc = new HashMap<>(); componentDoc.put(GROUP, component.namespace()); componentDoc.put(NAME, component.name()); componentDoc.put(VERSION, component.version()); componentDoc.put(ATTRIBUTES, component.attributes().backing()); componentDoc.put(NORMALIZED_VERSION, getNormalizedVersion(component)); componentDoc.put(IS_PRERELEASE_KEY, isPrerelease(component)); Collection<FluentAsset> assets = component.assets(); lastBlobUpdated(assets).ifPresent(dateTime -> componentDoc.put(LAST_BLOB_UPDATED_KEY, format(dateTime))); lastDownloaded(assets).ifPresent(dateTime -> componentDoc.put(LAST_DOWNLOADED_KEY, format(dateTime))); List<Map<String, Object>> assetDocs = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetDoc = new HashMap<>(); assetDoc.put(ID, internalAssetId(asset)); assetDoc.put(NAME, asset.path()); Map<String, Object> attributes = new HashMap<>(asset.attributes().backing()); assetDoc.put(CONTENT_TYPE, ""); asset.blob().ifPresent(blob -> { assetDoc.put(CONTENT_TYPE, blob.contentType()); attributes.put("checksum", blob.checksums()); }); assetDoc.put(ATTRIBUTES, attributes); assetDocs.add(assetDoc); } if (!assetDocs.isEmpty()) { componentDoc.put(ASSETS, assetDocs); } for (SearchDocumentExtension extension : documentExtensions) { componentDoc.putAll(extension.getFields(component)); } componentDoc.putAll(commonFields); try { return WRITER.writeValueAsString(componentDoc); } catch (IOException e) { throw new UncheckedIOException(e); } } @Inject  DefaultSearchDocumentProducer(final Set<SearchDocumentExtension> documentExtensions); @Override String getDocument(final FluentComponent component, final Map<String, Object> commonFields); }
DefaultSearchDocumentProducer extends ComponentSupport implements SearchDocumentProducer { @Override public String getDocument(final FluentComponent component, final Map<String, Object> commonFields) { checkNotNull(component); checkNotNull(commonFields); Map<String, Object> componentDoc = new HashMap<>(); componentDoc.put(GROUP, component.namespace()); componentDoc.put(NAME, component.name()); componentDoc.put(VERSION, component.version()); componentDoc.put(ATTRIBUTES, component.attributes().backing()); componentDoc.put(NORMALIZED_VERSION, getNormalizedVersion(component)); componentDoc.put(IS_PRERELEASE_KEY, isPrerelease(component)); Collection<FluentAsset> assets = component.assets(); lastBlobUpdated(assets).ifPresent(dateTime -> componentDoc.put(LAST_BLOB_UPDATED_KEY, format(dateTime))); lastDownloaded(assets).ifPresent(dateTime -> componentDoc.put(LAST_DOWNLOADED_KEY, format(dateTime))); List<Map<String, Object>> assetDocs = new ArrayList<>(); for (Asset asset : assets) { Map<String, Object> assetDoc = new HashMap<>(); assetDoc.put(ID, internalAssetId(asset)); assetDoc.put(NAME, asset.path()); Map<String, Object> attributes = new HashMap<>(asset.attributes().backing()); assetDoc.put(CONTENT_TYPE, ""); asset.blob().ifPresent(blob -> { assetDoc.put(CONTENT_TYPE, blob.contentType()); attributes.put("checksum", blob.checksums()); }); assetDoc.put(ATTRIBUTES, attributes); assetDocs.add(assetDoc); } if (!assetDocs.isEmpty()) { componentDoc.put(ASSETS, assetDocs); } for (SearchDocumentExtension extension : documentExtensions) { componentDoc.putAll(extension.getFields(component)); } componentDoc.putAll(commonFields); try { return WRITER.writeValueAsString(componentDoc); } catch (IOException e) { throw new UncheckedIOException(e); } } @Inject  DefaultSearchDocumentProducer(final Set<SearchDocumentExtension> documentExtensions); @Override String getDocument(final FluentComponent component, final Map<String, Object> commonFields);  }