/** Convert strings to a List of {@link Node Nodes}. */ public static List<Node> convertToListNodes(List<String> namedGraphs) { List<Node> nodes = ListUtils.toList( namedGraphs.stream().map(NodeFactory::createURI) ); return nodes; }
public static <T> List<T> unique(List<T> list) { return toList(list.stream().distinct()); }
public static <T> List<T> unique(List<T> list) { return toList(list.stream().distinct()); }
private void checkFiles(List<String> urls) { List<String> problemFiles = ListUtils.toList( urls.stream() .map(Paths::get) .filter(p-> !Files.exists(p) || !Files.isRegularFile(p /*follow links*/) || !Files.isReadable(p) ) .map(Path::toString) ); if ( ! problemFiles.isEmpty() ) { throw new CmdException("Can't read files : ["+problemFiles+"]"); } }
private void checkFiles(List<String> urls) { List<String> problemFiles = ListUtils.toList( urls.stream() .map(Paths::get) .filter(p-> !Files.exists(p) || !Files.isRegularFile(p /*follow links*/) || !Files.isReadable(p) ) .map(Path::toString) ); if ( ! problemFiles.isEmpty() ) { throw new CmdException("Can't read files : ["+problemFiles+"]"); } }
/** Release all the patches and any other state for this {@code PatchStorage} */ public default void delete() { // Copy to isolate. List<Id> x = ListUtils.toList(find()); x.forEach(this::delete); } }
@Override public List<DataSourceDescription> listDescriptions() { checkLink(); return toList(localServer.listDataSources().stream().map(ds -> ds.getDescription())); }
/** All the patch logs currently managed by this {@code PatchStore}. */ public List<DataSourceDescription> listDataSources() { checkInitialized(); return ListUtils.toList(dataRegistry.dataSources().map(log->log.getDescription())); }
public static List<Resource> findRootsByType(Model model, Resource atype) { String s = String.join("\n", "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>", "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", "SELECT DISTINCT ?root { { ?root rdf:type ?ATYPE } UNION { ?root rdf:type ?t . ?t rdfs:subClassOf ?ATYPE } }") ; Query q = QueryFactory.create(s) ; QuerySolutionMap qsm = new QuerySolutionMap() ; qsm.add("ATYPE", atype) ; try(QueryExecution qExec = QueryExecutionFactory.create(q, model, qsm)) { return ListUtils.toList( QueryExecUtils.getAll(qExec, "root").stream().map(r->(Resource)r)); } }
/** * Scan a directory for DataSource areas. * These must have a file called source.cfg. */ /*package*/ static Pair<List<Path>/*enabled*/, List<Path>/*disabled*/> scanDirectory(Path directory) { try { List<Path> directoryEntries = ListUtils.toList( Files.list(directory).filter(p->Files.isDirectory(p)).sorted() ); // directoryEntries.stream() // .filter(LocalServer::isFormattedDataSource) // .collect(Collectors.toList()); List<Path> enabled = directoryEntries.stream() .filter(path -> isEnabled(path)) .collect(Collectors.toList()); List<Path> disabled = directoryEntries.stream() .filter(path -> !isEnabled(path)) .collect(Collectors.toList()); return Pair.create(enabled, disabled); } catch (IOException ex) { Log.error(CfgFile.class, "Exception while reading "+directory); throw IOX.exception(ex); } }
/** * Look for {@link DataSource DataSources} in a disk area given by {@code location}. * <p> * Scan the given area for directories (must have a config file), check they are enabled, * and deal with {@code log_type}. */ public static List<DataSourceDescription> scanForLogs(Path location, PatchStore ps) { // PatchStore's that rely on the scan of local directories and checking the "log_type" field. Pair<List<Path>, List<Path>> pair = scanDirectory(location); List<Path> dataSourcePaths = pair.getLeft(); List<Path> disabledDataSources = pair.getRight(); //dataSourcePaths.forEach(p->LOG.info("Data source paths: "+p)); disabledDataSources.forEach(p->LOG.info("Data source: "+p+" : Disabled")); List<DataSourceDescription> descriptions = ListUtils.toList (dataSourcePaths.stream() .map(p->{ // Extract name from disk name. String dsName = p.getFileName().toString(); // read config file. JsonObject sourceObj = JSON.read(p.resolve(FileNames.DS_CONFIG).toString()); DataSourceDescription dsd = DataSourceDescription.fromJson(sourceObj); if ( ! Objects.equals(dsName, dsd.getName()) ) throw new DeltaConfigException("Names do not match: directory="+dsName+", dsd="+dsd); return dsd; }) .filter(Objects::nonNull) ); return descriptions; }
List<Id> firsts = ListUtils.toList(mapIdToPrev.entrySet().stream().filter(e->e.getValue()==null).map(e->e.getKey())); if ( firsts.isEmpty() ) { FmtLog.error(LOG, "No initial patch found");
private List<DataSourceDescription> listDataSourcesZkPath_alt(String logsPath) { List<String> logNames = Zk.zkSubNodes(client, logsPath); Stream<DataSourceDescription> descriptions = logNames.stream() .map(name->{ FmtLog.info(LOGZK, "[%d] listDataSources: %s", instance, name); String logDsd = ZKPaths.makePath(ZkConst.pLogs, name, ZkConst.nDsd); JsonObject obj = zkFetchJson(client, logDsd); if ( obj == null ) { FmtLog.info(LOGZK, "[%d] listDataSourcesZkPath: %s: no DSD", instance, name); return null; } DataSourceDescription dsd = DataSourceDescription.fromJson(obj); return dsd; }) .filter(Objects::nonNull) ; return ListUtils.toList(descriptions); }
/** * Create a graph filter for a TDB1 {@link DatasetGraph}. The filter matches (returns * true) for Tuples where the graph slot in quad is in the collection or for triples in the default * graph according the boolean. */ public static GraphFilterTDB1 graphFilter(DatasetGraph dsg, Collection<Node> namedGraphs, boolean matchDefaultGraph) { if ( ! TDBInternal.isTDB1(dsg) ) throw new IllegalArgumentException("DatasetGraph is not TDB1-backed"); List<NodeId> x = Txn.calculateRead(dsg, ()->{ NodeTable nt = TDBInternal.getDatasetGraphTDB(dsg).getQuadTable().getNodeTupleTable().getNodeTable(); return ListUtils.toList( namedGraphs.stream() .map(n->nt.getNodeIdForNode(n)) .filter(Objects::nonNull) ); }); return new GraphFilterTDB1(x, matchDefaultGraph); } }
/** * Create a graph filter for a TDB2 {@link DatasetGraph}. The filter matches (returns * true) for Tuples where the graph slot in quad is in the collection or for triples in the default * graph according the boolean. */ public static GraphFilterTDB2 graphFilter(DatasetGraph dsg, Collection<Node> namedGraphs, boolean matchDefaultGraph) { if ( ! TDBInternal.isTDB2(dsg) ) throw new IllegalArgumentException("DatasetGraph is not TDB2-backed"); List<NodeId> x = Txn.calculateRead(dsg, ()->{ NodeTable nt = TDBInternal.getDatasetGraphTDB(dsg).getQuadTable().getNodeTupleTable().getNodeTable(); return ListUtils.toList( namedGraphs.stream() .map(n->nt.getNodeIdForNode(n)) .filter(Objects::nonNull) ); }); return new GraphFilterTDB2(x, matchDefaultGraph); } }
protected void addGraphs(Dataset ds) { try { if ( hasEntries(dataURLs) ) { if ( ds.supportsTransactions() ) { Txn.executeWrite(ds, () -> { for ( String url : dataURLs ) RDFDataMgr.read(ds, url); }); } else { for ( String url : dataURLs ) RDFDataMgr.read(ds, url); } } if ( hasEntries(graphURLs) || hasEntries(namedGraphURLs) ) { // Resolve named graph URLs so the graphname is an absolute IRI. List<String> x = ListUtils.toList(namedGraphURLs.stream().map(IRIResolver::resolveFileURL)); DatasetUtils.addInGraphs(ds, graphURLs, x, null) ; } } catch (LabelExistsException ex) { throw new CmdException(ex.getMessage()) ; } catch (JenaException ex) { throw ex ; } catch (Exception ex) { throw new CmdException("Error creating dataset", ex) ; } }
private List<String> getAsMultiStringValue(Resource r, Property p) { Statement stmt = r.getProperty(p) ; if ( stmt == null ) return null ; RDFNode obj = stmt.getObject(); if ( obj.isLiteral() ) return Arrays.asList(obj.asLiteral().getLexicalForm()); if ( obj.isURIResource() ) return Arrays.asList(obj.asResource().getURI()); RDFList rdfList = obj.asResource().as( RDFList.class ); List<RDFNode> x = rdfList.asJavaList(); List<String> xs = ListUtils.toList(x.stream().map(n->{ if ( n.isLiteral() ) return n.asLiteral().getLexicalForm(); if ( n.isURIResource() ) return n.asResource().getURI(); throw new AssemblerException(r, "Not a string or URI: "+n); })); return xs; }
protected void addGraphs(Dataset ds) { try { if ( hasEntries(dataURLs) ) { if ( ds.supportsTransactions() ) { Txn.executeWrite(ds, () -> { for ( String url : dataURLs ) RDFDataMgr.read(ds, url); }); } else { for ( String url : dataURLs ) RDFDataMgr.read(ds, url); } } if ( hasEntries(graphURLs) || hasEntries(namedGraphURLs) ) { // Resolve named graph URLs so the graphname is an absolute IRI. List<String> x = ListUtils.toList(namedGraphURLs.stream().map(IRIResolver::resolveFileURL)); DatasetUtils.addInGraphs(ds, graphURLs, x, null) ; } } catch (LabelExistsException ex) { throw new CmdException(ex.getMessage()) ; } catch (JenaException ex) { throw ex ; } catch (Exception ex) { throw new CmdException("Error creating dataset", ex) ; } }
@Test public void patchStorage_2_singlePatch() { PatchStorage patchStorage = patchStorage(); RDFPatch patch = RDFPatchOps.emptyPatch(); Id id = Id.create(); patchStorage.store(id, patch); RDFPatch patch1 = patchStorage.fetch(id); assertNotNull(patch1); assertEquals(patch.getId(), patch1.getId()); List<Id> x = ListUtils.toList(patchStorage.find()); assertFalse(x.isEmpty()); }