Search in sources :

Example 1 with DictionaryMap

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;
}
Also used : ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Callable(java.util.concurrent.Callable) MetacardType(ddf.catalog.data.MetacardType) DictionaryMap(org.codice.ddf.configuration.DictionaryMap) MetacardValidator(ddf.catalog.validation.MetacardValidator) ReportingMetacardValidator(ddf.catalog.validation.ReportingMetacardValidator) RequiredAttributesMetacardValidator(ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator) JsonObject(com.google.gson.JsonObject) RequiredAttributesMetacardValidator(ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator) BundleContext(org.osgi.framework.BundleContext) HashSet(java.util.HashSet)

Example 2 with DictionaryMap

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);
}
Also used : StringWriter(java.io.StringWriter) Configuration(org.osgi.service.cm.Configuration) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) DictionaryMap(org.codice.ddf.configuration.DictionaryMap)

Example 3 with DictionaryMap

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) DictionaryMap(org.codice.ddf.configuration.DictionaryMap) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 4 with DictionaryMap

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;
}
Also used : SortByType(net.opengis.filter.v_1_1_0.SortByType) Arrays(java.util.Arrays) WfsMetadata(org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata) XmlSchemaMessageBodyReaderWfs11(org.codice.ddf.spatial.ogc.wfs.v110.catalog.source.reader.XmlSchemaMessageBodyReaderWfs11) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) MarkableStreamInterceptor(org.codice.ddf.spatial.ogc.wfs.catalog.source.MarkableStreamInterceptor) ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Map(java.util.Map) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection) BigInteger(java.math.BigInteger) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) AvailabilityTask(org.codice.ddf.spatial.ogc.catalog.common.AvailabilityTask) ServiceReference(org.osgi.framework.ServiceReference) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Set(java.util.Set) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.DescribeFeatureTypeRequest) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) IOUtils(org.apache.commons.io.IOUtils) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) AvailabilityCommand(org.codice.ddf.spatial.ogc.catalog.common.AvailabilityCommand) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) Dictionary(java.util.Dictionary) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) FilterAdapter(ddf.catalog.filter.FilterAdapter) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) QueryRequest(ddf.catalog.operation.QueryRequest) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WfsMetadataImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsMetadataImpl) ConnectException(java.net.ConnectException) Result(ddf.catalog.data.Result) ResultTypeType(net.opengis.wfs.v_1_1_0.ResultTypeType) DictionaryMap(org.codice.ddf.configuration.DictionaryMap) SortOrder(org.opengis.filter.sort.SortOrder) ContentType(ddf.catalog.data.ContentType) Properties(java.util.Properties) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Query(ddf.catalog.operation.Query) Paths(java.nio.file.Paths) ScheduledFuture(java.util.concurrent.ScheduledFuture) QueryType(net.opengis.wfs.v_1_1_0.QueryType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) GetFeatureType(net.opengis.wfs.v_1_1_0.GetFeatureType) LoggerFactory(org.slf4j.LoggerFactory) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) WfsMetacardTypeRegistry(org.codice.ddf.spatial.ogc.wfs.catalog.metacardtype.registry.WfsMetacardTypeRegistry) URI(java.net.URI) Collectors.toSet(java.util.stream.Collectors.toSet) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType) FeatureTypeType(net.opengis.wfs.v_1_1_0.FeatureTypeType) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Predicate(java.util.function.Predicate) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) ClientBuilder(org.codice.ddf.cxf.client.ClientBuilder) SourceMonitor(ddf.catalog.source.SourceMonitor) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) BundleContext(org.osgi.framework.BundleContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) List(java.util.List) ObjectFactory(net.opengis.wfs.v_1_1_0.ObjectFactory) Response(javax.ws.rs.core.Response) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) Entry(java.util.Map.Entry) FilterType(net.opengis.filter.v_1_1_0.FilterType) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) WFSCapabilitiesType(net.opengis.wfs.v_1_1_0.WFSCapabilitiesType) FeatureTransformationService(org.codice.ddf.spatial.ogc.wfs.featuretransformer.FeatureTransformationService) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.GetCapabilitiesRequest) LAT_LON_ORDER(org.codice.ddf.libs.geo.util.GeospatialUtil.LAT_LON_ORDER) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) SortOrderType(net.opengis.filter.v_1_1_0.SortOrderType) HashSet(java.util.HashSet) SortBy(org.opengis.filter.sort.SortBy) MetadataTransformer(org.codice.ddf.spatial.ogc.catalog.MetadataTransformer) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) EncryptionService(ddf.security.encryption.EncryptionService) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) JAXBContext(javax.xml.bind.JAXBContext) AbstractWfsSource(org.codice.ddf.spatial.ogc.wfs.catalog.common.AbstractWfsSource) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Wfs11Constants(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.Wfs11Constants) Logger(org.slf4j.Logger) MetacardTypeEnhancer(org.codice.ddf.spatial.ogc.wfs.catalog.MetacardTypeEnhancer) TimeUnit(java.util.concurrent.TimeUnit) SourceResponse(ddf.catalog.operation.SourceResponse) ContentTypeFilterDelegate(org.codice.ddf.spatial.ogc.catalog.common.ContentTypeFilterDelegate) Collections(java.util.Collections) InputStream(java.io.InputStream) MetacardTypeEnhancer(org.codice.ddf.spatial.ogc.wfs.catalog.MetacardTypeEnhancer) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) HashSet(java.util.HashSet) DictionaryMap(org.codice.ddf.configuration.DictionaryMap)

Example 5 with DictionaryMap

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());
}
Also used : UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) DictionaryMap(org.codice.ddf.configuration.DictionaryMap)

Aggregations

DictionaryMap (org.codice.ddf.configuration.DictionaryMap)17 Configuration (org.osgi.service.cm.Configuration)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 BundleContext (org.osgi.framework.BundleContext)3 ServiceRegistration (org.osgi.framework.ServiceRegistration)3 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 StringWriter (java.io.StringWriter)2 JAXBException (javax.xml.bind.JAXBException)2 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)2 JsonObject (com.google.gson.JsonObject)1 ActionProvider (ddf.action.ActionProvider)1 Constants (ddf.catalog.Constants)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 ContentType (ddf.catalog.data.ContentType)1 Metacard (ddf.catalog.data.Metacard)1 MetacardType (ddf.catalog.data.MetacardType)1 Result (ddf.catalog.data.Result)1