use of org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings in project open-smart-grid-platform by OSGP.
the class BaseDeviceSteps method updateDevice.
/**
* Update an existing device with the given settings.
*
* @param device The Device to update
* @param settings The settings to update the device with.
* @return The Device
*/
public Device updateDevice(Device device, final Map<String, String> settings) {
// Now set the optional stuff
if (settings.containsKey(PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE))) {
device.setTechnicalInstallationDate(getDate(settings, PlatformKeys.KEY_TECHNICAL_INSTALLATION_DATE).toDate());
}
/*
* Model code does not uniquely identify a device model, which is why
* deviceModelRepository is changed to return a list of device models.
* In the test data that is set up, there probably is only one device
* model for the given model code, and just selecting the first device
* model returned should work.
*
* A better solution might be to add the manufacturer in the scenario
* data and do a lookup by manufacturer and model code, which should
* uniquely define the device model.
*/
final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.KEY_DEVICE_MODEL, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE));
final DeviceModel deviceModel = deviceModels.get(0);
device.setDeviceModel(deviceModel);
device.updateProtocol(this.protocolInfoRepository.findByProtocolAndProtocolVersion(getString(settings, PlatformKeys.KEY_PROTOCOL, PlatformDefaults.DEFAULT_PROTOCOL), getString(settings, PlatformKeys.KEY_PROTOCOL_VERSION, PlatformDefaults.DEFAULT_PROTOCOL_VERSION)));
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(getString(settings, PlatformKeys.IP_ADDRESS, this.configuration.getDeviceNetworkAddress()));
} catch (final UnknownHostException e) {
inetAddress = InetAddress.getLoopbackAddress();
}
device.setBtsId(getInteger(settings, PlatformKeys.BTS_ID, null));
device.setCellId(getInteger(settings, PlatformKeys.CELL_ID, null));
device.updateRegistrationData(inetAddress, getString(settings, PlatformKeys.KEY_DEVICE_TYPE, PlatformDefaults.DEFAULT_DEVICE_TYPE));
device.updateInMaintenance(getBoolean(settings, PlatformKeys.IN_MAINTENANCE, PlatformDefaults.IN_MAINTENANCE));
device.setDeviceLifecycleStatus(getEnum(settings, PlatformKeys.KEY_DEVICE_LIFECYCLE_STATUS, DeviceLifecycleStatus.class, PlatformDefaults.DEFAULT_DEVICE_LIFECYCLE_STATUS));
if (!Objects.equals(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION), "null")) {
device.addOrganisation(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
}
device.updateMetaData(getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_ALIAS), new Address(getString(settings, PlatformKeys.KEY_CITY, PlatformDefaults.DEFAULT_CONTAINER_CITY), getString(settings, PlatformKeys.KEY_POSTCODE, PlatformDefaults.DEFAULT_CONTAINER_POSTALCODE), getString(settings, PlatformKeys.KEY_STREET, PlatformDefaults.DEFAULT_CONTAINER_STREET), getInteger(settings, PlatformKeys.KEY_NUMBER, PlatformDefaults.DEFAULT_CONTAINER_NUMBER), getString(settings, PlatformKeys.KEY_NUMBER_ADDITION, PlatformDefaults.DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, PlatformKeys.KEY_MUNICIPALITY, PlatformDefaults.DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(settings.containsKey(PlatformKeys.KEY_LATITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LATITUDE)) ? getFloat(settings, PlatformKeys.KEY_LATITUDE, PlatformDefaults.DEFAULT_LATITUDE) : null, settings.containsKey(PlatformKeys.KEY_LONGITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LONGITUDE)) ? getFloat(settings, PlatformKeys.KEY_LONGITUDE, PlatformDefaults.DEFAULT_LONGITUDE) : null));
device.setActivated(getBoolean(settings, PlatformKeys.KEY_ACTIVATED, PlatformDefaults.DEFAULT_ACTIVATED));
final String integrationType = getString(settings, PlatformKeys.KEY_INTEGRATION_TYPE, PlatformDefaults.DEFAULT_INTEGRATION_TYPE).toUpperCase();
device.setIntegrationType(IntegrationType.valueOf(integrationType));
device = this.deviceRepository.save(device);
device = this.updateWithAuthorization(device, settings);
this.addEanToDevice(device, settings);
final String mastSegment = getString(settings, PlatformKeys.KEY_CDMA_MAST_SEGMENT, PlatformDefaults.DEFAULT_CDMA_MAST_SEGMENT);
final Short batchNumber = getShort(settings, PlatformKeys.KEY_CDMA_BATCH_NUMBER, PlatformDefaults.DEFAULT_CDMA_BATCH_NUMBER);
final CdmaSettings cdmaSettings = mastSegment == null && batchNumber == null ? null : new CdmaSettings(mastSegment, batchNumber);
device.updateCdmaSettings(cdmaSettings);
return device;
}
use of org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings in project open-smart-grid-platform by OSGP.
the class UpdateDeviceCdmaSettingsSteps method theDeviceCdmaSettingsShouldBeSet.
@Then("^the device CDMA settings should be stored in the platform$")
public void theDeviceCdmaSettingsShouldBeSet(final Map<String, String> settings) {
final String mastSegment = getString(settings, PlatformKeys.KEY_CDMA_MAST_SEGMENT);
final Short batchNumber = getShort(settings, PlatformKeys.KEY_CDMA_BATCH_NUMBER);
CdmaSettings expectedCdmaSettings = null;
if (StringUtils.isNotBlank(mastSegment) || batchNumber != null) {
expectedCdmaSettings = new CdmaSettings(mastSegment, batchNumber);
}
LOGGER.info("THEN: Store {}", expectedCdmaSettings == null ? "null" : expectedCdmaSettings.toString());
final String deviceIdentification = (String) ScenarioContext.current().get(PlatformKeys.KEY_DEVICE_IDENTIFICATION);
final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
if (expectedCdmaSettings == null) {
assertThat(device.getCdmaSettings()).isNull();
} else {
assertThat(device.getCdmaSettings()).isEqualTo(expectedCdmaSettings);
}
}
use of org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings in project open-smart-grid-platform by OSGP.
the class CommonUpdateDeviceCdmaSettingsRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing common set device verification key message");
String correlationUid = null;
String messageType = null;
String organisationIdentification = null;
String deviceIdentification = null;
CdmaSettings cdmaSettings = null;
try {
correlationUid = message.getJMSCorrelationID();
messageType = message.getJMSType();
organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
cdmaSettings = (CdmaSettings) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug("correlationUid: {}", correlationUid);
LOGGER.debug("messageType: {}", messageType);
LOGGER.debug("organisationIdentification: {}", organisationIdentification);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
return;
}
try {
LOGGER.info("Calling application service function: {}", messageType);
this.deviceManagementService.updateDeviceCdmaSettings(organisationIdentification, deviceIdentification, correlationUid, cdmaSettings);
} catch (final Exception e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, MessagePriorityEnum.DEFAULT.getPriority());
}
}
use of org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings in project open-smart-grid-platform by OSGP.
the class DeviceManagementServiceTest method testUpdateDeviceCdmaSettings.
@Test
public void testUpdateDeviceCdmaSettings() throws FunctionalException {
final CdmaSettings cdmaSettings = new CdmaSettings("testSettings", (short) 1);
this.deviceManagementService.updateDeviceCdmaSettings(TEST_ORGANISATION, TEST_DEVICE, TEST_UID, cdmaSettings);
final ArgumentCaptor<CdmaSettings> argumentCdmaSettings = ArgumentCaptor.forClass(CdmaSettings.class);
verify(this.transactionalDeviceService).updateDeviceCdmaSettings(this.argumentDeviceIdentification.capture(), argumentCdmaSettings.capture());
verify(this.webServiceResponseMessageSender).send(this.argumentResponseMessage.capture());
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(TEST_UID).withOrganisationIdentification(TEST_ORGANISATION).withDeviceIdentification(TEST_DEVICE).withMessageType(MessageType.UPDATE_DEVICE_CDMA_SETTINGS.name()).withResult(ResponseMessageResultType.OK).build();
assertThat(this.argumentDeviceIdentification.getValue()).isEqualTo(TEST_DEVICE);
assertThat(argumentCdmaSettings.getValue()).isEqualTo(cdmaSettings);
assertThat(this.argumentResponseMessage.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.domain.core.valueobjects.CdmaSettings in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method updateDeviceCdmaSettingsRequest.
@PayloadRoot(localPart = "UpdateDeviceCdmaSettingsRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public UpdateDeviceCdmaSettingsAsyncResponse updateDeviceCdmaSettingsRequest(@OrganisationIdentification final String organisationIdentification, @RequestPayload final UpdateDeviceCdmaSettingsRequest request) throws OsgpException {
LOGGER.info("UpdateDeviceCdmaSettingsRequest received for device: {} and organisation: {}.", request.getDeviceIdentification(), organisationIdentification);
final UpdateDeviceCdmaSettingsAsyncResponse asyncResponse = new UpdateDeviceCdmaSettingsAsyncResponse();
try {
final CdmaSettings cdmaSettings = new CdmaSettings(request.getMastSegment(), request.getBatchNumber());
final String correlationUid = this.deviceManagementService.enqueueUpdateDeviceCdmaSettingsRequest(organisationIdentification, request.getDeviceIdentification(), cdmaSettings);
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
} catch (final Exception e) {
this.handleException(e);
}
return asyncResponse;
}
Aggregations