Exemple #1
0
  public void publish(SensorObservation observation, SensorMetaData sensorMetaData) {

    logger.warn("asked to publish");
    logger.warn(observation);
    logger.warn(sensorMetaData);

    if (true) return;

    // create an Observation object
    Observation obs = new Observation();

    logger.warn(sensorMetaData.getSensorID());
    // set SensorURL of observation
    Sensor sensor2 = lsmStore.getSensorById(sensorMetaData.getSensorID());
    obs.setSensor(sensor2.getId());
    // set time when the observation was observed. In this example, the time is current local time.
    obs.setTimes(observation.getTime());

    ObservedProperty obvTem = new ObservedProperty();
    obvTem.setObservationId(obs.getId());
    obvTem.setPropertyName(observation.getPropertyName());
    obvTem.setValue(observation.getValue());
    obvTem.setUnit(observation.getUnit());
    obs.addReading(obvTem);
    lsmStore.sensorDataUpdate(obs);
  }
  private void registerService() {
    User user = new User();
    user.setUsername(lsmUserName);
    user.setPass(lsmPassword);

    LSMTripleStore lsmStore = new LSMTripleStore();
    lsmStore.setUser(user);

    LSMSchema myOnt = new LSMSchema(OntModelSpec.OWL_DL_MEM);
    LSMSchema myOntInstance = new LSMSchema();

    org.openiot.scheduler.core.utils.lsmpa.entities.User userEnt =
        new org.openiot.scheduler.core.utils.lsmpa.entities.User(
            myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
    userEnt.setId(osdSpec.getUserID());
    // //
    userEnt.createClassIdv();

    for (OAMO oamo : osdSpec.getOAMO()) {
      logger.debug("OAMO Description: {}  ID: {}", oamo.getDescription(), oamo.getId());
      logger.debug("OAMO Name: {}", oamo.getName());

      org.openiot.scheduler.core.utils.lsmpa.entities.OAMO oamoEnt =
          new org.openiot.scheduler.core.utils.lsmpa.entities.OAMO(
              myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
      oamoEnt.setId(oamo.getId());
      oamoEnt.setName(oamo.getName());
      oamoEnt.setUser(userEnt);
      oamoEnt.setDescription(oamo.getDescription());
      oamoEnt.setGraphMeta(oamo.getGraphMeta());
      //
      oamoEnt.createClassIdv();
      oamoEnt.createPoamoName();
      oamoEnt.createPoamoUserOf();
      oamoEnt.createPoamoDescription();
      oamoEnt.createPoamoGraphMeta();

      userEnt.addService(oamoEnt);
      //
      userEnt.createPuserOf();

      for (OSMO osmo : oamo.getOSMO()) {
        logger.debug("OSMO ID: {}", osmo.getId());
        logger.debug("OSMO Name: {}", osmo.getName());
        logger.debug("OSMO Description: {}", osmo.getDescription());
        for (QueryRequest qr : osmo.getQueryRequest()) {
          logger.debug("qr.getQuery():" + qr.getQuery());
        }

        Service srvcEnt = new Service(myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
        srvcEnt.setId(osmo.getId());
        srvcEnt.setName(osmo.getName());
        srvcEnt.setDescription(osmo.getDescription());
        //

        for (QueryRequest qr : osmo.getQueryRequest()) {
          Query qstring = new Query(myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
          qstring.setqString(qr.getQuery());
          //
          qstring.createClassIdv();
          qstring.createPqueryString();

          srvcEnt.addQueryString(qstring);
        }

        //
        srvcEnt.createClassIdv();
        srvcEnt.createPserviceName();
        srvcEnt.createPserviceDescription();
        srvcEnt.createPqString();

        for (Widget widget : osmo.getRequestPresentation().getWidget()) {
          WidgetPresentation widgetPre =
              new WidgetPresentation(myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
          widgetPre.setService(srvcEnt);
          //
          widgetPre.createClassIdv();
          widgetPre.createPwidgetPresOf();
          //
          srvcEnt.addWidgetPresentation(widgetPre);
          srvcEnt.createPwidgetPres();

          logger.debug("widget available id: {}", widget.getWidgetID());
          WidgetAvailable wAvail =
              new WidgetAvailable(myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
          wAvail.setId(widget.getWidgetID());
          wAvail.setWidgetPre(widgetPre);
          // /
          wAvail.createClassIdv();
          wAvail.createPWidgetOf();
          //
          widgetPre.setWidgetAvailable(wAvail);
          widgetPre.createPwidget();
          // //
          for (PresentationAttr pAttr : widget.getPresentationAttr()) {
            logger.debug("pAttr id: {} --- name: {}", pAttr.getName(), pAttr.getValue());

            WidgetAttributes wAttr =
                new WidgetAttributes(myOnt, myOntInstance, lsmFunctionalGraph, lsmStore);
            wAttr.setDescription(pAttr.getValue());
            wAttr.setName(pAttr.getName());
            wAttr.setWidgetPre(widgetPre);
            // /
            wAttr.createClassIdv();
            wAttr.createPdesc();
            wAttr.createPname();
            wAttr.createPWidgetAttrOf();
            //
            widgetPre.addWidgetAttr(wAttr);
            widgetPre.createPwidgetAttr();
          } // PresentationAttr
        } // widget

        srvcEnt.setOAMO(oamoEnt);
        // //
        srvcEnt.createPOAMO();

        oamoEnt.addService(srvcEnt);
        //
        oamoEnt.createPoamoService();
        //

      } // osmo
    } // oamo

    logger.debug(myOntInstance.exportToTriples("TURTLE"));
    boolean ok = lsmStore.pushRDF(lsmFunctionalGraph, myOntInstance.exportToTriples("N-TRIPLE"));

    if (ok) {
      replyMessage = "regester service successfull";
    } else {
      replyMessage = "regester service error";
    }

    logger.debug(replyMessage);
  }
Exemple #3
0
  public Sensor createLSMSensor(VSensorConfig vs) {
    SensorMetaData s = createSensorMetaData(vs);

    String id =
        TestLSM.addSensorToLSM(
            "swissex",
            "swissex1234",
            s.getSensorName(),
            s.getAuthor(),
            s.getSourceType(),
            s.getSensorType(),
            s.getInformation(),
            s.getSource(),
            0,
            0);

    System.out.println("SENSOR ID published to LSM => " + id);

    if (true) return null;

    Sensor sensor = null;
    LSMTripleStore lsmStore = null;

    try {

      System.out.println("Testing LSM...");

      // 1. Create an instanse of Sensor class and set the sensor metadata
      sensor = new Sensor();
      sensor.setName(s.getSensorName());
      sensor.setAuthor(s.getAuthor());
      sensor.setSensorType(s.getSensorType());
      sensor.setSourceType(s.getSourceType());
      sensor.setInfor(s.getInformation());
      sensor.setSource(s.getSource());
      sensor.setMetaGraph("http://lsm.deri.ie/OpenIoT/test/sensormeta#");
      sensor.setDataGraph("http://lsm.deri.ie/OpenIoT/test/sensordata#");
      sensor.setTimes(new Date());

      System.out.println(sensor.getId());

      // set sensor location information (latitude, longitude, city, country, continent...)
      Place place = new Place();
      place.setLat(vs.getLatitude());
      place.setLng(vs.getLongitude());
      sensor.setPlace(place);

      sensor.setUser(user);

      // create LSMTripleStore instance
      lsmStore = new LSMTripleStore();

      // set user information for authentication
      lsmStore.setUser(user);

      System.out.printf(sensor.getId());
      // call sensorAdd method
      lsmStore.sensorAdd(sensor);

      System.out.printf(sensor.getId());

    } catch (Exception e) {
      logger.warn("cannot send the data to server");
      logger.warn(e);
    }

    return sensor;
  }