Search in sources :

Example 1 with GwtConfigParameter

use of org.eclipse.kura.web.shared.model.GwtConfigParameter 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;
}
Also used : AD(org.eclipse.kura.configuration.metatype.AD) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentConfiguration(org.eclipse.kura.configuration.ComponentConfiguration) OCD(org.eclipse.kura.configuration.metatype.OCD) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) Option(org.eclipse.kura.configuration.metatype.Option) ConfigurationService(org.eclipse.kura.configuration.ConfigurationService) Icon(org.eclipse.kura.configuration.metatype.Icon) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent)

Example 2 with GwtConfigParameter

use of org.eclipse.kura.web.shared.model.GwtConfigParameter in project kura by eclipse.

the class AbstractServicesUi method restoreConfiguration.

protected void restoreConfiguration(GwtConfigComponent originalConfig) {
    this.m_configurableComponent = new GwtConfigComponent();
    this.m_configurableComponent.setComponentDescription(originalConfig.getComponentDescription());
    this.m_configurableComponent.setComponentIcon(originalConfig.getComponentIcon());
    this.m_configurableComponent.setComponentId(originalConfig.getComponentId());
    this.m_configurableComponent.setComponentName(originalConfig.getComponentName());
    List<GwtConfigParameter> originalParameters = new ArrayList<GwtConfigParameter>();
    for (GwtConfigParameter parameter : originalConfig.getParameters()) {
        GwtConfigParameter tempParam = new GwtConfigParameter(parameter);
        originalParameters.add(tempParam);
    }
    this.m_configurableComponent.setParameters(originalParameters);
    Map<String, Object> originalProperties = new HashMap<String, Object>();
    originalProperties.putAll(originalConfig.getProperties());
    this.m_configurableComponent.setProperties(originalProperties);
}
Also used : HashMap(java.util.HashMap) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) ArrayList(java.util.ArrayList) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent)

Example 3 with GwtConfigParameter

use of org.eclipse.kura.web.shared.model.GwtConfigParameter in project kura by eclipse.

the class GwtComponentServiceImpl method createGwtComponentConfiguration.

private GwtConfigComponent createGwtComponentConfiguration(ComponentConfiguration config) throws GwtKuraException {
    GwtConfigComponent gwtConfig = null;
    OCD ocd = config.getDefinition();
    if (ocd != null) {
        gwtConfig = new GwtConfigComponent();
        gwtConfig.setComponentId(config.getPid());
        Map<String, Object> props = config.getConfigurationProperties();
        if (props != null && props.get(SERVICE_FACTORY_PID) != null) {
            String pid = stripPidPrefix(config.getPid());
            gwtConfig.setComponentName(pid);
        } else {
            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);
        if (config.getConfigurationProperties() != null) {
            List<GwtConfigParameter> metatypeProps = getADProperties(config);
            gwtParams.addAll(metatypeProps);
            List<String> addedIds = new ArrayList<String>();
            for (GwtConfigParameter gwtParam : gwtParams) {
                addedIds.add(gwtParam.getId());
            }
            List<GwtConfigParameter> nonMetatypeProps = getNonMetatypeProperties(config, addedIds);
            gwtParams.addAll(nonMetatypeProps);
        }
    }
    return gwtConfig;
}
Also used : OCD(org.eclipse.kura.configuration.metatype.OCD) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) ArrayList(java.util.ArrayList) Icon(org.eclipse.kura.configuration.metatype.Icon) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent)

Example 4 with GwtConfigParameter

use of org.eclipse.kura.web.shared.model.GwtConfigParameter in project kura by eclipse.

the class GwtComponentServiceImpl method updateComponentConfiguration.

