#!/usr/bin/env groovy /** * A utility for uploading RDF files to the Talis Platform * 3kbo for details. */ import com._3kbo.talis.TalisStoreLoader; /** * TalisStore is a Groovy utility class which wraps {@link com._3kbo.talis.TalisStoreLoader TalisStoreLoader} * and uploads RDF * files to the Talis Platform. * See Using Groovy to Upload RDF files to the Talis Platform * for details on using this script and also on using the config file TalisConfig.groovy * to set the store, user and password. * @author Richard Hancock */ class TalisStore { /** * Lists the RDF files in the current directory. * Reads the store, user and password from the config file TalisConfig.groovy * which is expected to be on the classpath. * @see com._3kbo.talis.TalisStoreLoader#listDirectory */ static def list() { def store = new TalisStoreLoader() println "Store uri: ${store.metaboxPath}" store.listDirectory(".") } /** * Loads the RDF files in the current directory. * Reads the store, user and password from the config file TalisConfig.groovy * which is expected to be on the classpath. * See Using Groovy to Upload RDF files to the Talis Platform * for details on using the config file TalisConfig.groovy to set the store, user and password * and making the config file available on the classpath. * @see com._3kbo.talis.TalisStoreLoader#loadDirectory * @return number of RDF files uploaded to the Talis store */ static int load() { def store = new TalisStoreLoader() println "Loading RDF files in the current directory to ${store.metaboxPath}" return store.loadDirectory() } /** * Loads either a specific RDF file or scans * the nominated directory and uploads all the RDF files found. * Reads the store, user and password from the config file TalisConfig.groovy * which is expected to be on the classpath. * See Using Groovy to Upload RDF files to the Talis Platform * for details on using the config file TalisConfig.groovy to set the store, user and password * and making the config file available on the classpath. * @see com._3kbo.talis.TalisStoreLoader#loadRdfFile * @see com._3kbo.talis.TalisStoreLoader#loadDirectory * @param fileOrDirectory Path to either a specific RDF file or a directory containing RDF files * @return number of RDF files uploaded to the Talis store */ static int load(String fileOrDirectory) { println "Loading a file or directory: ${fileOrDirectory}" File file = new File(fileOrDirectory) if (file.exists() ) { def store = new TalisStoreLoader() if (file.file) { return store.loadRdfFile(file) } else { return store.loadDirectory(file) } } println "${fileOrDirectory} not found" return 0 } /** * Loads the RDF files in the current directory. * Explicitly sets the store, user and password. * @see com._3kbo.talis.TalisStoreLoader#loadDirectory * @param store Talis store name * @param user Talis store username * @param password Talis store password * @return number of RDF files uploaded to the Talis store */ static int load(String store, String user,String password) { println "Using store: ${store} ${user} ${password}" def loader = new TalisStoreLoader(store, user, password) println "Loading RDF files in the current directory to ${loader.metaboxPath}" return loader.loadDirectory() } /** * Loads RDF files by explicitly setting the store, user and password * and nominating either a specific RDF file to upload * or a directory to scan and upload all the RDF files found. * @see com._3kbo.talis.TalisStoreLoader#loadRdfFile * @see com._3kbo.talis.TalisStoreLoader#loadDirectory * @param store Talis store name * @param user Talis store username * @param password Talis store password * @param fileOrDirectory Path to either a specific RDF file or a directory containing RDF files * @return number of RDF files uploaded to the Talis store */ static int load(String store, String user,String password,String fileOrDirectory) { println "Using store: ${store} ${user} ${password}" def loader = new TalisStoreLoader(store, user, password) println "Loading a file or directory: ${fileOrDirectory}" File file = new File(fileOrDirectory) if (file.exists() ) { if (file.file) { return loader.loadRdfFile(file) } else { return loader.loadDirectory(file) } } println "${fileOrDirectory} not found" return 0 } /** * Depending on the parameters passed, loads either a specific RDF file or * scans the current or nominated directory and uploads all the RDF files found. * The store, user and password may be passed as parameters or read from the * config file TalisConfig.groovy which is expected to be on the classpath. * See Using Groovy to Upload RDF files to the Talis Platform * for details on using the config file TalisConfig.groovy to set the store, user and password * and making the config file available on the classpath. * The four options for running the script are: *