Examples of XfoafSscfResource


Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

            resp.sendRedirect(resUri.substring(0,resUri.lastIndexOf("__")));
          else resp.sendRedirect(resUri);
        }
        else
        {
          XfoafSscfResource xfsr = XfoafSscfResource.getXfoafSscfResource(resUri);
          if(xfsr != null)
          {
            xfsr.increaseResourceHits();
         
            resp.sendRedirect(xfsr.getStringURI());
          }
        } 
    }
    else
      resp.sendRedirect(SscfAjax.getServiceAddr(req));
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

              item = request.getParameter("item");
              parent = request.getParameter("parent");
              permanently = request.getParameter("permanently");
              resourceType = request.getParameter("resType");
             
              XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(item);
              XfoafSscfResource parentRes = XfoafSscfResource.getXfoafSscfResource(parent);
             
              //check the rights to remove the resource
              //String resIssuer = null;
              //boolean userOwnsRes = false;
             // if(res.getIssuedBy()!=null) {
             //   resIssuer = res.getIssuedBy().getUri().toString();
              //  resIssuer = (resIssuer.startsWith("mailto:"))?resIssuer.substring(7):resIssuer;
              //  userOwnsRes = resIssuer.equals(viewerLogged);
              //}
             
              //TODO possible null here
              String parentResIssuer = parentRes.getIssuedBy().getURI().toString();
              parentResIssuer = (parentResIssuer.startsWith("mailto:"))?parentResIssuer.substring(7):parentResIssuer;
              boolean userOwnsParentRes = parentResIssuer.equals(viewerLogged);
             
              try {
               
                 if(!userOwnsParentRes) sendJSONResponse(response,ERROR);
               
          if(res != null &&!"".equals(parentRes))
          {
            //if permanently was set it means that the suggested directory should be removed
            // permanently
            if(permanently!=null&&!"".equals(permanently)&&permanently.equals("1"))
            {
              res.addRemovedSuggested(parentRes)
            }
            else
            {
              res.deleteIsIn(parentRes);
              if(!res.listIsIn().hasNext()) //&&userOwnsRes
              {
                if(resourceType!=null&&!"".equals(resourceType))
                {
                  if(resourceType.equals("webBookmark"))
                  {
                    WebBookmarkResource web = WebBookmarkResource.getWebBookmarkResource(item);
                    web.remove();
                  }
                  //TODO: other types ...
                  //TODO: use &&userOwnsRes
                }
                else
                  res.remove();
              }
            }
            sendJSONResponse(response,OK);
          }
          else
            sendJSONResponse(response,ERROR);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      else if(type.equals("removeAll"))
      {
              String item;
              String parent;
             
              item = request.getParameter("item");
              parent = request.getParameter("parent");
             
              XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(item);
              XfoafSscfResource parentRes = XfoafSscfResource.getXfoafSscfResource(parent);
             
              String loggedPerson = null;
             
              if(request.getUserPrincipal()!=null) {
          try {
            TomcatPerson person = ((FOAFPrincipal)request.getUserPrincipal()).getPerson();
            loggedPerson = person.getURI().toString();
          }
          catch (Exception e){/*ignore viewerLogged will stay null*/}
        }
           
              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) {
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

   * @param session - httpsession
   * @return - Json representation of imported resource.
   */
  public String importSuggestedResource(String resource,String parent,String viewer,String level,HttpSession session,String serviceAddr)
  {
    XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(resource);
    XfoafSscfResource par = XfoafSscfResource.getXfoafSscfResource(parent);
   
    int levelInt = -1;
    try {
      levelInt = Integer.parseInt(level);
    }
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

      return null;
    }
   
    //TODO: change to get person - this person exists
    viewer = PersonFactory.findPerson(view);     
    XfoafSscfResource category = XfoafSscfResource.getXfoafSscfResource(destination);
    XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(item);
    XfoafSscfResource oldParentRes = null;
    if(oldParent!=null)
    {
      oldParentRes = XfoafSscfResource.getXfoafSscfResource(oldParent);
    }
   
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

    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

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

      port = ":"+request.getLocalPort();
   
    String bookUriBegin = request.getScheme()+"://"+request.getServerName()+port+request.getContextPath()+"/directory/";
    String uriAnn = bookUriBegin + Sha1sum.getInstance().calc(newDesc + destination + date.getTime());

    XfoafSscfResource category = XfoafSscfResource.getXfoafSscfResource(uriAnn, S3B_SSCF.Directory, true);

    if(category!=null)
    {
      category.setLabel(name);
      if(!"".equals(newDesc))
        category.setComment(newDesc);
      category.setIssuedBy(person);
      category.setIssueDate(date);
 
      // it will be done eventually in paste resource method.
      /*if (destination != null ) {
        XfoafSscfResource previ = XfoafSscfResource.getXfoafSscfResource(destination);
        if (previ != null
            //&& SscfHelper.getInstance().checkCredit(person, previ) - new dir link will be avaliable only if there is rights for user.
            ) {
          //first addIsIn!
          category.addIsIn(previ);
        }
      }*/
      //set word net
      SscfDomain domain = SscfDomain.getSscfDomain(category.getResource().toString());
      domain.setPersonInterest(person, 1);
     
      //Save wordnet and other thesauri
      if(thValues!=null&&thValues.size()>0)
      {
        Set<String> thesUris = thValues.keySet();
        for(String thesUri:thesUris)
        {
          Collection<String> thesList = thValues.get(thesUri);
          ThesaurusContext thesaurus = Thesauri.getInstance().getContext(thesUri);
            if (thesaurus!=null)
            {
              List<ThesaurusEntry> thesEntries = new ArrayList<ThesaurusEntry>();
              for(String entry:thesList)
            {
              ThesaurusEntry thEntry = thesaurus.getEntryByUri(entry,null);
                thesEntries.add(thEntry);
            }
              domain.setWordNetClassification(thesEntries);
            }
        }
      }
      /*if(wnValues!=null&&wnValues.size()>0)
      { 
        //currently only wordnet is supported on the client side
        ThesaurusContext wnContext = Thesauri.getInstance().getContext("http://www.w3.org/2006/03/wn/wn20/");
         
        List<ThesaurusEntry> chosenClassifications = new ArrayList<ThesaurusEntry>();
        for(String uri:wnValues) {
          //if (uri.startsWith(JOntoWordNetOntology.WNO_NS_WN_OFFSET.getUri()) ||
          //    uri.startsWith(JOntoWordNetOntology.WNO_NS_I18N_WORDNET.getUri())) {
          try
          {
            chosenClassifications.add(wnContext.getEntryByUri(uri));
          }
          catch (Exception e)
          {
             ignore
          } 
          //}
        }
        domain.setWordNetClassification(chosenClassifications);
      }*/
     
      //Save other classifications.
      if(taxValues!=null&&taxValues.size()>0)
      {
        Set<String> taxUris = taxValues.keySet();
        for(String taxUri:taxUris)
        {
          Collection<String> taxList = taxValues.get(taxUri);
          TaxonomyContext<TaxonomyEntry> taxonomy = Taxonomies.getInstance().getContext(taxUri);
            if (taxonomy!=null)
            {
              List<TaxonomyEntry> taxEntries = new ArrayList<TaxonomyEntry>();
              for(String entry:taxList)
            {
              TaxonomyEntry taxonomyEntry = taxonomy.getEntryByUri(entry,null);
                taxEntries.add(taxonomyEntry);
            }
              domain.setClassification(taxEntries);
            }
        }
      }
     
      //===== GENERATING NODE TO PUT INTO TREE =====
      // using pasteResource function.
      return pasteResource(destination,category.getURI().toString(),view,level,false,null,request.getSession(),getServiceAddr(request),null);
    }

    return null;
  }
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

   
    if(desc==null||"".equals(desc.trim()))
      newDesc = "";
   
    //get directory to edit (must exist)
    XfoafSscfResource dir = XfoafSscfResource.getXfoafSscfResource(uri);
   
    int change = 0;
    StringBuilder changeValue = new StringBuilder();
   
    if(dir!=null)
    {
      if(dir.getLabel()!=null&&name!=null&&!dir.getLabel().equals(name))
      {
        change+=ChangeTypes.CHANGED_NAME.getChangeType();
        changeValue.append(ChangeTypes.CHANGED_NAME.getChangeType()).append(':')
          .append(dir.getLabel()).append("::").append(name);
      }
      dir.setLabel(name);
     
      if((dir.getComment()!=null&&!dir.getComment().equals(newDesc))
          ||((dir.getComment()==null||"".equals(dir.getComment()))&&!"".equals(newDesc))
          ||(dir.getComment()!=null&&!"".equals(dir.getComment())&&newDesc=="")) {
        change+=ChangeTypes.CHANGED_DESC.getChangeType();
        if(changeValue.length()>0) changeValue.append("||");
        changeValue.append(ChangeTypes.CHANGED_DESC.getChangeType()).append(':')
          .append(dir.getComment()).append("::").append(newDesc);
      }
     
      if(dir.getComment()!=null||(dir.getComment()==null&&!"".equals(newDesc)))
        dir.setComment(newDesc);
 
      //set word net
      SscfDomain domain = SscfDomain.getSscfDomain(dir.getResource().toString());
     
      List<ThesaurusEntry> oldWnClass = domain.getWordNetClassification();
      List<ThesaurusEntry> finalWnClass = new ArrayList<ThesaurusEntry>();
      List<ThesaurusEntry> removedWnClass = new ArrayList<ThesaurusEntry>();
      //for future use
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

      response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format(MISSING_AUTHOR_MBOX));
      return;
    }
   
    //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
    if (request.getParameter("rating") != null && !"".equals(request.getParameter("rating"))) {
      resource.setEvaluation(person, new Float(request.getParameter("rating")));
    }
  }
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

         
          //check if the url is ok
          String personLogged = ((FOAFPrincipal)req.getUserPrincipal()).getEmail();
          if(personLogged!=null)
          {
            XfoafSscfResource newRes = WebBookmarkResource.getWebBookmarkResource(addurl, personLogged, null, null);
            if(newRes!=null)
            {
             
              XfoafSscfResource inbox = XfoafSscfResource.getXfoafSscfResource(getInboxUri(req, personLogged));
              if(inbox!=null)
              {
                newRes.setLabel(addname);
                //need to do this because it would add to WebBookmarkResource::listIsIn list
                XfoafSscfResource newResXfoaf = XfoafSscfResource.getXfoafSscfResource(newRes.getURI().toString());
                newResXfoaf.addIsIn(inbox);
              }
            }
          }
         
          resp.sendRedirect(addurl);
View Full Code Here

Examples of org.corrib.s3b.sscf.manage.XfoafSscfResource

  }
 
  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)
      {
        inbox.setIssuedBy(per);
        //set other properties
        inbox.setType(S3B_SSCF.Directory);
        inbox.setIssueDate(new Date());
        inbox.setLabel("Inbox");
      }
    }
    JSONObject result = new JSONObject();
    JSONArray ja = new JSONArray();
   
    int i = 0;
   
    if(inbox!=null) {
      Iterator<XResource> it = inbox.listContent();
     
      while(it.hasNext())
      {
        XResource br = it.next();
        JSONObject jo = new JSONObject();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.