Esempio n. 1
0
 public static Container setup(
     DataSource dataSource,
     Properties properties,
     Optional<File> pluginsPath,
     Optional<ClassLoader> classLoader)
     throws IOException {
   ClassLoader loader;
   if (pluginsPath.isPresent()) {
     File[] jars = pluginsPath.get().listFiles(f -> f.getPath().toLowerCase().endsWith(".jar"));
     List<URL> urls = new ArrayList<>(jars.length);
     for (File j : jars) {
       try {
         urls.add(j.toURI().toURL());
       } catch (MalformedURLException ex) {
         throw new IOException(ex);
       }
     }
     loader =
         classLoader.isPresent()
             ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader.get())
             : new URLClassLoader(urls.toArray(new URL[urls.size()]));
   } else if (classLoader.isPresent()) {
     loader = classLoader.get();
   } else {
     loader = Thread.currentThread().getContextClassLoader();
   }
   ServiceLoader<SystemAspect> aspects = ServiceLoader.load(SystemAspect.class, loader);
   return setup(dataSource, properties, Optional.of(loader), aspects.iterator());
 }
Esempio n. 2
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()));
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
  @Test
  public void testSQLMapping() throws IOException {
    ServiceLocator locator = container;
    CoverageUpdateRepository covUpdateRepo = locator.resolve(CoverageUpdateRepository.class);
    CoverageVersions1Repository covVersionsRepo =
        locator.resolve(CoverageVersions1Repository.class);

    String suppID = UUID.randomUUID().toString();
    covUpdateRepo.submit(new CoverageUpdate().setSupplierID(suppID));
    try {
      Thread.sleep(100);
    } catch (InterruptedException ignore) {
    }
    covUpdateRepo.submit(new CoverageUpdate().setSupplierID(suppID));

    List<CoverageVersions1> items =
        covVersionsRepo.query(it -> it.getSupplierID().equals(suppID)).list();
    Assert.assertEquals(items.size(), 2);
    Assert.assertNotEquals(
        items.get(0).getProcessedAt().isEqual(items.get(1).getProcessedAt()), true);
  }