Search in sources :

Example 81 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testConfigurationCreateActivateConfigWithExistingDisabledConfig.

@Test
public void testConfigurationCreateActivateConfigWithExistingDisabledConfig() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, null);
    when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { config });
    Hashtable<String, Object> props = new Hashtable<>();
    props.put("id", "TestRegNode");
    props.put("origConfig", "origConfigValue");
    props.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    props.put("bindingType", "CSW_2.0.2");
    when(config.getProperties()).thenReturn(props);
    when(config.getFactoryPid()).thenReturn("Csw_Federated_Source_disabled");
    sch.setActivateConfigurations(true);
    setupSerialExecutor();
    sch.handleEvent(createEvent);
    verify(config, times(1)).delete();
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source", null);
    verify(config, times(2)).update(captor.capture());
    Dictionary passedValues = captor.getAllValues().get(1);
    assertCswProperties(passedValues);
    assertThat(passedValues.get("origConfig"), equalTo("origConfigValue"));
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 82 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testConfigurationUpdateActivateConfigNotFirstPriority.

@Test
public void testConfigurationUpdateActivateConfigNotFirstPriority() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, null);
    when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { config });
    Hashtable<String, Object> props = new Hashtable<>();
    props.put("id", "TestRegNode");
    props.put("origConfig", "origConfigValue");
    props.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    props.put("bindingType", "SomeOtherBindingType");
    when(config.getProperties()).thenReturn(props);
    when(config.getFactoryPid()).thenReturn("Some_Other_Source");
    Configuration newConfig = mock(Configuration.class);
    when(newConfig.getFactoryPid()).thenReturn("Some_Other_Source_disabled");
    when(configAdmin.createFactoryConfiguration("Some_Other_Source_disabled", null)).thenReturn(newConfig);
    List<String> priority = new ArrayList();
    priority.add("Top_Priority_Source");
    priority.add("CSW_2.0.2");
    sch.setSourceActivationPriorityOrder(priority);
    sch.setPreserveActiveConfigurations(false);
    sch.setActivateConfigurations(true);
    setupSerialExecutor();
    sch.handleEvent(updateEvent);
    verify(config, times(1)).delete();
    verify(configAdmin, times(1)).createFactoryConfiguration("Some_Other_Source_disabled", null);
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source", null);
    verify(configAdmin, times(1)).createFactoryConfiguration("Some_Other_Source_disabled", null);
    verify(config).update(captor.capture());
    List<Dictionary> values = captor.getAllValues();
    assertThat(values.size(), equalTo(1));
    Dictionary passedValues = values.get(0);
    assertThat(passedValues.get("attId"), equalTo("attValue"));
    assertCswProperties(passedValues);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 83 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class CamelServletCreator method registerServlet.

/**
     * Register the Camel Servlet with the HTTP Service
     */
public void registerServlet() {
    Dictionary props = new Hashtable();
    props.put("alias", SERVLET_PATH);
    props.put("servlet-name", SERVLET_NAME);
    bundleContext.registerService("javax.servlet.Servlet", new HttpProxyCamelHttpTransportServlet(camelContext), props);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable)

Example 84 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class ActionProviderRegistryProxy method bind.

public void bind(ServiceReference<MetacardTransformer> reference) {
    LOGGER.info("New service registered [{}]", reference);
    String transformerId = null;
    if (reference.getProperty(Constants.SERVICE_ID) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_ID).toString();
    // backwards compatibility
    }
    if (StringUtils.isBlank(transformerId) && reference.getProperty(Constants.SERVICE_SHORTNAME) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_SHORTNAME).toString();
    }
    if (StringUtils.isBlank(transformerId)) {
        return;
    }
    String actionProviderId = ACTION_ID_PREFIX + transformerId;
    String attributeName = getAttributeName(reference);
    ActionProvider provider = actionFactory.createActionProvider(actionProviderId, transformerId, attributeName);
    Dictionary actionProviderProperties = new Hashtable<String, String>();
    actionProviderProperties.put(Constants.SERVICE_ID, actionProviderId);
    ServiceRegistration actionServiceRegistration = getBundleContext().registerService(PROVIDER_INTERFACE_NAME, provider, actionProviderProperties);
    LOGGER.info("Registered new {} [{}]", PROVIDER_INTERFACE_NAME, actionServiceRegistration);
    actionProviderRegistry.put(reference, actionServiceRegistration);
}
Also used : ActionProvider(ddf.action.ActionProvider) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 85 with Dictionary

use of java.util.Dictionary in project sling by apache.

