Search in sources :

Example 1 with ConfigurationProperties

use of org.codice.ddf.admin.core.api.ConfigurationProperties in project ddf by codice.

the class AdminPollerServiceBean method allSourceInfo.

@Override
public List<Service> allSourceInfo() {
    // Get list of metatypes
    List<Service> metatypes = helper.getMetatypes();
    // Loop through each metatype and find its configurations
    for (Service metatype : metatypes) {
        try {
            List<Configuration> configs = helper.getConfigurations(metatype);
            List<ConfigurationDetails> configurations = new ArrayList<>();
            if (configs != null) {
                for (Configuration config : configs) {
                    ConfigurationDetails source = new ConfigurationDetailsImpl();
                    String pid = config.getPid();
                    String fPid = config.getFactoryPid();
                    boolean disabled = pid.endsWith(ConfigurationStatus.DISABLED_EXTENSION);
                    if (fPid != null) {
                        disabled = disabled || fPid.endsWith(ConfigurationStatus.DISABLED_EXTENSION);
                    }
                    source.setId(pid);
                    source.setEnabled(!disabled);
                    source.setFactoryPid(fPid);
                    if (!disabled) {
                        source.setName(helper.getName(config));
                        source.setBundleName(helper.getBundleName(config));
                        source.setBundleLocation(config.getBundleLocation());
                        source.setBundle(helper.getBundleId(config));
                    } else {
                        source.setName(config.getPid());
                    }
                    Dictionary<String, Object> properties = config.getProperties();
                    ConfigurationProperties plist = new ConfigurationPropertiesImpl();
                    for (String key : Collections.list(properties.keys())) {
                        plist.put(key, properties.get(key));
                    }
                    source.setConfigurationProperties(plist);
                    source.put(MAP_ENTRY_REPORT_ACTIONS, getActions(config, reportActionProviders));
                    source.put(MAP_ENTRY_OPERATION_ACTIONS, getActions(config, operationActionProviders));
                    configurations.add(source);
                }
                metatype.setConfigurations(configurations);
            }
        } catch (Exception e) {
            LOGGER.debug("Error getting source info: {}", e.getMessage());
        }
    }
    metatypes.sort(Comparator.comparing(Service::getId, String.CASE_INSENSITIVE_ORDER));
    return metatypes;
}
Also used : Configuration(org.osgi.service.cm.Configuration) ArrayList(java.util.ArrayList) ConfiguredService(ddf.catalog.service.ConfiguredService) Service(org.codice.ddf.admin.core.api.Service) ConfigurationProperties(org.codice.ddf.admin.core.api.ConfigurationProperties) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ConfigurationDetails(org.codice.ddf.admin.core.api.ConfigurationDetails)

Example 2 with ConfigurationProperties

use of org.codice.ddf.admin.core.api.ConfigurationProperties in project ddf by codice.

the class ConfigurationAdminImpl method addConfigurationData.

