コード例 #1
0
 /**
  * Checks if the new neighbor code is unique within the concept including properties.
  *
  * @param newNeighborConfig neighbor configuration entity
  * @return <code>true</code> if the add precondition is satisfied
  */
 protected boolean preAdd(NeighborConfig newNeighborConfig) {
   boolean validation = true;
   String newNeighborCode = newNeighborConfig.getCode();
   if (newNeighborCode != null) {
     for (NeighborConfig neighborConfig : this) {
       if (neighborConfig.getCode().equals(newNeighborCode)) {
         validation = false;
         log.info(newNeighborCode + " neighbor code must be unique within the concept.");
         break;
       }
     }
     for (PropertyConfig propertyConfig : conceptConfig.getPropertiesConfig()) {
       if (propertyConfig.getCode().equals(newNeighborCode)) {
         validation = false;
         log.info(
             newNeighborCode
                 + " neighbor code must be unique within the concept including properties.");
         break;
       }
     }
   } else {
     validation = false;
     log.info("Neighbor code is required.");
   }
   return validation;
 }
コード例 #2
0
ファイル: Application.java プロジェクト: francescocambi/News
  private static void configureArticleDownloaderTask() {
    if (!Boolean.parseBoolean(props.getProp("HOURLY_ARTICLE_DOWNLOAD"))) return;
    log.info("Configuring hourly Article Download task...");
    ArticlesDownloaderTask task = new ArticlesDownloaderTask();
    task.setCreator(Application.class.getName());

    // Compute difference in minutes from now to next o'clock hour
    long now = System.currentTimeMillis() / 3600000;
    long time = (now + 1) * 3600000;
    Date schedule = new Date(time);

    task.setScheduleTime(schedule);
    task.setPeriod(60 * 60 * 1000);

    scheduler.schedule(task);
  }
