Search in sources :

Example 1 with KapuaTicon

use of org.eclipse.kapua.model.config.metatype.KapuaTicon in project kapua by eclipse.

the class TranslatorAppConfigurationKapuaKura method translate.

private KapuaTocd translate(KapuaTocd kapuaDefinition) {
    TocdImpl definition = new TocdImpl();
    definition.setId(kapuaDefinition.getId());
    definition.setName(kapuaDefinition.getName());
    definition.setDescription(kapuaDefinition.getDescription());
    for (KapuaTad kapuaAd : kapuaDefinition.getAD()) {
        TadImpl ad = new TadImpl();
        ad.setCardinality(kapuaAd.getCardinality());
        ad.setDefault(ad.getDefault());
        ad.setDescription(kapuaAd.getDescription());
        ad.setId(kapuaAd.getId());
        ad.setMax(kapuaAd.getMax());
        ad.setMin(kapuaAd.getMin());
        ad.setName(kapuaAd.getName());
        ad.setType(kapuaAd.getType());
        ad.setRequired(kapuaAd.isRequired());
        for (KapuaToption kuraToption : kapuaAd.getOption()) {
            ToptionImpl kapuaToption = new ToptionImpl();
            kapuaToption.setLabel(kuraToption.getLabel());
            kapuaToption.setValue(kuraToption.getValue());
            ad.addOption(kapuaToption);
        }
        for (Entry<QName, String> entry : kapuaAd.getOtherAttributes().entrySet()) {
            ad.putOtherAttribute(entry.getKey(), entry.getValue());
        }
        definition.addAD(ad);
    }
    for (KapuaTicon kapuaIcon : kapuaDefinition.getIcon()) {
        KapuaTicon icon = new TiconImpl();
        icon.setResource(kapuaIcon.getResource());
        icon.setSize(kapuaIcon.getSize());
        definition.addIcon(icon);
    }
    for (Object kapuaAny : kapuaDefinition.getAny()) {
        definition.addAny(kapuaAny);
    }
    for (Entry<QName, String> entry : kapuaDefinition.getOtherAttributes().entrySet()) {
        definition.putOtherAttribute(entry.getKey(), entry.getValue());
    }
    return definition;
}
Also used : KapuaTad(org.eclipse.kapua.model.config.metatype.KapuaTad) KapuaToption(org.eclipse.kapua.model.config.metatype.KapuaToption) TadImpl(org.eclipse.kapua.commons.configuration.metatype.TadImpl) KapuaTicon(org.eclipse.kapua.model.config.metatype.KapuaTicon) TocdImpl(org.eclipse.kapua.commons.configuration.metatype.TocdImpl) QName(javax.xml.namespace.QName) ToptionImpl(org.eclipse.kapua.commons.configuration.metatype.ToptionImpl) TiconImpl(org.eclipse.kapua.commons.configuration.metatype.TiconImpl)

Example 2 with KapuaTicon

use of org.eclipse.kapua.model.config.metatype.KapuaTicon in project kapua by eclipse.

the class TranslatorAppConfigurationKuraKapua method translate.

private KapuaTocd translate(KapuaTocd kuraDefinition) {
    TocdImpl definition = new TocdImpl();
    definition.setId(kuraDefinition.getId());
    definition.setName(kuraDefinition.getName());
    definition.setDescription(kuraDefinition.getDescription());
    for (KapuaTad kuraAd : kuraDefinition.getAD()) {
        TadImpl ad = new TadImpl();
        ad.setCardinality(kuraAd.getCardinality());
        ad.setDefault(ad.getDefault());
        ad.setDescription(kuraAd.getDescription());
        ad.setId(kuraAd.getId());
        ad.setMax(kuraAd.getMax());
        ad.setMin(kuraAd.getMin());
        ad.setName(kuraAd.getName());
        ad.setType(kuraAd.getType());
        ad.setRequired(kuraAd.isRequired());
        for (KapuaToption kuraToption : kuraAd.getOption()) {
            ToptionImpl kapuaToption = new ToptionImpl();
            kapuaToption.setLabel(kuraToption.getLabel());
            kapuaToption.setValue(kuraToption.getValue());
            ad.addOption(kapuaToption);
        }
        for (Entry<QName, String> entry : kuraAd.getOtherAttributes().entrySet()) {
            ad.putOtherAttribute(entry.getKey(), entry.getValue());
        }
        definition.addAD(ad);
    }
    for (KapuaTicon kuraIcon : kuraDefinition.getIcon()) {
        KapuaTicon icon = new TiconImpl();
        icon.setResource(kuraIcon.getResource());
        icon.setSize(kuraIcon.getSize());
        definition.addIcon(icon);
    }
    for (Object kuraAny : kuraDefinition.getAny()) {
        definition.addAny(kuraAny);
    }
    for (Entry<QName, String> entry : kuraDefinition.getOtherAttributes().entrySet()) {
        definition.putOtherAttribute(entry.getKey(), entry.getValue());
    }
    return definition;
}
Also used : KapuaTad(org.eclipse.kapua.model.config.metatype.KapuaTad) KapuaToption(org.eclipse.kapua.model.config.metatype.KapuaToption) TadImpl(org.eclipse.kapua.commons.configuration.metatype.TadImpl) KapuaTicon(org.eclipse.kapua.model.config.metatype.KapuaTicon) TocdImpl(org.eclipse.kapua.commons.configuration.metatype.TocdImpl) QName(javax.xml.namespace.QName) ToptionImpl(org.eclipse.kapua.commons.configuration.metatype.ToptionImpl) TiconImpl(org.eclipse.kapua.commons.configuration.metatype.TiconImpl)

Example 3 with KapuaTicon

