use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class QueryOperations method populateQueryResponsePolicyMap.
private QueryResponse populateQueryResponsePolicyMap(QueryResponse queryResponse) throws FederationException {
HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryResponse.getProperties());
for (Result result : queryResponse.getResults()) {
HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
try {
PolicyResponse policyResponse = plugin.processPostQuery(result, unmodifiableProperties);
opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
} catch (StopProcessingException e) {
throw new FederationException("Query could not be executed.", e);
}
}
result.getMetacard().setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
}
queryResponse.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
return queryResponse;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class CachedResourceMetacardComparatorTest method createMetacard.
private MetacardImpl createMetacard(String metacardId, Instant createdDate, Instant effectiveDate, Instant expireDate, Instant modDate) throws Exception {
String locWkt = "POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))";
URI nsUri = new URI("http://" + CachedResourceMetacardComparatorTest.class.getName());
URI resourceUri = new URI(nsUri.toString() + "/resource1.png");
URI derivedResourceUri = new URI(nsUri.toString() + "/derived.png");
URL deriverResourceUrl = derivedResourceUri.toURL();
HashMap<String, List<String>> securityMap = new HashMap<>();
securityMap.put("key1", ImmutableList.of("value1"));
securityMap.put("key2", ImmutableList.of("value1", "value2"));
MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
metacard.setContentTypeName("testContentType");
metacard.setContentTypeVersion("testContentTypeVersion");
metacard.setCreatedDate(Date.from(createdDate));
metacard.setDescription("testDescription");
metacard.setEffectiveDate(Date.from(effectiveDate));
metacard.setExpirationDate(Date.from(expireDate));
metacard.setId(metacardId);
metacard.setLocation(locWkt);
metacard.setMetadata("testMetadata");
metacard.setModifiedDate(Date.from(modDate));
metacard.setPointOfContact("pointOfContact");
metacard.setResourceURI(resourceUri);
metacard.setSourceId("testSourceId");
metacard.setTargetNamespace(nsUri);
metacard.setThumbnail(new byte[] { 1, 2, 3, 4, 5 });
metacard.setTitle("testTitle");
metacard.setResourceSize("1");
metacard.setSecurity(securityMap);
metacard.setTags(ImmutableSet.of("tag1", "tag2"));
metacard.setAttribute(Metacard.CHECKSUM, "1");
metacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM_ALGORITHM, "sha1"));
metacard.setAttribute(new AttributeImpl(Metacard.DEFAULT_TAG, "tag1"));
metacard.setAttribute(new AttributeImpl(Metacard.DERIVED, "derivedMetacard"));
metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_DOWNLOAD_URL, deriverResourceUrl));
metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_URI, derivedResourceUri));
metacard.setAttribute(new AttributeImpl(Metacard.RELATED, "otherMetacardId"));
return metacard;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class RESTEndpoint method generateMetacard.
private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException {
Metacard generatedMetacard = null;
List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
List<String> stackTraceList = new ArrayList<>();
LOGGER.trace("Entering generateMetacard.");
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
if (null != message) {
IOUtils.copy(message, fileBackedOutputStream);
} else {
throw new MetacardCreationException("Could not copy bytes of content message. Message was NULL.");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not copy bytes of content message.", e);
}
Iterator<InputTransformer> it = listOfCandidates.iterator();
if (StringUtils.isNotEmpty(transformerId)) {
BundleContext bundleContext = getBundleContext();
Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext.getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")");
it = serviceReferences.stream().map(bundleContext::getService).iterator();
}
while (it.hasNext()) {
InputTransformer transformer = it.next();
try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
generatedMetacard = transformer.transform(inputStreamMessageCopy);
} catch (CatalogTransformerException | IOException e) {
List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer));
stackTraceList.addAll(stackTraces);
LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n")));
}
if (id != null) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
} else {
LOGGER.debug("Metacard had a null id");
}
} catch (IOException e) {
throw new MetacardCreationException("Could not create metacard.", e);
} catch (InvalidSyntaxException e) {
throw new MetacardCreationException("Could not determine transformer", e);
}
return generatedMetacard;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryObjectsWithEmptyMetadata.
@Test(expected = FederationAdminException.class)
public void testGetRegistryObjectsWithEmptyMetadata() throws Exception {
Metacard metacard = getTestMetacard();
metacard.setAttribute(new AttributeImpl(Metacard.METADATA, ""));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, metacard);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
federationAdminServiceImpl.getRegistryObjects();
verify(catalogFramework).query(any(QueryRequest.class));
verify(parser, never()).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryMetacards.
@Test
public void testGetRegistryMetacards() throws Exception {
Metacard findThisMetacard = testMetacard;
findThisMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, findThisMetacard, getTestMetacard());
when(security.getSystemSubject()).thenReturn(subject);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
List<Metacard> metacards = federationAdminServiceImpl.getRegistryMetacards();
assertThat(metacards, hasSize(2));
}
Aggregations