2012-03-06 23:41:56 +00:00
|
|
|
package de.ctdo.bunti.web;
|
|
|
|
|
|
|
|
import de.ctdo.bunti.control.BuntiController;
|
2012-03-09 22:37:26 +00:00
|
|
|
import de.ctdo.bunti.model.BuntiDevice;
|
2012-03-12 00:17:52 +00:00
|
|
|
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
|
|
|
import de.ctdo.bunti.webmodel.DeviceUpdates;
|
2012-03-09 22:37:26 +00:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2012-03-06 23:41:56 +00:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Controller;
|
2012-03-07 18:21:53 +00:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2012-03-09 22:37:26 +00:00
|
|
|
|
|
|
|
import javax.validation.Validator;
|
2012-03-12 00:17:52 +00:00
|
|
|
import java.util.*;
|
2012-03-06 23:41:56 +00:00
|
|
|
|
|
|
|
@Controller
|
2012-03-12 00:17:52 +00:00
|
|
|
@RequestMapping(value = "/control")
|
2012-03-06 23:41:56 +00:00
|
|
|
public class RestController {
|
2012-03-09 22:37:26 +00:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
|
2012-03-06 23:41:56 +00:00
|
|
|
private BuntiController controller;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public final void setController(BuntiController controller) {
|
|
|
|
this.controller = controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/devices", method = RequestMethod.GET)
|
2012-03-09 22:37:26 +00:00
|
|
|
public @ResponseBody Collection<BuntiDevice> getAll() {
|
|
|
|
LOGGER.info("handle GET /devices request");
|
|
|
|
return controller.getAllDevices();
|
2012-03-06 23:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
|
2012-03-09 22:37:26 +00:00
|
|
|
public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) {
|
|
|
|
LOGGER.info("handle GET /devices/" + id + " request");
|
|
|
|
return controller.getDeviceById(id);
|
2012-03-06 23:41:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
@RequestMapping(value = "/devices/{id}", method = RequestMethod.POST)
|
|
|
|
public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) {
|
2012-03-09 22:37:26 +00:00
|
|
|
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
|
|
|
|
controller.updateDeviceData(id, update.getOptions());
|
|
|
|
return controller.getDeviceById(id);
|
2012-03-09 22:37:26 +00:00
|
|
|
}
|
2012-03-06 23:41:56 +00:00
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
@RequestMapping(value = "/devices", method = RequestMethod.POST)
|
|
|
|
public String setDevices(@RequestBody DeviceUpdates updates) {
|
2012-03-12 00:17:52 +00:00
|
|
|
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
for (DeviceUpdate update: updates.getUpdates()) {
|
2012-03-12 00:17:52 +00:00
|
|
|
LOGGER.info("Update deviceId=" + update.getDeviceId());
|
|
|
|
|
|
|
|
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
|
|
|
|
}
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
return "bla";
|
2012-03-12 00:17:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:41:56 +00:00
|
|
|
}
|