Search in sources :

Example 1 with ConfiguredService

use of ddf.catalog.service.ConfiguredService in project admin-console-beta by connexta.

the class SourceUtilCommons method populateAvailability.

@SuppressWarnings("squid:S135")
public void populateAvailability(BooleanField availability, PidField pid) {
    for (Source source : getAllSourceReferences()) {
        if (source instanceof ConfiguredService) {
            ConfiguredService service = (ConfiguredService) source;
            String servicePid = service.getConfigurationPid();
            if (servicePid != null && servicePid.equals(pid.getValue())) {
                availability.setValue(source.isAvailable());
                break;
            } else {
                LOGGER.debug("Unable to determine availability for source with pid [{}]", pid.getValue());
                availability.setValue(false);
                break;
            }
        }
    }
}
Also used : ConfiguredService(ddf.catalog.service.ConfiguredService) Source(ddf.catalog.source.Source) ConnectedSource(ddf.catalog.source.ConnectedSource) InputSource(org.xml.sax.InputSource) FederatedSource(ddf.catalog.source.FederatedSource)

Example 2 with ConfiguredService

use of ddf.catalog.service.ConfiguredService in project ddf by codice.

the class SourceConfigurationAdminPlugin method getConfigurationData.

/**
 * Returns a map of configuration data that should be appended to the configurationDataMap
 * parameter. The configurationDataMap that is passed into this function is unmodifiable and is
 * passed in to simply expose what information already exists.
 *
 * @param configurationPid service.pid for the ConfigurationAdmin configuration
 * @param configurationDataMap map of what properties have already been added to the configuration
 *     in question
 * @param bundleContext used to retrieve list of services
 * @return Map defining additional properties to add to the configuration
 */
@Override
public Map<String, Object> getConfigurationData(String configurationPid, Map<String, Object> configurationDataMap, BundleContext bundleContext) {
    LOGGER.debug("Obtaining configuration data for the following configuration PID: {}", configurationPid);
    Map<String, Object> statusMap = new HashMap<String, Object>();
    try {
        List<ServiceReference<? extends Source>> refs = new ArrayList<ServiceReference<? extends Source>>();
        refs.addAll(bundleContext.getServiceReferences(FederatedSource.class, null));
        refs.addAll(bundleContext.getServiceReferences(CatalogProvider.class, null));
        Set<SourceDescriptor> sources = null;
        if (catalogFramework != null) {
            sources = catalogFramework.getSourceInfo(new SourceInfoRequestEnterprise(true)).getSourceInfo();
        }
        boolean foundSources = CollectionUtils.isNotEmpty(sources);
        for (ServiceReference<? extends Source> ref : refs) {
            Source superService = bundleContext.getService(ref);
            if (superService instanceof ConfiguredService) {
                ConfiguredService cs = (ConfiguredService) superService;
                LOGGER.debug("ConfiguredService configuration PID: {}", cs.getConfigurationPid());
                boolean csConfigPidMatchesTargetPid = false;
                if (StringUtils.isNotEmpty(cs.getConfigurationPid()) && cs.getConfigurationPid().equals(configurationPid)) {
                    csConfigPidMatchesTargetPid = true;
                }
                if (foundSources) {
                    // class name, then we can match them up this way.
                    if (csConfigPidMatchesTargetPid || cs.getClass().getCanonicalName().equals(configurationPid)) {
                        for (SourceDescriptor descriptor : sources) {
                            if (descriptor.getSourceId().equals(superService.getId())) {
                                statusMap.put("available", descriptor.isAvailable());
                                statusMap.put("sourceId", descriptor.getSourceId());
                                return statusMap;
                            }
                        }
                    }
                } else if (csConfigPidMatchesTargetPid) {
                    // we don't want to call isAvailable because that can
                    // potentially block execution but if for some reason we
                    // have no catalog framework, just hit the source
                    // directly
                    statusMap.put("available", superService.isAvailable());
                    return statusMap;
                }
            }
        }
    } catch (org.osgi.framework.InvalidSyntaxException ise) {
        // this should never happen because the filter is always null
        LOGGER.debug("Error reading LDAP service filter", ise);
    } catch (SourceUnavailableException sue) {
        LOGGER.info("Unable to retrieve sources from Catalog Framework", sue);
    }
    return statusMap;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfiguredService(ddf.catalog.service.ConfiguredService) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) FederatedSource(ddf.catalog.source.FederatedSource) Source(ddf.catalog.source.Source) ServiceReference(org.osgi.framework.ServiceReference) FederatedSource(ddf.catalog.source.FederatedSource) CatalogProvider(ddf.catalog.source.CatalogProvider)

Aggregations

ConfiguredService (ddf.catalog.service.ConfiguredService)2 FederatedSource (ddf.catalog.source.FederatedSource)2 Source (ddf.catalog.source.Source)2 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)1 CatalogProvider (ddf.catalog.source.CatalogProvider)1 ConnectedSource (ddf.catalog.source.ConnectedSource)1 SourceDescriptor (ddf.catalog.source.SourceDescriptor)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ServiceReference (org.osgi.framework.ServiceReference)1 InputSource (org.xml.sax.InputSource)1