use of org.codice.ddf.configuration.DictionaryMap in project ddf by codice.
the class DefinitionParser method parseMetacardTypes.
@SuppressWarnings("squid:S1149")
private List<Callable<Boolean>> parseMetacardTypes(Changeset changeset, List<Outer.MetacardType> incomingMetacardTypes) {
List<Callable<Boolean>> staged = new ArrayList<>();
BundleContext context = getBundleContext();
List<MetacardType> stagedTypes = new ArrayList<>();
for (Outer.MetacardType metacardType : incomingMetacardTypes) {
Set<AttributeDescriptor> attributeDescriptors = new HashSet<>(MetacardImpl.BASIC_METACARD.getAttributeDescriptors());
Set<String> requiredAttributes = new HashSet<>();
Set<AttributeDescriptor> extendedAttributes = Optional.of(metacardType).map(omt -> omt.extendsTypes).orElse(Collections.emptyList()).stream().flatMap(getSpecifiedTypes(stagedTypes)).collect(Collectors.toSet());
attributeDescriptors.addAll(extendedAttributes);
Optional.ofNullable(metacardType.attributes).orElse(Collections.emptyMap()).forEach((attributeName, attribute) -> processAttribute(metacardType, attributeDescriptors, requiredAttributes, attributeName, attribute));
if (!requiredAttributes.isEmpty()) {
final MetacardValidator validator = new RequiredAttributesMetacardValidator(metacardType.type, requiredAttributes);
staged.add(() -> {
ServiceRegistration<MetacardValidator> registration = context.registerService(MetacardValidator.class, validator, null);
changeset.metacardValidatorServices.add(registration);
return registration != null;
});
}
Dictionary<String, Object> properties = new DictionaryMap<>();
properties.put(NAME_PROPERTY, metacardType.type);
MetacardType type = new MetacardTypeImpl(metacardType.type, attributeDescriptors);
stagedTypes.add(type);
staged.add(() -> {
ServiceRegistration<MetacardType> registration = context.registerService(MetacardType.class, type, properties);
changeset.metacardTypeServices.add(registration);
return registration != null;
});
}
return staged;
}
use of org.codice.ddf.configuration.DictionaryMap in project ddf by codice.
the class CswSubscriptionEndpoint method persistSubscription.
/**
* Persist the subscription to the OSGi ConfigAdmin service. Persisted registeredSubscriptions can
* then be restored if DDF is restarted after a DDF outage or DDF is shutdown. Pass in
* client-provided subscriptionId and subscription UUID because the filter XML to be persisted for
* this subscription will be used to restore this subscription and should consist of the exact
* values the client originally provided.
*/
private void persistSubscription(CswSubscription subscription, String deliveryMethodUrl, String subscriptionUuid) {
String methodName = "persistSubscription";
LOGGER.trace(ENTERING_STR, methodName);
try {
StringWriter sw = new StringWriter();
CswQueryFactory.getJaxBContext().createMarshaller().marshal(objectFactory.createGetRecords(subscription.getOriginalRequest()), sw);
String filterXml = sw.toString();
ConfigurationAdmin configAdmin = getConfigAdmin();
// OSGi CongiAdmin
if (filterXml != null && configAdmin != null) {
Configuration config = configAdmin.createFactoryConfiguration(CswSubscriptionConfigFactory.FACTORY_PID, null);
Dictionary<String, String> props = new DictionaryMap<>();
props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_ID, subscriptionUuid);
props.put(CswSubscriptionConfigFactory.FILTER_XML, filterXml);
props.put(CswSubscriptionConfigFactory.DELIVERY_METHOD_URL, deliveryMethodUrl);
props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_UUID, subscriptionUuid);
LOGGER.debug("Done adding persisting subscription to ConfigAdmin");
config.update(props);
}
} catch (JAXBException | IOException e) {
LOGGER.debug("Unable to persist subscription {}", subscriptionUuid, e);
}
LOGGER.trace(EXITING_STR, methodName);
}
use of org.codice.ddf.configuration.DictionaryMap in project ddf by codice.
the class XsltBundleObserver method addingEntries.
@Override
public void addingEntries(Bundle bundle, List<String> resources) {
for (String fileName : resources) {
// extract the format from the file name
File file = new File(fileName);
String format = file.getName().substring(0, file.getName().lastIndexOf('.'));
Dictionary<String, String> properties = new DictionaryMap<>();
LOGGER.debug("Found started bundle with name: {}", fileName);
// setup the properties for the service
properties.put(Constants.SERVICE_SHORTNAME, format);
properties.put(Constants.SERVICE_TITLE, "View as " + (format.length() > 4 ? capitalize(format) : format.toUpperCase()) + "...");
properties.put(Constants.SERVICE_DESCRIPTION, "Transforms query results into " + format);
// define a transformer object that points to the xsl
T xmt = null;
try {
xmt = transformerClass.newInstance();
xmt.init(bundle, fileName);
} catch (InstantiationException e) {
LOGGER.debug("InstantiationException", e);
continue;
} catch (IllegalAccessException e) {
LOGGER.debug("IllegalAccessException", e);
continue;
}
// register the service
ServiceRegistration sr = bundleContext.registerService(publishedInterface, xmt, properties);
// store the service registration object
if (serviceRegistrationMap.containsKey(bundle)) {
// if it's already in the map, add the sr to the appropriate
// list
serviceRegistrationMap.get(bundle).add(sr);
} else {
// if it's not in the map, make the initial list and put it in
// the map
List<ServiceRegistration> srList = new ArrayList<>();
srList.add(sr);
serviceRegistrationMap.put(bundle, srList);
}
}
}
use of org.codice.ddf.configuration.DictionaryMap in project ddf by codice.
the class WfsSource method createFeatureMetacardTypeRegistration.
private FeatureMetacardType createFeatureMetacardTypeRegistration(FeatureTypeType featureTypeType, String ftName, XmlSchema schema) {
MetacardTypeEnhancer metacardTypeEnhancer = metacardTypeEnhancers.stream().filter(me -> me.getFeatureName() != null).filter(me -> me.getFeatureName().equalsIgnoreCase(ftName)).findAny().orElse(FeatureMetacardType.DEFAULT_METACARD_TYPE_ENHANCER);
FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.stream(nonQueryableProperties).collect(toSet()) : new HashSet<>(), Wfs11Constants.GML_3_1_1_NAMESPACE, metacardTypeEnhancer);
Dictionary<String, Object> props = new DictionaryMap<>();
props.put(Metacard.CONTENT_TYPE, new String[] { ftName });
LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);
return ftMetacard;
}
use of org.codice.ddf.configuration.DictionaryMap in project ddf by codice.
the class UrlResourceReaderConfigurator method updateUrlResourceReaderRootDirs.
private void updateUrlResourceReaderRootDirs(Configuration configuration, Collection<String> newRootResourceDirs) {
Dictionary<String, Object> properties = new DictionaryMap<>();
properties.put(ROOT_RESOURCE_DIRECTORIES_PROPERTY_KEY, newRootResourceDirs);
try {
configuration.update(properties);
} catch (IOException e) {
throw new UncheckedIOException(String.format("Unexpected failure updating [%s %s] configuration!", PID, ROOT_RESOURCE_DIRECTORIES_PROPERTY_KEY), e);
}
with().pollInterval(1, SECONDS).await().atMost(30, SECONDS).until(() -> propertyIsUpdated(configuration, newRootResourceDirs));
LOGGER.debug("{} properties after update: {}", PID, configuration.getProperties());
}
Aggregations