Skip to content

Commit

Permalink
SMHE-832: ValueType as enum and lombok version the same as in osgp
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Bolder committed Jun 29, 2022
1 parent 4a94c2d commit 9dd0cab
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Attribute {
public int id;
public String description;
public String datatype;
public String valuetype;
public ValueType valuetype;
public String value;
public String access;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Alliander N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/

package org.opensmartgridplatform.domain.smartmetering.config;

public enum ValueType {
FIXED_IN_PROFILE,
FIXED_IN_METER,
DYNAMIC
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,34 @@ public DlmsObjectService(final List<MeterConfig> meterConfigList) {
}

public Map<DlmsObjectType, CosemObject> getCosemObjects(
final String protocolName, final String protocolVersion) throws IOException {
final String protocolName, final String protocolVersion) {

if (this.meterConfigList == null || this.meterConfigList.isEmpty()) {
this.meterConfigList = this.getMeterConfigListFromResources();
}
try {
if (this.meterConfigList == null || this.meterConfigList.isEmpty()) {
this.meterConfigList = this.getMeterConfigListFromResources();
}

final Optional<MeterConfig> meterConfig =
this.meterConfigList.stream()
.filter(config -> protocolVersion.equalsIgnoreCase(config.version))
.filter(config -> protocolName.equalsIgnoreCase(config.profile))
.findAny();
if (!meterConfig.isPresent()) {
return new HashMap<DlmsObjectType, CosemObject>();
}
return this.getCosemObjectFromMeterConfig(meterConfig.get())
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"no config found for protocol '%s' version '%s' ",
protocolName, protocolVersion)));

final Optional<MeterConfig> meterConfig =
this.meterConfigList.stream()
.filter(config -> protocolVersion.equalsIgnoreCase(config.version))
.filter(config -> protocolName.equalsIgnoreCase(config.profile))
.findAny();
if (!meterConfig.isPresent()) {
return null;
} catch (final IOException exception) {
throw new IllegalArgumentException(
String.format(
"no config found for protocol '%s' version '%s' ", protocolName, protocolVersion));
}
return this.getCosemObjectFromMeterConfig(meterConfig.get())
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"no config found for protocol '%s' version '%s' ",
protocolName, protocolVersion)));
}

private Optional<Map<DlmsObjectType, CosemObject>> getCosemObjectFromMeterConfig(
Expand All @@ -71,7 +78,7 @@ private Optional<Map<DlmsObjectType, CosemObject>> getCosemObjectFromMeterConfig
}

