/** * Deletes the context of a node * @see getNodeContext() */ public void deleteNodeContext() { for (Triple triple : getNodeContext()) { graph.remove(triple); } }
/** * Deletes the context of a node * @see getNodeContext() */ public void deleteNodeContext() { for (Triple triple : getNodeContext()) { graph.remove(triple); } }
@Override public void render(GraphNode resource, GraphNode context, String mode, OutputStream os) throws IOException { Renderer renderer = manager.createRenderer(resource, mode, mediaTypeList); if (renderer == null) { throw new RuntimeException("no renderer could be created for "+ resource+" (in "+resource.getNodeContext()+"), "+mode+","+mediaTypeList); } renderer.render(resource, context, mode, uriInfo, requestHeaders, responseHeaders, sharedRenderingValue, os); }
private Graph getLanguageContext(NonLiteral langUri) { Graph lingvojRdf = getLingvojGraph(); GraphNode languageNode = new GraphNode(langUri, lingvojRdf); return languageNode.getNodeContext(); }
/** * RESTful access to individual user data * * [has integration test] currently has a kludge to return an empty graph if * user not found should return a 404 * * @param userName * @return context graph for user * @throws UnsupportedEncodingException */ @GET @Path("users/{username}") public Graph getUserContext(@PathParam("username") String userName) throws UnsupportedEncodingException { GraphNode userNode = getUser(userName); if (userNode == null) { // a kludge return new SimpleGraph(); } return userNode.getNodeContext(); }
@Override public RuntimeException run(){ try { final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt"); final GraphNode graphNode = new GraphNode(listRDFTerm, tc); Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE); fileOutputStream.flush(); logger.warn("GraphNode: " + graphNode); final Iterator<IRI> properties = graphNode.getProperties(); while (properties.hasNext()) { logger.warn("available: " + properties.next()); } return new RuntimeException("broken list " + listRDFTerm, e); } catch (Exception ex) { return new RuntimeException(ex); } } });
@Override public RuntimeException run(){ try { final FileOutputStream fileOutputStream = new FileOutputStream("/tmp/broken-list.nt"); final GraphNode graphNode = new GraphNode(listRDFTerm, tc); Serializer.getInstance().serialize(fileOutputStream, graphNode.getNodeContext(), SupportedFormat.N_TRIPLE); fileOutputStream.flush(); logger.warn("GraphNode: " + graphNode); final Iterator<IRI> properties = graphNode.getProperties(); while (properties.hasNext()) { logger.warn("available: " + properties.next()); } return new RuntimeException("broken list " + listRDFTerm, e); } catch (Exception ex) { return new RuntimeException(ex); } } });
private Graph getExpandedContext(GraphNode node, GraphNode recipe) { final Graph result = new SimpleGraph(node.getNodeContext()); final Set<RDFTerm> expandedResources = new HashSet<RDFTerm>(); expandedResources.add(node.getNode()); while (true) { Set<RDFTerm> additionalExpansionRes = getAdditionalExpansionResources(result, recipe); additionalExpansionRes.removeAll(expandedResources); if (additionalExpansionRes.size() == 0) { return result; } for (RDFTerm resource : additionalExpansionRes) { final GraphNode additionalNode = new GraphNode(resource, node.getGraph()); result.addAll(additionalNode.getNodeContext()); expandedResources.add(resource); } } }
private Graph getExpandedContext(GraphNode node) { final Graph result = new SimpleGraph(node.getNodeContext()); final Set<RDFTerm> expandedResources = new HashSet<RDFTerm>(); expandedResources.add(node.getNode()); while (true) { Set<RDFTerm> additionalExpansionRes = getAdditionalExpansionResources(result); additionalExpansionRes.removeAll(expandedResources); if (additionalExpansionRes.size() == 0) { return result; } for (RDFTerm resource : additionalExpansionRes) { final GraphNode additionalNode = new GraphNode(resource, node.getGraph()); result.addAll(additionalNode.getNodeContext()); expandedResources.add(resource); } } }
private Graph getExpandedContext(GraphNode node) { final Graph result = new SimpleGraph(node.getNodeContext()); final Set<RDFTerm> expandedResources = new HashSet<RDFTerm>(); expandedResources.add(node.getNode()); while (true) { Set<RDFTerm> additionalExpansionRes = getAdditionalExpansionResources(result); additionalExpansionRes.removeAll(expandedResources); if (additionalExpansionRes.size() == 0) { return result; } for (RDFTerm resource : additionalExpansionRes) { final GraphNode additionalNode = new GraphNode(resource, node.getGraph()); result.addAll(additionalNode.getNodeContext()); expandedResources.add(resource); } } }
@Override public GraphNode getUserGraphNode(final String name) { Graph systemGraph = getSystemGraph(); BlankNodeOrIRI user = getUserByUserName(name); if (user != null) { GraphNode userNodeInSystemGraph = new GraphNode(getUserByUserName(name), systemGraph); Graph copiedUserContext = new SimpleGraph(userNodeInSystemGraph.getNodeContext()); return new GraphNode(userNodeInSystemGraph.getNode(), copiedUserContext); } else { return null; } }
ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode)potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); object = null; ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext);
ImmutableGraph context = objectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null); while (potentialIter.hasNext()) { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode)potentialTriple.getObject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext); object = null; ImmutableGraph context = subjectGN.getNodeContext(); Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object); while (potentialIter.hasNext()) { final Triple potentialTriple = potentialIter.next(); BlankNode potentialMatch = (BlankNode)potentialTriple.getSubject(); final ImmutableGraph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext(); if (potentialContext.equals(context)) { removingTriples.addAll(potentialContext);
private boolean fillMSG(Triple triple, Graph tc, Graph msg) { boolean containsBlankNode = false; RDFTerm resource = triple.getSubject(); if (resource instanceof BlankNode) { containsBlankNode = true; } else { resource = triple.getObject(); if (resource instanceof BlankNode) { containsBlankNode = true; } } if (containsBlankNode) { GraphNode gn = new GraphNode(resource, tc); ImmutableGraph context = gn.getNodeContext(); msg.addAll(context); tc.removeAll(context); } else { msg.add(triple); tc.remove(triple); } return containsBlankNode; }
@Override public GraphNode addUserContext(GraphNode node) { final AccessControlContext context = AccessController.getContext(); GraphNode agent = AccessController.doPrivileged(new PrivilegedAction<GraphNode>() { @Override public GraphNode run() { final String userName = UserUtil.getUserName(context); if (userName == null) { return null; } return userManager.getUserGraphNode(userName); } }); if (agent != null) { if (agent.getNode() instanceof UriRef) { WebIdInfo webIdInfo = webIdGraphsService.getWebIdInfo((UriRef)agent.getNode()); MGraph userGraph = webIdInfo.localPublicUserData(); agent = new GraphNode(agent.getNode(), new UnionMGraph(agent.getGraph(), userGraph)); } node.addProperty(PLATFORM.user, agent.getNode()); MGraph userContext = new SimpleMGraph(agent.getNodeContext()); removeTripleWithProperty(userContext, PERMISSION.password); removeTripleWithProperty(userContext, PERMISSION.passwordSha1); node.getGraph().addAll(userContext); } return node; }
private GraphNode addLanguages(GraphNode node, NonLiteral platformInstance, List<LanguageDescription> languages, boolean copyToNode) { TripleCollection graph = node.getGraph(); BNode listNode = new BNode(); RdfList list = new RdfList(listNode, graph); LockableMGraph configGraph = getConfigGraph(); Lock readLock = configGraph.getLock().readLock(); for (LanguageDescription languageDescription : languages) { NonLiteral languageUri = (NonLiteral) languageDescription.getResource().getNode(); list.add(languageUri); if (copyToNode) { readLock.lock(); try { graph.addAll(new GraphNode(languageUri, configGraph).getNodeContext()); } finally { readLock.unlock(); } } } node.addProperty(PLATFORM.instance, platformInstance); graph.add(new TripleImpl(platformInstance, RDF.type, PLATFORM.Instance)); graph.add(new TripleImpl(platformInstance, PLATFORM.languages, listNode)); graph.add(new TripleImpl(listNode, RDF.type, LANGUAGE.LanguageList)); if (!copyToNode) { node = new GraphNode(node.getNode(), new UnionMGraph(graph, configGraph)); } return node; }