Search in sources :

Example 1 with SpecialDayDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto in project open-smart-grid-platform by OSGP.

the class ConfigurationService method setSpecialDays.

public void setSpecialDays(final DlmsConnectionManager conn, final DlmsDevice device, final SpecialDaysRequestDto specialDaysRequest, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    // The Special days towards the Smart Meter
    final SpecialDaysRequestDataDto specialDaysRequestData = specialDaysRequest.getSpecialDaysRequestData();
    LOGGER.info(VISUAL_SEPARATOR);
    LOGGER.info("********** Set Special Days: 0-0:11.0.0.255 **********");
    LOGGER.info(VISUAL_SEPARATOR);
    final List<SpecialDayDto> specialDays = specialDaysRequestData.getSpecialDays();
    for (final SpecialDayDto specialDay : specialDays) {
        LOGGER.info("Date :{}, dayId : {} ", specialDay.getSpecialDayDate(), specialDay.getDayId());
    }
    LOGGER.info(VISUAL_SEPARATOR);
    final AccessResultCode accessResultCode = this.setSpecialDaysCommandExecutor.execute(conn, device, specialDays, messageMetadata);
    if (!AccessResultCode.SUCCESS.equals(accessResultCode)) {
        throw new ProtocolAdapterException("Set special days reported result is: " + accessResultCode);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)

Example 2 with SpecialDayDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto in project open-smart-grid-platform by OSGP.

the class SetSpecialDaysCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final List<SpecialDayDto> specialDays, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final StringBuilder specialDayData = new StringBuilder();
    final List<DataObject> specialDayEntries = new ArrayList<>();
    int i = 0;
    for (final SpecialDayDto specialDay : specialDays) {
        specialDayData.append(", ").append(specialDay.getDayId()).append(" => ").append(specialDay.getSpecialDayDate());
        final List<DataObject> specDayEntry = new ArrayList<>();
        specDayEntry.add(DataObject.newUInteger16Data(i));
        specDayEntry.add(this.dlmsHelper.asDataObject(specialDay.getSpecialDayDate()));
        specDayEntry.add(DataObject.newUInteger8Data((short) specialDay.getDayId()));
        final DataObject dayStruct = DataObject.newStructureData(specDayEntry);
        specialDayEntries.add(dayStruct);
        i += 1;
    }
    final AttributeAddress specialDaysTableEntries = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
    final DataObject entries = DataObject.newArrayData(specialDayEntries);
    final SetParameter request = new SetParameter(specialDaysTableEntries, entries);
    final String specialDayValues;
    if (specialDayData.length() == 0) {
        specialDayValues = "";
    } else {
        specialDayValues = ", values [" + specialDayData.substring(2) + "]";
    }
    conn.getDlmsMessageListener().setDescription("SetSpecialDays" + specialDayValues + ", set attribute: " + JdlmsObjectToStringUtil.describeAttributes(specialDaysTableEntries));
    try {
        return conn.getConnection().set(request);
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) SetParameter(org.openmuc.jdlms.SetParameter) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 3 with SpecialDayDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto in project open-smart-grid-platform by OSGP.

the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyListNoCosemDate.

// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value), where CosemDate is not specified.
@Test
public void testSpecialDaysRequestMappingNonEmptyListNoCosemDate() {
    final String deviceIdentification = "nr1";
    final int dayId = 1;
    final SpecialDay specialDay = new SpecialDay(new CosemDate(), dayId);
    final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
    final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
    final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
    assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
    assertThat(requestDataDto).isNotNull();
    assertThat(requestDataDto.getSpecialDays()).isNotNull();
    assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
    final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
    assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
    final CosemDate specialDayDate = specialDay.getSpecialDayDate();
    final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
    assertThat(specialDayDateDto.getYear()).isEqualTo(specialDayDate.getYear());
    assertThat(specialDayDateDto.getMonth()).isEqualTo(specialDayDate.getMonth());
    assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(specialDayDate.getDayOfMonth());
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Example 4 with SpecialDayDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto in project open-smart-grid-platform by OSGP.

the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyList.

// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value).
@Test
public void testSpecialDaysRequestMappingNonEmptyList() {
    final String deviceIdentification = "nr1";
    final int year = 2016;
    final int month = 3;
    final int dayOfMonth = 11;
    final int dayId = 1;
    final SpecialDay specialDay = new SpecialDay(new CosemDate(year, month, dayOfMonth), dayId);
    final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
    final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
    final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
    assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
    assertThat(requestDataDto).isNotNull();
    assertThat(requestDataDto.getSpecialDays()).isNotNull();
    assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
    final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
    assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
    final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
    assertThat(specialDayDateDto.getYear()).isEqualTo(year);
    assertThat(specialDayDateDto.getMonth()).isEqualTo(month);
    assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(dayOfMonth);
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Aggregations

SpecialDayDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto)4 SpecialDaysRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)3 Test (org.junit.jupiter.api.Test)2 CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)2 SpecialDay (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay)2 SpecialDaysRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest)2 SpecialDaysRequestData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData)2 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)2 SpecialDaysRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AccessResultCode (org.openmuc.jdlms.AccessResultCode)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 SetParameter (org.openmuc.jdlms.SetParameter)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1