use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class OpenSearchSource method createResponseFromEntry.
/**
* Creates a single response from input parameters. Performs XPath operations on the document to
* retrieve data not passed in.
*
* @param entry a single Atom entry
* @return single response
* @throws ddf.catalog.source.UnsupportedQueryException
*/
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
String id = entry.getUri();
if (id != null && !id.isEmpty()) {
id = id.substring(id.lastIndexOf(':') + 1);
}
List<SyndContent> contents = entry.getContents();
List<SyndCategory> categories = entry.getCategories();
List<Metacard> metacards = new ArrayList<>();
List<Element> foreignMarkup = entry.getForeignMarkup();
String relevance = "";
String source = "";
for (Element element : foreignMarkup) {
if (element.getName().equals("score")) {
relevance = element.getContent(0).getValue();
}
}
//we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
for (SyndContent content : contents) {
MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
metacard.setSourceId(this.shortname);
String title = metacard.getTitle();
if (StringUtils.isEmpty(title)) {
metacard.setTitle(entry.getTitle());
}
if (!source.isEmpty()) {
metacard.setSourceId(source);
}
metacards.add(metacard);
}
for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
SyndCategory category = categories.get(i);
Metacard metacard = metacards.get(i);
if (StringUtils.isBlank(metacard.getContentTypeName())) {
((MetacardImpl) metacard).setContentTypeName(category.getName());
}
}
List<Result> results = new ArrayList<>();
for (Metacard metacard : metacards) {
ResultImpl result = new ResultImpl(metacard);
if (relevance == null || relevance.isEmpty()) {
LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
relevance = "0";
}
result.setRelevanceScore(new Double(relevance));
results.add(result);
}
return results;
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestOpenSearchSource method testQueryBySearchPhraseContentTypeSetRss.
@Test
public void testQueryBySearchPhraseContentTypeSetRss() throws UnsupportedQueryException, URISyntaxException, IOException {
WebClient client = mock(WebClient.class);
Response clientResponse = mock(Response.class);
when(client.get()).thenReturn(clientResponse);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(clientResponse.getEntity()).thenReturn(getSampleRssStream());
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
InputTransformer inputTransformer = mock(InputTransformer.class);
MetacardImpl generatedMetacard = new MetacardImpl();
generatedMetacard.setMetadata(getSample());
generatedMetacard.setId(SAMPLE_ID);
generatedMetacard.setContentTypeName("myType");
try {
when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
} catch (IOException e) {
fail();
} catch (CatalogTransformerException e) {
fail();
}
source.setInputTransformer(inputTransformer);
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
Filter filter = filterBuilder.attribute(Metacard.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
Assert.assertEquals(1, response.getHits());
List<Result> results = response.getResults();
Assert.assertTrue(results.size() == 1);
Result result = results.get(0);
Metacard metacard = result.getMetacard();
Assert.assertNotNull(metacard);
Assert.assertEquals("myType", metacard.getContentTypeName());
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestOpenSearchSource method testQueryBySearchPhraseContentTypeSet.
@Test
public void testQueryBySearchPhraseContentTypeSet() throws UnsupportedQueryException, URISyntaxException, IOException {
WebClient client = mock(WebClient.class);
Response clientResponse = mock(Response.class);
when(client.get()).thenReturn(clientResponse);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(clientResponse.getEntity()).thenReturn(getSampleAtomStream());
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
InputTransformer inputTransformer = mock(InputTransformer.class);
MetacardImpl generatedMetacard = new MetacardImpl();
generatedMetacard.setMetadata(getSample());
generatedMetacard.setId(SAMPLE_ID);
generatedMetacard.setContentTypeName("myType");
try {
when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
} catch (IOException e) {
fail();
} catch (CatalogTransformerException e) {
fail();
}
source.setInputTransformer(inputTransformer);
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
Filter filter = filterBuilder.attribute(Metacard.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
Assert.assertEquals(1, response.getHits());
List<Result> results = response.getResults();
Assert.assertTrue(results.size() == 1);
Result result = results.get(0);
Metacard metacard = result.getMetacard();
Assert.assertNotNull(metacard);
Assert.assertEquals("myType", metacard.getContentTypeName());
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestCswQueryResponseTransformer method createResults.
private List<Result> createResults(int start, int finish) {
List<Result> list = new LinkedList<>();
for (int i = start; i <= finish; i++) {
MetacardImpl metacard = new MetacardImpl();
metacard.setId("id_" + i);
metacard.setSourceId("source_" + i);
metacard.setTitle("title " + i);
list.add(new ResultImpl(metacard));
}
return list;
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestGmdConverter method getTestMetacard.
private MetacardImpl getTestMetacard(String wkt) {
MetacardImpl metacard = getSparseMetacard();
metacard.setAttribute(Core.CREATED, createdDate.getTime());
metacard.setAttribute(Core.MODIFIED, modifiedDate.getTime());
metacard.setAttribute(Core.RESOURCE_DOWNLOAD_URL, RESOURCE_DOWNLOAD_URL);
metacard.setAttribute(Core.DESCRIPTION, "example description");
metacard.setAttribute(Core.LOCATION, wkt);
metacard.setAttribute(Core.METADATA, "</xml>");
metacard.setAttribute(Core.RESOURCE_SIZE, "123TB");
metacard.setAttribute(Core.LANGUAGE, (Serializable) Arrays.asList("ger", "eng"));
metacard.setAttribute(Core.SOURCE_ID, "sourceID");
metacard.setAttribute(Core.TITLE, "example title");
metacard.setAttribute(Core.ID, "1234");
metacard.setAttribute(Core.METACARD_CREATED, modifiedDate.getTime());
metacard.setAttribute(Core.METACARD_MODIFIED, modifiedDate.getTime());
metacard.setAttribute(Contact.POINT_OF_CONTACT_NAME, "John Doe");
metacard.setAttribute(Contact.POINT_OF_CONTACT_EMAIL, "john.doe@example.com");
metacard.setAttribute(Contact.POINT_OF_CONTACT_PHONE, "12345");
metacard.setAttribute(Contact.POINT_OF_CONTACT_ADDRESS, "10 Downing Street London Westminster SW1A 2AA United Kingdom");
metacard.setAttribute(Contact.PUBLISHER_NAME, "Jane Doe");
metacard.setAttribute(Contact.PUBLISHER_EMAIL, "jane.doe@example.com");
metacard.setAttribute(Contact.PUBLISHER_PHONE, "6789");
metacard.setAttribute(Contact.POINT_OF_CONTACT_ADDRESS, "123 Fake Street Springfield MO 12345");
metacard.setAttribute(Location.COORDINATE_REFERENCE_SYSTEM_CODE, "EPSG:4326");
metacard.setAttribute(Location.COUNTRY_CODE, "FRA");
metacard.setAttribute(Location.ALTITUDE, 123.0);
metacard.setAttribute(DateTime.START, effectiveDate.getTime());
metacard.setAttribute(DateTime.END, effectiveDate.getTime());
metacard.setAttribute(Media.FORMAT, "gzip");
metacard.setAttribute(Media.FORMAT_VERSION, "2.0");
metacard.setAttribute(Topic.KEYWORD, "keyword");
metacard.setAttribute(Topic.CATEGORY, "category");
metacard.setAttribute(Core.RESOURCE_DOWNLOAD_URL, RESOURCE_DOWNLOAD_URL);
try {
metacard.setAttribute(Core.RESOURCE_URI, new URI(RESOURCE_URI));
} catch (URISyntaxException e) {
LOGGER.debug("URISyntaxException", e);
}
return metacard;
}
Aggregations