Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

In this page you can find the example usage for java.util Dictionary put.

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java

/**
 * Tests the {@link ConfigurationAdmin#enableConfiguration(String)} method
 * for the case where the configuration is already enabled
 *
 * @throws Exception//from w  ww  .  ja  v  a  2s  .  com
 */
@Test(expected = IOException.class)
public void testEnableConfigurationsAlreadyEnabled() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);

    Configuration testConfig = mock(Configuration.class);
    Configuration testFactoryConfig = mock(Configuration.class);
    Dictionary<String, Object> testProperties = new Hashtable<>();

    testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACTORY_PID);

    when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')'))
            .thenReturn(new Configuration[] { testConfig });
    when(testConfig.getProperties()).thenReturn(testProperties);
    when(testFactoryConfig.getPid()).thenReturn(TEST_FACTORY_PID);
    when(testConfigAdmin.createFactoryConfiguration(TEST_FACTORY_PID, null)).thenReturn(testFactoryConfig);

    configAdmin.enableConfiguration(TEST_PID);
}

From source file:org.opennaas.core.protocols.sessionmanager.ProtocolSessionManager.java

private Dictionary<String, String> addWSRegistrationProperties(Dictionary<String, String> props)
        throws ProtocolException {
    IResource resource;//from   w  w  w  .j a v a2s  .  c o m
    try {
        resource = getResource(resourceID);
        String resourceType = resource.getResourceDescriptor().getInformation().getType();
        String resourceName = resource.getResourceDescriptor().getInformation().getName();

        ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(Activator.getBundleContext());
        String url = configurationAdmin.getProperty("org.opennaas", "ws.rest.url");

        if (props != null) {
            props.put("service.exported.interfaces", "*");
            props.put("service.exported.configs", "org.apache.cxf.rs");
            props.put("service.exported.intents", "HTTP");
            props.put("org.apache.cxf.rs.httpservice.context",
                    url + "/" + resourceType + "/" + resourceName + "/protocolSessionManager");
            props.put("org.apache.cxf.rs.address", "/");
            props.put("org.apache.cxf.httpservice.requirefilter", "true");
        }
        log.info("Registering ws in url: " + props.get("org.apache.cxf.rs.address"));
    } catch (ResourceException e) {
        throw new ProtocolException(e);
    } catch (IOException e) {
        throw new ProtocolException(e);
    }
    return props;
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java

/**
 * Tests the {@link ConfigurationAdmin#enableConfiguration(String)} method
 *
 * @throws Exception//w  ww . j a va  2  s .  com
 */
@Test
public void testEnableConfigurations() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);

    Configuration testConfig = mock(Configuration.class);
    Configuration testFactoryConfig = mock(Configuration.class);
    Dictionary<String, Object> testProperties = new Hashtable<>();

    testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACT_PID_DISABLED);

    when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')'))
            .thenReturn(new Configuration[] { testConfig });
    when(testConfig.getProperties()).thenReturn(testProperties);
    when(testFactoryConfig.getPid()).thenReturn(TEST_FACTORY_PID);
    when(testConfigAdmin.createFactoryConfiguration(TEST_FACTORY_PID, null)).thenReturn(testFactoryConfig);

    Map<String, Object> result = configAdmin.enableConfiguration(TEST_PID);

    assertThat("Should show the pid in an enabled state.", (String) result.get("newFactoryPid"),
            is(TEST_FACTORY_PID));
    assertThat("Should show the original disabled pid.", (String) result.get("originalFactoryPid"),
            is(TEST_FACT_PID_DISABLED));
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java

/**
 * Tests the {@link ConfigurationAdmin#disableConfiguration(String)} method
 *
 * @throws Exception/*  w  w w  . ja va2 s. c  o m*/
 */
