#!/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: *
    *
  1. Command line> TalisStore. No paramteres passed. Loads RDF files from the current directory. Reads store, user and password from config file.
  2. *
  3. Command line> TalisStore fileOrDirectory. Loads RDF files from the specified directory or the nominated file. Reads store, user and password from config file.
  4. *
  5. Command line> TalisStore store user password. Explicitly sets the store, user and password and loads RDF files from the current directory.
  6. *
  7. Command line> TalisStore store user password fileOrDirectory. Explicitly sets the store, user and password. Loads RDF files from the specified directory or the nominated file.
  8. *
* @see com._3kbo.talis.TalisStoreLoader#loadRdfFile * @see com._3kbo.talis.TalisStoreLoader#loadDirectory * @param args as described above */ static main(args) { println "Usage: TalisStore " println "Usage: TalisStore fileOrDirectory" println "Usage: TalisStore store user password" println "Usage: TalisStore store user password fileOrDirectory" println "Using parameters: ${args}" if (args.size() == 0) { println "Loading RDF files in current directory" TalisStore.load() } else if (args.size() == 1 ) { println "Loading RDF file(s) ${args[0]}" TalisStore.load(args[0]) } else if (args.size() == 3 ) { println "Loading RDF files in current directory" TalisStore.load(args[0],args[1],args[2]) } else if (args.size() == 4 ) { println "Loading RDF file(s) ${args[3]}" TalisStore.load(args[0],args[1],args[2],args[3]) } } }