|
1 |
| -package tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.REST; |
| 1 | +package tw.edu.ntust.connectivitylab.jojllman.kura.gativity.REST; |
2 | 2 |
|
3 | 3 | import org.slf4j.Logger;
|
4 | 4 | import org.slf4j.LoggerFactory;
|
5 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.access.*; |
6 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.device.DeviceManager; |
7 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.device.IDeviceProfile; |
8 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.device.TopicChannel; |
9 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.event.Event; |
10 |
| -import tw.edu.ntust.connectivitylab.jojllman.kura.iotgateway.event.EventManager; |
| 5 | +import tw.edu.ntust.connectivitylab.jojllman.kura.gativity.access.*; |
| 6 | +import tw.edu.ntust.connectivitylab.jojllman.kura.gativity.device.DeviceManager; |
| 7 | +import tw.edu.ntust.connectivitylab.jojllman.kura.gativity.device.IDeviceProfile; |
| 8 | +import tw.edu.ntust.connectivitylab.jojllman.kura.gativity.device.TopicChannel; |
11 | 9 |
|
12 | 10 | import java.security.GeneralSecurityException;
|
13 |
| -import java.util.Iterator; |
14 | 11 | import java.util.List;
|
15 |
| -import java.util.Map; |
16 | 12 | import javax.ejb.Stateless;
|
17 | 13 | import javax.json.Json;
|
18 | 14 | import javax.json.JsonArrayBuilder;
|
@@ -235,58 +231,6 @@ public Response queryDeviceList(HttpHeaders httpHeaders) {
|
235 | 231 | return getNoCacheResponseBuilder(Response.Status.OK).entity(jsonObj.toString()).build();
|
236 | 232 | }
|
237 | 233 |
|
238 |
| - @Override |
239 |
| - public Response queryEventList(HttpHeaders httpHeaders) { |
240 |
| - User caller = Authenticator.getInstance(). |
241 |
| - getAuthenticatedUser( |
242 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.SERVICE_KEY), |
243 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.AUTH_TOKEN)); |
244 |
| - |
245 |
| - JsonObjectBuilder jsonObjBuilder = Json.createObjectBuilder(); |
246 |
| - JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); |
247 |
| - s_logger.debug("Query event list"); |
248 |
| - if (caller.isAdministrator()) { |
249 |
| - Map<String, List<Event>> userEvents = EventManager.getInstance().getAllEvents(); |
250 |
| - Iterator<Map.Entry<String, List<Event>>> it = userEvents.entrySet().iterator(); |
251 |
| - while (it.hasNext()) { |
252 |
| - s_logger.debug("Has events"); |
253 |
| - JsonArrayBuilder eventJsonArrayBuilder = Json.createArrayBuilder(); |
254 |
| - Map.Entry<String, List<Event>> entry = it.next(); |
255 |
| - String userid = entry.getKey(); |
256 |
| - User user = UserManager.getInstance().findUserById(userid); |
257 |
| - List<Event> events = entry.getValue(); |
258 |
| - for (Event event : events) { |
259 |
| - eventJsonArrayBuilder.add(Json.createObjectBuilder() |
260 |
| - .add("name", event.getEventName()) |
261 |
| - .add("id", event.getEventId()) |
262 |
| - .add("if", event.getIfString()) |
263 |
| - .add("then", event.getThenString()) |
264 |
| - .add("repeat", event.isRepeat()) |
265 |
| - .add("period", event.getPeriod()) |
266 |
| - .add("active", event.isActive())); |
267 |
| - } |
268 |
| - jsonArrayBuilder.add(Json.createObjectBuilder() |
269 |
| - .add("user_id", userid) |
270 |
| - .add("events", eventJsonArrayBuilder)); |
271 |
| - } |
272 |
| - } else { |
273 |
| - List<Event> events = EventManager.getInstance().getUserEvents(caller.getUserId()); |
274 |
| - JsonArrayBuilder eventJsonArrayBuilder = Json.createArrayBuilder(); |
275 |
| - for (Event event : events) { |
276 |
| - eventJsonArrayBuilder.add(Json.createObjectBuilder() |
277 |
| - .add("name", event.getEventId()) |
278 |
| - .add("if", event.getIfString()) |
279 |
| - .add("then", event.getThenString())); |
280 |
| - } |
281 |
| - jsonArrayBuilder.add(Json.createObjectBuilder() |
282 |
| - .add("user_id", caller.getUserId()) |
283 |
| - .add("events", eventJsonArrayBuilder)); |
284 |
| - } |
285 |
| - jsonObjBuilder.add("user_events", jsonArrayBuilder); |
286 |
| - JsonObject jsonObj = jsonObjBuilder.build(); |
287 |
| - return getNoCacheResponseBuilder(Response.Status.OK).entity(jsonObj.toString()).build(); |
288 |
| - } |
289 |
| - |
290 | 234 | @Override
|
291 | 235 | public Response writeChannelData(HttpHeaders httpHeaders, String channelId, String type, String value) {
|
292 | 236 | User caller = Authenticator.getInstance().
|
@@ -672,60 +616,6 @@ public Response getChannelGroup(HttpHeaders httpHeaders, String channelId) {
|
672 | 616 | return null;
|
673 | 617 | }
|
674 | 618 |
|
675 |
| - @Override |
676 |
| - public Response addEvent(HttpHeaders httpHeaders, |
677 |
| - String eventName, |
678 |
| - String ifString, |
679 |
| - String thenString, |
680 |
| - String repeat, |
681 |
| - String period) { |
682 |
| - User caller = Authenticator.getInstance(). |
683 |
| - getAuthenticatedUser( |
684 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.SERVICE_KEY), |
685 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.AUTH_TOKEN)); |
686 |
| - |
687 |
| - boolean repeatVal; |
688 |
| - if(repeat == null) |
689 |
| - repeatVal = false; |
690 |
| - else |
691 |
| - repeatVal = Boolean.valueOf(repeat); |
692 |
| - |
693 |
| - int periodVal; |
694 |
| - if(period == null) |
695 |
| - periodVal = 1000; |
696 |
| - else |
697 |
| - periodVal = Integer.valueOf(period); |
698 |
| - |
699 |
| - Event event = new Event(eventName, ifString, thenString, repeatVal, periodVal); |
700 |
| - //TODO: Access control |
701 |
| - String eventId = EventManager.getInstance().addEvent(caller.getUserId(), event); |
702 |
| - |
703 |
| - JsonObjectBuilder jsonObjBuilder = Json.createObjectBuilder(); |
704 |
| - jsonObjBuilder.add("message", "event has been added"); |
705 |
| - jsonObjBuilder.add("event_id", eventId); |
706 |
| - JsonObject jsonObj = jsonObjBuilder.build(); |
707 |
| - return getNoCacheResponseBuilder(Response.Status.ACCEPTED).entity(jsonObj.toString()).build(); |
708 |
| - } |
709 |
| - |
710 |
| - @Override |
711 |
| - public Response removeEvent(HttpHeaders httpHeaders, String eventId) { |
712 |
| - User caller = Authenticator.getInstance(). |
713 |
| - getAuthenticatedUser( |
714 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.SERVICE_KEY), |
715 |
| - httpHeaders.getHeaderString(HTTPHeaderNames.AUTH_TOKEN)); |
716 |
| - |
717 |
| - if(EventManager.getInstance().doesUserHasEvent(caller.getUserId(), eventId)) { |
718 |
| - EventManager.getInstance().removeEvent(caller.getUserId(), |
719 |
| - EventManager.getInstance().getUserEvent(caller.getUserId(), eventId)); |
720 |
| - JsonObjectBuilder jsonObjBuilder = Json.createObjectBuilder(); |
721 |
| - jsonObjBuilder.add("message", "event has been removed"); |
722 |
| - JsonObject jsonObj = jsonObjBuilder.build(); |
723 |
| - return getNoCacheResponseBuilder(Response.Status.ACCEPTED).entity(jsonObj.toString()).build(); |
724 |
| - } |
725 |
| - |
726 |
| - return null; |
727 |
| - } |
728 |
| - |
729 | 619 | @Override
|
730 | 620 | public Response logout(
|
731 | 621 | HttpHeaders httpHeaders) {
|
|
0 commit comments