Search in sources :

Example 1 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue in project open-smart-grid-platform by OSGP.

the class TariffScheduleToScheduleConverter method convert.

@Override
public ScheduleEntry convert(final TariffSchedule source, final Type<? extends ScheduleEntry> destinationType, final MappingContext context) {
    final ScheduleEntry schedule = new ScheduleEntry();
    // Copy values
    schedule.setWeekDay(this.mapperFacade.map(source.getWeekDay(), WeekDayType.class));
    schedule.setStartDay(this.mapperFacade.map(source.getStartDay(), DateTime.class));
    schedule.setEndDay(this.mapperFacade.map(source.getEndDay(), DateTime.class));
    schedule.setTime(source.getTime());
    schedule.setIndex(source.getIndex());
    schedule.setIsEnabled(source.isIsEnabled());
    schedule.setMinimumLightsOn(source.getMinimumLightsOn());
    // Set the lightvalue
    // For now a High tariff means the Relay is switched off (Situation
    // in Zaltbommel)
    // schedule.setLightValue( Arrays.asList(new LightValue(null,
    // !source.isHigh(), null)) )
    final List<LightValue> lightValues = new ArrayList<>();
    for (final TariffValue tariffValue : source.getTariffValue()) {
        final LightValue lightValue = new LightValue(tariffValue.getIndex(), !tariffValue.isHigh(), null);
        lightValues.add(lightValue);
    }
    schedule.setLightValue(lightValues);
    // Set defaults for Tariff schedules
    schedule.setActionTime(ActionTimeType.ABSOLUTETIME);
    schedule.setTriggerType(null);
    return schedule;
}
Also used : ScheduleEntry(org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) TariffValue(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffValue) WeekDayType(org.opensmartgridplatform.domain.core.valueobjects.WeekDayType) DateTime(org.joda.time.DateTime)

Example 2 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue in project open-smart-grid-platform by OSGP.

the class FilterLightAndTariffValuesHelper method filterTariffValues.

/**
 * Filter light values based on TariffSwitching domain. Only matching values will be returned.
 *
 * @param source list to filter
 * @param dosMap mapping of output settings
 * @param allowedDomainType type of domain allowed
 * @return list with filtered values or empty list when domain is not allowed.
 */
public static List<TariffValue> filterTariffValues(final List<LightValue> source, final Map<Integer, DeviceOutputSetting> dosMap, final DomainType allowedDomainType) {
    final List<TariffValue> filteredValues = new ArrayList<>();
    if (allowedDomainType != DomainType.TARIFF_SWITCHING) {
        // Return empty list
        return filteredValues;
    }
    for (final LightValue lv : source) {
        if (dosMap.containsKey(lv.getIndex()) && dosMap.get(lv.getIndex()).getOutputType().domainType().equals(allowedDomainType)) {
            // Map light value to tariff value
            final TariffValue tf = new TariffValue();
            tf.setIndex(lv.getIndex());
            if (dosMap.get(lv.getIndex()).getOutputType().equals(RelayType.TARIFF_REVERSED)) {
                // Reversed means copy the 'isOn' value to the 'isHigh'
                // value without inverting the boolean value
                tf.setHigh(lv.isOn());
            } else {
                // Not reversed means copy the 'isOn' value to the 'isHigh'
                // value inverting the boolean value
                tf.setHigh(!lv.isOn());
            }
            filteredValues.add(tf);
        }
    }
    return filteredValues;
}
Also used : LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue)

Example 3 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue in project open-smart-grid-platform by OSGP.

the class DeviceInstallationServiceTest method testHandleGetStatusResponseOkLmdStatusNotNull.

@Test
public void testHandleGetStatusResponseOkLmdStatusNotNull() throws FunctionalException, ValidationException {
    final TariffValue editedTariffValue = new TariffValue();
    editedTariffValue.setHigh(true);
    editedTariffValue.setIndex(10);
    final DeviceStatusMapped deviceStatus = new DeviceStatusMapped(null, Arrays.asList(new LightValue(0, true, 50), new LightValue(MESSAGE_PRIORITY, true, 75), new LightValue(2, false, 0)), LinkType.ETHERNET, LinkType.GPRS, LightType.ONE_TO_TEN_VOLT, 0);
    when(this.domainCoreMapper.map(null, DeviceStatus.class)).thenReturn(deviceStatus);
    final Device mockedDevice = Mockito.mock(Device.class);
    when(mockedDevice.getDeviceType()).thenReturn(LightMeasurementDevice.LMD_TYPE);
    when(this.deviceDomainService.searchDevice(TEST_DEVICE)).thenReturn(mockedDevice);
    this.deviceInstallationService.handleGetStatusResponse(null, CORRELATION_IDS, TEST_MESSAGE_TYPE, MESSAGE_PRIORITY, ResponseMessageResultType.OK, null);
    verify(this.webServiceResponseMessageSender).send(this.argumentResponseMessage.capture());
    assertThat(this.argumentResponseMessage.getValue()).usingRecursiveComparison().isEqualTo(this.createNewResponseMessage(ResponseMessageResultType.OK, null, deviceStatus));
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue) Test(org.junit.jupiter.api.Test)

Example 4 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method updateDeviceRelayStatusForGetStatus.

/**
 * Updates the relay overview from a device for a get status response, based on the given device
 * status.
 *
 * @param device The device to update.
 */
private void updateDeviceRelayStatusForGetStatus(final Ssld device, final DeviceStatusMapped deviceStatusMapped) {
    final List<RelayStatus> relayStatuses = device.getRelayStatuses();
    for (final LightValue lightValue : deviceStatusMapped.getLightValues()) {
        boolean updated = false;
        for (final RelayStatus relayStatus : relayStatuses) {
            if (relayStatus.getIndex() == lightValue.getIndex()) {
                relayStatus.updateLastKnownState(lightValue.isOn(), new Date());
                updated = true;
                break;
            }
        }
        if (!updated) {
            final RelayStatus newRelayStatus = new RelayStatus.Builder(device, lightValue.getIndex()).withLastKnownState(lightValue.isOn(), new Date()).build();
            relayStatuses.add(newRelayStatus);
        }
    }
    this.ssldRepository.save(device);
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) Date(java.util.Date)

Example 5 with LightValue

use of org.opensmartgridplatform.domain.core.valueobjects.LightValue in project open-smart-grid-platform by OSGP.

the class PublicLightingAdHocManagementEndpoint method setLight.

// === SET LIGHT ===
@PayloadRoot(localPart = "SetLightRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightAsyncResponse setLight(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Light Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetLightAsyncResponse response = new SetLightAsyncResponse();
    try {
        final List<LightValue> lightValues = new ArrayList<>(this.adHocManagementMapper.mapAsList(request.getLightValue(), LightValue.class));
        final String correlationUid = this.adHocManagementService.enqueueSetLightRequest(organisationIdentification, request.getDeviceIdentification(), lightValues, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ResumeScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse) GetStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse) SetTransitionAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)6 ArrayList (java.util.ArrayList)3 Device (org.opensmartgridplatform.domain.core.entities.Device)2 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)2 ScheduleEntry (org.opensmartgridplatform.domain.core.valueobjects.ScheduleEntry)2 TariffValue (org.opensmartgridplatform.domain.core.valueobjects.TariffValue)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Date (java.util.Date)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 GetStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse)1 ResumeScheduleAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse)1 SetLightAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse)1 SetTransitionAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse)1 TariffValue (org.opensmartgridplatform.adapter.ws.schema.tariffswitching.schedulemanagement.TariffValue)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)1