Refine search
/** * Adds triples that point from the bundle resource to its documentations. * * @param bundle * @param docGraph */ private void addAdditionalTriples(Bundle bundle, Graph docGraph) { IRI bundleUri = new IRI(bundle.getLocation()); Triple triple = new TripleImpl(bundleUri, RDF.type, OSGI.Bundle); docGraph.add(triple); Iterator<Triple> titledContents = docGraph.filter(null, RDF.type, DISCOBITS.TitledContent); Set<Triple> newTriples = new HashSet<Triple>(); for (Iterator<Triple> it = titledContents; it.hasNext();) { BlankNodeOrIRI titledContent = it.next().getSubject(); if (docGraph.filter(null, DISCOBITS.holds, titledContent).hasNext()) { continue; } triple = new TripleImpl(bundleUri, DOCUMENTATION.documentation, titledContent); newTriples.add(triple); } docGraph.addAll(newTriples); }
@Test public void testRemoveAllTriples() { Graph graph = getEmptyGraph(); Assert.assertEquals(0, graph.size()); graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3)); graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4)); Assert.assertEquals(2, graph.size()); graph.clear(); Assert.assertEquals(0, graph.size()); }
@Override public ImmutableGraph getImmutableGraph() { return this.triples.getImmutableGraph(); }
private BlankNodeOrIRI getPlatformInstanceRDFTerm() { Lock l = systemGraph.getLock().readLock(); l.lock(); try { Iterator<Triple> instances = systemGraph.filter(null, RDF.type, PLATFORM.Instance); if (!instances.hasNext()) { throw new RuntimeException("No Platform:Instance in system graph."); } return instances.next().getSubject(); } finally { l.unlock(); } }
private void removeExistingRequiredReadPermissions(IRI GraphUri, Graph permissionMGraph) { try { Triple t = permissionMGraph.filter(GraphUri, readPermissionListProperty, null).next(); RDFTerm list = t.getObject(); removeList((BlankNodeOrIRI) list, permissionMGraph); permissionMGraph.remove(t); } catch (NoSuchElementException e) { //There was no existing to remove } }
/** * Set the set of permissions required for read access to a triple-collection, if * the set is non-empty the default TCPermisson is no longer required. * * @param GraphUri * @param permissionDescriptions */ public void setRequiredReadPermissionStrings(IRI GraphUri, Collection<String> permissionDescriptions) { readPermissionCache.remove(GraphUri); final Graph permissionMGraph = getOrCreatePermisionGraph(); Lock l = permissionMGraph.getLock().writeLock(); l.lock(); try { removeExistingRequiredReadPermissions(GraphUri, permissionMGraph); final BlankNodeOrIRI permissionList = createList(permissionDescriptions.iterator(), permissionMGraph); permissionMGraph.add(new TripleImpl(GraphUri, readPermissionListProperty, permissionList)); } finally { l.unlock(); } }
Graph systemGraph = getSystemGraph(); Literal javaPermEntry = new PlainLiteralImpl(permissionString); Lock readLock = systemGraph.getLock().readLock(); readLock.lock(); try { Iterator<Triple> javaPermTriples = systemGraph.filter(null, PERMISSION.javaPermissionEntry, javaPermEntry); if (javaPermTriples.hasNext()) { return javaPermTriples.next().getSubject(); readLock.unlock(); Lock writeLock = systemGraph.getLock().writeLock(); writeLock.lock(); try { BlankNode result = new BlankNode(); systemGraph.add(new TripleImpl(result, PERMISSION.javaPermissionEntry, javaPermEntry)); return result;
@PUT @Path("users/{username}") @Consumes(SupportedFormat.TURTLE) public Response createUser(@Context UriInfo uriInfo, @PathParam("username") String userName, ImmutableGraph inputGraph) { Lock writeLock = systemGraph.getLock().writeLock(); writeLock.lock(); systemGraph.addAll(inputGraph); writeLock.unlock(); UriBuilder uriBuilder = uriInfo.getBaseUriBuilder(); URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build(); return Response.created(createdResource).build(); }
private void deletePermissionEntriesOfARole(BlankNodeOrIRI role, String id, List<String> permissionEntries) { AccessController.checkPermission(new SecurityPermission("getPolicy")); if (role == null) { logger.debug("Cannot delete permissions: {} does not exist", id); return; } if (permissionEntries.isEmpty()) { return; } Graph systemGraph = getSystemGraph(); Lock writeLock = systemGraph.getLock().writeLock(); writeLock.lock(); try { for (String permissionEntry : permissionEntries) { BlankNodeOrIRI permission = getPermissionOfAJavaPermEntry(permissionEntry); systemGraph.remove(new TripleImpl(role, PERMISSION.hasPermission, permission)); } } finally { writeLock.unlock(); } //refresh the policy so it will recheck the permissions Policy.getPolicy().refresh(); }
/** * Internally used to create Representations for URIs * @param uri the uri * @param check if <code>false</code> than there is no check if the URI * refers to a RDFTerm in the graph that is of type {@link #REPRESENTATION} * @return the Representation */ protected final Representation getRepresentation(IRI uri, boolean check) { final Lock readLock = readLockGraph(); try { if(!check || isRepresentation(uri)){ Graph nodeGraph = createRepresentationGraph(uri, graph); //Remove the triple internally used to represent an empty Representation // ... this will only remove the triple if the Representation is empty // but a check would take longer than the this call nodeGraph.remove(new TripleImpl(uri,MANAGED_REPRESENTATION,TRUE_LITERAL)); return ((RdfValueFactory)getValueFactory()).createRdfRepresentation(uri, nodeGraph); } else { return null; //not found } } finally { if(readLock != null){ readLock.unlock(); } } } /**
private void attachScopeImportsClerezza(Graph target, org.semanticweb.owlapi.model.IRI prefix) { IRI iri = new IRI(prefix + _id); String scopePrefix = prefix.toString(); scopePrefix = scopePrefix.substring(0, scopePrefix.lastIndexOf("/" + shortName + "/")) + "/ontology/"; for (String scopeID : attachedScopes) { IRI physIRI = new IRI(scopePrefix + scopeID); target.add(new TripleImpl(iri, OWL.imports, physIRI)); } }
@Test public void testUseTypedLiterals() { Graph graph = getEmptyGraph(); Assert.assertEquals(0, graph.size()); Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType); final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value); graph.add(triple1); Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null); Assert.assertTrue(tripleIter.hasNext()); RDFTerm gotValue = tripleIter.next().getObject(); Assert.assertEquals(value, gotValue); }
void mapLocator(org.semanticweb.owlapi.model.IRI locator, IRI graphName) { if (graphName == null) throw new IllegalArgumentException("A null graph name is not allowed."); // Null locator is a legal argument, will remove all locator mappings from the supplied graph Set<Triple> remove = new HashSet<Triple>(); for (Iterator<Triple> nodes = graph.filter(graphName, null, null); nodes.hasNext();) { Triple t = nodes.next(); // isOntology |= RDF.type.equals(t.getPredicate()) && OWL.Ontology.equals(t.getObject()); if (RETRIEVED_FROM_URIREF.equals(t.getPredicate())) remove.add(t); } graph.removeAll(remove); if (locator != null) { Literal litloc = LiteralFactory.getInstance().createTypedLiteral( new IRI(locator.toString())); graph.add(new TripleImpl(graphName, RETRIEVED_FROM_URIREF, litloc)); } }
OWLOntologyID getReverseMapping(IRI graphName) { // Logical mappings first. Iterator<Triple> it = graph.filter(null, MAPS_TO_GRAPH_URIREF, graphName); while (it.hasNext()) { RDFTerm obj = it.next().getSubject(); if (obj instanceof IRI) return buildPublicKey((IRI) obj); } Literal litloc = LiteralFactory.getInstance().createTypedLiteral( new IRI(graphName.getUnicodeString())); // Logical mappings failed, try physical mappings. it = graph.filter(null, RETRIEVED_FROM_URIREF, litloc); while (it.hasNext()) { RDFTerm subj = it.next().getSubject(); if (subj instanceof IRI) return buildPublicKey((IRI) subj); } return null; }
Set<OWLOntologyID> getVersions(org.semanticweb.owlapi.model.IRI ontologyIri) { if (ontologyIri == null) throw new IllegalArgumentException("Cannot get versions for a null IRI."); Set<OWLOntologyID> keys = new HashSet<OWLOntologyID>(); LiteralFactory lf = LiteralFactory.getInstance(); Literal iri = lf.createTypedLiteral(new IRI(ontologyIri.toString())); // Exclude aliases. for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI_URIREF, iri); it.hasNext();) { RDFTerm sub = it.next().getSubject(); if (sub instanceof IRI) keys.add(buildPublicKey((IRI) sub)); } // Also check for physical locations for (Iterator<Triple> it = graph.filter(null, RETRIEVED_FROM_URIREF, iri); it.hasNext();) { RDFTerm sub = it.next().getSubject(); if (sub instanceof IRI) keys.add(buildPublicKey((IRI) sub)); } return keys; }