Exemple #1
0
 public static Container setup() throws IOException {
   Properties properties = new Properties();
   File revProps = new File("revenj.properties");
   if (revProps.exists() && revProps.isFile()) {
     properties.load(new FileReader(revProps));
   } else {
     String location = System.getProperty("revenj.properties");
     if (location != null) {
       revProps = new File(location);
       if (revProps.exists() && revProps.isFile()) {
         properties.load(new FileReader(revProps));
       } else {
         throw new IOException(
             "Unable to find revenj.properties in alternative location. Searching in: "
                 + revProps.getAbsolutePath());
       }
     } else {
       throw new IOException(
           "Unable to find revenj.properties. Searching in: " + revProps.getAbsolutePath());
     }
   }
   String plugins = properties.getProperty("revenj.pluginsPath");
   File pluginsPath = null;
   if (plugins != null) {
     File pp = new File(plugins);
     pluginsPath = pp.isDirectory() ? pp : null;
   }
   return setup(
       dataSource(properties),
       properties,
       Optional.ofNullable(pluginsPath),
       Optional.ofNullable(Thread.currentThread().getContextClassLoader()));
 }
Exemple #2
0
 public static Container setup(
     DataSource dataSource,
     Properties properties,
     Optional<ClassLoader> classLoader,
     Iterator<SystemAspect> aspects)
     throws IOException {
   ClassLoader loader = classLoader.orElse(Thread.currentThread().getContextClassLoader());
   SimpleContainer container =
       new SimpleContainer("true".equals(properties.getProperty("revenj.resolveUnknown")));
   container.registerInstance(properties);
   container.registerInstance(ServiceLocator.class, container, false);
   container.registerInstance(DataSource.class, dataSource, false);
   container.registerInstance(ClassLoader.class, loader, false);
   String ns = properties.getProperty("revenj.namespace");
   SimpleDomainModel domainModel = new SimpleDomainModel(ns, loader);
   container.registerInstance(DomainModel.class, domainModel, false);
   container.registerFactory(DataContext.class, LocatorDataContext::asDataContext, false);
   container.registerFactory(UnitOfWork.class, LocatorDataContext::asUnitOfWork, false);
   PluginLoader plugins = new ServicesPluginLoader(loader);
   container.registerInstance(PluginLoader.class, plugins, false);
   PostgresDatabaseNotification databaseNotification =
       new PostgresDatabaseNotification(
           dataSource, Optional.of(domainModel), properties, container);
   container.registerInstance(EagerNotification.class, databaseNotification, false);
   container.registerInstance(DataChangeNotification.class, databaseNotification, true);
   ChangeNotification.registerContainer(container, databaseNotification);
   container.registerFactory(RepositoryBulkReader.class, PostgresBulkReader::create, false);
   container.registerInstance(
       PermissionManager.class, new RevenjPermissionManager(container), false);
   container.registerClass(
       new Generic<Serialization<String>>() {}.type, DslJsonSerialization.class, false);
   int total = 0;
   if (aspects != null) {
     JinqMetaModel.configure(container);
     while (aspects.hasNext()) {
       aspects.next().configure(container);
       total++;
     }
   }
   String nsAfter = properties.getProperty("revenj.namespace");
   if (!Objects.equals(ns, nsAfter)) {
     domainModel.updateNamespace(nsAfter);
   }
   properties.setProperty("revenj.aspectsCount", Integer.toString(total));
   return container;
 }
Exemple #3
0
 public static DataSource dataSource(Properties properties) throws IOException {
   String jdbcUrl = properties.getProperty("revenj.jdbcUrl");
   if (jdbcUrl == null) {
     throw new IOException("revenj.jdbcUrl is missing from Properties");
   }
   org.postgresql.ds.PGPoolingDataSource dataSource = new PGPoolingDataSource();
   dataSource.setUrl(jdbcUrl);
   String user = properties.getProperty("user");
   String revUser = properties.getProperty("revenj.user");
   if (revUser != null && revUser.length() > 0) {
     dataSource.setUser(revUser);
   } else if (user != null && user.length() > 0) {
     dataSource.setUser(user);
   }
   String password = properties.getProperty("password");
   String revPassword = properties.getProperty("revenj.password");
   if (revPassword != null && revPassword.length() > 0) {
     dataSource.setPassword(revPassword);
   } else if (password != null && password.length() > 0) {
     dataSource.setPassword(password);
   }
   return dataSource;
 }