Search in sources :

Example 86 with ResultImpl

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;
}
Also used : ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) SecurityLogger(ddf.security.common.audit.SecurityLogger) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) Map(java.util.Map) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) FederatedSource(ddf.catalog.source.FederatedSource) ResultImpl(ddf.catalog.data.impl.ResultImpl) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Operation(ddf.catalog.operation.Operation) PreAuthorizationPlugin(ddf.catalog.plugin.PreAuthorizationPlugin) AccessPlugin(ddf.catalog.plugin.AccessPlugin) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FederationStrategy(ddf.catalog.federation.FederationStrategy) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) FilterAdapter(ddf.catalog.filter.FilterAdapter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Source(ddf.catalog.source.Source) Requests(ddf.catalog.util.impl.Requests) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ConnectedSource(ddf.catalog.source.ConnectedSource) SecurityConstants(ddf.security.SecurityConstants) QueryRequest(ddf.catalog.operation.QueryRequest) Request(ddf.catalog.operation.Request) Result(ddf.catalog.data.Result) DescribableImpl(ddf.catalog.util.impl.DescribableImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) CollectionPermission(ddf.security.permission.CollectionPermission) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(ddf.security.Subject) FederationException(ddf.catalog.federation.FederationException) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) Query(ddf.catalog.operation.Query) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Filter(org.opengis.filter.Filter) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Collections(java.util.Collections) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 87 with ResultImpl

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);
}
Also used : Serializable(java.io.Serializable) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) CollectionPermission(ddf.security.permission.CollectionPermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) Subject(ddf.security.Subject) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Principal(java.security.Principal) Before(org.junit.Before)

Example 88 with ResultImpl

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);
}
Also used : ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 89 with ResultImpl

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 90 with ResultImpl

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);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FileChannel(java.nio.channels.FileChannel) ResultImpl(ddf.catalog.data.impl.ResultImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) FileInputStream(java.io.FileInputStream) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) MappedByteBuffer(java.nio.MappedByteBuffer) File(java.io.File) Test(org.junit.Test)

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