use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class DeleteOperations method populateDeleteRequestPolicyMap.
private DeleteRequest populateDeleteRequestPolicyMap(DeleteRequest deleteRequest, DeleteResponse deleteResponse) throws StopProcessingException {
HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(deleteRequest.getProperties());
if (deleteResponse != null && deleteResponse.getDeletedMetacards() != null) {
for (Metacard metacard : deleteResponse.getDeletedMetacards()) {
HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
PolicyResponse policyResponse = plugin.processPostDelete(metacard, unmodifiableProperties);
opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
}
metacard.setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
}
}
deleteRequest.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
return deleteRequest;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class MetacardFactory method generateMetacard.
Metacard generateMetacard(String mimeTypeRaw, String id, String fileName, Path tmpContentPath) throws MetacardCreationException, MimeTypeParseException {
Metacard generatedMetacard = null;
MimeType mimeType = new MimeType(mimeTypeRaw);
List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
List<String> stackTraceList = new ArrayList<>();
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
for (InputTransformer candidate : listOfCandidates) {
try (InputStream transformerStream = com.google.common.io.Files.asByteSource(tmpContentPath.toFile()).openStream()) {
generatedMetacard = candidate.transform(transformerStream);
} catch (CatalogTransformerException | IOException e) {
List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
stackTraceList.add(String.format("Transformer [%s] could not create metacard.", candidate));
stackTraceList.addAll(stackTraces);
LOGGER.debug("Transformer [{}] could not create metacard.", candidate, e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeTypeRaw, StringUtils.join(stackTraceList, "\n")));
}
if (id != null) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
} else {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, uuidGenerator.generateUuid()));
}
if (StringUtils.isBlank(generatedMetacard.getTitle())) {
generatedMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, fileName));
}
return generatedMetacard;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class PointOfContactUpdatePluginTest method processPreUpdateDoesNothingIfNewPOCHasAValue.
@Test
public void processPreUpdateDoesNothingIfNewPOCHasAValue() throws Exception {
listOfUpdatedMetacards.forEach(m -> m.setAttribute(new AttributeImpl(Metacard.POINT_OF_CONTACT, NEW_EMAIL)));
UpdateRequest updateRequestOutput = pointOfContactUpdatePlugin.processPreUpdate(updateRequestInput, existingMetacards);
assertThat(updateRequestOutput.getUpdates().get(0).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
assertThat(updateRequestOutput.getUpdates().get(1).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
assertThat(updateRequestOutput.getUpdates().get(2).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class PointOfContactUpdatePluginTest method getPreviousMetacardsWithPointOfContact.
private Map<String, Metacard> getPreviousMetacardsWithPointOfContact() {
Attribute pocAttribute = new AttributeImpl(Metacard.POINT_OF_CONTACT, ADMIN_EMAIL);
Metacard resourceMetacard1 = getMetacardWithIdAndTag(RESOURCE_ID1, "resource");
resourceMetacard1.setAttribute(pocAttribute);
Metacard resourceMetacard2 = getMetacardWithIdAndTag(RESOURCE_ID2, null);
resourceMetacard2.setAttribute(pocAttribute);
Metacard registryMetacard = getMetacardWithIdAndTag(REGISTRY_ID, "registry");
registryMetacard.setAttribute(pocAttribute);
Map<String, Metacard> existingMetacards = new HashMap<String, Metacard>();
existingMetacards.put(RESOURCE_ID1, resourceMetacard1);
existingMetacards.put(RESOURCE_ID2, resourceMetacard2);
existingMetacards.put(REGISTRY_ID, registryMetacard);
return existingMetacards;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class GeoCoderPlugin method setCountryCode.
/**
* Sets the country code attribute of the {@param metacard} when the {@param metacard} has a
* location and there is not already a country code attribute. Does not update the country code
* if the country code attribute is already set.
*
* @param metacard
*/
private void setCountryCode(Metacard metacard, GeoCoder geoCoder) {
Optional<String> wktLocation = Optional.ofNullable(metacard.getLocation());
if (geoCoder != null && wktLocation.isPresent() && !hasCountryCode(metacard)) {
Optional<String> alpha3CountryCode = geoCoder.getCountryCode(wktLocation.get(), radiusInKm);
alpha3CountryCode.ifPresent(countryCode -> {
LOGGER.trace("Setting metacard country code to {} for metacard with id {}", countryCode, metacard.getId());
metacard.setAttribute(new AttributeImpl(Location.COUNTRY_CODE, countryCode));
});
}
}
Aggregations