@Override
public void updateComponentConfiguration(GwtXSRFToken xsrfToken, GwtConfigComponent gwtCompConfig) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    ConfigurationService cs = ServiceLocator.getInstance().getService(ConfigurationService.class);
    try {
        // Build the new properties
        Map<String, Object> properties = new HashMap<String, Object>();
        ComponentConfiguration backupCC = cs.getComponentConfiguration(gwtCompConfig.getComponentId());
        Map<String, Object> backupConfigProp = backupCC.getConfigurationProperties();
        for (GwtConfigParameter gwtConfigParam : gwtCompConfig.getParameters()) {
            Object objValue;
            ComponentConfiguration currentCC = cs.getComponentConfiguration(gwtCompConfig.getComponentId());
            Map<String, Object> currentConfigProp = currentCC.getConfigurationProperties();
            Object currentObjValue = currentConfigProp.get(gwtConfigParam.getId());
            int cardinality = gwtConfigParam.getCardinality();
            if (cardinality == 0 || cardinality == 1 || cardinality == -1) {
                String strValue = gwtConfigParam.getValue();
                if (currentObjValue instanceof Password && PLACEHOLDER.equals(strValue)) {
                    objValue = currentConfigProp.get(gwtConfigParam.getId());
                } else {
                    objValue = getObjectValue(gwtConfigParam, strValue);
                }
            } else {
                String[] strValues = gwtConfigParam.getValues();
                if (currentObjValue instanceof Password[]) {
                    Password[] currentPasswordValue = (Password[]) currentObjValue;
                    for (int i = 0; i < strValues.length; i++) {
                        if (PLACEHOLDER.equals(strValues[i])) {
                            strValues[i] = new String(currentPasswordValue[i].getPassword());
                        }
                    }
                }
                objValue = getObjectValue(gwtConfigParam, strValues);
            }
            properties.put(gwtConfigParam.getId(), objValue);
        }
        // Force kura.service.pid into properties, if originally present
        if (backupConfigProp.get(KURA_SERVICE_PID) != null) {
            properties.put(KURA_SERVICE_PID, backupConfigProp.get(KURA_SERVICE_PID));
        }
        // 
        // apply them
        cs.updateConfiguration(gwtCompConfig.getComponentId(), properties);
    } catch (Throwable t) {
        KuraExceptionHandler.handle(t);
    }
}
Also used : ComponentConfiguration(org.eclipse.kura.configuration.ComponentConfiguration) HashMap(java.util.HashMap) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) ConfigurationService(org.eclipse.kura.configuration.ConfigurationService) Password(org.eclipse.kura.configuration.Password)

Example 5 with GwtConfigParameter

use of org.eclipse.kura.web.shared.model.GwtConfigParameter in project kura by eclipse.

the class DeviceConfigPanel method getUpdatedConfiguration.

public GwtConfigComponent getUpdatedConfiguration() {
    List<Component> fields = m_actionFieldSet.getItems();
    for (int i = 0; i < fields.size(); i++) {
        if (fields.get(i) instanceof Field<?>) {
            Field<?> field = (Field<?>) fields.get(i);
            String fieldName = field.getItemId();
            GwtConfigParameter param = m_configComponent.getParameter(fieldName);
            if (param == null) {
                System.err.println(field);
            }
            if (!(field instanceof MultiField) || (field instanceof RadioGroup)) {
                // get the updated values for the single field
                String value = getUpdatedFieldConfiguration(param, field);
                param.setValue(value);
            } else {
                // iterate over the subfields and extract each value
                List<String> multiFieldValues = new ArrayList<String>();
                MultiField<?> multiField = (MultiField<?>) field;
                List<Field<?>> childFields = multiField.getAll();
                for (int j = 0; j < childFields.size(); j++) {
                    Field<?> childField = (Field<?>) childFields.get(j);
                    String value = getUpdatedFieldConfiguration(param, childField);
                    if (value != null) {
                        multiFieldValues.add(value);
                    }
                }
                param.setValues(multiFieldValues.toArray(new String[] {}));
            }
        }
    }
    return m_configComponent;
}
Also used : RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) ArrayList(java.util.ArrayList) MultiField(com.extjs.gxt.ui.client.widget.form.MultiField) MultiField(com.extjs.gxt.ui.client.widget.form.MultiField) TextField(com.extjs.gxt.ui.client.widget.form.TextField) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) Field(com.extjs.gxt.ui.client.widget.form.Field) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) Component(com.extjs.gxt.ui.client.widget.Component) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent)

Aggregations

GwtConfigParameter (org.eclipse.kura.web.shared.model.GwtConfigParameter)13 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)6 GwtConfigComponent (org.eclipse.kura.web.shared.model.GwtConfigComponent)6 OCD (org.eclipse.kura.configuration.metatype.OCD)5 AD (org.eclipse.kura.configuration.metatype.AD)4 ComponentConfiguration (org.eclipse.kura.configuration.ComponentConfiguration)3 ConfigurationService (org.eclipse.kura.configuration.ConfigurationService)3 Icon (org.eclipse.kura.configuration.metatype.Icon)3 Option (org.eclipse.kura.configuration.metatype.Option)3 FormGroup (org.gwtbootstrap3.client.ui.FormGroup)2 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 Margins (com.extjs.gxt.ui.client.util.Margins)1 Component (com.extjs.gxt.ui.client.widget.Component)1 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)1 Field (com.extjs.gxt.ui.client.widget.form.Field)1 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)1 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)1 MultiField (com.extjs.gxt.ui.client.widget.form.MultiField)1 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)1