Search in sources :

Example 1 with SeasonProfileDto

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

the class SetActivityCalendarCommandExecutor method execute.

@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActivityCalendarDto activityCalendar, final MessageMetadata messageMetadata) throws ProtocolAdapterException, FunctionalException {
    LOGGER.debug("SetActivityCalendarCommandExecutor.execute {} called", activityCalendar.getCalendarName());
    ActivityCalendarValidator.validate(activityCalendar);
    final List<SeasonProfileDto> seasonProfileList = activityCalendar.getSeasonProfileList();
    final Set<WeekProfileDto> weekProfileSet = this.getWeekProfileSet(seasonProfileList);
    final Set<DayProfileDto> dayProfileSet = this.getDayProfileSet(weekProfileSet);
    final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors("SetActivityCalendar").addExecutor(this.getCalendarNameExecutor(activityCalendar)).addExecutor(this.getSeasonProfileExecutor(seasonProfileList)).addExecutor(this.getWeekProfileTableExecutor(weekProfileSet)).addExecutor(this.getDayProfileTablePassiveExecutor(dayProfileSet));
    conn.getDlmsMessageListener().setDescription("SetActivityCalendar for calendar " + activityCalendar.getCalendarName() + ", set attributes: " + dataObjectExecutors.describeAttributes());
    dataObjectExecutors.execute(conn);
    LOGGER.info("Finished setting the passive activity calendar");
    // in the exception to throw
    try {
        this.setActivityCalendarCommandActivationExecutor.execute(conn, device, null, messageMetadata);
        LOGGER.info("Finished activating the passive to the active activity calendar");
    } catch (final ProtocolAdapterException e) {
        final StringBuilder message = new StringBuilder();
        for (final DataObjectAttrExecutor executor : dataObjectExecutors.getDataObjectAttrExecutorList()) {
            message.append(executor.createRequestAndResultCodeInfo());
        }
        throw new ProtocolAdapterException(e.getMessage() + message, e);
    }
    return AccessResultCode.SUCCESS;
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SeasonProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto) WeekProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto) DayProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto) DataObjectAttrExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)

Example 2 with SeasonProfileDto

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

the class ActivityCalendarMappingTest method checkListMapping.

// method to test mapping of Filled Lists
private void checkListMapping(final List<SeasonProfile> seasonProfileList, final List<SeasonProfileDto> seasonProfileDtoList) {
    assertThat(seasonProfileList).isNotNull();
    assertThat(seasonProfileDtoList).isNotNull();
    assertThat(seasonProfileList.isEmpty()).isFalse();
    assertThat(seasonProfileDtoList.isEmpty()).isFalse();
    final SeasonProfile seasonProfile = seasonProfileList.get(0);
    final SeasonProfileDto seasonProfileDto = seasonProfileDtoList.get(0);
    assertThat(seasonProfileDto.getSeasonProfileName()).isEqualTo(seasonProfile.getSeasonProfileName());
    this.checkCosemDateTimeMapping(seasonProfile.getSeasonStart(), seasonProfileDto.getSeasonStart());
    final WeekProfile weekProfile = seasonProfile.getWeekProfile();
    final WeekProfileDto weekProfileDto = seasonProfileDto.getWeekProfile();
    assertThat(weekProfileDto.getWeekProfileName()).isEqualTo(weekProfile.getWeekProfileName());
    final DayProfile dayProfile = weekProfile.getMonday();
    final DayProfileDto dayProfileDto = weekProfileDto.getMonday();
    assertThat(dayProfileDto.getDayId()).isEqualTo(dayProfile.getDayId());
    assertThat(dayProfile.getDayProfileActionList().size()).isEqualTo(dayProfile.getDayProfileActionList().size());
    final DayProfileAction dayProfileAction = dayProfile.getDayProfileActionList().get(0);
    final DayProfileActionDto dayProfileActionDto = dayProfileDto.getDayProfileActionList().get(0);
    assertThat(dayProfileActionDto.getScriptSelector()).isEqualTo(dayProfileAction.getScriptSelector());
    final CosemTime cosemTime = dayProfileAction.getStartTime();
    final CosemTimeDto cosemTimeDto = dayProfileActionDto.getStartTime();
    assertThat(cosemTimeDto.getHour()).isEqualTo(cosemTime.getHour());
    assertThat(cosemTimeDto.getMinute()).isEqualTo(cosemTime.getMinute());
    assertThat(cosemTimeDto.getSecond()).isEqualTo(cosemTime.getSecond());
    assertThat(cosemTimeDto.getHundredths()).isEqualTo(cosemTime.getHundredths());
}
Also used : WeekProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WeekProfile) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) DayProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile) DayProfileAction(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfileAction) SeasonProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto) WeekProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto) DayProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto) SeasonProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile) DayProfileActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileActionDto) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)

Example 3 with SeasonProfileDto

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

the class ActivityCalendarValidatorTest method createActivityCalendarDto.