コード例 #3
0
ファイル: Application.java プロジェクト: francescocambi/News
  public static void main(String[] args) {

    String title =
        "\n"
            + "      _   __                     ___                \n"
            + "     / | / /__ _      _______   /   |  ____  ____   \n"
            + "    /  |/ / _ \\ | /| / / ___/  / /| | / __ \\/ __ \\  \n"
            + "   / /|  /  __/ |/ |/ (__  )  / ___ |/ /_/ / /_/ /  \n"
            + "  /_/ |_/\\___/|__/|__/____/  /_/  |_/ .___/ .___/   \n"
            + "                                   /_/   /_/        \n";

    System.out.println(title);
    System.out.flush();

    if (args.length != 0 && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("h"))) {
      InputStream stream = Application.class.getResourceAsStream("/help.txt");
      BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
      reader.lines().forEach(System.out::println);
      System.out.flush();
      return;
    }

    System.out.println("Starting Up...");

    try {
      props = new PropertyConfig();
    } catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      System.exit(-1);
    }

    Logging.setUp();
    log = Logging.registerLogger(Application.class.getName());
    Logging.registerLogger("");
    Logging.registerLogger("org.hibernate", Level.WARNING);

    log.info("Initializing Entity Manager factory...");
    log.info("Persistence Unit: " + props.getProp("PERSISTENCE_UNIT"));
    persistenceManager = new PersistenceManager(props.getProp("PERSISTENCE_UNIT"));

    if (args.length != 0 && args[0].equals("multilevel-clustering")) {

      String clusteringName = args[1];
      double metaNewsThreshold = Double.parseDouble(args[2]);
      double newsThreshold = Double.parseDouble(args[3]);
      String tfDictionaryName = args[4];
      String languageString = args[5];

      try {
        MultilevelIncrementalClusteringTask.execTask(
            clusteringName, metaNewsThreshold, newsThreshold, tfDictionaryName, languageString);
      } catch (Exception e) {
        e.printStackTrace();
        Application.tearDown();
        System.exit(-1);
      }

      Application.tearDown();
      System.exit(0);
    } else if (args.length != 0 && args[0].equals("multilevel-performance")) {

      double metaNewsThresholdSeed = Double.parseDouble(args[1]);
      int metaNewsThresholdLimit = Integer.parseInt(args[2]);
      double newsThresholdSeed = Double.parseDouble(args[3]);
      int newsThresholdLimit = Integer.parseInt(args[4]);
      String tfDictionaryName = args[5];
      String languageString = args[6];

      try {
        MultilevelClusteringPerformanceTask.execTask(
            metaNewsThresholdSeed,
            metaNewsThresholdLimit,
            newsThresholdSeed,
            newsThresholdLimit,
            tfDictionaryName,
            languageString);
      } catch (Exception e) {
        e.printStackTrace();
        Application.tearDown();
        System.exit(-1);
      }

      Application.tearDown();
      System.exit(0);

    } else if (args.length != 0 && args[0].equals("generate-tf-dictionary")) {

      String dictionaryName = args[1];
      String languageString = args[2];

      if (dictionaryName == null || dictionaryName.length() == 0) {
        System.err.println("Please provide a valid name for TF Dictionary");
        Application.tearDown();
        System.exit(-1);
      }

      int returnCode = -1;

      try {
        TFDictionaryGenerationTask.generateDictionary(dictionaryName, languageString);
        returnCode = 0;
      } catch (Exception e) {
        e.printStackTrace();
        returnCode = -1;
      } finally {
        Application.tearDown();
        System.exit(returnCode);
      }

    } else if (args.length != 0 && args[0].equals("load-words-list")) {

      String filePath = args[1];
      String languageString = args[2];

      if (!Files.exists(Paths.get(filePath))) {
        System.err.println("File does not exists.");
        Application.tearDown();
        System.exit(-1);
      }

      Language language = null;
      try {
        language = Language.valueOf(languageString);
      } catch (Exception e) {
        System.err.println(e.getMessage());
        Application.tearDown();
        System.exit(-1);
      }

      EntityManager em = Application.createEntityManager();

      em.getTransaction().begin();

      NoiseWordsList old =
          em.createQuery(
                  "select l from NoiseWordsList l where l.language=:lang", NoiseWordsList.class)
              .setParameter("lang", language)
              .getSingleResult();
      em.remove(old);

      NoiseWordsList list = new NoiseWordsList();
      list.setDescription(languageString);
      list.setLanguage(language);

      try {
        Files.lines(Paths.get(filePath))
            .forEach(
                w -> {
                  list.getWords().add(w.trim());
                });
      } catch (IOException e) {
        System.err.println("Cannot open file.");
        e.printStackTrace();
        Application.tearDown();
        System.exit(-1);
      }

      em.persist(list);

      em.getTransaction().commit();
      em.close();

      System.out.println("Task completed successfully.");
      Application.tearDown();
      System.exit(0);

    } else if (args.length != 0 && args[0].equals("add-user")) {
      if (args.length < 4) {
        System.err.println("Wrong command syntax, missing arguments.");
        Application.tearDown();
        System.exit(-1);
      }

      String username = args[1];
      String password = args[2];
      String role = args[3];

      if (!role.equalsIgnoreCase("admin") && !role.equalsIgnoreCase("guest")) {
        System.err.println("Role can be one of [admin, guest]");
        Application.tearDown();
        System.exit(-1);
      }

      EntityManager em = Application.createEntityManager();

      User user = null;
      try {
        user =
            em.createQuery("select u from User u where u.username=:uname", User.class)
                .setParameter("uname", username)
                .getSingleResult();
      } catch (NoResultException e) {
        user = new User();
        user.setEmail("");
      }

      user.setUsername(username);
      user.setPassword(password);
      user.setRole(role.toLowerCase());

      em.getTransaction().begin();
      em.persist(user);
      em.getTransaction().commit();

      System.out.println("User successfully created.");
      Application.tearDown();
      System.exit(0);
    }

    log.info("Setting up Scheduler");
    Task.setLogger(Logging.registerLogger("it.fcambi.news.Tasks"));
    configureScheduler();

    log.info("Starting up Web Services...");
    log.info("Bind url >> " + props.getProp("BIND_URI"));
    httpServer = new Server(props);
    httpServer.startServer();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {
                Application.tearDown();
              }
            });

    configureArticleDownloaderTask();

    log.info("Startup Completed - All OK");

    System.out.println(
        "\nApplication Ready\n\t- Server @ "
            + props.getProp("BIND_URI")
            + "\n\t- GUI @ "
            + props.getProp("BIND_URI")
            + "/gui/app/\n");
    System.out.println("Press CTRL+C to stop...");

    try {
      Thread.currentThread().join();
    } catch (Exception e) {
      log.log(Level.SEVERE, "Error joining current thread.", e);
      System.exit(-1);
    }
  }
