Search in sources :

Example 81 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestAtomTransformer method testNoCreatedDate.

@Test
public void testNoCreatedDate() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    AtomTransformer transformer = new AtomTransformer();
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getHits()).thenReturn(new Long(1));
    when(response.getRequest()).thenReturn(getStubRequest());
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setCreatedDate(null);
    result1.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
    result1.setRelevanceScore(0.3345);
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    assertXpathNotExists("atom:feed/atom:entry/atom:published", output);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 82 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestAtomTransformer method testNoModifiedDate.

@Test
public void testNoModifiedDate() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    AtomTransformer transformer = new AtomTransformer();
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getHits()).thenReturn(new Long(1));
    when(response.getRequest()).thenReturn(getStubRequest());
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setModifiedDate(null);
    result1.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
    result1.setRelevanceScore(0.3345);
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    assertXpathExists("atom:feed/atom:entry/atom:updated", output);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 83 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestAtomTransformer method testItemsPerPageNegativeInteger.

@Test
public void testItemsPerPageNegativeInteger() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    AtomTransformer transformer = new AtomTransformer();
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getHits()).thenReturn(new Long(1));
    QueryImpl query = new QueryImpl(FILTER_BUILDER.attribute(Metacard.METADATA).text("you"));
    query.setPageSize(-1);
    query.setStartIndex(2);
    query.setRequestsTotalResultsCount(true);
    QueryRequestImpl queryRequestImpl = new QueryRequestImpl(query);
    when(response.getRequest()).thenReturn(queryRequestImpl);
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    result1.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    assertXpathEvaluatesTo("1", "/atom:feed/os:itemsPerPage", output);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 84 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TwitterSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    Twitter instance = twitterFactory.getInstance();
    try {
        instance.getOAuth2Token();
    } catch (TwitterException e) {
        throw new UnsupportedQueryException("Unable to get OAuth2 token.", e);
    }
    TwitterFilterVisitor visitor = new TwitterFilterVisitor();
    request.getQuery().accept(visitor, null);
    Query query = new Query();
    query.setCount(request.getQuery().getPageSize());
    if (visitor.hasSpatial()) {
        GeoLocation geoLocation = new GeoLocation(visitor.getLatitude(), visitor.getLongitude());
        query.setGeoCode(geoLocation, visitor.getRadius(), Query.Unit.km);
    }
    if (visitor.getContextualSearch() != null) {
        query.setQuery(visitor.getContextualSearch().getSearchPhrase());
    }
    if (visitor.getTemporalSearch() != null) {
        Calendar.Builder builder = new Calendar.Builder();
        builder.setInstant(visitor.getTemporalSearch().getStartDate());
        Calendar calendar = builder.build();
        query.setSince(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH));
        builder = new Calendar.Builder();
        builder.setInstant(visitor.getTemporalSearch().getEndDate());
        calendar = builder.build();
        query.setUntil(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH));
    }
    QueryResult queryResult;
    try {
        queryResult = instance.search().search(query);
    } catch (TwitterException e) {
        throw new UnsupportedQueryException(e);
    }
    List<Result> resultList = new ArrayList<>(queryResult.getCount());
    resultList.addAll(queryResult.getTweets().stream().map(status -> new ResultImpl(getMetacard(status))).collect(Collectors.toList()));
    return new SourceResponseImpl(request, resultList);
}
Also used : Query(twitter4j.Query) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) ResultImpl(ddf.catalog.data.impl.ResultImpl) QueryResult(twitter4j.QueryResult) Result(ddf.catalog.data.Result) QueryResult(twitter4j.QueryResult) GeoLocation(twitter4j.GeoLocation) TwitterException(twitter4j.TwitterException)

Example 85 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class CommandCatalogFrameworkCommon method getResultList.

protected List<Result> getResultList(String... ids) {
    List<Result> results = new ArrayList<>();
    for (int i = 0; i < ids.length; i++) {
        String id = ids[i];
        MetacardImpl metacard = new MetacardImpl();
        metacard.setAttribute(new AttributeImpl(Core.CREATED, new DateTime(2010 + i, 3, 11, 14, 3).toDate()));
        metacard.setId(id);
        Result result = new ResultImpl(metacard);
        results.add(result);
    }
    return results;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)91 Result (ddf.catalog.data.Result)59 Test (org.junit.Test)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)47 Metacard (ddf.catalog.data.Metacard)46 ArrayList (java.util.ArrayList)35 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryRequest (ddf.catalog.operation.QueryRequest)28 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)18 QueryResponse (ddf.catalog.operation.QueryResponse)15 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)12 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7 File (java.io.File)7 Before (org.junit.Before)7