@Test
public void testDisableConfiguration() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);

    Configuration testConfig = mock(Configuration.class);
    Configuration testFactoryConfig = mock(Configuration.class);
    Dictionary<String, Object> testProperties = new Hashtable<>();

    testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACTORY_PID);

    when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')'))
            .thenReturn(new Configuration[] { testConfig });
    when(testConfigAdmin.createFactoryConfiguration(TEST_FACT_PID_DISABLED, null))
            .thenReturn(testFactoryConfig);
    when(testConfig.getProperties()).thenReturn(testProperties);
    when(testFactoryConfig.getPid()).thenReturn(TEST_FACT_PID_DISABLED);

    Map<String, Object> result = configAdmin.disableConfiguration(TEST_PID);

    assertThat("Should show the pid in a disabled state.", (String) result.get("newFactoryPid"),
            is(TEST_FACT_PID_DISABLED));
    assertThat("Should return the given original pid.", (String) result.get("originalFactoryPid"),
            is(TEST_FACTORY_PID));

    verify(testConfig).delete();
    verify(testFactoryConfig).update(testProperties);
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java

private ConfigurationAdmin getConfigAdmin() throws IOException, InvalidSyntaxException {
    final BundleContext testBundleContext = mock(BundleContext.class);
    final MetaTypeService testMTS = mock(MetaTypeService.class);

    ConfigurationAdminExt configurationAdminExt = new ConfigurationAdminExt(CONFIGURATION_ADMIN) {
        @Override//from  w w w .  j  a v  a 2s .c om
        BundleContext getBundleContext() {
            return testBundleContext;
        }

        @Override
        MetaTypeService getMetaTypeService() {
            return testMTS;
        }
    };

    ConfigurationAdmin configurationAdmin = new ConfigurationAdmin(CONFIGURATION_ADMIN, configurationAdminExt);

    Dictionary<String, Object> testProp = new Hashtable<>();
    testProp.put(TEST_KEY, TEST_VALUE);

    when(testConfig.getPid()).thenReturn(TEST_PID);
    when(testConfig.getFactoryPid()).thenReturn(TEST_FACTORY_PID);
    when(testConfig.getBundleLocation()).thenReturn(TEST_LOCATION);
    when(testConfig.getProperties()).thenReturn(testProp);

    Bundle testBundle = mock(Bundle.class);
    Dictionary bundleHeaders = mock(Dictionary.class);
    MetaTypeInformation testMTI = mock(MetaTypeInformation.class);
    ObjectClassDefinition testOCD = mock(ObjectClassDefinition.class);
    ServiceReference testRef1 = mock(ServiceReference.class);
    ServiceReference[] testServRefs = { testRef1 };

    ArrayList<AttributeDefinition> attDefs = new ArrayList<>();
    for (int cardinality : CARDINALITIES) {
        for (TYPE type : TYPE.values()) {
            AttributeDefinition testAttDef = mock(AttributeDefinition.class);
            when(testAttDef.getCardinality()).thenReturn(cardinality);
            when(testAttDef.getType()).thenReturn(type.getType());
            when(testAttDef.getID()).thenReturn(getKey(cardinality, type));
            attDefs.add(testAttDef);
        }
    }

    when(testRef1.getProperty(Constants.SERVICE_PID)).thenReturn(TEST_PID);
    when(testRef1.getBundle()).thenReturn(testBundle);

    when(testBundle.getLocation()).thenReturn(TEST_LOCATION);
    when(testBundle.getHeaders(anyString())).thenReturn(bundleHeaders);
    when(bundleHeaders.get(Constants.BUNDLE_NAME)).thenReturn(TEST_BUNDLE_NAME);

    when(testOCD.getName()).thenReturn(TEST_OCD);
    when(testOCD.getAttributeDefinitions(ObjectClassDefinition.ALL))
            .thenReturn(attDefs.toArray(new AttributeDefinition[attDefs.size()]));

    when(testMTI.getBundle()).thenReturn(testBundle);
    when(testMTI.getFactoryPids()).thenReturn(new String[] { TEST_FACTORY_PID });
    when(testMTI.getPids()).thenReturn(new String[] { TEST_PID });
    when(testMTI.getObjectClassDefinition(anyString(), anyString())).thenReturn(testOCD);

    when(testMTS.getMetaTypeInformation(testBundle)).thenReturn(testMTI);

    when(testBundleContext.getBundles()).thenReturn(new Bundle[] { testBundle });

    when(CONFIGURATION_ADMIN.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig });
    when(CONFIGURATION_ADMIN.getConfiguration(anyString(), anyString())).thenReturn(testConfig);

    when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);
    when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);

    return configurationAdmin;
}