コード例 #4
0
ファイル: Application.java プロジェクト: francescocambi/News
 public static String getProperty(String name) {
   return props.getProp(name);
 }
コード例 #5
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the Integer Array of values of the given property name
   *
   * @param name the property name
   * @param required whether the property is required
   * @return the integer Array
   * @throws ConfigurationException if the required property is not found
   */
  public static int[] getIntegerArray(String name, boolean required) throws ConfigurationException {
    validateName(name);

    return config.getIntegerArray(name, required);
  }
コード例 #6
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Checks whether a given property name is contained in the properties.
   *
   * @param name the property name to check
   * @return <code>true</code> if the property name is found.
   */
  public static boolean contains(String name) {
    validateName(name);

    return config.contains(name);
  }
コード例 #7
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the int value of the given property name.
   *
   * @param name the property name
   * @defaultVal the default value
   * @return the integer value; if not found, return defaultValue
   */
  public static int getInteger(String name, int defaultVal) {
    validateName(name);

    return config.getInteger(name, defaultVal);
  }
コード例 #8
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the Integer Array of values of the given property name
   *
   * @param name the property name
   * @return the integer Array; null if the property not found.
   */
  public static int[] getIntegerArray(String name) {
    validateName(name);

    return config.getIntegerArray(name);
  }
コード例 #9
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the boolean value of the given property name.
   *
   * @param name the property name
   * @defaultVal the default value
   * @return the boolean value; defaultValue if not found
   */
  public static boolean getBoolean(String name, boolean defaultVal) {
    validateName(name);

    return config.getBoolean(name, defaultVal);
  }
コード例 #10
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the int value of the given property name.
   *
   * @param name the property name
   * @return the integer value; -1 if not found
   */
  public static int getInteger(String name) {
    validateName(name);

    return config.getInteger(name);
  }
コード例 #11
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the boolean value of the given property name.
   *
   * @param name the property name
   * @return the boolean value; false if not found
   */
  public static boolean getBoolean(String name) {
    validateName(name);

    return config.getBoolean(name);
  }
コード例 #12
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the String Array of values of the given property name
   *
   * @param name the property name
   * @return the String Array; null if not found
   */
  public static String[] getStringArray(String name) {
    validateName(name);

    return config.getStringArray(name);
  }
コード例 #13
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the String value of the given property name
   *
   * @param name the property name
   * @defaultVal the default value
   * @return the String value; return defaultVal if not found
   */
  public static String getString(String name, String defaultVal) {
    validateName(name);

    return config.getString(name, defaultVal);
  }
コード例 #14
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the String value of the given property name
   *
   * @param name the property name
   * @param required whether the property is required
   * @return the String value
   * @throws ConfigurationException if the required property is not found
   */
  public static String getString(String name, boolean required) throws ConfigurationException {
    validateName(name);

    return config.getString(name, required);
  }
コード例 #15
0
ファイル: PropertyFacade.java プロジェクト: openhie/os-cr
  /**
   * Gets the String value of the given property name
   *
   * @param name the property name
   * @return the String value; null if not found
   */
  public static String getString(String name) {
    validateName(name);

    return config.getString(name);
  }