Class SGrRestApiDevice
- java.lang.Object
-
- com.smartgridready.communicator.common.impl.SGrDeviceBase<com.smartgridready.ns.v0.DeviceFrame,com.smartgridready.ns.v0.RestApiFunctionalProfile,com.smartgridready.ns.v0.RestApiDataPoint>
-
- com.smartgridready.communicator.rest.impl.SGrRestApiDevice
-
- All Implemented Interfaces:
GenDeviceApi,GenDeviceApi4Rest
public class SGrRestApiDevice extends SGrDeviceBase<com.smartgridready.ns.v0.DeviceFrame,com.smartgridready.ns.v0.RestApiFunctionalProfile,com.smartgridready.ns.v0.RestApiDataPoint> implements GenDeviceApi4Rest
Implements a device interface for HTTP / REST APIs.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.smartgridready.communicator.common.impl.SGrDeviceBase
SGrDeviceBase.Comparator, SGrDeviceBase.RwpDirections
-
-
Field Summary
-
Fields inherited from class com.smartgridready.communicator.common.impl.SGrDeviceBase
device
-
-
Constructor Summary
Constructors Constructor Description SGrRestApiDevice(com.smartgridready.ns.v0.DeviceFrame deviceDescription, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidauthenticate()Authenticates the REST API client.voidconnect()Connect the device.voiddisconnect()Disconnect the device.protected java.util.Optional<com.smartgridready.ns.v0.RestApiDataPoint>findDataPointForProfile(com.smartgridready.ns.v0.RestApiFunctionalProfile aProfile, java.lang.String aDataPointName)Finds a data point.protected java.util.Optional<com.smartgridready.ns.v0.RestApiFunctionalProfile>findProfile(java.lang.String profileName)Finds a functional profile.ValuegetVal(java.lang.String profileName, java.lang.String dataPointName)Reads a value in its string representation from the REST API device.ValuegetVal(java.lang.String profileName, java.lang.String dataPointName, java.util.Properties parameters)Reads a value in its string representation from the REST API device.booleanisConnected()Checks if the device is connected.voidsetVal(java.lang.String profileName, java.lang.String dataPointName, Value value)Writes a value to the REST API device.-
Methods inherited from class com.smartgridready.communicator.common.impl.SGrDeviceBase
applyUnitConversion, canSubscribe, checkOutOfRange, checkOutOfRange, checkReadWritePermission, divide, findDataPoint, getDataPoint, getDataPoints, getDeviceConfigurationInfo, getDeviceInfo, getFunctionalProfile, getFunctionalProfiles, getValues, isNumeric, multiply, subscribe, unsubscribe
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.smartgridready.communicator.common.api.GenDeviceApi
canSubscribe, getDataPoint, getDataPoints, getDeviceConfigurationInfo, getDeviceInfo, getFunctionalProfile, getFunctionalProfiles, getValues, subscribe, unsubscribe
-
-
-
-
Constructor Detail
-
SGrRestApiDevice
public SGrRestApiDevice(com.smartgridready.ns.v0.DeviceFrame deviceDescription, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory) throws RestApiAuthenticationExceptionConstructs a new instance.- Parameters:
deviceDescription- the EID descriptionhttpClientFactory- the HTTP client factory implementation- Throws:
RestApiAuthenticationException- on HTTP authentication error
-
-
Method Detail
-
connect
public void connect() throws com.smartgridready.driver.api.common.GenDriverExceptionDescription copied from interface:GenDeviceApiConnect the device.- Specified by:
connectin interfaceGenDeviceApi- Throws:
com.smartgridready.driver.api.common.GenDriverException- Generic error while reading from the device
-
disconnect
public void disconnect() throws com.smartgridready.driver.api.common.GenDriverExceptionDescription copied from interface:GenDeviceApiDisconnect the device.- Specified by:
disconnectin interfaceGenDeviceApi- Throws:
com.smartgridready.driver.api.common.GenDriverException- Generic error while reading from the device
-
isConnected
public boolean isConnected()
Description copied from interface:GenDeviceApiChecks if the device is connected.- Specified by:
isConnectedin interfaceGenDeviceApi- Returns:
- true if connected, false otherwise
-
authenticate
public void authenticate() throws RestApiAuthenticationException, java.io.IOException, RestApiServiceCallException, RestApiResponseParseExceptionDescription copied from interface:GenDeviceApi4RestAuthenticates the REST API client. Authenticate uses the authentication method and credentials given within the external interface description XML of the device. The credentials may be given as parameters when loading theSGrRestApiDeviceusing the properties parameter of theDeviceDescriptionLoader.- Specified by:
authenticatein interfaceGenDeviceApi4Rest- Throws:
RestApiAuthenticationException- If the authentication failed.java.io.IOException- If the communication with the server failed.RestApiServiceCallException- If the service call could not be executed on the remote side.RestApiResponseParseException- If parsing of the service response failed.- See Also:
SGrRestApiDevice,DeviceDescriptionLoader
-
getVal
public Value getVal(java.lang.String profileName, java.lang.String dataPointName) throws java.io.IOException, RestApiServiceCallException, RestApiResponseParseException, com.smartgridready.driver.api.common.GenDriverException
Description copied from interface:GenDeviceApi4RestReads a value in its string representation from the REST API device.- Specified by:
getValin interfaceGenDeviceApi- Specified by:
getValin interfaceGenDeviceApi4Rest- Parameters:
profileName- The name of the functional profile.dataPointName- The name of the data point within the functional profile.- Returns:
- The value read from the device.
- Throws:
java.io.IOException- If the communication with the server failed.RestApiServiceCallException- If the service call could not be executed on the remote side.RestApiResponseParseException- If parsing of the service response failed.com.smartgridready.driver.api.common.GenDriverException- If a common error occured.
-
getVal
public Value getVal(java.lang.String profileName, java.lang.String dataPointName, java.util.Properties parameters) throws java.io.IOException, RestApiServiceCallException, RestApiResponseParseException, com.smartgridready.driver.api.common.GenDriverException
Description copied from interface:GenDeviceApi4RestReads a value in its string representation from the REST API device.- Specified by:
getValin interfaceGenDeviceApi- Specified by:
getValin interfaceGenDeviceApi4Rest- Parameters:
profileName- The name of the functional profile.dataPointName- The name of the data point within the functional profile.parameters- Key value pairs with request parameters- Returns:
- The value read from the device.
- Throws:
java.io.IOException- If the communication with the server failed.RestApiServiceCallException- If the service call could not be executed on the remote side.RestApiResponseParseException- If parsing of the service response failed.com.smartgridready.driver.api.common.GenDriverException- If a common error occurred.
-
setVal
public void setVal(java.lang.String profileName, java.lang.String dataPointName, Value value) throws java.io.IOException, RestApiServiceCallException, RestApiResponseParseException, com.smartgridready.driver.api.common.GenDriverExceptionDescription copied from interface:GenDeviceApi4RestWrites a value to the REST API device. The value may be provided as:- single string value
- http request body on json or XML
- Specified by:
setValin interfaceGenDeviceApi- Specified by:
setValin interfaceGenDeviceApi4Rest- Parameters:
profileName- The name of the functional profile.dataPointName- The name of the data point within the functional profile.value- The value to be written. Will replace the value tagged with[[value]]within the external interfaceRestApiServiceCallelement for the given data point.- Throws:
java.io.IOException- If the communication with the server failed.RestApiServiceCallException- If the service call could not be executed on the remote side.RestApiResponseParseException- If parsing of the service response failed.com.smartgridready.driver.api.common.GenDriverException- If a common error occurred.
-
findProfile
protected java.util.Optional<com.smartgridready.ns.v0.RestApiFunctionalProfile> findProfile(java.lang.String profileName)
Finds a functional profile.- Specified by:
findProfilein classSGrDeviceBase<com.smartgridready.ns.v0.DeviceFrame,com.smartgridready.ns.v0.RestApiFunctionalProfile,com.smartgridready.ns.v0.RestApiDataPoint>- Parameters:
profileName- the functional profile name- Returns:
- an optional
RestApiFunctionalProfile
-
findDataPointForProfile
protected java.util.Optional<com.smartgridready.ns.v0.RestApiDataPoint> findDataPointForProfile(com.smartgridready.ns.v0.RestApiFunctionalProfile aProfile, java.lang.String aDataPointName)Finds a data point.- Specified by:
findDataPointForProfilein classSGrDeviceBase<com.smartgridready.ns.v0.DeviceFrame,com.smartgridready.ns.v0.RestApiFunctionalProfile,com.smartgridready.ns.v0.RestApiDataPoint>- Parameters:
aProfile- the functional profileaDataPointName- the data point name- Returns:
- an optional
RestApiFunctionalProfile
-
-