示例#1
0
  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);
  }
示例#2
0
  private void registerUser() {
    SesameSPARQLClient sparqlCl = null;
    try {
      sparqlCl = new SesameSPARQLClient();
    } catch (RepositoryException e) {
      logger.error("Init sparql repository error. Error checking if mail already exists", e);
      replyMessage = "error checking if mail already exists";
      return;
    }

    // check if user with same mail exists
    TupleQueryResult qres =
        sparqlCl.sparqlToQResult(
            org.openiot.scheduler.core.utils.lsmpa.entities.User.Queries.selectUserByEmail(
                SchedulerLsmFunctionalGraph, this.mail));
    ArrayList<org.openiot.scheduler.core.utils.lsmpa.entities.User> usrEnt =
        org.openiot.scheduler.core.utils.lsmpa.entities.User.Queries.parseUserData(qres);

    if (usrEnt.size() == 0) {
      //			User user = new User();
      //			user.setUsername(schedulerLsmUserName);
      //			user.setPass(schedulerLsmPassword);

      LSMTripleStore lsmStore = new LSMTripleStore(lsmDeriServer);
      //			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, SchedulerLsmFunctionalGraph, lsmStore);
      userEnt.setName(this.name);
      userEnt.setEmail(this.mail);
      userEnt.setDescription(this.description);
      userEnt.setPasswd(this.passwd);
      //
      userEnt.createClassIdv();
      userEnt.createPName();
      userEnt.createPemail();
      userEnt.createPdescription();
      userEnt.createPpasswd();

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

      //			if(ok){
      qres =
          sparqlCl.sparqlToQResult(
              org.openiot.scheduler.core.utils.lsmpa.entities.User.Queries.selectUserByEmail(
                  SchedulerLsmFunctionalGraph, this.mail));
      // parse userdata list should always contain one element
      org.openiot.scheduler.core.utils.lsmpa.entities.User usrEntity =
          org.openiot.scheduler.core.utils.lsmpa.entities.User.Queries.parseUserData(qres).get(0);

      replyMessage = usrEntity.getId();
      //			}
      //			else{
      //				replyMessage= "register user error";
      //			}
    } else {
      replyMessage = "mail already exists";
    }
  }