use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class QueryOperations method injectAttributes.
private QueryResponse injectAttributes(QueryResponse response) {
List<Result> results = response.getResults().stream().map(result -> {
Metacard original = result.getMetacard();
Metacard metacard = opsMetacardSupport.applyInjectors(original, frameworkProperties.getAttributeInjectors());
ResultImpl newResult = new ResultImpl(metacard);
newResult.setDistanceInMeters(result.getDistanceInMeters());
newResult.setRelevanceScore(result.getRelevanceScore());
return newResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(response.getRequest(), results, true, response.getHits(), response.getProperties());
queryResponse.setProcessingDetails(response.getProcessingDetails());
return queryResponse;
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class FilterPluginTest method setup.
@Before
public void setup() {
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return "testuser";
}
}, realm.getName());
Subject systemSubject = new MockSubject(manager, principalCollection);
plugin = new FilterPlugin() {
@Override
protected Subject getSystemSubject() {
return systemSubject;
}
};
QueryRequestImpl request = getSampleRequest();
Map<String, Serializable> properties = new HashMap<>();
Subject subject = new MockSubject(manager, principalCollection);
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
request.setProperties(properties);
incomingResponse = new QueryResponseImpl(request);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
when(resourceRequest.getProperties()).thenReturn(properties);
resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
resourceResponse.setProperties(properties);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
when(deleteRequest.getProperties()).thenReturn(properties);
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(getExactRolesMetacard());
deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
List<Metacard> badDeletedMetacards = new ArrayList<>();
badDeletedMetacards.add(getMoreRolesMetacard());
badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
createRequest = new CreateRequestImpl(getExactRolesMetacard());
createRequest.setProperties(properties);
badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
badCreateRequest.setProperties(properties);
updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
updateRequest.setProperties(properties);
ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
incomingResponse.addResult(result1, false);
incomingResponse.addResult(result2, false);
incomingResponse.addResult(result3, false);
incomingResponse.addResult(result4, false);
incomingResponse.addResult(result5, true);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class PointOfContactPolicyPluginTest method processPostQueryDoesNothing.
@Test
public void processPostQueryDoesNothing() throws java.lang.Exception {
PolicyResponse response = pointOfContactPolicyPlugin.processPostQuery(new ResultImpl(), Collections.emptyMap());
responseIsEmpty(response);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestCswEndpoint method testPostGetRecordById.
@Test
public void testPostGetRecordById() throws CswException, FederationException, SourceUnavailableException, UnsupportedQueryException {
final GetRecordByIdType getRecordByIdType = new GetRecordByIdType();
getRecordByIdType.setId(Collections.singletonList("123,456"));
getRecordByIdType.setOutputFormat(MediaType.APPLICATION_XML);
getRecordByIdType.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
final Metacard metacard1 = new MetacardImpl();
final Metacard metacard2 = new MetacardImpl();
final List<Result> mockResults = Arrays.asList(new ResultImpl(metacard1), new ResultImpl(metacard2));
final QueryResponse queryResponse = new QueryResponseImpl(null, mockResults, mockResults.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
final CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, null);
verifyCswRecordCollection(cswRecordCollection, metacard1, metacard2);
// "summary" is the default if none is specified in the request.
assertThat(cswRecordCollection.getElementSetType(), is(ElementSetType.SUMMARY));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestXmlResponseQueueTransformer method testXmlResponseQueueTransformer.
@Test
public void testXmlResponseQueueTransformer() throws Exception {
MetacardImpl mc = new MetacardImpl();
final String testId = "1234567890987654321";
final String testSource = "FooBarSource";
final String testTitle = "Title!";
final Date testDate = new Date();
final String testLocation = "POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),(20 30, 35 35, 30 20, 20 30))";
final byte[] testThumbnail = { 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1 };
mc.setId(testId);
mc.setSourceId(testSource);
mc.setTitle(testTitle);
mc.setExpirationDate(testDate);
mc.setLocation(testLocation);
mc.setThumbnail(testThumbnail);
String metadata;
try (FileInputStream stream = new FileInputStream(new File("src/test/resources/extensibleMetacard.xml"))) {
FileChannel fc = stream.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
/* Instead of using default, pass in a decoder. */
metadata = Charset.defaultCharset().decode(bb).toString();
}
mc.setMetadata(metadata);
Metacard mci = mc;
transformer.setThreshold(2);
SourceResponse response = new SourceResponseImpl(null, Arrays.asList((Result) new ResultImpl(mci)));
BinaryContent bc = transformer.transform(response, null);
if (bc == null) {
fail("Binary Content is null.");
}
String outputXml = new String(bc.getByteArray());
LOGGER.debug(outputXml);
assertXpathEvaluatesTo(testId, "/mc:metacards/mc:metacard/@gml:id", outputXml);
assertXpathEvaluatesTo(testSource, "/mc:metacards/mc:metacard/mc:source", outputXml);
assertXpathEvaluatesTo(testTitle, "/mc:metacards/mc:metacard/mc:string[@name='title']/mc:value", outputXml);
// TODO convert GML representation?
// outputXml);
assertXpathExists("/mc:metacards/mc:metacard/mc:geometry[@name='location']/mc:value", outputXml);
assertXpathExists("/mc:metacards/mc:metacard/mc:base64Binary[@name='thumbnail']/mc:value", outputXml);
// TODO XML Date representation?
assertXpathExists("/mc:metacards/mc:metacard/mc:dateTime[@name='expiration']/mc:value", outputXml);
}
Aggregations