Пример #1
0
  private static String getMessagesFromBibiscoWebSite() {

    String lStrJsonMessages = null;

    mLog.debug("Start getMessagesFromBibiscoWebSite()");

    String lStrVersion = VersionManager.getInstance().getVersion();
    String lStrLanguage = LocaleManager.getInstance().getLocale().getLanguage();

    try {
      ClientConfig lClientConfig = new DefaultClientConfig();
      Client lClient = Client.create(lClientConfig);
      WebResource lWebResource = lClient.resource(ContextManager.getInstance().getURIWeb());
      WebResource.Builder lBuilder =
          lWebResource
              .path("rest")
              .path("messages")
              .path("get")
              .path(lStrVersion)
              .path(lStrLanguage)
              .accept(MediaType.APPLICATION_JSON);
      lStrJsonMessages = lBuilder.get(String.class);
    } catch (Throwable t) {
      // Maybe we are offline...
      mLog.error(t);
    }

    mLog.debug("End getMessagesFromBibiscoWebSite()");

    return lStrJsonMessages;
  }
  private SqlSessionFactory buildSqlSessionFactory(String pStrDBUrl) {

    SqlSessionFactory mSqlSessionFactory;

    mLog.debug("Start buildSqlSessionFactory(String)");
    mLog.debug("DB_URL: ", pStrDBUrl);

    try {
      Reader lReader = Resources.getResourceAsReader(RESOURCE_FILE_NAME);
      Properties lProperties = new Properties();
      lProperties.setProperty("url", pStrDBUrl);
      lProperties.setProperty("username", DB_USERNAME);
      lProperties.setProperty("password", DB_PASSWORD);

      mSqlSessionFactory = new SqlSessionFactoryBuilder().build(lReader, lProperties);
      mLog.debug("SqlSessionFactory built.");

    } catch (IOException e) {
      mLog.error(e);
      throw new BibiscoException(BibiscoException.IO_EXCEPTION);
    }

    mLog.debug("End buildSqlSessionFactory(String)");

    return mSqlSessionFactory;
  }
Пример #3
0
  public static void precompileLoadingPage(String lStrURL) {

    mLog.debug("Start precompileLoadingPage()");

    try {
      ClientConfig lClientConfig = new DefaultClientConfig();
      Client lClient = Client.create(lClientConfig);
      WebResource lWebResource = lClient.resource(lStrURL);
      WebResource.Builder lBuilder = lWebResource.accept(MediaType.TEXT_HTML);
      lBuilder.get(String.class);
    } catch (Throwable t) {
      // Maybe we Jetty is not started...
      mLog.error(t);
    }

    mLog.debug("End precompileLoadingPage()");
  }
Пример #4
0
  private static boolean showMessage(WebMessage pWebMessage) {

    boolean lBlnResult = false;

    mLog.debug("Start showMessage(WebMessage)");

    SqlSessionFactory lSqlSessionFactory =
        SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

      MessagesMapper lMessagesMapper = lSqlSession.getMapper(MessagesMapper.class);
      Messages lMessages = lMessagesMapper.selectByPrimaryKey(pWebMessage.getIdMessage());

      if (lMessages != null) {
        // message already read: check if i can show another time
        if (lMessages.getNumberOfViews() < pWebMessage.getNumberOfViewsAllowed()) {
          lMessages.setNumberOfViews(lMessages.getNumberOfViews() + 1);
          lMessagesMapper.updateByPrimaryKey(lMessages);
          lBlnResult = true;
        } else {
          lBlnResult = false;
        }
      } else {
        // message not read
        lMessages = new Messages();
        lMessages.setIdMessage(pWebMessage.getIdMessage());
        lMessages.setNumberOfViews(1);
        lMessagesMapper.insert(lMessages);
        lBlnResult = true;
      }

      lSqlSession.commit();

    } catch (Throwable t) {
      mLog.error(t);
      lSqlSession.rollback();
      throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
      lSqlSession.close();
    }

    mLog.debug("End showMessage(WebMessage)");

    return lBlnResult;
  }