Search in sources :

Example 76 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPublicationServiceImplTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    String registryId1 = "registryId1";
    String registryId2 = "registryId2";
    String registryId3 = "registryId3";
    String storeId1 = "store1";
    String storeId3 = "store3";
    // Purposely leave out mock for registry store 2
    // so a store id won't be found for registryId2
    // Not a likely case but should be handled
    RegistryStore store1 = mock(RegistryStore.class);
    when(store1.getId()).thenReturn(storeId1);
    when(store1.getRegistryId()).thenReturn(registryId1);
    RegistryStore store3 = mock(RegistryStore.class);
    when(store3.getId()).thenReturn(storeId3);
    when(store3.getRegistryId()).thenReturn(registryId3);
    when(bundleContext.getService(serviceReference)).thenReturn(store1);
    registryPublicationService.bindRegistryStore(serviceReference);
    when(bundleContext.getService(serviceReference)).thenReturn(store3);
    registryPublicationService.bindRegistryStore(serviceReference);
    List<Serializable> publishedLocations = ImmutableList.of(registryId1, registryId2, registryId3);
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, publishedLocations));
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    registryPublicationService.update(metacard);
    // update will only be callled with storeIds 1 and 3, 2 didn't have a storeId match for registryId2
    verify(federationAdminService, times(1)).updateRegistryEntry(eq(metacard), (Set<String>) argThat(contains(storeId1, storeId3)));
    verify(federationAdminService, times(1)).updateRegistryEntry(metacard);
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate.after(before), is(equalTo(true)));
}
Also used : Serializable(java.io.Serializable) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 77 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPublicationServiceImplTest method testNoRegistryStores.

@Test(expected = FederationAdminException.class)
public void testNoRegistryStores() throws Exception {
    doReturn(Collections.singletonList(metacard)).when(federationAdminService).getRegistryMetacardsByRegistryIds(any(List.class));
    registryPublicationService.unbindRegistryStore(serviceReference);
    String publishThisRegistryId = "publishThisRegistryId";
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    MetacardImpl metacard = new MetacardImpl();
    Attribute publishedLocationsAttribute = new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, Collections.singletonList(REGISTRY_STORE_REGISTRY_ID));
    metacard.setAttribute(publishedLocationsAttribute);
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    registryPublicationService.publish(publishThisRegistryId, REGISTRY_STORE_REGISTRY_ID);
    verify(federationAdminService, never()).updateRegistryEntry(metacard);
    Attribute publicationsAfter = metacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    assertThat(publicationsAfter, is(equalTo(publishedLocationsAttribute)));
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate, is(equalTo(before)));
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 78 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class GenericFeatureConverterWfs20 method marshal.

/**
     * This method will convert a {@link Metacard} instance into xml that will validate against the
     * GML 2.1.2 AbstractFeatureType.
     *
     * @param value
     *            the {@link Metacard} to convert
     * @param writer
     *            the stream writer responsible for writing this xml doc
     * @param context
     *            a reference back to the Xstream marshalling context. Allows you to call
     *            "convertAnother" which will lookup other registered converters.
     */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;
    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
    // Add the "id" attribute if we have an ID
    if (metacard.getAttribute(Metacard.ID).getValue() != null) {
        String id = (String) metacard.getAttribute(Metacard.ID).getValue();
        writer.addAttribute(ID, id);
    }
    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
        }
    }
    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
        }
    }
    writer.endNode();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 79 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class PropertyJsonMetacardTransformer method convertToJSON.

public static Map<String, Object> convertToJSON(Metacard metacard, List<AttributeType.AttributeFormat> dontInclude) throws CatalogTransformerException {
    if (metacard == null) {
        throw new CatalogTransformerException("Cannot transform null metacard.");
    }
    Map<String, Object> rootObject = new HashMap<>();
    Map<String, Object> properties = new HashMap<>();
    for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(ad.getName());
        if (attribute != null) {
            Object value = convertAttribute(attribute, ad, dontInclude);
            if (value != null) {
                properties.put(attribute.getName(), value);
            }
        }
    }
    properties.put(METACARD_TYPE_PROPERTY_KEY, metacard.getMetacardType().getName());
    if (StringUtils.isNotBlank(metacard.getSourceId())) {
        properties.put(SOURCE_ID_PROPERTY, metacard.getSourceId());
    }
    rootObject.put("properties", properties);
    return rootObject;
}
Also used : HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException)

Example 80 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class SolrMetacardClientImpl method createMetacard.

public MetacardImpl createMetacard(SolrDocument doc) throws MetacardCreationException {
    MetacardType metacardType = resolver.getMetacardType(doc);
    MetacardImpl metacard = new MetacardImpl(metacardType);
    for (String solrFieldName : doc.getFieldNames()) {
        if (!resolver.isPrivateField(solrFieldName)) {
            Collection<Object> fieldValues = doc.getFieldValues(solrFieldName);
            Attribute attr = new AttributeImpl(resolver.resolveFieldName(solrFieldName), resolver.getDocValues(solrFieldName, fieldValues));
            metacard.setAttribute(attr);
        }
    }
    return metacard;
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7