use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class ExpirationDatePlugin method updateExpirationDate.
/**
* Updates a metacard's expiration date.
*
* @param metacard
* the metacard to update.
*/
private void updateExpirationDate(Metacard metacard) {
Date currentExpirationDate = metacard.getExpirationDate();
if (currentExpirationDate == null && !overwriteIfBlank) {
// Don't overwrite empty expiration date if configuration disallows
LOGGER.debug("The Expiration Date Pre-Ingest Plugin is not configured to overwrite 'empty' expiration dates. Not overwriting null expiration date for metacard ID [{}]. ", metacard.getId());
return;
} else if (currentExpirationDate != null && !overwriteIfExists) {
// Don't overwrite existing expiration date if configuration disallows
LOGGER.debug("The Expiration Date Pre-Ingest Plugin is not configured to overwrite 'existing' expiration dates. Not overwriting the existing expiration date of {} for metacard ID [{}]. ", currentExpirationDate, metacard.getId());
return;
}
Date metacardCreatedDate = getMetacardCreatedDate(metacard);
Date newExpirationDate = calculateNewExpirationDate(metacardCreatedDate);
LOGGER.debug("Metacard ID [{}] has an expiration date of {}. Calculating new expiration date by adding {} day(s) to the created date of {}. The new expiration date is {}.", metacard.getId(), currentExpirationDate, this.offsetFromCreatedDate, metacardCreatedDate, newExpirationDate);
Attribute expirationDate = new AttributeImpl(Metacard.EXPIRATION, newExpirationDate);
metacard.setAttribute(expirationDate);
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class RegistryTransformerTest method testMetacardToXmlBadTag.
@Test(expected = CatalogTransformerException.class)
public void testMetacardToXmlBadTag() throws Exception {
String in = IOUtils.toString(getClass().getResourceAsStream("/csw-rim-node.xml"));
Metacard metacard = registryTransformer.transform(IOUtils.toInputStream(in));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "JustSomeMadeUpStuff"));
String out = IOUtils.toString(registryTransformer.transform(metacard, null).getInputStream());
assertThat(in, is(out));
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdmin method createLocalEntry.
@Override
public String createLocalEntry(String base64EncodedXmlData) throws FederationAdminException {
if (StringUtils.isBlank(base64EncodedXmlData)) {
throw new FederationAdminException("Error creating local entry. String provided was blank.");
}
String metacardId;
try (InputStream xmlStream = new ByteArrayInputStream(Base64.getDecoder().decode(base64EncodedXmlData))) {
Metacard metacard = getRegistryMetacardFromInputStream(xmlStream);
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true));
metacardId = federationAdminService.addRegistryEntry(metacard);
} catch (IOException | IllegalArgumentException e) {
throw new FederationAdminException("Error creating local entry. Couldn't decode string.", e);
}
return metacardId;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdmin method updateLocalEntry.
@Override
public void updateLocalEntry(Map<String, Object> registryObjectMap) throws FederationAdminException {
Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryObjectMap);
RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error updating local registry entry. Couldn't convert registry map to a registry package."));
updateDateFields(registryPackage);
List<Metacard> existingMetacards = federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryPackage.getId()));
if (CollectionUtils.isEmpty(existingMetacards)) {
String message = "Error updating local registry entry. Registry metacard not found.";
LOGGER.debug("{} Registry ID: {}", message, registryPackage.getId());
throw new FederationAdminException(message);
}
if (existingMetacards.size() > 1) {
throw new FederationAdminException("Error updating local registry entry. Multiple registry metacards found.");
}
Metacard existingMetacard = existingMetacards.get(0);
Metacard updateMetacard = getRegistryMetacardFromRegistryPackage(registryPackage);
updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
federationAdminService.updateRegistryEntry(updateMetacard);
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FederationAdminTest method testUpdateLocalEntry.
@Test
public void testUpdateLocalEntry() throws Exception {
RegistryPackageType registryObject = getRegistryObjectFromResource("/csw-registry-package-smaller.xml");
Map<String, Object> registryMap = getMapFromRegistryObject(registryObject);
String existingMetacardId = "someUpdateMetacardId";
Metacard existingMetacard = getTestMetacard();
existingMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacardId));
List<Metacard> existingMetacards = new ArrayList<>();
existingMetacards.add(existingMetacard);
Metacard updateMetacard = getTestMetacard();
when(federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()))).thenReturn(existingMetacards);
when(registryTransformer.transform(any(InputStream.class))).thenReturn(updateMetacard);
federationAdmin.updateLocalEntry(registryMap);
verify(federationAdminService).getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()));
verify(registryTransformer).transform(any(InputStream.class));
verify(federationAdminService).updateRegistryEntry(updateMetacard);
}
Aggregations