use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method updateDevice.
@Transactional(value = "writableTransactionManager")
public void updateDevice(@Identification final String organisationIdentification, final String deviceToUpdateIdentification, @Valid final Ssld updateDevice) throws FunctionalException {
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(deviceToUpdateIdentification);
if (existingDevice == null) {
// device does not exist
LOGGER.info("Device does not exist, nothing to update.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceToUpdateIdentification));
}
final List<DeviceAuthorization> owners = this.writableAuthorizationRepository.findByDeviceAndFunctionGroup(existingDevice, DeviceFunctionGroup.OWNER);
// Check organisation against owner of device
boolean isOwner = false;
for (final DeviceAuthorization owner : owners) {
if (owner.getOrganisation().getOrganisationIdentification().equalsIgnoreCase(organisationIdentification)) {
isOwner = true;
}
}
if (!isOwner) {
LOGGER.info("Device has no owner yet, or organisation is not the owner.");
throw new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_CORE, new NotAuthorizedException(organisationIdentification));
}
// Update the device
existingDevice.updateMetaData(updateDevice.getAlias(), updateDevice.getContainerAddress(), updateDevice.getGpsCoordinates());
existingDevice.setActivated(updateDevice.isActivated());
if (updateDevice.getDeviceLifecycleStatus() != null) {
existingDevice.setDeviceLifecycleStatus(updateDevice.getDeviceLifecycleStatus());
}
if (updateDevice.getTechnicalInstallationDate() != null) {
existingDevice.setTechnicalInstallationDate(updateDevice.getTechnicalInstallationDate());
}
final Ssld ssld = this.writableSsldRepository.findById(existingDevice.getId()).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE));
ssld.updateOutputSettings(updateDevice.receiveOutputSettings());
ssld.setEans(updateDevice.getEans());
for (final Ean ean : updateDevice.getEans()) {
ean.setDevice(ssld);
}
this.writableSsldRepository.save(ssld);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceInstallationEndpoint method updateDevice.
@PayloadRoot(localPart = "UpdateDeviceRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public UpdateDeviceResponse updateDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceRequest request) throws OsgpException {
LOGGER.info("Updating device: {}.", request.getDeviceIdentification());
try {
final Ssld device = this.deviceInstallationMapper.map(request.getUpdatedDevice(), Ssld.class);
this.deviceInstallationService.updateDevice(organisationIdentification, device);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
LOGGER.error(EXCEPTION_WHILE_UPDATING_DEVICE, e.getMessage(), request.getUpdatedDevice().getDeviceIdentification(), organisationIdentification, e);
this.handleException(e);
}
try {
this.notificationService.sendNotification(organisationIdentification, request.getDeviceIdentification(), null, null, null, NotificationType.DEVICE_UPDATED);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new UpdateDeviceResponse();
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceManagementMapperTest method mapsUpdatedDeviceToDevice.
@Test
public void mapsUpdatedDeviceToDevice() {
final UpdatedDevice updatedDevice = new UpdatedDevice();
final DeviceOutputSetting outputSetting = new DeviceOutputSetting();
outputSetting.setAlias(DOS_ALIAS);
outputSetting.setInternalId(RELAY_INTERNAL_ID);
outputSetting.setExternalId(RELAY_EXTERNAL_ID);
outputSetting.setRelayType(RelayType.LIGHT);
updatedDevice.getOutputSettings().add(outputSetting);
final Address address = new Address();
address.setStreet(STREET);
address.setNumber(HOUSE_NUMBER);
address.setNumberAddition(HOUSE_NUMBER_ADDITION);
address.setPostalCode(POSTAL_CODE);
address.setCity(CITY);
address.setMunicipality(MUNICIPALITY);
updatedDevice.setContainerAddress(address);
updatedDevice.setDeviceLifecycleStatus(DeviceLifecycleStatus.IN_USE);
final Ssld expected = new Ssld();
final List<org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting> expectedOutputSettings = new ArrayList<>();
final org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting expectedOutputSetting = new org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting(RELAY_INTERNAL_ID, RELAY_EXTERNAL_ID, org.opensmartgridplatform.domain.core.valueobjects.RelayType.LIGHT, DOS_ALIAS);
expectedOutputSettings.add(expectedOutputSetting);
expected.updateOutputSettings(expectedOutputSettings);
final org.opensmartgridplatform.domain.core.valueobjects.Address expectedAddress = new org.opensmartgridplatform.domain.core.valueobjects.Address(CITY, POSTAL_CODE, STREET, HOUSE_NUMBER, HOUSE_NUMBER_ADDITION, MUNICIPALITY);
expected.setContainerAddress(expectedAddress);
expected.setDeviceLifecycleStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceLifecycleStatus.IN_USE);
final Ssld actual = this.mapper.map(updatedDevice, Ssld.class);
assertThat(expected).usingRecursiveComparison().ignoringFields("creationTime", "modificationTime").isEqualTo(actual);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method resumeSchedule.
// === RESUME SCHEDULE ===
public void resumeSchedule(final CorrelationIds ids, final Integer index, final boolean isImmediate, final String messageType, final int messagePriority) throws FunctionalException {
this.findOrganisation(ids.getOrganisationIdentification());
final Device device = this.findActiveDevice(ids.getDeviceIdentification());
final Ssld ssld = this.findSsldForDevice(device);
if (!ssld.getHasSchedule()) {
throw new FunctionalException(FunctionalExceptionType.UNSCHEDULED_DEVICE, ComponentType.DOMAIN_PUBLIC_LIGHTING, new ValidationException(String.format("Device %1$s does not have a schedule.", ids.getDeviceIdentification())));
}
final ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainerDto = new ResumeScheduleMessageDataContainerDto(index, isImmediate);
this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, resumeScheduleMessageDataContainerDto), messageType, messagePriority, device.getIpAddress());
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method setHasSchedule.
// === SET HAS SCHEDULE ===
/**
* Method for setting the 'hasSchedule' boolean for a device.
*
* @throws FunctionalException
*/
public void setHasSchedule(final String deviceIdentification, final Boolean hasSchedule) throws FunctionalException {
LOGGER.info("setHasSchedule called for device {} with hasSchedule: {}.", deviceIdentification, hasSchedule);
final Device device = this.findActiveDevice(deviceIdentification);
final Ssld ssld = this.findSsldForDevice(device);
ssld.setHasSchedule(hasSchedule);
this.ssldRepository.save(ssld);
}
Aggregations