Search in sources :

Example 71 with ResultImpl

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

the class RegistryIdPostIngestPluginTest method testInit.

@Test
public void testInit() throws Exception {
    Metacard metacard = getDefaultMetacard();
    QueryResponseImpl response = new QueryResponseImpl(null, Collections.singletonList(new ResultImpl(metacard)), 1L);
    when(security.runAsAdminWithException(any(PrivilegedExceptionAction.class))).thenAnswer(invocation -> ((PrivilegedExceptionAction) invocation.getArguments()[0]).run());
    when(security.runWithSubjectOrElevate(any(Callable.class))).thenAnswer(invocation -> ((Callable) invocation.getArguments()[0]).call());
    when(framework.query(any(QueryRequest.class))).thenReturn(response);
    registryIdPostIngestPlugin.init();
    assertThat(registryIdPostIngestPlugin.getRegistryIds().size(), equalTo(1));
    assertThat(registryIdPostIngestPlugin.getRegistryIds().iterator().next(), equalTo("regId"));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 72 with ResultImpl

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

the class RegistryPolicyPluginTest method testWhiteListPostQuery.

@Test
public void testWhiteListPostQuery() throws Exception {
    Metacard mcard = new MetacardImpl();
    mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
    mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    rpp.setWhiteList(true);
    rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
    PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.operationPolicy().size(), is(0));
    assertThat(response.itemPolicy(), equalTo(rpp.getBypassAccessPolicy()));
    rpp.setRegistryEntryIds(Collections.singleton("1234567890abcdefg987654321"));
    response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.itemPolicy().size(), is(0));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 73 with ResultImpl

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

the class RegistryPolicyPluginTest method testNonRegistryMcardTypes.

@Test
public void testNonRegistryMcardTypes() throws Exception {
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
    Metacard mcard = new MetacardImpl();
    mcard.setAttribute(new AttributeImpl(Metacard.TAGS, "some.type"));
    mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
    PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.itemPolicy().isEmpty(), is(true));
    response = rpp.processPreCreate(mcard, null);
    assertThat(response.operationPolicy().isEmpty(), is(true));
    response = rpp.processPreUpdate(mcard, null);
    assertThat(response.operationPolicy().isEmpty(), is(true));
    response = rpp.processPreDelete(Collections.singletonList(mcard), null);
    assertThat(response.operationPolicy().isEmpty(), is(true));
    Metacard mcard2 = new MetacardImpl();
    mcard2.setAttribute(new AttributeImpl(Metacard.ID, "abcdefghijklmnop1234567890"));
    response = rpp.processPostQuery(new ResultImpl(mcard2), null);
    assertThat(response.itemPolicy().isEmpty(), is(true));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 74 with ResultImpl

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

the class SolrMetacardClientImpl method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    if (request == null || request.getQuery() == null) {
        return new QueryResponseImpl(request, new ArrayList<Result>(), true, 0L);
    }
    SolrQuery query = getSolrQuery(request, filterDelegateFactory.newInstance(resolver));
    long totalHits;
    List<Result> results = new ArrayList<>();
    try {
        QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
        totalHits = solrResponse.getResults().getNumFound();
        SolrDocumentList docs = solrResponse.getResults();
        for (SolrDocument doc : docs) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("SOLR DOC: {}", doc.getFieldValue(Metacard.ID + SchemaFields.TEXT_SUFFIX));
            }
            ResultImpl tmpResult;
            try {
                tmpResult = createResult(doc);
            } catch (MetacardCreationException e) {
                throw new UnsupportedQueryException("Could not create metacard(s).", e);
            }
            results.add(tmpResult);
        }
    } catch (SolrServerException | IOException | SolrException e) {
        throw new UnsupportedQueryException("Could not complete solr query.", e);
    }
    SourceResponse sourceResponse = new SourceResponseImpl(request, results, totalHits);
    return sourceResponse;
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrException(org.apache.solr.common.SolrException)

Example 75 with ResultImpl

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

the class Jpeg2000ThumbnailConverterTest method testConversion.

@Test
public void testConversion() throws IOException, StopProcessingException, PluginExecutionException {
    IIORegistry.getDefaultInstance().registerServiceProvider(jpeg2000ThumbnailConverter);
    List<Result> resultList = new ArrayList<>();
    Metacard metacard = new MetacardImpl();
    byte[] j2kbytes = new byte[0];
    resultList.add(new ResultImpl(metacard));
    QueryResponseImpl queryResponse = new QueryResponseImpl(null, resultList, 1);
    // there are two possible byte signatures, so test an example of each one
    for (String image : new String[] { "/Bretagne2.j2k", "/Cevennes2.jp2" }) {
        URL imageResource = Jpeg2000ThumbnailConverterTest.class.getResource(image);
        if (imageResource == null) {
            fail("The Image Resource came back null. Was the resources folder removed?");
        }
        String imageResourcePath = new File(imageResource.getFile()).getAbsolutePath();
        j2kbytes = Files.readAllBytes(Paths.get(imageResourcePath));
        metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, j2kbytes));
        jpeg2000ThumbnailConverter.process(queryResponse);
        // verify the plugin converted the j2k/jp2 image
        assertTrue(!Arrays.equals(j2kbytes, metacard.getThumbnail()));
    }
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ImageIO.write(ImageIO.read(new ByteArrayInputStream(j2kbytes)), "gif", output);
    metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, output.toByteArray()));
    jpeg2000ThumbnailConverter.process(queryResponse);
    // verify the plugin ignored  the non-j2k
    assertTrue(Arrays.equals(output.toByteArray(), metacard.getThumbnail()));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) URL(java.net.URL) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) 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