From source file:org.opendaylight.controller.clustering.services_implementation.internal.ClusteringServicesIT.java

@Test
public void clusterContainerAndGlobalTest()
        throws CacheExistException, CacheConfigException, CacheListenerAddException, InterruptedException {
    String cache1 = "Cache1";
    String cache2 = "Cache2";
    // Lets test the case of caches with same name in different
    // containers (actually global an container case)
    String cache3 = "Cache2";

    HashSet<cacheMode> cacheModeSet = new HashSet<cacheMode>();
    cacheModeSet.add(cacheMode.NON_TRANSACTIONAL);
    ConcurrentMap cm11 = this.clusterDefaultServices.createCache(cache1, cacheModeSet);
    assertNotNull(cm11);//from w ww.ja v  a2s.  com

    assertTrue(this.clusterDefaultServices.existCache(cache1));
    assertEquals(cm11, this.clusterDefaultServices.getCache(cache1));

    ConcurrentMap cm12 = this.clusterDefaultServices.createCache(cache2, cacheModeSet);
    ConcurrentMap cm23 = this.clusterGlobalServices.createCache(cache3, cacheModeSet);

    // Now given cahe2 and cache3 have same name lets make sure
    // they don't return the same reference
    assertNotNull(this.clusterGlobalServices.getCache(cache2));
    // cm12 reference must be different than cm23
    assertTrue(cm12 != cm23);

    HashSet<String> cacheList = (HashSet<String>) this.clusterDefaultServices.getCacheList();
    assertEquals(2, cacheList.size());
    assertTrue(cacheList.contains(cache1));
    assertTrue(cacheList.contains(cache2));

    assertNotNull(this.clusterDefaultServices.getCacheProperties(cache1));

    {
        /***********************************/
        /* Testing cacheAware in Container */
        /***********************************/
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        Set<String> propSet = new HashSet<String>();
        propSet.add(cache1);
        propSet.add(cache2);
        props.put("cachenames", propSet);
        CacheAware listener = new CacheAware();
        CacheAware listenerRepeated = new CacheAware();
        ServiceRegistration updateServiceReg = ServiceHelper.registerServiceWReg(ICacheUpdateAware.class,
                "default", listener, props);
        assertNotNull(updateServiceReg);

        // Register another service for the same caches, this
        // should not get any update because we don't allow to
        // override the existing unless before unregistered
        ServiceRegistration updateServiceRegRepeated = ServiceHelper
                .registerServiceWReg(ICacheUpdateAware.class, "default", listenerRepeated, props);
        assertNotNull(updateServiceRegRepeated);
        CountDownLatch res = null;
        List<Update> ups = null;
        Update up = null;
        Integer k1 = new Integer(10);
        Long k2 = new Long(100L);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm11.put(k1, "foo");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("foo"));
        assertTrue(up.cacheName.equals(cache1));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache1));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache1));

        /**********************************/
        /* RE-UPDATE AN EXISTING KEY CASE */
        /**********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache1));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.remove(k1);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache1));

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm12.put(k2, new Short((short) 15));
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k2));
        assertTrue(up.value.equals(new Short((short) 15)));
        assertTrue(up.cacheName.equals(cache2));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k2));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache2));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm12.put(k2, "BAZ");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k2));
        assertTrue(up.value.equals("BAZ"));
        assertTrue(up.cacheName.equals(cache2));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm12.remove(k2);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k2));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache2));

        /******************************************************************/
        /* NOW LETS REMOVE THE REGISTRATION AND MAKE SURE NO UPDATS COMES */
        /******************************************************************/
        updateServiceReg.unregister();
        // Start monitoring the updates, noone should come in
        res = listener.restart(1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm11.put(k1, "foo");

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm11.put(k1, "baz");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm11.remove(k1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm12.put(k2, new Short((short) 15));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm12.put(k2, "BAZ");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm12.remove(k2);

        // Wait to make sure no updates came in, clearly this is
        // error prone as logic, but cannot find a better way than
        // this to make sure updates didn't get in
        res.await(1L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 0);
    }

    {
        /***********************************/
        /* Testing cacheAware in Global */
        /***********************************/
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        Set<String> propSet = new HashSet<String>();
        propSet.add(cache3);
        props.put("cachenames", propSet);
        CacheAware listener = new CacheAware();
        ServiceRegistration updateServiceReg = ServiceHelper.registerGlobalServiceWReg(ICacheUpdateAware.class,
                listener, props);
        assertNotNull(updateServiceReg);

        CountDownLatch res = null;
        List<Update> ups = null;
        Update up = null;
        Integer k1 = new Integer(10);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm23.put(k1, "foo");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("foo"));
        assertTrue(up.cacheName.equals(cache3));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache3));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm23.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache3));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm23.remove(k1);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache3));

        /******************************************************************/
        /* NOW LETS REMOVE THE REGISTRATION AND MAKE SURE NO UPDATS COMES */
        /******************************************************************/
        updateServiceReg.unregister();
        // Start monitoring the updates, noone should come in
        res = listener.restart(1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm23.put(k1, "foo");

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm23.put(k1, "baz");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm23.remove(k1);

        // Wait to make sure no updates came in, clearly this is
        // error prone as logic, but cannot find a better way than
        // this to make sure updates didn't get in
        res.await(1L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 0);
    }

    InetAddress addr = this.clusterDefaultServices.getMyAddress();
    assertNotNull(addr);

    List<InetAddress> addrList = this.clusterDefaultServices.getClusteredControllers();

    this.clusterDefaultServices.destroyCache(cache1);
    assertFalse(this.clusterDefaultServices.existCache(cache1));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.WfsSource.java

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, List<String> supportedGeo)
        throws SecurityServiceException {

    // Use local Map for metacardtype registrations and once they are populated with latest
    // MetacardTypes, then do actual registration
    Map<String, MetacardTypeRegistration> mcTypeRegs = new HashMap<String, MetacardTypeRegistration>();
    Wfs wfs = factory.getClient();/*from  w  w  w.j  a v a 2s  .co  m*/

    for (FeatureTypeType featureTypeType : featureTypes) {
        String ftName = featureTypeType.getName().getLocalPart();

        if (mcTypeRegs.containsKey(ftName)) {
            LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type",
                    getId(), ftName);
            continue;
        }

        LOGGER.debug("ftName: {}", ftName);
        try {
            XmlSchema schema = wfs
                    .describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));

            if ((schema != null)) {
                FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(),
                        nonQueryableProperties != null ? Arrays.asList(nonQueryableProperties)
                                : new ArrayList<String>(),
                        Wfs10Constants.GML_NAMESPACE);

                Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Metacard.CONTENT_TYPE, new String[] { ftName });

                LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);

                // Update local map with enough info to create actual MetacardType registrations
                // later
                mcTypeRegs.put(ftName,
                        new MetacardTypeRegistration(ftMetacard, props, featureTypeType.getSRS()));

                FeatureConverter featureConverter = null;

                if (!CollectionUtils.isEmpty(featureConverterFactories)) {
                    for (FeatureConverterFactory factory : featureConverterFactories) {
                        if (ftName.equalsIgnoreCase(factory.getFeatureType())) {
                            featureConverter = factory.createConverter();
                            LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}",
                                    getId(), ftName, featureConverter.getClass().getSimpleName());
                            break;
                        }

                    }

                    if (featureConverter == null) {
                        LOGGER.warn(
                                "WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter",
                                getId(), ftName);
                        featureConverter = new GenericFeatureConverter();
                    }
                } else {
                    LOGGER.warn(
                            "WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter",
                            getId(), ftName);
                    featureConverter = new GenericFeatureConverter();

                }
                featureConverter.setSourceId(getId());
                featureConverter.setMetacardType(ftMetacard);
                featureConverter.setWfsUrl(wfsUrl);

                // Add the Feature Type name as an alias for xstream
                featureCollectionReader.registerConverter(featureConverter);
            }

        } catch (WfsException wfse) {
            LOGGER.warn(WFS_ERROR_MESSAGE, wfse);
        } catch (WebApplicationException wae) {
            handleWebApplicationException(wae);
        } catch (IllegalArgumentException ie) {
            LOGGER.warn(WFS_ERROR_MESSAGE, ie);
        }

    }

    // Unregister all MetacardType services - the DescribeFeatureTypeRequest should
    // have returned all of the most current metacard types that will now be registered.
    // As Source(s) are added/removed from this instance or to other Source(s)
    // that this instance is federated to, the list of metacard types will change.
    // This is done here vs. inside the above loop so that minimal time is spent clearing and
    // registering the MetacardTypes - the concern is that if this registration is too lengthy
    // a query could come in that is handled while the MetacardType registrations are
    // in a state of flux.
    unregisterAllMetacardTypes();
    this.featureTypeFilters.clear();
    if (!mcTypeRegs.isEmpty()) {
        Set<Entry<String, MetacardTypeRegistration>> entries = mcTypeRegs.entrySet();

        for (Map.Entry<String, MetacardTypeRegistration> entry : mcTypeRegs.entrySet()) {
            MetacardTypeRegistration mcTypeReg = entry.getValue();
            FeatureMetacardType ftMetacard = mcTypeReg.getFtMetacard();
            ServiceRegistration serviceRegistration = context.registerService(MetacardType.class.getName(),
                    ftMetacard, mcTypeReg.getProps());
            this.metacardTypeServiceRegistrations.put(entry.getKey(), serviceRegistration);
            this.featureTypeFilters.put(ftMetacard.getFeatureType(),
                    new WfsFilterDelegate(ftMetacard, supportedGeo, mcTypeReg.getSrs()));
        }
    }

    if (featureTypeFilters.isEmpty()) {
        LOGGER.warn("Wfs Source {}: No Feature Type schemas validated. Marking source as unavailable", getId());
    }
    LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

