Search in sources :

Example 1 with ConfigurationException

use of org.vcell.util.ConfigurationException in project vcell by virtualcell.

the class PropertyLoader method getOptionalDirectory.

public static final File getOptionalDirectory(String propertyName) throws ConfigurationException {
    String directoryString = getProperty(propertyName, null);
    if (directoryString == null) {
        return null;
    }
    if (!directoryString.toLowerCase().equals(USE_CURRENT_WORKING_DIRECTORY)) {
        return new File(directoryString);
    }
    File cwd = Paths.get("").toAbsolutePath().toFile();
    if (!cwd.isDirectory()) {
        throw new ConfigurationException("PropertyLoader::getOptionalDirectory failed to read directory from current working directory " + cwd);
    }
    return cwd;
}
Also used : ConfigurationException(org.vcell.util.ConfigurationException) File(java.io.File)

Example 2 with ConfigurationException

use of org.vcell.util.ConfigurationException in project vcell by virtualcell.

the class PropertyLoader method getRequiredProperty.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 * @param propertyName java.lang.String
 */
public static final synchronized String getRequiredProperty(String propertyName) throws ConfigurationException {
    if (checkRequired) {
        MetaProp mp = propMap.get(propertyName);
        if (mp != null) {
            if (!mp.sentToMongo && !mp.required) {
                report(mp, "PROPERTY: " + propertyName + " not marked required");
            }
        } else {
            mp = new MetaProp(ValueType.GEN);
            propMap.put(propertyName, mp);
            report(mp, "PROPERTY: required property " + propertyName + " not mapped");
        }
    }
    try {
        String propertyValue = System.getProperty(propertyName);
        if (propertyValue == null) {
            throw new ConfigurationException("required System property \"" + propertyName + "\" not defined");
        } else {
            return propertyValue.trim();
        }
    } catch (Exception e) {
        throw new ConfigurationException("required System property \"" + propertyName + "\" not defined");
    }
}
Also used : ConfigurationException(org.vcell.util.ConfigurationException) IOException(java.io.IOException) ConfigurationException(org.vcell.util.ConfigurationException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with ConfigurationException

use of org.vcell.util.ConfigurationException in project vcell by virtualcell.

the class PropertyLoader method getRequiredDirectory.

/**
 * return file from property. If property value is {@value #USE_CURRENT_WORKING_DIRECTORY}, return current working directory
 * @param propertyName
 * @return File object
 * @throws ConfigurationException
 */
public static final File getRequiredDirectory(String propertyName) throws ConfigurationException {
    String directoryString = getRequiredProperty(propertyName);
    if (!directoryString.toLowerCase().equals(USE_CURRENT_WORKING_DIRECTORY)) {
        return new File(directoryString);
    }
    File cwd = Paths.get("").toAbsolutePath().toFile();
    if (!cwd.isDirectory()) {
        throw new ConfigurationException("PropertyLoader::getRequiredDirectory failed to read directory from current working directory " + cwd);
    }
    return cwd;
}
Also used : ConfigurationException(org.vcell.util.ConfigurationException) File(java.io.File)

Example 4 with ConfigurationException

use of org.vcell.util.ConfigurationException in project vcell by virtualcell.

the class VCellConfiguration method getConfiguration.

private static synchronized Configuration getConfiguration() throws ConfigurationException {
    if (configurationBuilder == null) {
        Parameters params = new Parameters();
        File propertiesFile = new File(ResourceUtil.getVcellHome(), "vcellconfig.properties");
        if (!propertiesFile.exists()) {
            try {
                propertiesFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileBasedBuilderParameters thing = params.fileBased().setFile(propertiesFile);
        configurationBuilder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(thing);
        configurationBuilder.setAutoSave(true);
        try {
            propertiesConfiguration = configurationBuilder.getConfiguration();
            propertiesConfiguration.setSynchronizer(new ReadWriteSynchronizer());
        } catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
            e.printStackTrace();
            throw new ConfigurationException("failed to create configuration from file " + propertiesFile + ": " + e.getMessage());
        }
    }
    return propertiesConfiguration;
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) ConfigurationException(org.vcell.util.ConfigurationException) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) ReadWriteSynchronizer(org.apache.commons.configuration2.sync.ReadWriteSynchronizer) IOException(java.io.IOException) File(java.io.File)

Example 5 with ConfigurationException

use of org.vcell.util.ConfigurationException in project vcell by virtualcell.

the class SimulationControllerImpl method getUserSimulationDirectory.

private File getUserSimulationDirectory(String simDataRoot) {
    String userName = localVCellConnection.getUserLoginInfo().getUserName();
    File directory = new File(new File(simDataRoot), userName);
    if (!directory.exists()) {
        if (!directory.mkdirs()) {
            String msg = "could not create directory " + directory;
            if (lg.isWarnEnabled())
                lg.warn(msg);
            throw new ConfigurationException(msg);
        }
        // 
        // directory create from container (possibly) as root, make this user directory accessible from user "vcell"
        // 
        directory.setWritable(true, false);
        directory.setExecutable(true, false);
        directory.setReadable(true, false);
    }
    return directory;
}
Also used : ConfigurationException(org.vcell.util.ConfigurationException) File(java.io.File)

Aggregations

ConfigurationException (org.vcell.util.ConfigurationException)5 File (java.io.File)4 IOException (java.io.IOException)2 NoSuchElementException (java.util.NoSuchElementException)1 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)1 FileBasedBuilderParameters (org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 ReadWriteSynchronizer (org.apache.commons.configuration2.sync.ReadWriteSynchronizer)1