use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdmin method getConfigurations.
/**
* @see ConfigurationAdminMBean#getConfigurations(java.lang.String)
*/
public String[][] getConfigurations(String filter) throws IOException {
if (filter == null || filter.length() < 1) {
throw new IOException("Argument filter cannot be null or empty");
}
List<String[]> result = new ArrayList<>();
Configuration[] configurations;
try {
configurations = configurationAdmin.listConfigurations(filter);
} catch (InvalidSyntaxException e) {
throw new IOException("Invalid filter [" + filter + "] : " + e);
}
if (configurations != null) {
for (Configuration config : configurations) {
if (isPermittedToViewService(config.getPid())) {
result.add(new String[] { config.getPid(), config.getBundleLocation() });
}
}
}
return result.toArray(new String[result.size()][]);
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdmin method updateForLocation.
/**
* @see ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String, java.util.Map)
*/
public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable) throws IOException {
if (pid == null || pid.length() < 1) {
throw loggedException("Argument pid cannot be null or empty");
}
if (configurationTable == null) {
throw loggedException("Argument configurationTable cannot be null");
}
Configuration config = configurationAdmin.getConfiguration(pid, location);
if (isPermittedToViewService(config.getPid())) {
final List<Map<String, Object>> metatype = findMetatypeForConfig(config);
List<Map.Entry<String, Object>> configEntries = new ArrayList<>();
CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator());
if (metatype == null) {
throw loggedException("Could not find metatype for " + pid);
}
// now we have to filter each property based on its cardinality
CollectionUtils.transform(configEntries, new CardinalityTransformer(metatype, pid));
Dictionary<String, Object> newConfigProperties = new Hashtable<>();
// "password", do not update the password.
for (Map.Entry<String, Object> configEntry : configEntries) {
String configEntryKey = configEntry.getKey();
Object configEntryValue = configEntry.getValue();
if (configEntryValue.equals("password")) {
for (Map<String, Object> metatypeProperties : metatype) {
if (metatypeProperties.get("id").equals(configEntry.getKey()) && AttributeDefinition.PASSWORD == (Integer) metatypeProperties.get("type")) {
Dictionary<String, Object> configProperties = config.getProperties();
if (configProperties != null) {
configEntryValue = configProperties.get(configEntryKey);
}
break;
}
}
}
newConfigProperties.put(configEntryKey, configEntryValue);
}
config.update(newConfigProperties);
}
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdmin method createFactoryConfigurationForLocation.
/**
* @see ConfigurationAdminMBean#createFactoryConfigurationForLocation(java.lang.String, java.lang.String)
*/
public String createFactoryConfigurationForLocation(String factoryPid, String location) throws IOException {
if (StringUtils.isBlank(factoryPid)) {
throw new IOException("Argument factoryPid cannot be null or empty");
}
if (isPermittedToViewService(factoryPid)) {
Configuration config = configurationAdmin.createFactoryConfiguration(factoryPid);
config.setBundleLocation(location);
return config.getPid();
}
return null;
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminExtTest method testGetConfigurationIOException.
/**
* Tests the {@link ConfigurationAdminExt#getConfiguration(String)} method
* for the case where configurationAdmin.listConfigurations(..) throws an IOException
*
* @throws Exception
*/
@Test
public void testGetConfigurationIOException() throws Exception {
doThrow(new IOException()).when(testConfigAdmin).listConfigurations(anyString());
Configuration result = configurationAdminExt.getConfiguration(TEST_PID);
assertThat("Should handle the exception gracefully and return null.", result, is(nullValue()));
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdmin method deleteForLocation.
/**
* @see ConfigurationAdminMBean#deleteForLocation(java.lang.String, java.lang.String)
*/
public void deleteForLocation(String pid, String location) throws IOException {
if (pid == null || pid.length() < 1) {
throw new IOException("Argument pid cannot be null or empty");
}
if (isPermittedToViewService(pid)) {
Configuration config = configurationAdmin.getConfiguration(pid, location);
config.delete();
}
}
Aggregations