Search in sources :

Example 46 with ExternalDataIdentifier

use of org.vcell.util.document.ExternalDataIdentifier 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

ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)46 DataAccessException (org.vcell.util.DataAccessException)15 KeyValue (org.vcell.util.document.KeyValue)15 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)12 File (java.io.File)12 UserCancelException (org.vcell.util.UserCancelException)12 User (org.vcell.util.document.User)12 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)9 Hashtable (java.util.Hashtable)9 ISize (org.vcell.util.ISize)9 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)8 Expression (cbit.vcell.parser.Expression)8 Origin (org.vcell.util.Origin)8 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)7 Element (org.jdom.Element)7 Extent (org.vcell.util.Extent)7 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)7 ImageException (cbit.image.ImageException)6 FieldDataDBOperationResults (cbit.vcell.field.FieldDataDBOperationResults)6 RegionImage (cbit.vcell.geometry.RegionImage)6