Package org.apache.clerezza.rdf.core.access

Examples of org.apache.clerezza.rdf.core.access.LockableMGraph


    node.addProperty(predicate, object);
  }

  @Override
  public boolean nameExists(String name) {
    LockableMGraph systemGraph = getSystemGraph();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
      return systemGraph.filter(null, PLATFORM.userName,
        new PlainLiteralImpl(name)).hasNext();
    } finally {
      readLock.unlock();
    }   
  }
View Full Code Here


    }   
  }

  @Override
  public boolean emailExists(String email) {
    LockableMGraph systemGraph = getSystemGraph();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
      return systemGraph.filter(null, FOAF.mbox,
          new UriRef("mailto:" + email)).hasNext();
    } finally {
      readLock.unlock();
    }
  }
View Full Code Here

  public Iterator<NonLiteral> getUsers() {
    return getResourcesOfType(FOAF.Agent);
  }

  private Iterator<NonLiteral> getResourcesOfType(UriRef type) {
    LockableMGraph systemGraph = getSystemGraph();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
      final Iterator<Triple> triples = systemGraph.filter(null, RDF.type, type);
      Set<NonLiteral> userRoles = new HashSet<NonLiteral>();
      while (triples.hasNext()) {
        userRoles.add(triples.next().getSubject());
      }
      return userRoles.iterator();
View Full Code Here

    return new String(result);
  }

  @Override
  public GraphNode getUserInSystemGraph(final String name) {
    LockableMGraph systemGraph = getSystemGraph();
    NonLiteral user = getUserByUserName(name);
    if (user != null) {
      return new GraphNode(user, systemGraph);
    } else {
      return null;
View Full Code Here

    }
  }

  @Override
  public GraphNode getUserInContentGraph(final String name) {
    final LockableMGraph contentGraph = (LockableMGraph) cgProvider.getContentGraph();
    Iterator<Triple> triples = contentGraph.filter(null, PLATFORM.userName,
        new PlainLiteralImpl(name));
    GraphNode resultNode = null;
    if (triples.hasNext()) {
      Lock readLock = contentGraph.getLock().readLock();
      readLock.lock();
      try {
        resultNode = new GraphNode(triples.next().getSubject(), contentGraph);
      } finally {
        readLock.unlock();
      }     
    } else {
      NonLiteral user = AccessController.doPrivileged(
          new PrivilegedAction<NonLiteral>() {

            @Override
            public NonLiteral run() {
              return getUserByUserName(name);
            }
          });
      if (user != null) {
        Lock writeLock = contentGraph.getLock().writeLock();
        writeLock.lock();
        try {
          resultNode = new GraphNode(new BNode(), contentGraph);
        resultNode.addProperty(PLATFORM.userName,
            new PlainLiteralImpl(name));
View Full Code Here

    return resultNode;
  }

  @Override
  public GraphNode getUserGraphNode(final String name) {
    LockableMGraph systemGraph = getSystemGraph();
    NonLiteral user = getUserByUserName(name);
    if (user != null) {
      GraphNode userNodeInSystemGraph =
          new GraphNode(getUserByUserName(name), systemGraph);
      MGraph copiedUserContext = new SimpleMGraph(userNodeInSystemGraph.getNodeContext());
View Full Code Here

      return null;
    }
  }

  private NonLiteral getUserByUserName(String name) {
    LockableMGraph systemGraph = getSystemGraph();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
      Iterator<Triple> triples = systemGraph.filter(null, PLATFORM.userName,
          new PlainLiteralImpl(name));
      if (triples.hasNext()) {
        return triples.next().getSubject();
      }
      return null;
View Full Code Here

   * @param triples
   */
  @PUT
  public void putTriples(@QueryParam("name") UriRef name, TripleCollection triples) {
    AccessController.checkPermission(new WebAccessPermission());
    LockableMGraph mGraph;
    try {
      mGraph = tcManager.getMGraph(name);
    } catch (NoSuchEntityException e) {
      mGraph = tcManager.createMGraph(name);
    }
    Lock writeLock = mGraph.getLock().writeLock();
    writeLock.lock();
    try {
      mGraph.clear();
      mGraph.addAll(triples);
    } finally {
      writeLock.unlock();
    }
  }
View Full Code Here

      mode = "append";
    }
    InputStream is = new ByteArrayInputStream(graph);
    Graph parsedGraph = parser.parse(is, mediaType.toString());
    UriRef graphUri = new UriRef(graphName);
    LockableMGraph mGraph;
    boolean newGraph = false;
    try {
      mGraph = tcManager.getMGraph(graphUri);
    } catch (NoSuchEntityException e) {
      mGraph = tcManager.createMGraph(graphUri);
      newGraph = true;
    }
    Lock writeLock = mGraph.getLock().writeLock();
    writeLock.lock();
    try {
      if (!newGraph && mode.equals("replace")) {
        mGraph.clear();
      }
      mGraph.addAll(parsedGraph);
    } finally {
      writeLock.unlock();
    }
    String redirection = getFirstTextParameterValue(form, "redirection", false);
    if (redirection == null) {
View Full Code Here

    }
    if (getRoleByTitle(title) != null) {
      return;
    }
    BNode role = new BNode();
    LockableMGraph systemGraph = getSystemGraph();
    Lock writeLock = systemGraph.getLock().writeLock();
    writeLock.lock();
    try {
      systemGraph.add(new TripleImpl(role, RDF.type, PERMISSION.Role));
      systemGraph.add(new TripleImpl(role, DC.title,
          new PlainLiteralImpl(title)));
    } finally {
      writeLock.unlock();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.access.LockableMGraph

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.