コード例 #1
0
ファイル: UserRegisterImpl.java プロジェクト: KylinGu/openiot
  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";
    }
  }