-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nimble-platform/staging
Pull Request for Release 11.0.0
- Loading branch information
Showing
6 changed files
with
329 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
data-channel-service/src/main/java/eu/nimble/service/datachannel/controller/ErpAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package eu.nimble.service.datachannel.controller; | ||
|
||
import com.mashape.unirest.http.exceptions.UnirestException; | ||
import eu.nimble.service.datachannel.entity.ERPData.SensorValue; | ||
import io.swagger.annotations.*; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Api(value = "ERP", description = "ERP integration API") | ||
public interface ErpAPI { | ||
|
||
/** | ||
* See API documentation | ||
* | ||
* @param bearer OpenID Connect token storing requesting identity | ||
* @return See API documentation | ||
* @throws UnirestException Error while communication with the Identity Service | ||
*/ | ||
@ApiOperation(value = "Get all registered negotiation channels", nickname = "getAllActiveChannels") | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "Received all Nimble Channel IDs", response = Object.class), | ||
@ApiResponse(code = 400, message = "Error while getting Nimble Channel IDs"), | ||
@ApiResponse(code = 401, message = "Unauthorized"), | ||
@ApiResponse(code = 403, message = "Forbidden"), | ||
@ApiResponse(code = 404, message = "Not Found") }) | ||
@RequestMapping(value = "/getAllActiveChannels", produces = {"application/json"}, method = RequestMethod.GET) | ||
ResponseEntity<?> getAllActiveChannels( | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) | ||
throws UnirestException; | ||
|
||
/** | ||
* See API documentation | ||
* | ||
* @param channelID Nimble Channel ID | ||
* @param bearer OpenID Connect token storing requesting identity | ||
* @return See API documentation | ||
* @throws UnirestException Error while communication with the Identity Service | ||
*/ | ||
@ApiOperation(value = "Get config data for channel negotiation", nickname = "getConfigDataForChannel") | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "Received specific Nimble Channel Data", response = Object.class), | ||
@ApiResponse(code = 400, message = "Error while getting Nimble Channel Data"), | ||
@ApiResponse(code = 401, message = "Unauthorized"), | ||
@ApiResponse(code = 403, message = "Forbidden"), | ||
@ApiResponse(code = 404, message = "Not Found") }) | ||
@RequestMapping(value = "/getConfigData/{channelID}", produces = {"application/json"}, method = RequestMethod.GET) | ||
ResponseEntity<?> getConfigData( | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) | ||
throws UnirestException; | ||
|
||
/** | ||
* See API documentation | ||
* | ||
* @param sensorValueMap sensor data object | ||
* @param channelID Nimble Channel ID | ||
* @param bearer OpenID Connect token storing requesting identity | ||
* @return See API documentation | ||
* @throws UnirestException Error while communication with the Identity Service | ||
*/ | ||
@ApiOperation(value = "Produce sensor data for channel negotiation", nickname = "produceSensorData") | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "Sensor Data produced", response = Object.class), | ||
@ApiResponse(code = 400, message = "Error while producing sensor data"), | ||
@ApiResponse(code = 401, message = "Unauthorized"), | ||
@ApiResponse(code = 403, message = "Forbidden"), | ||
@ApiResponse(code = 404, message = "Not Found") }) | ||
@RequestMapping(value = "/produceSensorData/{channelID}", consumes = {"application/json"}, method = RequestMethod.POST) | ||
ResponseEntity<?> produceSensorData( | ||
@ApiParam(value = "erp data", required = true) | ||
@RequestBody Map<String, SensorValue> sensorValueMap, | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) | ||
throws UnirestException; | ||
|
||
/** | ||
* See API documentation | ||
* | ||
* @param channelID Nimble Channel ID | ||
* @param bearer OpenID Connect token storing requesting identity | ||
* @return See API documentation | ||
* @throws UnirestException Error while communication with the Identity Service | ||
*/ | ||
@ApiOperation(value = "Consume sensor data for channel negotiation", nickname = "consumeSensorData", response = Map.class) | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "Sensor Data consumed", response = Object.class), | ||
@ApiResponse(code = 400, message = "Error while consuming sensor data"), | ||
@ApiResponse(code = 401, message = "Unauthorized"), | ||
@ApiResponse(code = 403, message = "Forbidden"), | ||
@ApiResponse(code = 404, message = "Not Found") }) | ||
@RequestMapping(value = "/consumeSensorData/{channelID}", consumes = {"application/json"}, method = RequestMethod.GET) | ||
ResponseEntity<?> consumeSensorData( | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) | ||
throws UnirestException; | ||
} |
145 changes: 145 additions & 0 deletions
145
...channel-service/src/main/java/eu/nimble/service/datachannel/controller/ErpController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package eu.nimble.service.datachannel.controller; | ||
|
||
import com.mashape.unirest.http.exceptions.UnirestException; | ||
import eu.nimble.common.rest.identity.IdentityResolver; | ||
import eu.nimble.service.datachannel.entity.ChannelConfiguration; | ||
import eu.nimble.service.datachannel.entity.ERPData.SensorValue; | ||
import eu.nimble.service.datachannel.entity.Server; | ||
import eu.nimble.service.datachannel.repository.ChannelConfigurationRepository; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiParam; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* REST Controller for managing calls from ERP. | ||
* | ||
* @author Mathias Schmoigl | ||
*/ | ||
@Controller | ||
@RequestMapping(path = "/erp") | ||
@Api("ERP Integration API") | ||
public class ErpController implements ErpAPI { | ||
|
||
@Autowired | ||
private IdentityResolver identityResolver; | ||
|
||
@Autowired | ||
private ChannelConfigurationRepository channelConfigurationRepository; | ||
|
||
//-------------------------------------------------------------------------------------- | ||
// getAllActiveChannels | ||
//-------------------------------------------------------------------------------------- | ||
public ResponseEntity<?> getAllActiveChannels( | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) throws UnirestException { | ||
|
||
// extract ID of company | ||
String companyID = identityResolver.resolveCompanyId(bearer); | ||
|
||
// get associated channels | ||
Set<ChannelConfiguration> sellerChannels = channelConfigurationRepository.findBySellerCompanyID(companyID); | ||
Set<ChannelConfiguration> buyerChannels = channelConfigurationRepository.findByBuyerCompanyID(companyID); | ||
Map<String, String> resultChannels = new HashMap<String, String>(); | ||
|
||
// return if no channels found | ||
if (sellerChannels == null || buyerChannels == null) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
|
||
// search and group sellers | ||
for (ChannelConfiguration config : sellerChannels) { | ||
if (config.isOnLastPage() && config.isChannelOpened()) { | ||
resultChannels.put("seller", config.getChannelID()); | ||
} | ||
} | ||
|
||
// search and group buyers | ||
for (ChannelConfiguration config : buyerChannels) { | ||
if (config.isOnLastPage() && config.isChannelOpened()) { | ||
resultChannels.put("buyer", config.getChannelID()); | ||
} | ||
} | ||
|
||
// return all found buyer and seller datachannels that are ready to be streamed | ||
return ResponseEntity.ok(resultChannels); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
// getConfigData (for ChannelID) | ||
//-------------------------------------------------------------------------------------- | ||
public ResponseEntity<?> getConfigData( | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) throws UnirestException { | ||
|
||
ChannelConfiguration channelConfiguration = channelConfigurationRepository.findOneByChannelID(channelID); | ||
if (channelConfiguration == null) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
|
||
return ResponseEntity.ok(channelConfiguration); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
// produceSensorData (for ChannelID) | ||
//-------------------------------------------------------------------------------------- | ||
public ResponseEntity<?> produceSensorData( | ||
@ApiParam(value = "erp data", required = true) | ||
@RequestBody Map<String, SensorValue> sensorValueMap, | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) throws UnirestException { | ||
|
||
ChannelConfiguration channelConfiguration = channelConfigurationRepository.findOneByChannelID(channelID); | ||
if (channelConfiguration == null) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
|
||
// produce data for every negotiated server | ||
for(Server server: channelConfiguration.getAssociatedServers()) | ||
{ | ||
// TODO: send SensorValues to all configured servers | ||
// TODO: URL = jdbc:postgresql://${DATACHANNEL_DB_HOST:localhost}:${DATACHANNEL_DB_HOST_PORT:5432}/${DATACHANNEL_DB_NAME:sensordatadb} | ||
} | ||
|
||
// if sending to all servers worked, return true | ||
return ResponseEntity.ok(true); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
// consumeSensorData (for ChannelID) | ||
//-------------------------------------------------------------------------------------- | ||
public ResponseEntity<?> consumeSensorData( | ||
@ApiParam(value = "channelID", required = true) | ||
@PathVariable String channelID, | ||
@ApiParam(name = "Authorization", value = "OpenID Connect token containing identity of requester", required = true) | ||
@RequestHeader(value = "Authorization") String bearer) throws UnirestException { | ||
|
||
ChannelConfiguration channelConfiguration = channelConfigurationRepository.findOneByChannelID(channelID); | ||
if (channelConfiguration == null) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
|
||
// try to consume data from a negotiated server, try next if failed | ||
for(Server server: channelConfiguration.getAssociatedServers()) { | ||
|
||
// TODO: receive SensorValues from first available server | ||
// TODO: URL = jdbc:postgresql://${DATACHANNEL_DB_HOST:localhost}:${DATACHANNEL_DB_HOST_PORT:5432}/${DATACHANNEL_DB_NAME:sensordatadb} | ||
} | ||
|
||
// if no server provided data, return false | ||
return ResponseEntity.ok(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...annel-service/src/main/java/eu/nimble/service/datachannel/entity/ERPData/SensorValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package eu.nimble.service.datachannel.entity.ERPData; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotNull; | ||
|
||
@Entity | ||
@ApiModel(value = "SensorValue") | ||
public class SensorValue { | ||
|
||
@Id | ||
@JsonIgnore | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@NotNull | ||
@ApiModelProperty(value = "Value of sensor datum") | ||
private Integer sensorValue; | ||
|
||
@NotNull | ||
@Temporal(TemporalType.TIMESTAMP) | ||
@ApiModelProperty(value = "Timestamp of sensor datum") | ||
private java.util.Date sensorTime; | ||
|
||
|
||
public Integer getSensorValue() { | ||
return sensorValue; | ||
} | ||
public void setSensorValue(Integer value) { | ||
this.sensorValue = value; | ||
} | ||
|
||
public java.util.Date getSensorTime() { | ||
return sensorTime; | ||
} | ||
public void setSensorTime(java.util.Date time) { | ||
this.sensorTime = time; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters