use of org.eclipse.kura.configuration.metatype.Option in project kura by eclipse.
the class GwtComponentServiceImpl method findComponentConfiguration.
@Override
public List<GwtConfigComponent> findComponentConfiguration(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
ConfigurationService cs = ServiceLocator.getInstance().getService(ConfigurationService.class);
List<GwtConfigComponent> gwtConfigs = new ArrayList<GwtConfigComponent>();
try {
List<ComponentConfiguration> configs = cs.getComponentConfigurations();
// sort the list alphabetically by service name
Collections.sort(configs, new Comparator<ComponentConfiguration>() {
@Override
public int compare(ComponentConfiguration arg0, ComponentConfiguration arg1) {
String name0;
int start = arg0.getPid().lastIndexOf('.');
int substringIndex = start + 1;
if (start != -1 && substringIndex < arg0.getPid().length()) {
name0 = arg0.getPid().substring(substringIndex);
} else {
name0 = arg0.getPid();
}
String name1;
start = arg1.getPid().lastIndexOf('.');
substringIndex = start + 1;
if (start != -1 && substringIndex < arg1.getPid().length()) {
name1 = arg1.getPid().substring(substringIndex);
} else {
name1 = arg1.getPid();
}
return name0.compareTo(name1);
}
});
for (ComponentConfiguration config : configs) {
// ignore items we want to hide
if (!config.getPid().endsWith("CommandCloudApp")) {
continue;
}
OCD ocd = config.getDefinition();
if (ocd != null) {
GwtConfigComponent gwtConfig = new GwtConfigComponent();
gwtConfig.setComponentId(ocd.getId());
gwtConfig.setComponentName(ocd.getName());
gwtConfig.setComponentDescription(ocd.getDescription());
if (ocd.getIcon() != null && !ocd.getIcon().isEmpty()) {
Icon icon = ocd.getIcon().get(0);
gwtConfig.setComponentIcon(icon.getResource());
}
List<GwtConfigParameter> gwtParams = new ArrayList<GwtConfigParameter>();
gwtConfig.setParameters(gwtParams);
for (AD ad : ocd.getAD()) {
GwtConfigParameter gwtParam = new GwtConfigParameter();
gwtParam.setId(ad.getId());
gwtParam.setName(ad.getName());
gwtParam.setDescription(ad.getDescription());
gwtParam.setType(GwtConfigParameterType.valueOf(ad.getType().name()));
gwtParam.setRequired(ad.isRequired());
gwtParam.setCardinality(ad.getCardinality());
if (ad.getOption() != null && !ad.getOption().isEmpty()) {
Map<String, String> options = new HashMap<String, String>();
for (Option option : ad.getOption()) {
options.put(option.getLabel(), option.getValue());
}
gwtParam.setOptions(options);
}
gwtParam.setMin(ad.getMin());
gwtParam.setMax(ad.getMax());
if (config.getConfigurationProperties() != null) {
// handle the value based on the cardinality of the
// attribute
int cardinality = ad.getCardinality();
Object value = config.getConfigurationProperties().get(ad.getId());
if (value != null) {
if (cardinality == 0 || cardinality == 1 || cardinality == -1) {
gwtParam.setValue(value.toString());
} else {
// this could be an array value
if (value instanceof Object[]) {
Object[] objValues = (Object[]) value;
List<String> strValues = new ArrayList<String>();
for (Object v : objValues) {
if (v != null) {
strValues.add(v.toString());
}
}
gwtParam.setValues(strValues.toArray(new String[] {}));
}
}
}
gwtParams.add(gwtParam);
}
}
gwtConfigs.add(gwtConfig);
}
}
} catch (Throwable t) {
KuraExceptionHandler.handle(t);
}
return gwtConfigs;
}
use of org.eclipse.kura.configuration.metatype.Option in project kura by eclipse.
the class GwtComponentServiceImpl method getADProperties.
private List<GwtConfigParameter> getADProperties(ComponentConfiguration config) {
List<GwtConfigParameter> gwtParams = new ArrayList<GwtConfigParameter>();
OCD ocd = config.getDefinition();
for (AD ad : ocd.getAD()) {
GwtConfigParameter gwtParam = new GwtConfigParameter();
gwtParam.setId(ad.getId());
gwtParam.setName(ad.getName());
gwtParam.setDescription(ad.getDescription());
gwtParam.setType(GwtConfigParameterType.valueOf(ad.getType().name()));
gwtParam.setRequired(ad.isRequired());
gwtParam.setCardinality(ad.getCardinality());
if (ad.getOption() != null && !ad.getOption().isEmpty()) {
Map<String, String> options = new HashMap<String, String>();
for (Option option : ad.getOption()) {
options.put(option.getLabel(), option.getValue());
}
gwtParam.setOptions(options);
}
gwtParam.setMin(ad.getMin());
gwtParam.setMax(ad.getMax());
// handle the value based on the cardinality of the attribute
int cardinality = ad.getCardinality();
Object value = config.getConfigurationProperties().get(ad.getId());
if (value != null) {
if (cardinality == 0 || cardinality == 1 || cardinality == -1) {
if (gwtParam.getType().equals(GwtConfigParameterType.PASSWORD)) {
gwtParam.setValue(PLACEHOLDER);
} else {
gwtParam.setValue(String.valueOf(value));
}
} else {
// this could be an array value
if (value instanceof Object[]) {
Object[] objValues = (Object[]) value;
List<String> strValues = new ArrayList<String>();
for (Object v : objValues) {
if (v != null) {
if (gwtParam.getType().equals(GwtConfigParameterType.PASSWORD)) {
strValues.add(PLACEHOLDER);
} else {
strValues.add(String.valueOf(v));
}
}
}
gwtParam.setValues(strValues.toArray(new String[] {}));
}
}
}
gwtParams.add(gwtParam);
}
return gwtParams;
}
use of org.eclipse.kura.configuration.metatype.Option in project kura by eclipse.
the class XmlJavaMetadataMapper method marshallAD.
private void marshallAD(AD ocdAD, Element ad) {
String adId = ocdAD.getId();
String adName = ocdAD.getName();
Scalar adType = ocdAD.getType();
Integer adCardinality = ocdAD.getCardinality();
Boolean adRequired = ocdAD.isRequired();
String adDefault = ocdAD.getDefault();
String adDescription = ocdAD.getDescription();
String adMin = ocdAD.getMin();
String adMax = ocdAD.getMax();
List<Option> adOptions = ocdAD.getOption();
if (adName != null) {
Attr attrName = this.mashallDoc.createAttribute(METADATA_AD_NAME);
attrName.setNodeValue(adName);
ad.setAttributeNode(attrName);
}
if (adId != null) {
Attr attrId = this.mashallDoc.createAttribute(METADATA_AD_ID);
attrId.setNodeValue(adId);
ad.setAttributeNode(attrId);
}
if (adType != null) {
Attr attrType = this.mashallDoc.createAttribute(METADATA_AD_TYPE);
attrType.setNodeValue(adType.value());
ad.setAttributeNode(attrType);
}
if (adCardinality != null) {
Attr attrCardinality = this.mashallDoc.createAttribute(METADATA_AD_CARDINALITY);
attrCardinality.setNodeValue(adCardinality.toString());
ad.setAttributeNode(attrCardinality);
}
if (adRequired != null) {
Attr attrRequired = this.mashallDoc.createAttribute(METADATA_AD_REQUIRED);
attrRequired.setNodeValue(adRequired.toString());
ad.setAttributeNode(attrRequired);
}
if (adDefault != null) {
Attr attrDefault = this.mashallDoc.createAttribute(METADATA_AD_DEFAULT);
attrDefault.setNodeValue(adDefault);
ad.setAttributeNode(attrDefault);
}
if (adDescription != null) {
Attr attrDescription = this.mashallDoc.createAttribute(METADATA_AD_DESCRIPTION);
attrDescription.setNodeValue(adDescription);
ad.setAttributeNode(attrDescription);
}
if (adMin != null) {
Attr attrMin = this.mashallDoc.createAttribute(METADATA_AD_MIN);
attrMin.setNodeValue(adMin);
ad.setAttributeNode(attrMin);
}
if (adMax != null) {
Attr attrMax = this.mashallDoc.createAttribute(METADATA_AD_MAX);
attrMax.setNodeValue(adMax);
ad.setAttributeNode(attrMax);
}
if (adOptions != null) {
for (Option adOption : adOptions) {
Element option = this.mashallDoc.createElement(OCD_NAMESPACE + ":" + METADATA_AD_OPTION);
marshallOption(adOption, option);
ad.appendChild(option);
}
}
}
use of org.eclipse.kura.configuration.metatype.Option in project kura by eclipse.
the class GwtComponentServiceImpl method findComponentConfigurations.
@Override
public List<GwtConfigComponent> findComponentConfigurations(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
ConfigurationService cs = ServiceLocator.getInstance().getService(ConfigurationService.class);
List<GwtConfigComponent> gwtConfigs = new ArrayList<GwtConfigComponent>();
try {
List<ComponentConfiguration> configs = cs.getComponentConfigurations();
// sort the list alphabetically by service name
Collections.sort(configs, new Comparator<ComponentConfiguration>() {
@Override
public int compare(ComponentConfiguration arg0, ComponentConfiguration arg1) {
String name0;
int start = arg0.getPid().lastIndexOf('.');
int substringIndex = start + 1;
if (start != -1 && substringIndex < arg0.getPid().length()) {
name0 = arg0.getPid().substring(substringIndex);
} else {
name0 = arg0.getPid();
}
String name1;
start = arg1.getPid().lastIndexOf('.');
substringIndex = start + 1;
if (start != -1 && substringIndex < arg1.getPid().length()) {
name1 = arg1.getPid().substring(substringIndex);
} else {
name1 = arg1.getPid();
}
return name0.compareTo(name1);
}
});
for (ComponentConfiguration config : configs) {
// ignore items we want to hide
if (config.getPid().endsWith("SystemPropertiesService") || config.getPid().endsWith("NetworkAdminService") || config.getPid().endsWith("NetworkConfigurationService") || config.getPid().endsWith("SslManagerService") || config.getPid().endsWith("FirewallConfigurationService")) {
continue;
}
OCD ocd = config.getDefinition();
if (ocd != null) {
GwtConfigComponent gwtConfig = new GwtConfigComponent();
gwtConfig.setComponentId(ocd.getId());
gwtConfig.setComponentName(ocd.getName());
gwtConfig.setComponentDescription(ocd.getDescription());
if (ocd.getIcon() != null && !ocd.getIcon().isEmpty()) {
Icon icon = ocd.getIcon().get(0);
gwtConfig.setComponentIcon(icon.getResource());
}
List<GwtConfigParameter> gwtParams = new ArrayList<GwtConfigParameter>();
gwtConfig.setParameters(gwtParams);
for (AD ad : ocd.getAD()) {
GwtConfigParameter gwtParam = new GwtConfigParameter();
gwtParam.setId(ad.getId());
gwtParam.setName(ad.getName());
gwtParam.setDescription(ad.getDescription());
gwtParam.setType(GwtConfigParameterType.valueOf(ad.getType().name()));
gwtParam.setRequired(ad.isRequired());
gwtParam.setCardinality(ad.getCardinality());
if (ad.getOption() != null && !ad.getOption().isEmpty()) {
Map<String, String> options = new HashMap<String, String>();
for (Option option : ad.getOption()) {
options.put(option.getLabel(), option.getValue());
}
gwtParam.setOptions(options);
}
gwtParam.setMin(ad.getMin());
gwtParam.setMax(ad.getMax());
if (config.getConfigurationProperties() != null) {
// handle the value based on the cardinality of the
// attribute
int cardinality = ad.getCardinality();
Object value = config.getConfigurationProperties().get(ad.getId());
if (value != null) {
if (cardinality == 0 || cardinality == 1 || cardinality == -1) {
if (gwtParam.getType().equals(GwtConfigParameterType.PASSWORD)) {
gwtParam.setValue(PLACEHOLDER);
} else {
gwtParam.setValue(value.toString());
}
} else {
// this could be an array value
if (value instanceof Object[]) {
Object[] objValues = (Object[]) value;
List<String> strValues = new ArrayList<String>();
for (Object v : objValues) {
if (v != null) {
if (gwtParam.getType().equals(GwtConfigParameterType.PASSWORD)) {
strValues.add(PLACEHOLDER);
} else {
strValues.add(v.toString());
}
}
}
gwtParam.setValues(strValues.toArray(new String[] {}));
}
}
}
gwtParams.add(gwtParam);
}
}
gwtConfigs.add(gwtConfig);
}
}
} catch (Throwable t) {
KuraExceptionHandler.handle(t);
}
return gwtConfigs;
}
Aggregations