Search in sources :

Example 16 with UserInfo

use of org.vcell.util.document.UserInfo in project vcell by virtualcell.

the class ResultSetCrawler method main.

public static void main(String[] args) {
    ConnectionFactory conFactory = null;
    try {
        boolean SCAN_ONLY = true;
        String singleUsername = null;
        String startingUsername = null;
        String outputDirName = ".";
        String ampliCredName = null;
        String ampliCredPassword = null;
        int count = 0;
        while (count < args.length) {
            if (args[count].equals("-h")) {
                printUsage();
                System.exit(0);
            } else if (args[count].equals("-u")) {
                count++;
                singleUsername = args[count];
            } else if (args[count].equals("-c")) {
                count++;
                startingUsername = args[count];
            } else if (args[count].equals("-o")) {
                count++;
                outputDirName = args[count];
            } else if (args[count].equals("-d")) {
                SCAN_ONLY = false;
            } else if (args[count].equals("-s")) {
                SCAN_ONLY = true;
            } else if (args[count].equals("-y")) {
                count++;
                ampliCredName = args[count];
            } else if (args[count].equals("-z")) {
                count++;
                ampliCredPassword = args[count];
            } else {
                System.out.println("Wrong arguments, see usage below.");
                printUsage();
                System.exit(1);
            }
            count++;
        }
        File outputDir = null;
        if (outputDirName == null) {
            outputDir = new File(".");
        } else {
            outputDir = new File(outputDirName);
            if (!outputDir.exists()) {
                throw new RuntimeException("Outuput directory doesn't exist!");
            }
        }
        PropertyLoader.loadProperties();
        File primaryDataRootDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty));
        File secondaryDataRootDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty));
        if (primaryDataRootDir.equals(secondaryDataRootDir)) {
            secondaryDataRootDir = null;
        }
        // initialize database
        conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        DatabaseServerImpl dbServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        // 
        // determine the list of users to scan
        // 
        UserInfo[] allUserInfos = adminDbTopLevel.getUserInfos(true);
        HashMap<String, User> usersToScan = new HashMap<String, User>();
        for (UserInfo userInfo : allUserInfos) {
            if (singleUsername != null) {
                // accept only the "singleUser"
                if (userInfo.userid.equals(singleUsername)) {
                    usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
                    break;
                }
            } else if (startingUsername != null) {
                // accept all users starting with the "startingUser"
                if (userInfo.userid.compareToIgnoreCase(startingUsername) >= 0) {
                    usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
                }
            } else {
                // all users
                usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
            }
        }
        // 
        // get list of directories to scan (for selected users on both user data directories)
        // 
        List<File> useDirectoriesToScan = getDirectoriesToScan(usersToScan, primaryDataRootDir, secondaryDataRootDir);
        for (File userDir : useDirectoriesToScan) {
            try {
                if (lg.isTraceEnabled())
                    lg.trace("USER: " + userDir.getName());
                User user = usersToScan.get(userDir.getName());
                // find all the user simulations and external data sets (field data)
                SimulationInfo[] simulationInfos = dbServerImpl.getSimulationInfos(user, false);
                ExternalDataIdentifier[] extDataIDArr = adminDbTopLevel.getExternalDataIdentifiers(user, true);
                // scan this user directory
                scanUserDirectory(userDir, extDataIDArr, simulationInfos, outputDir, SCAN_ONLY, (ampliCredName == null || ampliCredPassword == null ? null : new AmplistorUtils.AmplistorCredential(ampliCredName, ampliCredPassword)));
            } catch (Exception ex) {
                lg.error(ex.getMessage(), ex);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    } finally {
        try {
            if (conFactory != null) {
                conFactory.close();
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
        System.exit(0);
    }
}
Also used : User(org.vcell.util.document.User) HashMap(java.util.HashMap) UserInfo(org.vcell.util.document.UserInfo) DataAccessException(org.vcell.util.DataAccessException) SQLException(java.sql.SQLException) ConnectionFactory(org.vcell.db.ConnectionFactory) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File) KeyFactory(org.vcell.db.KeyFactory) SimulationInfo(cbit.vcell.solver.SimulationInfo) AmplistorUtils(cbit.vcell.util.AmplistorUtils)

Aggregations

UserInfo (org.vcell.util.document.UserInfo)16 SQLException (java.sql.SQLException)10 User (org.vcell.util.document.User)7 DataAccessException (org.vcell.util.DataAccessException)6 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 UseridIDExistsException (org.vcell.util.UseridIDExistsException)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ConnectionFactory (org.vcell.db.ConnectionFactory)2 KeyFactory (org.vcell.db.KeyFactory)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 ClientServerInfo (cbit.vcell.client.server.ClientServerInfo)1 ConnectionStatus (cbit.vcell.client.server.ConnectionStatus)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 RegistrationPanel (cbit.vcell.desktop.RegistrationPanel)1 VCDestination (cbit.vcell.message.VCDestination)1 VCMessage (cbit.vcell.message.VCMessage)1 VCMessagingDelegate (cbit.vcell.message.VCMessagingDelegate)1