use of ddf.catalog.data.DefaultAttributeValueRegistry in project ddf by codice.
the class TestCatalog method testDefaultValuesCreate.
@Test
// DDF-2743
@ConditionalIgnore(condition = SkipUnstableTest.class)
public void testDefaultValuesCreate() throws Exception {
final String customMetacardTypeName = "custom";
File file = ingestDefinitionJsonWithWaitCondition("defaults.json", () -> {
expect("Service to be available: " + MetacardType.class.getName()).within(30, TimeUnit.SECONDS).until(() -> getServiceManager().getServiceReferences(MetacardType.class, "(name=" + customMetacardTypeName + ")"), not(empty()));
return null;
});
String metacard1Xml = getFileContent("metacard1.xml");
String metacard2Xml = getFileContent("metacard2.xml");
metacard2Xml = metacard2Xml.replaceFirst("ddf\\.metacard", customMetacardTypeName);
verifyMetacardDoesNotContainAttribute(metacard1Xml, Metacard.DESCRIPTION);
verifyMetacardDoesNotContainAttribute(metacard1Xml, Metacard.EXPIRATION);
verifyMetacardDoesNotContainAttribute(metacard2Xml, Metacard.DESCRIPTION);
verifyMetacardDoesNotContainAttribute(metacard2Xml, Metacard.EXPIRATION);
final String id1 = ingest(metacard1Xml, MediaType.APPLICATION_XML);
final String id2 = ingest(metacard2Xml, MediaType.APPLICATION_XML);
try {
final String defaultDescription = "Default description";
final String defaultCustomMetacardDescription = "Default custom description";
final String defaultExpiration = getDefaultExpirationAsString();
final String metacard1XPath = format(METACARD_X_PATH, id1);
final String metacard2XPath = format(METACARD_X_PATH, id2);
executeOpenSearch("xml", "q=*").log().all().assertThat().body(hasXPath(metacard1XPath + "/string[@name='title']/value", is("Metacard-1"))).body(hasXPath(metacard1XPath + "/string[@name='description']/value", is(defaultDescription))).body(hasXPath(metacard1XPath + "/dateTime[@name='expiration']/value", is(defaultExpiration))).body(hasXPath(metacard2XPath + "/string[@name='title']/value", is("Metacard-2"))).body(hasXPath(metacard2XPath + "/string[@name='description']/value", is(defaultCustomMetacardDescription))).body(hasXPath(metacard2XPath + "/dateTime[@name='expiration']/value", is(defaultExpiration)));
} finally {
deleteMetacard(id1);
deleteMetacard(id2);
uninstallDefinitionJson(file, () -> {
DefaultAttributeValueRegistry defaultsRegistry = getServiceManager().getService(DefaultAttributeValueRegistry.class);
expect("Defaults to be unregistered").within(10, TimeUnit.SECONDS).until(() -> !defaultsRegistry.getDefaultValue(customMetacardTypeName, Metacard.DESCRIPTION).isPresent());
return null;
});
}
}
use of ddf.catalog.data.DefaultAttributeValueRegistry in project ddf by codice.
the class OperationsMetacardSupport method setDefaultValues.
/**
* Updates any empty metacard attributes with those defined in the
* {@link DefaultAttributeValueRegistry}.
*
* @param metacard the metacard to update with default attribute values
*/
void setDefaultValues(Metacard metacard) {
MetacardType metacardType = metacard.getMetacardType();
DefaultAttributeValueRegistry registry = frameworkProperties.getDefaultAttributeValueRegistry();
metacardType.getAttributeDescriptors().stream().map(AttributeDescriptor::getName).filter(attributeName -> hasNoValue(metacard.getAttribute(attributeName))).forEach(attributeName -> {
registry.getDefaultValue(metacardType.getName(), attributeName).ifPresent(defaultValue -> metacard.setAttribute(new AttributeImpl(attributeName, defaultValue)));
});
}
use of ddf.catalog.data.DefaultAttributeValueRegistry in project ddf by codice.
the class TestCatalog method testDefaultValuesUpdate.
@Test
// DDF-2743
@ConditionalIgnore(condition = SkipUnstableTest.class)
public void testDefaultValuesUpdate() throws Exception {
final String customMetacardTypeName = "custom";
File file = ingestDefinitionJsonWithWaitCondition("defaults.json", () -> {
expect("Service to be available: " + MetacardType.class.getName()).within(30, TimeUnit.SECONDS).until(() -> getServiceManager().getServiceReferences(MetacardType.class, "(name=" + customMetacardTypeName + ")"), not(empty()));
return null;
});
String metacard1Xml = getFileContent("metacard1.xml");
final String id1 = ingest(metacard1Xml, MediaType.APPLICATION_XML);
String metacard2Xml = getFileContent("metacard2.xml");
metacard2Xml = metacard2Xml.replaceFirst("ddf\\.metacard", customMetacardTypeName);
final String id2 = ingest(metacard2Xml, MediaType.APPLICATION_XML);
try {
final String updatedTitle1 = "Metacard-1 (Updated)";
final String updatedTitle2 = "Metacard-2 (Updated)";
metacard1Xml = metacard1Xml.replaceFirst("Metacard\\-1", updatedTitle1);
metacard2Xml = metacard2Xml.replaceFirst("Metacard\\-2", updatedTitle2);
verifyMetacardDoesNotContainAttribute(metacard1Xml, Metacard.DESCRIPTION);
verifyMetacardDoesNotContainAttribute(metacard1Xml, Metacard.EXPIRATION);
verifyMetacardDoesNotContainAttribute(metacard2Xml, Metacard.DESCRIPTION);
verifyMetacardDoesNotContainAttribute(metacard2Xml, Metacard.EXPIRATION);
update(id1, metacard1Xml, MediaType.APPLICATION_XML);
update(id2, metacard2Xml, MediaType.APPLICATION_XML);
final String defaultDescription = "Default description";
final String defaultCustomMetacardDescription = "Default custom description";
final String defaultExpiration = getDefaultExpirationAsString();
final String metacard1XPath = format(METACARD_X_PATH, id1);
final String metacard2XPath = format(METACARD_X_PATH, id2);
executeOpenSearch("xml", "q=*").log().all().assertThat().body(hasXPath(metacard1XPath + "/string[@name='title']/value", is(updatedTitle1))).body(hasXPath(metacard1XPath + "/string[@name='description']/value", is(defaultDescription))).body(hasXPath(metacard1XPath + "/dateTime[@name='expiration']/value", is(defaultExpiration))).body(hasXPath(metacard2XPath + "/string[@name='title']/value", is(updatedTitle2))).body(hasXPath(metacard2XPath + "/string[@name='description']/value", is(defaultCustomMetacardDescription))).body(hasXPath(metacard2XPath + "/dateTime[@name='expiration']/value", is(defaultExpiration)));
} finally {
deleteMetacard(id1);
deleteMetacard(id2);
uninstallDefinitionJson(file, () -> {
DefaultAttributeValueRegistry defaultsRegistry = getServiceManager().getService(DefaultAttributeValueRegistry.class);
expect("Defaults to be unregistered").within(10, TimeUnit.SECONDS).until(() -> !defaultsRegistry.getDefaultValue(customMetacardTypeName, Metacard.DESCRIPTION).isPresent());
return null;
});
}
}
Aggregations