ActivityCalendarDto createActivityCalendarDto(final TestAnomaly testAnomaly) throws FunctionalException {
    final DayProfileActionDto dayAction1 = new DayProfileActionDto(1, new CosemTimeDto());
    final DayProfileActionDto dayAction2 = new DayProfileActionDto(2, new CosemTimeDto());
    final DayProfileActionDto dayAction3 = new DayProfileActionDto(3, new CosemTimeDto());
    final DayProfileActionDto dayAction4 = new DayProfileActionDto(4, new CosemTimeDto());
    final DayProfileActionDto dayAction5 = new DayProfileActionDto(5, new CosemTimeDto());
    final List<DayProfileActionDto> dayActions1 = Arrays.asList(dayAction1, dayAction2);
    final List<DayProfileActionDto> dayActions2 = Arrays.asList(dayAction3, dayAction4, dayAction5);
    int dayId = 2;
    if (testAnomaly == TestAnomaly.DUPLICATE_DAY) {
        // a second day with id 1 will be created with different day actions
        dayId = 1;
    }
    final DayProfileDto dayProfile1 = new DayProfileDto(1, dayActions1);
    final DayProfileDto dayProfile2 = new DayProfileDto(dayId, dayActions2);
    final DayProfileDto dayProfile3 = new DayProfileDto(3, dayActions2);
    final DayProfileDto dayProfile4 = new DayProfileDto(4, dayActions2);
    final DayProfileDto dayProfile5 = new DayProfileDto(5, dayActions2);
    final WeekProfileDto weekProfileDto1 = this.createWeekProfile("1", dayProfile1, dayProfile2);
    final SeasonProfileDto seasonProfileDto1 = new SeasonProfileDto("1", new CosemDateTimeDto(), weekProfileDto1);
    String weekProfileName = "2";
    if (testAnomaly == TestAnomaly.DUPLICATE_WEEK) {
        // a second week with name 'Week___1' will be created with different day profiles
        weekProfileName = "1";
    } else if (testAnomaly == TestAnomaly.INVALID_WEEK_NAME) {
        weekProfileName = "Week01";
    }
    final Builder weekProfileBuilder2 = WeekProfileDto.newBuilder();
    weekProfileBuilder2.withWeekProfileName(weekProfileName);
    weekProfileBuilder2.withMonday(dayProfile3);
    weekProfileBuilder2.withTuesday(dayProfile3);
    weekProfileBuilder2.withWednesday(dayProfile3);
    weekProfileBuilder2.withThursday(dayProfile3);
    weekProfileBuilder2.withFriday(dayProfile3);
    weekProfileBuilder2.withSaturday(dayProfile4);
    if (testAnomaly == TestAnomaly.FIFTH_DAY) {
        // an overall fifth day profile will be added
        weekProfileBuilder2.withSunday(dayProfile5);
    } else {
        weekProfileBuilder2.withSunday(dayProfile4);
    }
    final WeekProfileDto weekProfileDto2 = weekProfileBuilder2.build();
    String seasonProfileName = "2";
    if (testAnomaly == TestAnomaly.DUPLICATE_SEASON) {
        // a second season with name 'Season_1' will be created with a different week profile
        seasonProfileName = "1";
    } else if (testAnomaly == TestAnomaly.INVALID_SEASON_NAME) {
        seasonProfileName = "Season_1";
    }
    WeekProfileDto weekProfileDto = weekProfileDto2;
    if (testAnomaly == TestAnomaly.MULTIPLE_USES_SAME_WEEK) {
        // the same week profile is used in multiple seasons
        weekProfileDto = weekProfileDto1;
    }
    final SeasonProfileDto seasonProfileDto2 = new SeasonProfileDto(seasonProfileName, new CosemDateTimeDto(), weekProfileDto);
    final List<SeasonProfileDto> seasonList = new ArrayList<>();
    seasonList.addAll(Arrays.asList(seasonProfileDto1, seasonProfileDto2));
    if (testAnomaly == TestAnomaly.FIFTH_SEASON) {
        // a third, fourth and fifth season will be added to the activity calendar
        seasonList.addAll(Arrays.asList(new SeasonProfileDto("3", new CosemDateTimeDto(), WeekProfileDto.newBuilder().withWeekProfileName("3").build()), new SeasonProfileDto("4", new CosemDateTimeDto(), WeekProfileDto.newBuilder().withWeekProfileName("4").build()), new SeasonProfileDto("5", new CosemDateTimeDto(), WeekProfileDto.newBuilder().withWeekProfileName("5").build())));
    }
    return new ActivityCalendarDto("Calendar", new CosemDateTimeDto(), seasonList);
}
Also used : Builder(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto.Builder) ArrayList(java.util.ArrayList) DayProfileActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileActionDto) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) DayProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto) WeekProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto) SeasonProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)

Aggregations

DayProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto)3 SeasonProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto)3 WeekProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)2 DayProfileActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileActionDto)2 ArrayList (java.util.ArrayList)1 DataObjectAttrExecutor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)1 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)1 DayProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile)1 DayProfileAction (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfileAction)1 SeasonProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile)1 WeekProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WeekProfile)1 ActivityCalendarDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 Builder (org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto.Builder)1