private File getDefaultBootstrapFile(ConfigLocation.FileAccessType accessType) { Iterable<ConfigLocation> configLocations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : configLocations) { sb.append(configLocation.getLocation()).append(' '); try { return configLocation.getFile(BOOTSTRAP_PROPERTIES, accessType); } catch (MotechConfigurationException e) { LOG.warn(e.getMessage()); } } throw new MotechConfigurationException(String.format("%s file is not %s from any of the default locations. Searched directories: %s.", BOOTSTRAP_PROPERTIES, accessType.toString(), sb)); }
/** * <p> * This method Returns the {@link java.io.File} object for the given file name relative to the config location. * It also checks for the requested file accessibility. If the requested access type check is * {@link ConfigLocation.FileAccessType.READABLE}, the file's existence and readability will be checked. * Similarly, if the requested access type check is {@link ConfigLocation.FileAccessType.WRITABLE}, then the * write accessibility to the file will be checked. If the file does not exists, write accessibility of its * ancestors will be checked. * </p> * * @param fileName Name of the file to be added to the config location. * @param accessType One of {@link ConfigLocation.FileAccessType.READABLE} or {@link ConfigLocation.FileAccessType.WRITABLE}. * @return File relative to the config location. * @throws MotechConfigurationException if the file is not readable or writable depending on the given access type. */ public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } }