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;
}
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;
}
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));
}
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);
}
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;
}
Aggregations