private void addConfigurationData(Service service, Configuration[] configs, Map<String, ObjectClassDefinition> objectClassDefinitions) {
    for (Configuration config : configs) {
        // ignore configuration object if it is invalid
        final String pid = config.getPid();
        if (!isAllowedPid(pid)) {
            continue;
        }
        ConfigurationDetails configData = new ConfigurationDetailsImpl();
        configData.setId(pid);
        String fpid = config.getFactoryPid();
        if (fpid != null) {
            configData.setFactoryPid(fpid);
        }
        // insert an entry for the PID
        try {
            ObjectClassDefinition ocd = objectClassDefinitions.get(config.getPid());
            if (ocd != null) {
                configData.setName(ocd.getName());
            } else {
                // no object class definition, use plain PID
                configData.setName(pid);
            }
        } catch (IllegalArgumentException t) {
            // Catch exception thrown by getObjectClassDefinition so other configurations
            // are displayed
            // no object class definition, use plain PID
            configData.setName(pid);
        }
        final Bundle bundle = getBoundBundle(config);
        if (null != bundle) {
            configData.setBundle(bundle.getBundleId());
            configData.setBundleName(getName(bundle));
            configData.setBundleLocation(bundle.getLocation());
        }
        ConfigurationProperties propertiesTable = new ConfigurationPropertiesImpl();
        Dictionary<String, Object> properties = config.getProperties();
        if (properties != null) {
            Enumeration<String> keys = properties.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                propertiesTable.put(key, properties.get(key));
            }
        }
        // If the configuration property is a password that has been set,
        // mask its value to "password" so that the real password value will be hidden.
        List<MetatypeAttribute> metatypeList = service.getAttributeDefinitions();
        metatypeList.stream().filter(metatype -> AttributeDefinition.PASSWORD == metatype.getType()).forEach(metatype -> {
            setPasswordMask(metatype, propertiesTable);
        });
        configData.setConfigurationProperties(propertiesTable);
        Map<String, Object> pluginDataMap = getConfigurationPluginData(configData.getId(), Collections.unmodifiableMap(configData));
        if (pluginDataMap != null && !pluginDataMap.isEmpty()) {
            configData.putAll(pluginDataMap);
        }
        List<ConfigurationDetails> configurationDetails;
        if (service.containsKey(Service.CONFIGURATIONS)) {
            configurationDetails = service.getConfigurations();
        } else if (service.containsKey(Service.DISABLED_CONFIGURATIONS)) {
            configurationDetails = service.getDisabledConfigurations();
        } else {
            configurationDetails = new ArrayList<>();
        }
        configurationDetails.add(configData);
        if (configData.getId().contains(ConfigurationDetails.DISABLED_SERVICE_IDENTIFIER)) {
            configData.setEnabled(false);
        } else {
            configData.setEnabled(true);
        }
        service.setConfigurations(configurationDetails);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) Constants(org.osgi.framework.Constants) Enumeration(java.util.Enumeration) LoggerFactory(org.slf4j.LoggerFactory) ConfigurationStatus(org.codice.ddf.admin.core.api.ConfigurationStatus) LogSanitizer(org.codice.ddf.log.sanitizer.LogSanitizer) Locale(java.util.Locale) MetatypeAttribute(org.codice.ddf.admin.core.api.MetatypeAttribute) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) ServiceReference(org.osgi.framework.ServiceReference) Service(org.codice.ddf.admin.core.api.Service) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Metatype(org.codice.ddf.admin.core.api.Metatype) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ConfigurationAdminPlugin(org.codice.ddf.ui.admin.api.plugin.ConfigurationAdminPlugin) BundleContext(org.osgi.framework.BundleContext) ConfigurationDetails(org.codice.ddf.admin.core.api.ConfigurationDetails) Permissions(ddf.security.permission.Permissions) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) SecurityUtils(org.apache.shiro.SecurityUtils) ConfigurationProperties(org.codice.ddf.admin.core.api.ConfigurationProperties) Dictionary(java.util.Dictionary) SERVICE_PID(org.osgi.framework.Constants.SERVICE_PID) HashMap(java.util.HashMap) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) SERVICE_FACTORYPID(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID) Configuration(org.osgi.service.cm.Configuration) Subject(org.apache.shiro.subject.Subject) Hashtable(java.util.Hashtable) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory) Logger(org.slf4j.Logger) IOException(java.io.IOException) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) MetaTypeService(org.osgi.service.metatype.MetaTypeService) Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ManagedService(org.osgi.service.cm.ManagedService) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) Configuration(org.osgi.service.cm.Configuration) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ConfigurationProperties(org.codice.ddf.admin.core.api.ConfigurationProperties) MetatypeAttribute(org.codice.ddf.admin.core.api.MetatypeAttribute) ConfigurationDetails(org.codice.ddf.admin.core.api.ConfigurationDetails) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Aggregations

IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ConfigurationDetails (org.codice.ddf.admin.core.api.ConfigurationDetails)2 ConfigurationProperties (org.codice.ddf.admin.core.api.ConfigurationProperties)2 Service (org.codice.ddf.admin.core.api.Service)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 Configuration (org.osgi.service.cm.Configuration)2 Sets (com.google.common.collect.Sets)1 ConfiguredService (ddf.catalog.service.ConfiguredService)1 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)1 Permissions (ddf.security.permission.Permissions)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Dictionary (java.util.Dictionary)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1