use of org.eclipse.kapua.model.config.metatype.KapuaTicon in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method findDeviceConfigurations.

// 
// Configurations
// 
@Override
public List<GwtConfigComponent> findDeviceConfigurations(GwtDevice device) throws GwtKapuaException {
    List<GwtConfigComponent> gwtConfigs = new ArrayList<GwtConfigComponent>();
    try {
        // get the configuration
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceConfigurationManagementService deviceConfiguratiomManagementService = locator.getService(DeviceConfigurationManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(device.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(device.getId());
        DeviceConfiguration deviceConfigurations = deviceConfiguratiomManagementService.get(scopeId, deviceId, null, null, null);
        if (deviceConfigurations != null) {
            // sort the list alphabetically by service name
            List<DeviceComponentConfiguration> configs = deviceConfigurations.getComponentConfigurations();
            Collections.sort(configs, new Comparator<DeviceComponentConfiguration>() {

                @Override
                public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfiguration arg1) {
                    String name0 = arg0.getId();
                    String name1 = arg1.getId();
                    if (name0.contains(".")) {
                        name0 = name0.substring(name0.lastIndexOf('.'));
                    }
                    if (name1.contains(".")) {
                        name1 = name1.substring(name1.lastIndexOf('.'));
                    }
                    return name0.compareTo(name1);
                }
            });
            // prepare results
            ConsoleSetting consoleConfig = ConsoleSetting.getInstance();
            List<String> serviceIgnore = consoleConfig.getList(String.class, ConsoleSettingKeys.DEVICE_CONFIGURATION_SERVICE_IGNORE);
            for (DeviceComponentConfiguration config : deviceConfigurations.getComponentConfigurations()) {
                // ignore items we want to hide
                if (serviceIgnore != null && serviceIgnore.contains(config.getId())) {
                    continue;
                }
                KapuaTocd ocd = config.getDefinition();
                if (ocd != null) {
                    GwtConfigComponent gwtConfig = new GwtConfigComponent();
                    gwtConfig.setId(config.getId());
                    gwtConfig.setName(ocd.getName());
                    gwtConfig.setDescription(ocd.getDescription());
                    if (ocd.getIcon() != null && ocd.getIcon().size() > 0) {
                        KapuaTicon icon = ocd.getIcon().get(0);
                        checkIconResource(icon);
                        gwtConfig.setComponentIcon(icon.getResource());
                    }
                    List<GwtConfigParameter> gwtParams = new ArrayList<GwtConfigParameter>();
                    gwtConfig.setParameters(gwtParams);
                    for (KapuaTad ad : ocd.getAD()) {
                        if (ad != null) {
                            GwtConfigParameter gwtParam = new GwtConfigParameter();
                            gwtParam.setId(ad.getId());
                            gwtParam.setName(ad.getName());
                            gwtParam.setDescription(ad.getDescription());
                            gwtParam.setType(GwtConfigParameterType.fromString(ad.getType().value()));
                            gwtParam.setRequired(ad.isRequired());
                            gwtParam.setCardinality(ad.getCardinality());
                            if (ad.getOption() != null && ad.getOption().size() > 0) {
                                Map<String, String> options = new HashMap<String, String>();
                                for (KapuaToption option : ad.getOption()) {
                                    options.put(option.getLabel(), option.getValue());
                                }
                                gwtParam.setOptions(options);
                            }
                            gwtParam.setMin(ad.getMin());
                            gwtParam.setMax(ad.getMax());
                            if (config.getProperties() != null) {
                                // handle the value based on the cardinality of the attribute
                                int cardinality = ad.getCardinality();
                                Object value = config.getProperties().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) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtConfigs;
}
Also used : KapuaTad(org.eclipse.kapua.model.config.metatype.KapuaTad) KapuaToption(org.eclipse.kapua.model.config.metatype.KapuaToption) KapuaTicon(org.eclipse.kapua.model.config.metatype.KapuaTicon) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConsoleSetting(org.eclipse.kapua.app.console.setting.ConsoleSetting) KapuaId(org.eclipse.kapua.model.id.KapuaId) GwtConfigComponent(org.eclipse.kapua.app.console.shared.model.GwtConfigComponent) DeviceComponentConfiguration(org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration) DeviceConfigurationManagementService(org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationManagementService) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtConfigParameter(org.eclipse.kapua.app.console.shared.model.GwtConfigParameter) KapuaTocd(org.eclipse.kapua.model.config.metatype.KapuaTocd) DeviceConfiguration(org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration)

Aggregations

KapuaTad (org.eclipse.kapua.model.config.metatype.KapuaTad)3 KapuaTicon (org.eclipse.kapua.model.config.metatype.KapuaTicon)3 KapuaToption (org.eclipse.kapua.model.config.metatype.KapuaToption)3 QName (javax.xml.namespace.QName)2 TadImpl (org.eclipse.kapua.commons.configuration.metatype.TadImpl)2 TiconImpl (org.eclipse.kapua.commons.configuration.metatype.TiconImpl)2 TocdImpl (org.eclipse.kapua.commons.configuration.metatype.TocdImpl)2 ToptionImpl (org.eclipse.kapua.commons.configuration.metatype.ToptionImpl)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConsoleSetting (org.eclipse.kapua.app.console.setting.ConsoleSetting)1 GwtConfigComponent (org.eclipse.kapua.app.console.shared.model.GwtConfigComponent)1 GwtConfigParameter (org.eclipse.kapua.app.console.shared.model.GwtConfigParameter)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaTocd (org.eclipse.kapua.model.config.metatype.KapuaTocd)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 DeviceComponentConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration)1 DeviceConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration)1 DeviceConfigurationManagementService (org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationManagementService)1