public Map<String, Object> disableConfiguration(String servicePid) throws IOException {
    if (StringUtils.isEmpty(servicePid)) {
        throw new IOException(
                "Service PID of Source to be disabled must be specified.  Service PID provided: " + servicePid);
    }//from w w  w . ja va  2  s  .  co  m

    Configuration originalConfig = configurationAdminExt.getConfiguration(servicePid);

    if (originalConfig == null) {
        throw new IOException("No Source exists with the service PID: " + servicePid);
    }

    Dictionary<String, Object> properties = originalConfig.getProperties();
    String originalFactoryPid = (String) properties
            .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID);
    if (StringUtils.endsWith(originalFactoryPid, DISABLED)) {
        throw new IOException("Source is already disabled.");
    }

    // Copy configuration from the original configuration and change its factory PID to end with
    // "disabled"
    String disabledServiceFactoryPid = originalFactoryPid + DISABLED;
    properties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, disabledServiceFactoryPid);
    Configuration disabledConfig = configurationAdmin.createFactoryConfiguration(disabledServiceFactoryPid,
            null);
    disabledConfig.update(properties);

    // remove original configuration
    originalConfig.delete();

    Map<String, Object> rval = new HashMap<>();
    rval.put(ORIGINAL_PID, servicePid);
    rval.put(ORIGINAL_FACTORY_PID, originalFactoryPid);
    rval.put(NEW_PID, disabledConfig.getPid());
    rval.put(NEW_FACTORY_PID, disabledServiceFactoryPid);
    return rval;
}

