Search in sources :

Example 41 with MetacardImpl

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"));
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 42 with MetacardImpl

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"));
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 43 with MetacardImpl

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;
}
Also used : ParserException(org.codice.ddf.parser.ParserException) RegistryConversionException(org.codice.ddf.registry.converter.RegistryConversionException) TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 44 with MetacardImpl

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"));
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 45 with MetacardImpl

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"));
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)384 Test (org.junit.Test)247 Metacard (ddf.catalog.data.Metacard)144 ArrayList (java.util.ArrayList)102 Result (ddf.catalog.data.Result)62 HashMap (java.util.HashMap)59 Date (java.util.Date)52 ResultImpl (ddf.catalog.data.impl.ResultImpl)51 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)49 URI (java.net.URI)38 Matchers.anyString (org.mockito.Matchers.anyString)38 QueryRequest (ddf.catalog.operation.QueryRequest)36 QueryResponse (ddf.catalog.operation.QueryResponse)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)35 Serializable (java.io.Serializable)33 HashSet (java.util.HashSet)31 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)28 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)27 List (java.util.List)27