Example #1
0
  @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();
  }
Example #2
0
  @Path("/discover/{ObjID}/{ObjInsId}/{resourceId}")
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public Response sendDiscover(
      @PathParam("ObjID") String objectId,
      @PathParam("ObjInsId") String objectInstanceId,
      @PathParam("resourceId") String resourceID,
      @QueryParam("ep") String endPoint)
      throws Exception {
    String directory =
        "{\"operation\":\"discover\""
            + ","
            + "\""
            + "directory\":"
            + "\""
            + objectId
            + "/"
            + objectInstanceId
            + "/"
            + resourceID
            + "\"}";
    Info.setInfo(endPoint, directory);
    CountDownLatch signal = Info.getCountDown(endPoint);
    if (signal == null) {
      return Response.status(200).entity("Devices not registerd yet").build();
    }
    signal.countDown();

    CountDownLatch signalRead = new CountDownLatch(1);
    Info.setCountDownLatchMessageMap(endPoint, signalRead);
    signalRead.await();

    Datastore ds = MongoConnection.getServer();
    List<ClientObject> clientObjects =
        ds.createQuery(ClientObject.class).filter("client_bs_obj.device_id =", endPoint).asList();
    resource.Object obj = clientObjects.get(0).getObjectMap().get(Integer.parseInt(objectId));
    String message = "discover success! " + "pmin:" + obj.getPmin() + " pmax:" + obj.getPmax();

    return Response.status(200).entity(message).build();
  }