use of org.codice.ddf.admin.core.api.MetatypeAttribute 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.MetatypeAttribute 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