Search in sources :

Example 1 with MetaItemDescriptor

use of org.openremote.model.value.MetaItemDescriptor in project openremote by openremote.

the class AssetModelInfoExtension method emitElements.

@SuppressWarnings("rawtypes")
@Override
public void emitElements(Writer writer, Settings settings, boolean exportKeyword, TsModel model) {
    Map<String, String> assetMap = new HashMap<>();
    Map<String, String> otherMap = new HashMap<>();
    Arrays.stream(ValueUtil.getAssetInfos(null)).forEach(assetModelInfo -> {
        String assetDescriptorName = assetModelInfo.getAssetDescriptor().getName();
        assetMap.put(assetDescriptorName.toUpperCase(Locale.ROOT), assetDescriptorName);
        // Store attributes
        Arrays.stream(assetModelInfo.getAttributeDescriptors()).forEach(attributeDescriptor -> {
            String attributeName = attributeDescriptor.getName();
            otherMap.put(attributeName.toUpperCase(Locale.ROOT), attributeName);
        });
    });
    emitEnum(writer, "WellknownAssets", assetMap);
    writer.writeIndentedLine("");
    emitEnum(writer, "WellknownAttributes", otherMap);
    otherMap.clear();
    Arrays.stream(ValueUtil.getMetaItemDescriptors()).forEach(metaItemDescriptor -> {
        String metaName = metaItemDescriptor.getName();
        otherMap.put(metaName.toUpperCase(Locale.ROOT), metaName);
    });
    writer.writeIndentedLine("");
    emitEnum(writer, "WellknownMetaItems", otherMap);
    otherMap.clear();
    Arrays.stream(ValueUtil.getValueDescriptors()).forEach(valueDescriptor -> {
        String valueTypeName = valueDescriptor.getName();
        otherMap.put(valueTypeName.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), valueTypeName);
    });
    writer.writeIndentedLine("");
    emitEnum(writer, "WellknownValueTypes", otherMap);
    otherMap.clear();
    Arrays.stream(Constants.class.getFields()).filter(f -> f.getName().startsWith("UNITS_")).forEach(unitField -> {
        String unitName = unitField.getName().substring(6);
        try {
            otherMap.put(unitName.toUpperCase(Locale.ROOT), (String) unitField.get(null));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    });
    writer.writeIndentedLine("");
    emitEnum(writer, "WellknownUnitTypes", otherMap);
    otherMap.clear();
    Arrays.stream(Ruleset.class.getFields()).filter(f -> f.getType() == MetaItemDescriptor.class).forEach(rulesetMeta -> {
        try {
            MetaItemDescriptor metaItemDescriptor = (MetaItemDescriptor) rulesetMeta.get(null);
            otherMap.put(metaItemDescriptor.getName().toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), metaItemDescriptor.getName());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    });
    writer.writeIndentedLine("");
    emitEnum(writer, "WellknownRulesetMetaItems", otherMap);
}
Also used : Ruleset(org.openremote.model.rules.Ruleset) java.util(java.util) EmitterExtensionFeatures(cz.habarta.typescript.generator.emitter.EmitterExtensionFeatures) MetaItemDescriptor(org.openremote.model.value.MetaItemDescriptor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Extension(cz.habarta.typescript.generator.Extension) ValueUtil(org.openremote.model.util.ValueUtil) Constants(org.openremote.model.Constants) Settings(cz.habarta.typescript.generator.Settings) TsModel(cz.habarta.typescript.generator.emitter.TsModel) AgentModelProvider(org.openremote.agent.protocol.AgentModelProvider) Ruleset(org.openremote.model.rules.Ruleset) Constants(org.openremote.model.Constants) MetaItemDescriptor(org.openremote.model.value.MetaItemDescriptor)

Aggregations

Extension (cz.habarta.typescript.generator.Extension)1 Settings (cz.habarta.typescript.generator.Settings)1 EmitterExtensionFeatures (cz.habarta.typescript.generator.emitter.EmitterExtensionFeatures)1 TsModel (cz.habarta.typescript.generator.emitter.TsModel)1 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AgentModelProvider (org.openremote.agent.protocol.AgentModelProvider)1 Constants (org.openremote.model.Constants)1 Ruleset (org.openremote.model.rules.Ruleset)1 ValueUtil (org.openremote.model.util.ValueUtil)1 MetaItemDescriptor (org.openremote.model.value.MetaItemDescriptor)1