public ResponseEntity<String> registerDevice(@Valid @RequestBody DInfo dInfo) {
log.debug("request to register device : {}", dInfo);
- Optional<DeviceType> dt = deviceTypeService.findOne(dInfo.getType());
+ String dtype = dInfo.getType().toLowerCase();
+ Optional<DeviceType> dt = deviceTypeService.findOne(dtype);
if (!dt.isPresent()) {
- throw new DeviceServiceError.DeviceTypeNotFoundException();
+ dt = Optional.of(new DeviceType(dtype,"new type: created sn "+dInfo.getSn()));
+ deviceTypeService.save(dt.get());
}
- String duid = deviceService.getDeviceUID(dInfo.getType(), dInfo.getModel(), dInfo.getSn());
+ String duid = deviceService.getDeviceUID(dtype, dInfo.getModel(), dInfo.getSn());
deviceService.findOne(duid).ifPresent(d -> {throw new DeviceServiceError.DeviceAlreadyRegisteredException();});
Device result = deviceService.save(
- new Device(duid, dInfo.getModel(), dInfo.getDos(), dInfo.getSn(), dInfo.getDescr(), dt.get()));
+ new Device(duid, dInfo.getModel(), dInfo.getLocation(), dInfo.getSn(), dInfo.getDescr(), dt.get(),
+ dInfo.getSw(), dInfo.getOsname(), dInfo.getOsver()));
return ResponseEntity.ok()
.headers(new HttpHeaders())
@NotNull
private String model;
- @JsonProperty("dos")
- @NotNull
- private String dos;
+ @JsonProperty("location")
+ private String location;
@JsonProperty("sn")
@NotNull
@JsonProperty("descr")
private String descr;
+
+ @JsonProperty("sw")
+ private String sw;
+
+ @JsonProperty("osname")
+ @NotNull
+ private String osname;
+
+ @JsonProperty("osver")
+ @NotNull
+ private String osver;
}
}