the class OsgiInstallerImpl method getInstallationState.

/**
     * @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
     */
@Override
public InstallationState getInstallationState() {
    synchronized (this.resourcesLock) {
        final InstallationState state = new InstallationState() {

            private final List<ResourceGroup> activeResources = new ArrayList<>();

            private final List<ResourceGroup> installedResources = new ArrayList<>();

            private final List<RegisteredResource> untransformedResources = new ArrayList<>();

            @Override
            public List<ResourceGroup> getActiveResources() {
                return activeResources;
            }

            @Override
            public List<ResourceGroup> getInstalledResources() {
                return installedResources;
            }

            @Override
            public List<RegisteredResource> getUntransformedResources() {
                return untransformedResources;
            }

            @Override
            public String toString() {
                return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
            }
        };
        for (final String entityId : this.persistentList.getEntityIds()) {
            if (!this.persistentList.isSpecialEntityId(entityId)) {
                final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
                final String alias = group.getAlias();
                final List<Resource> resources = new ArrayList<>();
                boolean first = true;
                boolean isActive = false;
                for (final TaskResource tr : group.getResources()) {
                    final ResourceState resourceState = tr.getState();
                    if (first) {
                        if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
                            isActive = true;
                        }
                        first = false;
                    }
                    resources.add(new Resource() {

                        @Override
                        public String getScheme() {
                            return tr.getScheme();
                        }

                        @Override
                        public String getURL() {
                            return tr.getURL();
                        }

                        @Override
                        public String getType() {
                            return tr.getType();
                        }

                        @Override
                        public InputStream getInputStream() throws IOException {
                            return tr.getInputStream();
                        }

                        @Override
                        public Dictionary<String, Object> getDictionary() {
                            return tr.getDictionary();
                        }

                        @Override
                        public String getDigest() {
                            return tr.getDigest();
                        }

                        @Override
                        public int getPriority() {
                            return tr.getPriority();
                        }

                        @Override
                        public String getEntityId() {
                            return tr.getEntityId();
                        }

                        @Override
                        public ResourceState getState() {
                            return resourceState;
                        }

                        @Override
                        public Version getVersion() {
                            return tr.getVersion();
                        }

                        @Override
                        public long getLastChange() {
                            return ((RegisteredResourceImpl) tr).getLastChange();
                        }

                        @Override
                        public Object getAttribute(final String key) {
                            return tr.getAttribute(key);
                        }

                        @Override
                        @CheckForNull
                        public String getError() {
                            return tr.getError();
                        }

                        @Override
                        public String toString() {
                            return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
                        }
                    });
                }
                final ResourceGroup rg = new ResourceGroup() {

                    @Override
                    public List<Resource> getResources() {
                        return resources;
                    }

                    @Override
                    public String getAlias() {
                        return alias;
                    }

                    @Override
                    public String toString() {
                        return "group[" + resources + "]";
                    }
                };
                if (isActive) {
                    state.getActiveResources().add(rg);
                } else {
                    state.getInstalledResources().add(rg);
                }
            }
        }
        Collections.sort(state.getActiveResources(), COMPARATOR);
        Collections.sort(state.getInstalledResources(), COMPARATOR);
        state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
        return state;
    }
}
Also used : Dictionary(java.util.Dictionary) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) InputStream(java.io.InputStream) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) ArrayList(java.util.ArrayList) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Resource(org.apache.sling.installer.api.info.Resource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) InstallableResource(org.apache.sling.installer.api.InstallableResource) IOException(java.io.IOException) InstallationState(org.apache.sling.installer.api.info.InstallationState) Version(org.osgi.framework.Version) CheckForNull(javax.annotation.CheckForNull) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResourceState(org.apache.sling.installer.api.tasks.ResourceState) TaskResourceGroup(org.apache.sling.installer.api.tasks.TaskResourceGroup) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup)

Aggregations

Dictionary (java.util.Dictionary)198 Hashtable (java.util.Hashtable)91 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)28 State (org.eclipse.osgi.service.resolver.State)28 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)27 BundleContext (org.osgi.framework.BundleContext)24 ArrayList (java.util.ArrayList)22 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)20 ServiceRegistration (org.osgi.framework.ServiceRegistration)20 IOException (java.io.IOException)17 Map (java.util.Map)17 Bundle (org.osgi.framework.Bundle)16 LinkedHashMap (java.util.LinkedHashMap)13 List (java.util.List)13 Matchers.anyString (org.mockito.Matchers.anyString)11 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)11