Search in sources :

Example 31 with ResultImpl

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

the class TestDuplicationValidator method setup.

@Before
public void setup() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    QueryResponse response = mock(QueryResponse.class);
    when(mockFramework.query(any(QueryRequest.class))).thenReturn(response);
    testMetacard = new MetacardImpl();
    matchingMetacard = new MetacardImpl();
    matchingMetacard.setId(ID);
    testMetacard.setId("test metacard ID");
    matchingMetacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM, "checksum-value"));
    testMetacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM, "checksum-value"));
    matchingMetacard.setTags(tags);
    testMetacard.setTags(tags);
    List<Result> results = Arrays.asList(new ResultImpl(matchingMetacard));
    when(response.getResults()).thenReturn(results);
    validator = new DuplicationValidator(mockFramework, mockFilterBuilder);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Before(org.junit.Before)

Example 32 with ResultImpl

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

the class FilterPlugin method processPostQuery.

@Override
public QueryResponse processPostQuery(QueryResponse input) throws StopProcessingException {
    if (input.getRequest() == null || input.getRequest().getProperties() == null) {
        throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
    }
    Subject subject = getSubject(input);
    List<Result> results = input.getResults();
    List<Result> newResults = new ArrayList<>(results.size());
    Metacard metacard;
    KeyValueCollectionPermission securityPermission = new KeyValueCollectionPermission(CollectionPermission.READ_ACTION);
    int filteredMetacards = 0;
    for (Result result : results) {
        metacard = result.getMetacard();
        Attribute attr = metacard.getAttribute(Metacard.SECURITY);
        if (!checkPermissions(attr, securityPermission, subject, CollectionPermission.READ_ACTION)) {
            for (FilterStrategy filterStrategy : filterStrategies.values()) {
                FilterResult filterResult = filterStrategy.process(input, metacard);
                if (filterResult.processed()) {
                    if (filterResult.metacard() != null) {
                        newResults.add(new ResultImpl(filterResult.metacard()));
                    }
                    break;
                //returned responses are ignored for queries
                }
            }
            filteredMetacards++;
        } else {
            newResults.add(result);
        }
    }
    if (filteredMetacards > 0) {
        SecurityLogger.audit("Filtered " + filteredMetacards + " metacards, returned " + newResults.size(), subject);
    }
    input.getResults().clear();
    input.getResults().addAll(newResults);
    newResults.clear();
    return input;
}
Also used : Metacard(ddf.catalog.data.Metacard) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Attribute(ddf.catalog.data.Attribute) ArrayList(java.util.ArrayList) FilterStrategy(ddf.catalog.security.FilterStrategy) ResultImpl(ddf.catalog.data.impl.ResultImpl) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FilterResult(ddf.catalog.security.FilterResult) Subject(org.apache.shiro.subject.Subject) FilterResult(ddf.catalog.security.FilterResult) Result(ddf.catalog.data.Result)

Example 33 with ResultImpl

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

the class QueryOperations method replaceSourceId.

/**
     * Replaces the site name(s) of {@link FederatedSource}s in the {@link QueryResponse} with the
     * fanout's site name to keep info about the {@link FederatedSource}s hidden from the external
     * client.
     *
     * @param queryResponse the original {@link QueryResponse} from the query request
     * @return the updated {@link QueryResponse} with all site names replaced with fanout's site
     * name
     */
public QueryResponse replaceSourceId(QueryResponse queryResponse) {
    LOGGER.trace("ENTERING: replaceSourceId()");
    List<Result> results = queryResponse.getResults();
    QueryResponseImpl newResponse = new QueryResponseImpl(queryResponse.getRequest(), queryResponse.getProperties());
    for (Result result : results) {
        MetacardImpl newMetacard = new MetacardImpl(result.getMetacard());
        newMetacard.setSourceId(this.getId());
        ResultImpl newResult = new ResultImpl(newMetacard);
        // Copy over scores
        newResult.setDistanceInMeters(result.getDistanceInMeters());
        newResult.setRelevanceScore(result.getRelevanceScore());
        newResponse.addResult(newResult, false);
    }
    newResponse.setHits(queryResponse.getHits());
    newResponse.closeResultQueue();
    LOGGER.trace("EXITING: replaceSourceId()");
    return newResponse;
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 34 with ResultImpl

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

the class DistanceResultComparatorTest method setUp.

@Before
public void setUp() throws Exception {
    shortDistance = new ResultImpl();
    shortDistance.setDistanceInMeters(new Double(Short.MAX_VALUE));
    longDistance = new ResultImpl();
    longDistance.setDistanceInMeters(new Double(Long.MAX_VALUE));
    negativeDistance = new ResultImpl();
    negativeDistance.setDistanceInMeters(new Double(Short.MIN_VALUE));
    nullDistance = new ResultImpl();
    nullDistance.setDistanceInMeters(null);
    zeroDistance = new ResultImpl();
    zeroDistance.setDistanceInMeters(0.0);
    nullResult = null;
}
Also used : ResultImpl(ddf.catalog.data.impl.ResultImpl) Before(org.junit.Before)

Example 35 with ResultImpl

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

the class FanoutCatalogFrameworkTest method testReplaceDistance.

@Test
public void testReplaceDistance() {
    QueryRequest request = new QueryRequestImpl(null);
    List<Result> results = new ArrayList<Result>();
    MetacardImpl newCard1 = new MetacardImpl();
    ResultImpl result1 = new ResultImpl(newCard1);
    result1.setRelevanceScore(RELEVANCE_SCORE);
    result1.setDistanceInMeters(DISTANCE_SCORE);
    MetacardImpl newCard2 = new MetacardImpl();
    ResultImpl result2 = new ResultImpl(newCard2);
    result2.setRelevanceScore(RELEVANCE_SCORE);
    result2.setDistanceInMeters(DISTANCE_SCORE);
    results.add(result1);
    results.add(result2);
    QueryResponse response = new QueryResponseImpl(request, results, 2);
    QueryResponse newResponse = framework.getQueryOperations().replaceSourceId(response);
    assertNotNull(newResponse);
    List<Result> newResults = newResponse.getResults();
    assertNotNull(newResults);
    assertEquals(2, newResults.size());
    Metacard card = new MetacardImpl();
    // Make sure the relevance and distance score was copied over
    for (Result newResult : newResults) {
        card = newResult.getMetacard();
        assertNotNull(card);
        assertEquals(RELEVANCE_SCORE, newResult.getRelevanceScore());
        assertEquals(DISTANCE_SCORE, newResult.getDistanceInMeters());
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)114 Result (ddf.catalog.data.Result)74 Test (org.junit.Test)73 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)61 Metacard (ddf.catalog.data.Metacard)47 ArrayList (java.util.ArrayList)45 QueryRequest (ddf.catalog.operation.QueryRequest)33 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)23 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)21 QueryResponse (ddf.catalog.operation.QueryResponse)20 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Product (org.codice.alliance.nsili.common.UID.Product)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7