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)));
}
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)));
}
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();
}
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;
}
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;
}
Aggregations