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);
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations