Package org.foafrealm.manage

Examples of org.foafrealm.manage.Person


           
              String parentIssuer = null;
             
              //we want to delete all the resources of somebody and we know his mbox
              if(parent.startsWith("mailto:")) {
                Person person = PersonFactory.findPerson(parent);
                if(person!=null) parentIssuer = person.getURI().toString();
              }
              else if(parentRes.getIssuedBy()!=null) {
                parentIssuer = parentRes.getIssuedBy().getStringURI();
              }
             
              String resIssuer = res.getIssuedBy()!=null?res.getIssuedBy().getStringURI():loggedPerson;
             
              if(loggedPerson!=null&&loggedPerson.equals(parentIssuer)&&
                  resIssuer.equals(parentIssuer))
              {
                try {
            if(parentRes!= null)
            {
             
              ResourceRemover rm = new ResourceRemover();
              rm.removeAll(res, parentRes);
             
              sendJSONResponse(response,OK);
            }
            else
              sendJSONResponse(response,ERROR);
          } catch (IOException e) {
            e.printStackTrace();
          }
              }
      }
      else if(type.equals("addBookmark"))
      {
              String result = insertResource(request);
             
              try {
          if(result!=null)
            sendJSONResponse(response,result);
          else sendJSONResponse(response,ERROR);
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      else if(type.equals("directoryDescription"))
      {
              String uri = request.getParameter("uri");
              String sioc = request.getParameter("sioc");
              String webBookmark = request.getParameter("webBookmark");
             
              if(uri!=null&&!"".equals(uri))
              {
                String result;
                if(sioc!=null)
                  result = SscfHelper2.getInstance().getSiocResourceDescription(uri, sioc);
                else if(webBookmark!=null) {
                  result = SscfHelper2.getInstance().getWebBookmarkDescription(uri);
                }
                else result = SscfHelper2.getInstance().getDirectoryDescription(uri);
                try {
            if(result!=null)
            {
              //System.out.println(result);
              sendJSONResponse(response,result);
            }
            else sendJSONResponse(response,ERROR);
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
              }
      }
      else if(type.equals("importNode"))
      {
              String result = importSuggestedResource(request);
             
              try {
          if(result!=null)
            sendJSONResponse(response,result);
          else sendJSONResponse(response,ERROR);
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      else if(type.equals("directoryPolicy"))
      {
              String uri = request.getParameter("uri");
             
              //add new policy if parameter set.
              String policy = request.getParameter("policy");
              String remove = request.getParameter("remove");
             
              if(policy!=null&&!"".equals(policy))
              {
                XfoafSscfResource resource = XfoafSscfResource.getXfoafSscfResource(uri);
                if(resource!=null)
                {
                  if(remove!=null&&!"".equals(remove)&&"1".equals(remove))
                  { 
                    resource.deleteAccessibleTo(policy);
                  }
                  else
                    resource.addAccessibleTo(policy);
                }
              }
             
              if(uri!=null&&!"".equals(uri))
              {
                String result = SscfHelper2.getInstance().getDirectoryPolicies(uri);
                try {
            if(result!=null)
              sendJSONResponse(response,result);
            else sendJSONResponse(response,ERROR);
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
              }
      }
      else if(type.equals("generateWordnet"))
      {  
              String name = request.getParameter("name");
              String desc = request.getParameter("desc");
              String thesUri = request.getParameter("thesUri");
                   
              if(name!=null&&!"".equals(name.trim()) )
              {
                String result = SscfHelper2.getInstance().getWordNetValues(name,desc,thesUri);
                try {
            if(result!=null)
              sendJSONResponse(response,result);
            else sendJSONResponse(response,EMPTY);
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
              }
      }
      else if(type.equals("createDirectory"))
      {
              String bookmarks = createDirectory(request);
              try {
                if(bookmarks == null||"".equals(bookmarks.trim()))
                  sendJSONResponse(response,EMPTY);
                else
                  sendJSONResponse(response,bookmarks);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      else if(type.equals("sendClick"))
      {
              String uri = request.getParameter("item");
              String resType = request.getParameter("resourceType");
              try {
                if(uri == null||"".equals(uri.trim()))
                  response.getWriter().write(EMPTY);
                else
                {               
                  System.out.println("I received a click to: "+uri);
                 
                  if(resType!=null&&!"".equals(resType)&&resType.equals("web"))
                  {
                    WebBookmarkResource wbr = WebBookmarkResource.getWebBookmarkResource(uri);
                    if(wbr != null)
                      wbr.increaseResourceHits();
                  }
                  else
                  {
                    XfoafSscfResource xfsr = XfoafSscfResource.getXfoafSscfResource(uri);
                    if(xfsr != null)
                      xfsr.increaseResourceHits();
                  }
                 
                  sendJSONResponse(response,OK);
                }
        } catch (IOException e) {
          e.printStackTrace();
        }
       
      }
      else if(type.equals("importBookmarks"))
      {   
              String username = request.getParameter("username");
              String password = request.getParameter("password");
              String importType = request.getParameter("importType");
              String viewer = request.getParameter("viewer");
             
              String check = request.getParameter("check");
 
              String[] result = null;
             
              StringBuilder responseResult = new StringBuilder();
             
              if(username.contains("@yahoo.com")){ //fix username for flickr account
            username = username.substring(0,username.indexOf("@yahoo.com"));
              }
             
              if(username!=null&&password!=null&&importType!=null&&viewer!=null&&
                  !"".equals(username)&&!"".equals(password)&&!"".equals(importType)&&!"".equals(viewer)) {
                result = importBookmarks(importType, username, password,check,viewer,getServiceAddr(request));
              }
                
              try {
                if(username != null && !"".equals(username)){
                  request.getSession().setAttribute("username", username);
                }else if ( username == null && request.getSession().getAttribute("username") != null){
                  username = (String)request.getSession().getAttribute("username");
                }

          if(result!=null&&result[0]!=null&&!result[0].equals(TaskStatusInfo.ERROR.getMessage())
              &&!result[0].equals(TaskStatusInfo.DONE.getMessage())
              &&!result[0].equals(TaskStatusInfo.REMOTEERROR.getMessage())
              &&!result[0].equals(TaskStatusInfo.REDIRECTING.getMessage()))
          {
            responseResult.append("{stat:\"").append(result[0]).append("\"");
            if(result[1]!=null)
              responseResult.append(",message:\"").append(result[1]).append("\"");
            else responseResult.append(",message:\"\"");
           
            sendJSONResponse(response, responseResult.append("}").toString());
          }
          else if(result!=null&&result[0].equals(TaskStatusInfo.DONE.getMessage()))
          {
            responseResult.append("{stat:\"").append(result[0]).append("\"");

            Person view = PersonFactory.findPerson(viewer);
            if(view!=null)
            {
              String dir = getBookmarks(result[1], view.getURI().toString(), request.getSession(), 1,true, true, getServiceAddr(request),null)
              responseResult.append(",message:").append(dir);
           
            else responseResult.append(",message:\"\"");
           
            sendJSONResponse(response, responseResult.append("}").toString());
View Full Code Here


   * @param type - type of the resource that we want to get
   * @return - JSON object with tree nodes.
   */
  private String getBookmarks(String item,String view,HttpSession session,int level,boolean paste,boolean standalone,String serviceAddr,String type)
  {
    Person viewer;
    XResource resource;
   
    boolean personEqViewer = false;
   
    //TODO: change to get person - this person exists
View Full Code Here

   * @param session
   * @return - JSON of pasted element
   */
  public String pasteResource(String destination,String item,String view,String level,boolean cut,String oldParent,HttpSession session,String serviceAddr,String type)
  {
    Person viewer;
    String changedType;
   
    //    parse level
    int levelInt;
    try {
View Full Code Here

   * @return - JSON bookmark to insert into the tree
   */
  public String insertResource(String destinations,String item,String view,HttpSession session,String serviceAddr, String tags)
  {
    String[] destTable = destinations.split(";;");
    Person viewer = PersonFactory.findPerson(view);
   
    BookmarksHelper bh = new BookmarksHelper("http://foo.bar");
    String createdUri = bh.createResource(item);
   
    if(createdUri!=null)
    {
      XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(createdUri);
      if(res!=null)
      {
        bh.placeResources(res, destTable, viewer);
     
        //notify synchronization resource loader that resources of user were changed
          ResourcesLoader.setLastChangeDate(view, new Date());
        //it will be useful to have type here.
        return getBookmarks(res.getStringURI(), viewer.getURI().toString(), session, 2, true,false,serviceAddr,null);
      }
    }
    return null;
  }
View Full Code Here

   * @return - JSON bookmark to insert into the tree
   */
  public String insertWebResource(String destinations,String item,String view,HttpSession session,String serviceAddr,String label,String desc,String type,String ikhUri, String tags)
  {
    String[] destTable = destinations.split(";;");
    Person viewer = PersonFactory.findPerson(view);
    WebBookmarkResource wbr=null;
    String resourceType= null;
   
    //harvest the bookmark
    if(ikhUri!=null&&!"".equals(ikhUri.trim())) {
      IKHConnector ikhc = new IKHConnector(ikhUri+"$"+item+"$",tags,view);
      ikhc.start();
    }
   
    BookmarksHelper bh = new BookmarksHelper("http://foo.bar");
   
    if(type.equals("web"))
      resourceType = S3B_SSCF.WebResource;
    else if(type.equals("hex"))
      resourceType = S3B_SSCF.HexResource;
   
    if(viewer!=null)
    {
      if(viewer.getMbox_sha1sum()!=null)
        wbr = WebBookmarkResource.getWebBookmarkResource(item,null,viewer.getMbox_sha1sum(),resourceType);
      else
        wbr = WebBookmarkResource.getWebBookmarkResource(item,view,null,resourceType);
     
      if(wbr!=null)
      {
        wbr.setLabel(label);
        if(desc!=null&&!"".equals(desc.trim()))
          wbr.setComment(desc);
       
        //ArrayList<String> ltags = new ArrayList<String>();
        bh.placeResources(wbr, destTable, viewer);
        /*
         * Add tags for newly created resource
         */
        try {
          if (tags != null) {
         
            Tagging tagging = new Tagging(wbr.getURI(),viewer.getURI());
            List<Term> terms = tagging.addTerms(tags);
           
            TaggingDbLogic tdbl = new TaggingDbLogic();
            tdbl.addTagging(tagging, serviceAddr);
           
            List<String> atags = new ArrayList<String>();
            for(Term term:terms)
              atags.add(term.getTag());
            wbr.setTags(atags);
           
          }
        } catch (Exception e) {
          //logger.severe("URI of logged in user is incorrect " + e);
          e.printStackTrace();
        }
       
        //notify synchronization resource loader that resources of user were changed
          ResourcesLoader.setLastChangeDate(view, new Date());
        //it will be useful to have type here.
        return getBookmarks(wbr.getStringURI(), viewer.getURI().toString(), session, 2, true,false,serviceAddr,resourceType);
      }
    }
    return null;
  }
View Full Code Here

   * @return - JSON object with created tree nodes.
   */
  public String createDirectory(String name,String desc,Map<String,Collection<String>> thValues,Map<String,Collection<String>> taxValues,String view,String serverAddr,String destination,String level,HttpServletRequest request )
  {
    //==== PURE DIRECTORY CREATION ====
    Person person;
    person = PersonFactory.findPerson(view);
    String newDesc = desc;
   
    if(desc==null||"".equals(desc.trim()))
      newDesc = "";
View Full Code Here

   * @return
   */
  public String addFriend(String personId,String password,String friendId,float friendshipLevel)
  {
    boolean added = false;
    Person person = null;
    Person friend = null;
    person = PersonFactory.findPerson(personId);
    if(person != null)
    {
      friend = PersonFactory.findPerson(friendId);
      if(friend!=null)
      {
        //add locally
        person.addKnown(friend, friendshipLevel);
        //add in remote db (through SOA)
        FrSOAClient.getInstance().addFriend(personId, password, friendId, friendshipLevel);
       
        added = true;
      }
    }

    if(added&&person!=null&&friend!=null)
    {
      return getBookmarks(friend.getURI().toString(), person.getURI().toString(),
        null, 0,true, true, null,"friend");
    }
    return null;
  }
View Full Code Here

   
    //create the XfoafSscfResource object for current resource
    XfoafSscfResource resource = XfoafSscfResource.getXfoafSscfResource(resourceUri);
   
    //create a Person object for current user
    Person person = PersonFactory.findPerson(authorMbox);
    if (person == null) {
      person = PersonFactory.createPerson(authorMbox, null, false);
    }
   
    //save the rating
View Full Code Here

    }
  }
 
  public String getJSONInboxContent(HttpServletRequest req,String person)
  {
    Person per = PersonFactory.findPerson(person);
    XfoafSscfResource inbox = null;
    String inboxUri = null;
    if(per!=null) {
      String mbox = per.getMbox().toString();
      if(mbox.startsWith("mailto:")) mbox=mbox.substring(7);
     
      inboxUri = getInboxUri(req, mbox);
      inbox = XfoafSscfResource.getXfoafSscfResource(inboxUri);
      if(inbox.getIssuedBy()==null)
View Full Code Here

      String rdfq = rdfquery.getQuery();
      QueryLanguage ql = rdfquery.getQlanguage();

      if (rdfq != null && rdfq.indexOf("<$"+MYSELF+">") > 0) {

        Person issuer = FoafRealmHelper.getInstance().getLoggedPerson(request);

        if (issuer != null) {
          rdfq = rdfq.replaceAll("[$]"+MYSELF, issuer.getUri().toString());
        } else if (NLQueryTemplates.getInstance().getSDefaultUser() != null) {
          rdfq = rdfq.replaceAll("[$]"+MYSELF, NLQueryTemplates.getInstance().getSDefaultUser());
        } else {
          rdfq = rdfq.replaceAll("[<][$]"+MYSELF+"[>]", ALLUSERS);
        }
View Full Code Here

TOP

Related Classes of org.foafrealm.manage.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.