private List<MeterConfig> getMeterConfigListFromResources() throws IOException {
final ClassPathResource c = new ClassPathResource("/");
final ClassPathResource c = new ClassPathResource("/meter_config");
final ObjectMapper objectMapper = new ObjectMapper();

final List<MeterConfig> meterConfigs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
Expand Down Expand Up @@ -40,7 +41,7 @@ void setUp() throws IOException {
}

@Test
void testGetCosemObject() throws IOException {
void testGetCosemObject() {
final String protocolVersion52 = "5.2";
final String protocolVersion50 = "5.0";
final String protocolName = "SMR";
Expand All @@ -61,11 +62,11 @@ void testGetCosemObject() throws IOException {
}

@Test
void testNoCosemObjectFound() throws IOException {
void testNoCosemObjectFound() {
final Map<DlmsObjectType, CosemObject> cosemObjects =
this.dlmsObjectService.getCosemObjects("ABC", "12");

assertNull(cosemObjects);
assertTrue(cosemObjects.isEmpty());
}

private List<MeterConfig> getMeterConfigList() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
*/
package org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc;

import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_EXPORT;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_1;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_2;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_IMPORT;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_1;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_2;
import static org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType.CLOCK;
import static org.opensmartgridplatform.domain.smartmetering.config.ValueType.FIXED_IN_PROFILE;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_EXPORT;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_1;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_2;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_IMPORT;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_1;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_2;
import static org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType.CLOCK;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.joda.time.DateTime;
import org.openmuc.jdlms.AttributeAddress;
import org.openmuc.jdlms.GetResult;
import org.openmuc.jdlms.datatypes.DataObject;
import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor;
import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType;
import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper;
import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.JdlmsObjectToStringUtil;
import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice;
Expand All @@ -35,6 +34,8 @@
import org.opensmartgridplatform.dlms.interfaceclass.attribute.RegisterAttribute;
import org.opensmartgridplatform.domain.smartmetering.config.Attribute;
import org.opensmartgridplatform.domain.smartmetering.config.CosemObject;
import org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectService;
import org.opensmartgridplatform.domain.smartmetering.service.DlmsObjectType;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionRequestDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActiveEnergyValuesDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualMeterReadsDataDto;
Expand All @@ -58,6 +59,8 @@ public class GetActualMeterReadsCommandExecutor

@Autowired private DlmsHelper dlmsHelper;

@Autowired private DlmsObjectService dlmsObjectService;

public GetActualMeterReadsCommandExecutor() {
super(ActualMeterReadsDataDto.class);
}
Expand Down Expand Up @@ -153,16 +156,16 @@ public MeterReadsResponseDto execute(
}

private Map<DlmsObjectType, CosemObject> getCosemObjects(final DlmsDevice device) {
final Map<DlmsObjectType, CosemObject> objectMap = new HashMap<>();

// TODO: Get objects from service
objectMap.put(DlmsObjectType.CLOCK, this.getClock());
objectMap.put(ACTIVE_ENERGY_IMPORT, this.getActiveEnergyImport());
objectMap.put(ACTIVE_ENERGY_EXPORT, this.getActiveEnergyExport());
objectMap.put(ACTIVE_ENERGY_IMPORT_RATE_1, this.getActiveEnergyImportRate1());
objectMap.put(ACTIVE_ENERGY_IMPORT_RATE_2, this.getActiveEnergyImportRate2());
objectMap.put(ACTIVE_ENERGY_EXPORT_RATE_1, this.getActiveEnergyExportRate1());
objectMap.put(ACTIVE_ENERGY_EXPORT_RATE_2, this.getActiveEnergyExportRate2());
final Map<DlmsObjectType, CosemObject> objectMap =
this.dlmsObjectService.getCosemObjects(
device.getProtocolName(), device.getProtocolVersion());

if (objectMap.isEmpty()) {
LOGGER.error(
"CosemObject configuration is not found for device protocol {} and version {}",
device.getProtocolName(),
device.getProtocolVersion());
}

return objectMap;
}
Expand All @@ -182,7 +185,7 @@ private List<AttributeAddress> getAttributeAddressForObject(final CosemObject ob

if (object.classId == InterfaceClass.REGISTER.id()) {
final Attribute scalerUnit = object.getAttribute(RegisterAttribute.SCALER_UNIT.attributeId());
if (!scalerUnit.valuetype.equals("FIXED_IN_PROFILE")) {
if (!scalerUnit.valuetype.equals(FIXED_IN_PROFILE)) {
attributeAddresses.add(
new AttributeAddress(
object.classId, object.obis, RegisterAttribute.SCALER_UNIT.attributeId()));
Expand Down Expand Up @@ -226,7 +229,7 @@ private DataObject getScalerUnit(

final Attribute scalerUnit =
cosemObject.getAttribute(RegisterAttribute.SCALER_UNIT.attributeId());
if (!scalerUnit.valuetype.equals("FIXED_IN_PROFILE")) {
if (!scalerUnit.valuetype.equals(FIXED_IN_PROFILE)) {
final int index =
this.getIndex(
cosemObject.obis, RegisterAttribute.SCALER_UNIT.attributeId(), attributeAddresses);
Expand Down Expand Up @@ -255,66 +258,4 @@ private DlmsUnitTypeDto getUnit(final String scaler_unit) throws IllegalArgument
throw new IllegalArgumentException("Unknown unit in profile: " + unit);
}
}

// Dummy data
private CosemObject getActiveEnergyImport() {
return this.createDummyRegister("1.0.1.8.0.255");
}

private CosemObject getActiveEnergyExport() {
return this.createDummyRegister("1.0.2.8.0.255");
}

private CosemObject getActiveEnergyImportRate1() {
return this.createDummyRegister("1.0.1.8.1.255");
}

private CosemObject getActiveEnergyImportRate2() {
return this.createDummyRegister("1.0.1.8.2.255");
}

private CosemObject getActiveEnergyExportRate1() {
return this.createDummyRegister("1.0.2.8.1.255");
}

private CosemObject getActiveEnergyExportRate2() {
return this.createDummyRegister("1.0.2.8.2.255");
}

private CosemObject getClock() {
return this.createDummyClock("0.0.1.0.0.255");
}

private CosemObject createDummyRegister(final String obis) {
final CosemObject newObject = new CosemObject();
newObject.setClassId(InterfaceClass.REGISTER.id());
newObject.setObis(obis);

final ArrayList<Attribute> attributesObject = new ArrayList<>();
attributesObject.add(
this.createDummyAttribute(3, "scal_unit_type", "0, Wh", "FIXED_IN_PROFILE"));

newObject.setAttributes(attributesObject);

return newObject;
}

private CosemObject createDummyClock(final String obis) {
final CosemObject newObject = new CosemObject();
newObject.setClassId(InterfaceClass.CLOCK.id());
newObject.setObis(obis);

return newObject;
}

private Attribute createDummyAttribute(
final int id, final String dataType, final String value, final String valueType) {
final Attribute attribute = new Attribute();
attribute.setId(id);
attribute.setDatatype(dataType);
attribute.setValue(value);
attribute.setValuetype(valueType);

return attribute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,6 @@
<relativePath>../../parent-pa-dlms/pom.xml</relativePath>
</parent>

<!-- Description, Organization, Licenses, URL and Distribution Management
elements are needed for the maven-jxr-plugin to generate a maven site -->
<!--<description>A library to simulate behaviour of dlms devices.</description>
<organization>
<name>OSGP</name>
<url>http://opensmartgridplatform.org</url>
</organization>
<licenses>
<license>
<name>APACHE 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<url>${maven.site.url}</url>
<distributionManagement>
<site>
<id>osgp-simulator</id>
<name>osgp-simulator</name>
<url>${maven.site.distributionManagement.site.url}</url>
</site>
</distributionManagement> -->

<!-- <dependencyManagement> -->
<!-- <dependencies> -->
<!-- <dependency> -->
<!-- Import dependency management from Spring Boot -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-dependencies</artifactId> -->
<!-- <version>${spring.boot.version}</version> -->
<!-- <type>pom</type> -->
<!-- <scope>import</scope> -->
<!-- </dependency> -->
<!-- </dependencies> -->
<!-- </dependencyManagement> -->

<properties>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
</properties>
Expand Down Expand Up @@ -89,7 +54,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<doclint>none</doclint>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 9dd0cab

Please sign in to comment.