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;
}
}
}
}
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;
}
Aggregations