generated from openremote/custom-project
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from openremote/feature/configuration-assets
Feature/configuration assets
- Loading branch information
Showing
8 changed files
with
370 additions
and
35 deletions.
There are no files selected for viewing
187 changes: 158 additions & 29 deletions
187
manager/src/main/java/org/openremote/manager/custom/TeltonikaMQTTHandler.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
model/src/main/java/org/openremote/model/custom/CustomValueTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package org.openremote.model.custom; | ||
|
||
import org.openremote.model.teltonika.TeltonikaParameter; | ||
import org.openremote.model.value.ValueDescriptor; | ||
|
||
import java.util.HashMap; | ||
|
||
public class CustomValueTypes { | ||
public static final ValueDescriptor<AssetStateDuration> ASSET_STATE_DURATION = new ValueDescriptor<>("AssetStateDuration", AssetStateDuration.class); | ||
public static final ValueDescriptor<TeltonikaParameter> TELTONIKA_PARAMETER = new ValueDescriptor<>("TeltonikaParameter", TeltonikaParameter.class); | ||
public static class TeltonikaParameterMap extends HashMap<Integer, TeltonikaParameter> {} | ||
|
||
public static final ValueDescriptor<TeltonikaParameterMap> TELTONIKA_PARAMETER_MAP = new ValueDescriptor<>("TeltonikaParameterMap", TeltonikaParameterMap.class); | ||
} |
47 changes: 47 additions & 0 deletions
47
model/src/main/java/org/openremote/model/custom/TeltonikaConfigurationAsset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.openremote.model.custom; | ||
|
||
import jakarta.persistence.Entity; | ||
import org.openremote.model.asset.Asset; | ||
import org.openremote.model.asset.AssetDescriptor; | ||
import org.openremote.model.geo.GeoJSONPoint; | ||
import org.openremote.model.value.AttributeDescriptor; | ||
import org.openremote.model.value.ValueType; | ||
|
||
@Entity | ||
public class TeltonikaConfigurationAsset extends Asset<TeltonikaConfigurationAsset> { | ||
public static final AttributeDescriptor<String[]> WHITELIST = new AttributeDescriptor<>("deviceIMEIWhitelist", ValueType.TEXT.asArray()).withOptional(true); | ||
public static final AttributeDescriptor<Boolean> ENABLED = new AttributeDescriptor<>("Enabled", ValueType.BOOLEAN); | ||
public static final AttributeDescriptor<Boolean> CHECK_FOR_IMEI = new AttributeDescriptor<>("CheckForValidIMEI", ValueType.BOOLEAN); | ||
public static final AttributeDescriptor<String> DEFAULT_MODEL_NUMBER = new AttributeDescriptor<>("defaultModelNumber", ValueType.TEXT); | ||
|
||
public static final AssetDescriptor<TeltonikaConfigurationAsset> DESCRIPTOR = new AssetDescriptor<>("gear", null, TeltonikaConfigurationAsset.class); | ||
|
||
protected TeltonikaConfigurationAsset(){ | ||
|
||
} | ||
|
||
public TeltonikaConfigurationAsset(String name){ | ||
super(name); | ||
super.setLocation(new GeoJSONPoint(0,0,0)); | ||
super.setNotes(""); | ||
} | ||
|
||
public TeltonikaConfigurationAsset setWhitelist(String[] whitelist) { | ||
getAttributes().getOrCreate(WHITELIST).setValue(whitelist); | ||
return this; | ||
} | ||
public TeltonikaConfigurationAsset setEnabled(boolean enabled) { | ||
getAttributes().getOrCreate(ENABLED).setValue(enabled); | ||
return this; | ||
} | ||
|
||
public TeltonikaConfigurationAsset setCheckForImei(boolean enabled) { | ||
getAttributes().getOrCreate(CHECK_FOR_IMEI).setValue(enabled); | ||
return this; | ||
} | ||
|
||
public TeltonikaConfigurationAsset setDefaultModelNumber(String value) { | ||
getAttributes().getOrCreate(DEFAULT_MODEL_NUMBER).setValue(value); | ||
return this; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
model/src/main/java/org/openremote/model/custom/TeltonikaModelConfigurationAsset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.openremote.model.custom; | ||
|
||
import jakarta.persistence.Entity; | ||
import org.openremote.model.asset.Asset; | ||
import org.openremote.model.asset.AssetDescriptor; | ||
import org.openremote.model.attribute.Attribute; | ||
import org.openremote.model.attribute.MetaItem; | ||
import org.openremote.model.attribute.MetaMap; | ||
import org.openremote.model.geo.GeoJSONPoint; | ||
import org.openremote.model.teltonika.TeltonikaParameter; | ||
import org.openremote.model.value.AttributeDescriptor; | ||
import org.openremote.model.value.MetaItemType; | ||
import org.openremote.model.value.ValueType; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Entity | ||
public class TeltonikaModelConfigurationAsset extends Asset<TeltonikaModelConfigurationAsset> { | ||
public static final AttributeDescriptor<String> MODEL_NUMBER = new AttributeDescriptor<>("modelNumber", ValueType.TEXT); | ||
public static final AttributeDescriptor<TeltonikaParameter[]> PARAMETER_DATA = new AttributeDescriptor<>("TeltonikaParameterData", CustomValueTypes.TELTONIKA_PARAMETER.asArray()); | ||
|
||
public static final AttributeDescriptor<CustomValueTypes.TeltonikaParameterMap> PARAMETER_MAP = new AttributeDescriptor<>("TeltonikaParameterMap", CustomValueTypes.TELTONIKA_PARAMETER_MAP) | ||
.withMeta(new MetaMap(Map.of(MetaItemType.READ_ONLY.getName(), new MetaItem<>(MetaItemType.READ_ONLY, true)))); | ||
public static final AssetDescriptor<TeltonikaModelConfigurationAsset> DESCRIPTOR = new AssetDescriptor<>("switch", null, TeltonikaModelConfigurationAsset.class); | ||
|
||
protected TeltonikaModelConfigurationAsset(){} | ||
|
||
public TeltonikaModelConfigurationAsset(String name){ | ||
super(name); | ||
super.setLocation(new GeoJSONPoint(0,0,0)); | ||
super.setNotes(""); | ||
} | ||
|
||
public TeltonikaModelConfigurationAsset setModelNumber(String name) { | ||
getAttributes().getOrCreate(MODEL_NUMBER).setValue(name); | ||
return this; | ||
} | ||
|
||
public TeltonikaModelConfigurationAsset setParameterData(TeltonikaParameter[] data) { | ||
//Get TeltonikaParameter array, cast to Map with parameter ID as key, save to PARAMETER_MAP, remove from PARAMETER_DATA | ||
getAttributes().getOrCreate(PARAMETER_DATA).setValue(data); | ||
CustomValueTypes.TeltonikaParameterMap map = Arrays.stream(data).collect(Collectors.toMap( | ||
TeltonikaParameter::getPropertyId, // Key Mapper | ||
param -> param, // Value Mapper | ||
(existing, replacement) -> replacement, // Merge Function | ||
CustomValueTypes.TeltonikaParameterMap::new | ||
)); | ||
|
||
getAttributes().getOrCreate(PARAMETER_MAP).setValue(map); | ||
|
||
// | ||
|
||
|
||
|
||
return this; | ||
} | ||
|
||
public Optional<String> getModelNumber(){ | ||
return getAttributes().getValue(MODEL); | ||
} | ||
|
||
public CustomValueTypes.TeltonikaParameterMap getParameterMap() { | ||
Optional<Attribute<CustomValueTypes.TeltonikaParameterMap>> map = getAttributes().get(PARAMETER_MAP); | ||
|
||
return map.flatMap(Attribute::getValue) | ||
.orElse(null); // or provide a default value other than null, if appropriate | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
model/src/main/java/org/openremote/model/teltonika/TeltonikaConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.openremote.model.teltonika; | ||
|
||
import org.openremote.model.custom.CustomValueTypes; | ||
import org.openremote.model.custom.TeltonikaConfigurationAsset; | ||
import org.openremote.model.custom.TeltonikaModelConfigurationAsset; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class TeltonikaConfiguration { | ||
public TeltonikaConfigurationAsset getMasterAsset() { | ||
return masterAsset; | ||
} | ||
|
||
TeltonikaConfigurationAsset masterAsset; | ||
/** | ||
* Maps Model Number to Map of parameters: {@code [{"FMCOO3": {<map of parameters>}...]}} | ||
*/ | ||
HashMap<String, CustomValueTypes.TeltonikaParameterMap> parameterMap; | ||
|
||
public List<TeltonikaModelConfigurationAsset> getModelAssets() { | ||
return modelAssets; | ||
} | ||
|
||
private List<TeltonikaModelConfigurationAsset> modelAssets; | ||
|
||
public TeltonikaConfiguration(TeltonikaConfigurationAsset master, List<TeltonikaModelConfigurationAsset> models){ | ||
if (master == null) return; | ||
if (models.isEmpty()) return; | ||
|
||
masterAsset = master; | ||
|
||
parameterMap = models.stream().collect(Collectors.toMap( | ||
val ->val.getAttributes().get(TeltonikaModelConfigurationAsset.MODEL_NUMBER).get().getValue().get(), // Key Mapper | ||
TeltonikaModelConfigurationAsset::getParameterMap, // Value Mapper | ||
(existing, replacement) -> replacement, // Merge Function | ||
HashMap::new | ||
)); | ||
|
||
modelAssets = models; | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TeltonikaConfiguration{" + | ||
"masterAsset=" + masterAsset + | ||
", parameterMap=" + parameterMap + | ||
", modelAssets=" + modelAssets + | ||
'}'; | ||
} | ||
|
||
public List<String> getChildModelIDs(){ | ||
return modelAssets.stream().map(TeltonikaModelConfigurationAsset::getId).collect(Collectors.toList()); | ||
} | ||
|
||
public Boolean getEnabled(){ | ||
return masterAsset.getAttribute(TeltonikaConfigurationAsset.ENABLED).get().getValue().get(); | ||
} | ||
|
||
public boolean getCheckForImei() { | ||
return masterAsset.getAttribute(TeltonikaConfigurationAsset.CHECK_FOR_IMEI).get().getValue().get(); | ||
} | ||
|
||
public String getDefaultModelNumber() { | ||
return masterAsset.getAttribute(TeltonikaConfigurationAsset.DEFAULT_MODEL_NUMBER).get().getValue().get(); | ||
} | ||
|
||
public HashMap<String, CustomValueTypes.TeltonikaParameterMap> getParameterMap() { | ||
return parameterMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters