use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class RegistryTransformerTest method testLastUpdated.
@Test
public void testLastUpdated() throws Exception {
MetacardImpl metacard = convert("/csw-last-updated.xml");
String utc = metacard.getModifiedDate().toInstant().toString();
assertThat(utc, is("2016-01-26T17:16:34.996Z"));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class RegistryTransformerTest method testServiceBindingWithMultipleTypes.
@Test
public void testServiceBindingWithMultipleTypes() throws Exception {
MetacardImpl metacard = convert("/binding-service-multiple-types.xml");
List<String> serviceBindingsList = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.SERVICE_BINDING_TYPES);
assertThat(serviceBindingsList.size(), is(2));
assertThat(serviceBindingsList, hasItem("csw"));
assertThat(serviceBindingsList, hasItem("fakeBindingType"));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class RegistryTransformer method transform.
@Override
public Metacard transform(InputStream inputStream, String id) throws IOException, CatalogTransformerException {
MetacardImpl metacard;
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
IOUtils.copy(inputStream, fileBackedOutputStream);
} catch (IOException e) {
throw new CatalogTransformerException("Unable to transform from CSW RIM Service Record to Metacard. Error reading input stream.", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) {
metacard = (MetacardImpl) unmarshal(inputStreamCopy);
} catch (ParserException e) {
throw new CatalogTransformerException("Unable to transform from CSW RIM Service Record to Metacard. Parser exception caught", e);
} catch (RegistryConversionException e) {
throw new CatalogTransformerException("Unable to transform from CSW RIM Service Record to Metacard. Conversion exception caught", e);
}
if (metacard == null) {
throw new CatalogTransformerException("Unable to transform from CSW RIM Service Record to Metacard.");
} else if (StringUtils.isNotEmpty(id)) {
metacard.setAttribute(Metacard.ID, id);
}
String xml;
try (Reader reader = fileBackedOutputStream.asByteSource().asCharSource(Charsets.UTF_8).openStream()) {
xml = CharStreams.toString(reader);
}
metacard.setAttribute(Metacard.METADATA, xml);
metacard.setTags(Collections.singleton(RegistryConstants.REGISTRY_TAG));
} catch (IOException e) {
throw new CatalogTransformerException("Unable to transform from CSW RIM Service Record to Metacard. Error using file-backed stream.", e);
}
return metacard;
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class RegistryTransformerTest method testNullMetacardAttributeValues.
@Test
public void testNullMetacardAttributeValues() throws Exception {
MetacardImpl metacard = convert("/csw-null-metacard-attributes.xml");
assertRegistryMetacard(metacard);
assertThat(RegistryUtility.getStringAttribute(metacard, Contact.POINT_OF_CONTACT_NAME, null), is("Codice"));
assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_ADDRESS), hasItem("1234 Some Street, AZ 85037, USA"));
assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_PHONE), hasItem("555-5555 ext 1234"));
assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_PHONE), hasItem("123-4567"));
assertThat(RegistryUtility.getListOfStringAttribute(metacard, Contact.POINT_OF_CONTACT_EMAIL), hasItem("emailaddress@something.com"));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class RegistryTransformerTest method testServiceWithMinimumBinding.
@Test
public void testServiceWithMinimumBinding() throws Exception {
MetacardImpl metacard = convert("/valid-federation-min-service.xml");
assertThat(RegistryUtility.getStringAttribute(metacard, RegistryObjectMetacardType.SERVICE_BINDING_TYPES, null), is("csw"));
}
Aggregations