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