@Path("/writeAttribute") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response writeAttributeResponse(String input) throws Exception { JSONObject inputObj = new JSONObject(input); Datastore ds = MongoConnection.getServer(); List<ClientObject> clientObjects = ds.createQuery(ClientObject.class) .filter("client_bs_obj.device_id =", inputObj.getString("client_bs_obj.device_id")) .asList(); ClientObject clientObject = clientObjects.get(0); resource.Object obj = clientObject.getObjectMap().get(inputObj.getInt("ObjectId")); obj.setPmin(inputObj.getJSONObject("value").getString("pmin")); obj.setPmax(inputObj.getJSONObject("value").getString("pmax")); obj.setLessThan(inputObj.getJSONObject("value").getString("lt")); obj.setGreaterThan(inputObj.getJSONObject("value").getString("gt")); obj.setStep(inputObj.getJSONObject("value").getString("st")); ds.save(clientObject); CountDownLatch signalRead = Info.getCountDownMessage(inputObj.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity(inputObj.getString("message")).build(); }
@Path("/read") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response readResponse(String input) throws Exception { JSONObject test = new JSONObject(input); Datastore ds = MongoConnection.getServer(); List<ClientObject> clientObjects = ds.createQuery(ClientObject.class) .filter("client_bs_obj.device_id =", test.getString("client_bs_obj.device_id")) .asList(); Resource resourceO = clientObjects .get(0) .getObjectMap() .get(test.getInt("ObjectId")) .getObjInstanceMap() .get(test.getInt("ObjectInsId")) .getResourceMap() .get(test.getInt("resourceId")); ObjectMapper mapper = new ObjectMapper(); Resource resourceN = mapper.readValue(test.getString("value"), Resource.class); resourceO.getValue().putAll(resourceN.getValue()); ds.save(clientObjects.get(0)); CountDownLatch signalRead = Info.getCountDownMessage(test.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity("success").build(); }
@Path("/execute") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response sendExecute(String result) throws Exception { JSONObject jsonObject = new JSONObject(result); String device_id = jsonObject.getString("client_bs_obj.device_id"); CountDownLatch signalRead = Info.getCountDownMessage(jsonObject.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity("success").build(); }
@Path("/discover") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response discoverResponse(String input) throws Exception { JSONObject inputObj = new JSONObject(input); String value = "pmin:" + inputObj.getString("pmin") + "; pmax:" + inputObj.getString("pmax"); CountDownLatch signalRead = Info.getCountDownMessage(inputObj.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity(inputObj.getString("message") + "; " + value).build(); }
@Path("/create") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createResponse(String input) throws Exception { JSONObject inputObj = new JSONObject(input); Datastore ds = MongoConnection.getServer(); List<ClientObject> clientObjects = ds.createQuery(ClientObject.class) .filter("client_bs_obj.device_id =", inputObj.getString("client_bs_obj.device_id")) .asList(); ClientObject clientObject = clientObjects.get(0); Map<Integer, ObjInstance> objInstanceMap = clientObject.getObjectMap().get(inputObj.getInt("ObjectId")).getObjInstanceMap(); Map<Integer, Resource> resourceMap = objInstanceMap.get(inputObj.getInt("ObjectInsId")).getResourceMap(); ObjInstance objInstance = new ObjInstance(); objInstance.setObjInstance_id(inputObj.getInt("ObjectInsId") + 1); Resource resource = new Resource(); resource.setRecourse_id(0); resource.setName(inputObj.getString("value")); Map<Integer, Resource> resourceMapNew = objInstance.getResourceMap(); resourceMapNew.put(0, resource); objInstanceMap.put(objInstance.getObjInstance_id(), objInstance); // Map<Integer,Resource> resourceMap = objInstanceMap.get(ObjectInsId).getResourceMap(); ds.save(clientObject); CountDownLatch signalRead = Info.getCountDownMessage(inputObj.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity(inputObj.getString("message")).build(); }
@Path("/delete") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response deleteResponse(String input) throws Exception { JSONObject inputObj = new JSONObject(input); Datastore ds = MongoConnection.getServer(); List<ClientObject> clientObjects = ds.createQuery(ClientObject.class) .filter("client_bs_obj.device_id =", inputObj.getString("client_bs_obj.device_id")) .asList(); ClientObject clientObject = clientObjects.get(0); Map<Integer, ObjInstance> objInstanceMap = clientObject.getObjectMap().get(inputObj.getInt("ObjectId")).getObjInstanceMap(); objInstanceMap.remove(inputObj.getInt("ObjectInsId")); ds.save(clientObject); CountDownLatch signalRead = Info.getCountDownMessage(inputObj.getString("client_bs_obj.device_id")); signalRead.countDown(); return Response.status(200).entity(inputObj.getString("message")).build(); }