From source file:com.basistech.yca.FlatteningConfigFileManager.java

private void processAddOrUpdate(Path filename) {
    // create and modify look quite similar.
    Path child = configurationDirectory.resolve(filename);

    // The heck with content type probing, let's do this the simple way.
    int lastDot = filename.toString().lastIndexOf('.');
    if (lastDot == -1) {
        LOG.info("File has no suffix; ignoring: " + child);
        return;//  ww  w  .j  a  v a  2  s .  co  m
    }

    ObjectMapper mapper;
    String suffix = filename.toString().substring(lastDot + 1);
    if ("json".equals(suffix) || "js".equals(suffix)) {
        mapper = new ObjectMapper();
    } else if ("yaml".equals(suffix) || "yml".equals(suffix)) {
        mapper = new ObjectMapper(new YAMLFactory());
    } else {
        LOG.error("Unsupported file name " + filename.toString());
        return;
    }

    JsonNode content;
    try {
        content = mapper.readTree(child.toFile());
    } catch (IOException e) {
        LOG.error("Failed to read contents of " + child, e);
        return;
    }

    @SuppressWarnings("unchecked")
    Dictionary<String, Object> dict = (Dictionary<String, Object>) JsonNodeFlattener.flatten(content);

    String pid[] = parsePid(filename);
    Configuration config;
    try {
        config = getConfiguration(toConfigKey(filename), pid[0], pid[1]);
    } catch (IOException e) {
        LOG.error("Failed to get configuration for " + formatPid(pid));
        return;
    }

    Dictionary<String, Object> props = config.getProperties();
    Hashtable<String, Object> old = null;
    if (props != null) {
        old = new Hashtable<>(new DictionaryAsMap<>(props));
    }
    if (old != null) {
        old.remove(FILENAME_PROPERTY_KEY);
        old.remove(Constants.SERVICE_PID);
        old.remove(ConfigurationAdmin.SERVICE_FACTORYPID);
    }

    if (!dict.equals(old)) {
        dict.put(FILENAME_PROPERTY_KEY, toConfigKey(filename));
        if (old == null) {
            LOG.info("Creating configuration from " + filename);
        } else {
            LOG.info("Updating configuration from " + filename);
        }
        try {
            config.update(dict);
        } catch (IOException e) {
            LOG.error("Failed to update configuration for " + formatPid(pid));
        }
    }
}

From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java

/**
 * Tests the {@link AdminConsoleService#update(String, Map)} and {@link
 * AdminConsoleService#updateForLocation(String, String, Map)} methods and verifies when updating
 * a password with a value other than "password", it will update
 *
 * @throws Exception/*from  ww w .j a v  a2s .c  o m*/
 */
@Test
public void testUpdatePassword() throws Exception {
    AdminConsoleService configAdmin = getConfigAdmin();

    // Initialize password to "secret".
    Dictionary<String, Object> currentProps = new Hashtable<>();
    currentProps.put("TestKey_0_12", "secret");
    when(testConfig.getProperties()).thenReturn(currentProps);

    // Update the password with "newPassword".
    Hashtable<String, Object> values = new Hashtable<>();
    values.put("TestKey_0_12", "newPassword");

    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    configAdmin.update(TEST_PID, values);
    verify(testConfig, times(1)).update(captor.capture());

    // Assert the password updated to "newPassword".
    assertThat(captor.getValue().get("TestKey_0_12"), equalTo("newPassword"));
}