Exemplo n.º 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;
  }
Exemplo n.º 2
0
  public static WebMessage getMessageFromBibiscoWebSite() {

    WebMessage lWebMessage = null;

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

    String lStrJson = getMessagesFromBibiscoWebSite();
    if (StringUtils.isNotEmpty(lStrJson)) {
      Gson lGson = new Gson();
      WebMessage[] lWebMessages = lGson.fromJson(lStrJson, WebMessage[].class);

      for (int i = 0; i < lWebMessages.length; i++) {
        mLog.debug(lWebMessages[i].getIdMessage() + " " + lWebMessages[i].getTitle());
        if (showMessage(lWebMessages[i])) {
          lWebMessage = lWebMessages[i];
          break;
        }
      }
    }

    mLog.debug(
        "End getMessageFromBibiscoWebSite() return: ",
        lWebMessage != null ? lWebMessage.getMessage() : "null");

    return lWebMessage;
  }
  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;
  }
  public void cleanSqlSessionFactoryProject() {

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

    PooledDataSource lPooledDataSource =
        (PooledDataSource)
            mSqlSessionFactoryProject.getConfiguration().getEnvironment().getDataSource();
    lPooledDataSource.forceCloseAll();
    mSqlSessionFactoryProject = null;

    mLog.debug("End cleanSqlSessionFactoryProject()");
  }
Exemplo n.º 5
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()");
  }
Exemplo n.º 6
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;
  }