use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ApplicationServiceBeanTest method testGetServices.
/**
* Tests the {@link ApplicationServiceBean#getServices(String)} method
*
* @throws Exception
*/
@Test
public void testGetServices() throws Exception {
ApplicationServiceBean serviceBean = newApplicationServiceBean();
Bundle testBundle = mock(Bundle.class);
Bundle[] bundles = { testBundle };
when(bundleContext.getBundles()).thenReturn(bundles);
List<Service> services = new ArrayList<>();
Service testService1 = new ServiceImpl();
List<Map<String, Object>> testService1Configs = new ArrayList<>();
Map<String, Object> testConfig1 = new HashMap<>();
testConfig1.put("bundle_location", TEST_LOCATION);
testService1Configs.add(testConfig1);
services.add(testService1);
testService1.put("configurations", testService1Configs);
BundleInfo testBundle1 = mock(BundleInfo.class);
Set<BundleInfo> testBundles = new HashSet<>();
testBundles.add(testBundle1);
when(testApp.getBundles()).thenReturn(testBundles);
when(testBundle1.getLocation()).thenReturn(TEST_LOCATION);
when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
assertThat("Should find the given services.", serviceBean.getServices(TEST_APP_NAME).get(0), is(testService1));
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ServiceOperation method readState.
private static Map<String, Object> readState(String pid, AdminConsoleServiceMBean adminConsoleServiceMBean) throws ConfiguratorException {
try {
Map<String, Object> configResults = adminConsoleServiceMBean.getProperties(pid);
if (configResults.isEmpty()) {
Optional<Service> defaultMetatypeValues = adminConsoleServiceMBean.listServices().stream().filter(service -> service.getId() != null && service.getId().equals(pid)).findFirst();
List<MetatypeAttribute> metatypes = new ArrayList<>();
if (defaultMetatypeValues.isPresent()) {
metatypes = defaultMetatypeValues.get().getAttributeDefinitions();
}
return metatypes.stream().collect(Collectors.toMap(MetatypeAttribute::getId, MetatypeAttribute::getDefaultValue));
} else {
return configResults;
}
} catch (IOException e) {
throw new ConfiguratorException(String.format("Unable to find configuration for pid, %s", pid), e);
}
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ConfigurationAdminImplTest method testListServicesIOException.
/**
* Tests the {@link ConfigurationAdminImpl#listServices(String, String)} method for the case where
* configurationAdmin.listConfigurations(....) throws an IOException
*
* @throws Exception
*/
@Test
public void testListServicesIOException() throws Exception {
setUpListServices();
setUpTestConfig();
doThrow(new IOException()).when(testConfigAdmin).listConfigurations(anyString());
List<Service> result = configurationAdminImpl.listServices(TEST_FACT_FILTER, TEST_FILTER);
assertThat("Should recover gracefully but not add to the given data.", (String) result.get(0).get("name"), is(TEST_OCD));
assertThat("Should only contain one map.", result.size(), is(1));
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class AdminConsoleService method getService.
@Override
public Service getService(String filter) {
List<Service> services = configurationAdminImpl.listServices(filter, filter);
Service service = null;
if (!services.isEmpty()) {
// just grab the first one, they should have specified a filter that returned just a single
// result
// if not, that is not our problem
service = services.get(0);
}
return service;
}
use of org.codice.ddf.admin.core.api.Service 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);
}
}
Aggregations