/** This class provides methods to access templates stored in the database. */
public final class DatabaseTemplateHome {
  // Static variable pointed to the DAO instance
  private static IDatabaseTemplateDAO _dao = SpringContextService.getBean("databaseTemplateDAO");

  /** Instantiates a new database template home. */
  private DatabaseTemplateHome() {}

  /**
   * Get a template in the database from its key
   *
   * @param strKey The key of the template to get
   * @return The template loaded from the database
   */
  public static String getTemplateFromKey(String strKey) {
    return _dao.getTemplateFromKey(strKey);
  }

  /**
   * Update a template in the database
   *
   * @param strKey The key of the template
   * @param strValue The new value of the template
   */
  public static void updateTemplate(String strKey, String strValue) {
    _dao.updateTemplate(strKey, strValue);
  }
}
  /**
   * Get the records count
   *
   * @param directory the {@link Directory}
   * @param user the {@link AdminUser}
   * @return the record count
   */
  public int getRecordsCount(Directory directory, AdminUser user) {
    Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);
    int nNbRecords = 0;
    boolean bWorkflowServiceEnable = WorkflowService.getInstance().isAvailable();
    RecordFieldFilter filter = new RecordFieldFilter();
    filter.setIdDirectory(directory.getIdDirectory());
    filter.setWorkgroupKeyList(AdminWorkgroupService.getUserWorkgroups(user, user.getLocale()));

    if ((directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_NULL)
        && (directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_ZERO)
        && bWorkflowServiceEnable) {
      List<Integer> listResultRecordIds =
          DirectorySearchService.getInstance()
              .getSearchResults(directory, null, null, null, null, filter, plugin);
      List<Integer> listTmpResultRecordIds =
          WorkflowService.getInstance()
              .getAuthorizedResourceList(
                  Record.WORKFLOW_RESOURCE_TYPE,
                  directory.getIdWorkflow(),
                  DirectoryUtils.CONSTANT_ID_NULL,
                  Integer.valueOf(directory.getIdDirectory()),
                  user);
      listResultRecordIds =
          DirectoryUtils.retainAllIdsKeepingFirstOrder(listResultRecordIds, listTmpResultRecordIds);
      nNbRecords = listResultRecordIds.size();
    } else {
      IRecordService recordService = SpringContextService.getBean(RecordService.BEAN_SERVICE);
      nNbRecords = recordService.getCountRecord(filter, plugin);
    }

    return nNbRecords;
  }
  /**
   * Returns the instance of the singleton
   *
   * @return The instance of the singleton
   */
  public static synchronized DatabaseService getService() {
    if (_singleton == null) {
      _singleton = SpringContextService.getBean(BEAN_DATABASE_SERVICE);
    }

    return _singleton;
  }
  /** @return IEudonetWsService */
  public static IProfanityFilter getService() {
    if (_singleton == null) {
      _singleton = SpringContextService.getBean(BEAN_PROFANITY_FILTER_SERVICE);
    }

    return _singleton;
  }
Esempio n. 5
0
  /**
   * Send a text message asynchronously with attached files. The message is queued until a daemon
   * thread send all awaiting messages
   *
   * @param strRecipientsTo The list of the main recipients email.Every recipient must be separated
   *     by the mail separator defined in config.properties
   * @param strRecipientsCc The recipients list of the carbon copies .
   * @param strRecipientsBcc The recipients list of the blind carbon copies .
   * @param strSenderName The sender name.
   * @param strSenderEmail The sender email address.
   * @param strSubject The message subject.
   * @param strMessage The message.
   * @param filesAttachement The list of attached files.
   * @param bUniqueRecipientTo true if the mail must be send unitarily for each recipient
   */
  public static void sendMailMultipartText(
      String strRecipientsTo,
      String strRecipientsCc,
      String strRecipientsBcc,
      String strSenderName,
      String strSenderEmail,
      String strSubject,
      String strMessage,
      List<FileAttachment> filesAttachement,
      boolean bUniqueRecipientTo) {
    MailItem item = new MailItem();
    item.setRecipientsTo(strRecipientsTo);
    item.setRecipientsCc(strRecipientsCc);
    item.setRecipientsBcc(strRecipientsBcc);
    item.setSenderName(strSenderName);
    item.setSenderEmail(strSenderEmail);
    item.setSubject(strSubject);
    item.setMessage(strMessage);
    item.setFormat(MailItem.FORMAT_MULTIPART_TEXT);
    item.setFilesAttachement(filesAttachement);
    item.setUniqueRecipientTo(bUniqueRecipientTo);

    IMailQueue queue = (IMailQueue) SpringContextService.getBean(BEAN_MAIL_QUEUE);
    queue.send(item);
  }
Esempio n. 6
0
  /**
   * Send a calendar message asynchronously. The message is queued until a daemon thread send all
   * awaiting messages
   *
   * @param strRecipientsTo The list of the main recipients email. Every recipient must be separated
   *     by the mail separator defined in config.properties
   * @param strRecipientsCc The recipients list of the carbon copies .
   * @param strRecipientsBcc The recipients list of the blind carbon copies .
   * @param strSenderName The sender name.
   * @param strSenderEmail The sender email address.
   * @param strSubject The message subject.
   * @param strMessage The message.
   * @param strCalendarMessage The calendar message
   * @param bCreateEvent True to create the calendar event, false to remove it
   * @param bUniqueRecipientTo true if the mail must be send unitarily for each recipient
   */
  public static void sendMailCalendar(
      String strRecipientsTo,
      String strRecipientsCc,
      String strRecipientsBcc,
      String strSenderName,
      String strSenderEmail,
      String strSubject,
      String strMessage,
      String strCalendarMessage,
      boolean bCreateEvent,
      boolean bUniqueRecipientTo) {
    MailItem item = new MailItem();
    item.setRecipientsTo(strRecipientsTo);
    item.setRecipientsCc(strRecipientsCc);
    item.setRecipientsBcc(strRecipientsBcc);
    item.setSenderName(strSenderName);
    item.setSenderEmail(strSenderEmail);
    item.setSubject(strSubject);
    item.setMessage(strMessage);
    item.setCalendarMessage(strCalendarMessage);
    item.setCreateEvent(bCreateEvent);
    item.setFormat(MailItem.FORMAT_CALENDAR);
    item.setUniqueRecipientTo(bUniqueRecipientTo);

    IMailQueue queue = (IMailQueue) SpringContextService.getBean(BEAN_MAIL_QUEUE);
    queue.send(item);
  }
  /** Initialize the Database service */
  public void init() {
    RoleRemovalListenerService.getService().registerListener(new DatabaseUserRoleRemovalListener());
    DatabaseMyLuteceUserFieldListenerService.getService()
        .registerListener(new DatabaseUserFieldListener());

    _baseAuthentication = SpringContextService.getBean(AUTHENTICATION_BEAN_NAME);

    if (_baseAuthentication != null) {
      MultiLuteceAuthentication.registerAuthentication(_baseAuthentication);
    } else {
      AppLogService.error(
          "BaseAuthentication not found, please check your database_context.xml configuration");
    }
  }
 /**
  * Returns the removal service
  *
  * @return The removal service
  */
 public static RemovalListenerService getService() {
   return SpringContextService.getBean(BEAN_DIRECTORY_REMOVAL_SERVICE);
 }
/** This class provides instances management methods (create, find, ...) for DatabaseUser objects */
public final class DatabaseUserHome {
  // Static variable pointed at the DAO instance
  private static IDatabaseUserDAO _dao =
      SpringContextService.getBean("mylutece-database.databaseUserDAO");

  /** Private constructor - this class need not be instantiated */
  private DatabaseUserHome() {}

  /**
   * Creation of an instance of databaseUser
   *
   * @param databaseUser The instance of the DatabaseUser which contains the informations to store
   * @param strPassword The user's password
   * @param plugin The current plugin using this method
   * @return The instance of DatabaseUser which has been created with its primary key.
   */
  public static DatabaseUser create(DatabaseUser databaseUser, String strPassword, Plugin plugin) {
    _dao.insert(databaseUser, strPassword, plugin);

    return databaseUser;
  }

  /**
   * Update of the databaseUser which is specified in parameter
   *
   * @param databaseUser The instance of the DatabaseUser which contains the data to store
   * @param plugin The current plugin using this method
   * @return The instance of the DatabaseUser which has been updated
   */
  public static DatabaseUser update(DatabaseUser databaseUser, Plugin plugin) {
    _dao.store(databaseUser, plugin);
    LuteceUserService.userAttributesChanged(databaseUser.getLogin());

    return databaseUser;
  }

  /**
   * Update of the databaseUser which is specified in parameter
   *
   * @param databaseUser The instance of the DatabaseUser which contains the data to store
   * @param strNewPassword The new password to store
   * @param plugin The current plugin using this method
   * @return The instance of the DatabaseUser which has been updated
   */
  public static DatabaseUser updatePassword(
      DatabaseUser databaseUser, String strNewPassword, Plugin plugin) {
    _dao.updatePassword(databaseUser, strNewPassword, plugin);

    return databaseUser;
  }

  /**
   * Update of the databaseUser which is specified in parameter
   *
   * @param user The instance of the DatabaseUser which contains the data to store
   * @param bNewValue The new value of the reset password attribute
   * @param plugin The current plugin using this method
   * @return The instance of the DatabaseUser which has been updated
   */
  public static DatabaseUser updateResetPassword(
      DatabaseUser user, boolean bNewValue, Plugin plugin) {
    _dao.updateResetPassword(user, bNewValue, plugin);

    return user;
  }

  /**
   * Remove the databaseUser whose identifier is specified in parameter
   *
   * @param databaseUser The DatabaseUser object to remove
   * @param plugin The current plugin using this method
   */
  public static void remove(DatabaseUser databaseUser, Plugin plugin) {
    _dao.delete(databaseUser, plugin);
    LuteceUserService.userAttributesChanged(databaseUser.getLogin());
  }

  // /////////////////////////////////////////////////////////////////////////
  // Finders

  /**
   * Returns an instance of a DatabaseUser whose identifier is specified in parameter
   *
   * @param nKey The Primary key of the databaseUser
   * @param plugin The current plugin using this method
   * @return An instance of DatabaseUser
   */
  public static DatabaseUser findByPrimaryKey(int nKey, Plugin plugin) {
    return _dao.load(nKey, plugin);
  }

  /**
   * Returns a collection of DatabaseUser objects
   *
   * @param plugin The current plugin using this method
   * @return A collection of DatabaseUser
   */
  public static Collection<DatabaseUser> findDatabaseUsersList(Plugin plugin) {
    return _dao.selectDatabaseUserList(plugin);
  }

  /**
   * Returns a collection of DatabaseUser objects for a login
   *
   * @param strLogin The login of the databseUser
   * @param plugin The current plugin using this method
   * @return A collection of DatabaseUser
   */
  public static Collection<DatabaseUser> findDatabaseUsersListForLogin(
      String strLogin, Plugin plugin) {
    return _dao.selectDatabaseUserListForLogin(strLogin, plugin);
  }

  /**
   * Returns a collection of DatabaseUser objects for a email
   *
   * @param strEmail The email of the databseUser
   * @param plugin The current plugin using this method
   * @return A collection of DatabaseUser
   */
  public static Collection<DatabaseUser> findDatabaseUsersListForEmail(
      String strEmail, Plugin plugin) {
    return _dao.selectDatabaseUserListForEmail(strEmail, plugin);
  }

  /**
   * Returns the password of the specified user
   *
   * @param nKey The Primary key of the databaseUser
   * @param plugin The current plugin using this method
   * @return An instance of DatabaseUser
   */
  public static String findPasswordByPrimaryKey(int nKey, Plugin plugin) {
    return _dao.selectPasswordByPrimaryKey(nKey, plugin);
  }

  /**
   * Check the password for a DatabaseUser
   *
   * @param strLogin The user login of DatabaseUser
   * @param strPassword The password of DatabaseUser
   * @param plugin The Plugin using this data access service
   * @return true if password is ok
   */
  public static boolean checkPassword(String strLogin, String strPassword, Plugin plugin) {
    return _dao.checkPassword(strLogin, strPassword, plugin);
  }

  /**
   * Find DatabaseUsers by filter
   *
   * @param duFilter filter
   * @param plugin The plugin
   * @return a list of DatabaseUsers
   */
  public static List<DatabaseUser> findDatabaseUsersListByFilter(
      DatabaseUserFilter duFilter, Plugin plugin) {
    return _dao.selectDatabaseUsersListByFilter(duFilter, plugin);
  }

  /**
   * Get a user id from his login
   *
   * @param strLogin The login of the user
   * @param plugin The plugin
   * @return The user id, or 0 if no user has this login.
   */
  public static int findDatabaseUserIdFromLogin(String strLogin, Plugin plugin) {
    return _dao.findDatabaseUserIdFromLogin(strLogin, plugin);
  }

  /**
   * Gets the history of password of the given user
   *
   * @param nUserID Id of the user
   * @param plugin The plugin
   * @return The collection of recent passwords used by the user.
   */
  public static List<String> selectUserPasswordHistory(int nUserID, Plugin plugin) {
    return _dao.selectUserPasswordHistory(nUserID, plugin);
  }

  /**
   * Get the number of password change done by a user since the given date.
   *
   * @param minDate Minimum date to consider.
   * @param nUserId Id of the user
   * @param plugin The plugin
   * @return The number of password change done by the user since the given date.
   */
  public static int countUserPasswordHistoryFromDate(
      Timestamp minDate, int nUserId, Plugin plugin) {
    return _dao.countUserPasswordHistoryFromDate(minDate, nUserId, plugin);
  }

  /**
   * Log a password change in the password history
   *
   * @param strPassword New password of the user
   * @param nUserId Id of the user
   * @param plugin The plugin
   */
  public static void insertNewPasswordInHistory(String strPassword, int nUserId, Plugin plugin) {
    _dao.insertNewPasswordInHistory(strPassword, nUserId, plugin);
  }

  /**
   * Remove every password saved in the password history for a user.
   *
   * @param nUserId Id of the user
   * @param plugin The plugin
   */
  public static void removeAllPasswordHistoryForUser(int nUserId, Plugin plugin) {
    _dao.removeAllPasswordHistoryForUser(nUserId, plugin);
  }

  /**
   * Get the list of id of user with the expired status.
   *
   * @param plugin The plugin
   * @return The list of id of user with the expired status.
   */
  public static List<Integer> findAllExpiredUserId(Plugin plugin) {
    return _dao.findAllExpiredUserId(plugin);
  }

  /**
   * Get the list of id of users that have an expired time life but not the expired status
   *
   * @param currentTimestamp Timestamp describing the current time.
   * @param plugin The plugin
   * @return the list of id of users with expired time life
   */
  public static List<Integer> getIdUsersWithExpiredLifeTimeList(
      Timestamp currentTimestamp, Plugin plugin) {
    return _dao.getIdUsersWithExpiredLifeTimeList(currentTimestamp, plugin);
  }

  /**
   * Get the list of id of users that need to receive their first alert
   *
   * @param firstAlertMaxDate The maximum expiration date to send first alert.
   * @param plugin The plugin
   * @return the list of id of users that need to receive their first alert
   */
  public static List<Integer> getIdUsersToSendFirstAlert(
      Timestamp firstAlertMaxDate, Plugin plugin) {
    return _dao.getIdUsersToSendFirstAlert(firstAlertMaxDate, plugin);
  }

  /**
   * Get the list of id of users that need to receive their first alert
   *
   * @param alertMaxDate The maximum date to send alerts.
   * @param timeBetweenAlerts Timestamp describing the time between two alerts.
   * @param maxNumberAlerts Maximum number of alerts to send to a user
   * @param plugin The plugin
   * @return the list of id of users that need to receive their first alert
   */
  public static List<Integer> getIdUsersToSendOtherAlert(
      Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts, Plugin plugin) {
    return _dao.getIdUsersToSendOtherAlert(
        alertMaxDate, timeBetweenAlerts, maxNumberAlerts, plugin);
  }

  /**
   * Get the list of id of users that have an expired password but not the change password flag
   *
   * @param currentTimestamp Timestamp describing the current time.
   * @param plugin The plugin
   * @return the list of id of users with expired passwords
   */
  public static List<Integer> getIdUsersWithExpiredPasswordsList(
      Timestamp currentTimestamp, Plugin plugin) {
    return _dao.getIdUsersWithExpiredPasswordsList(currentTimestamp, plugin);
  }

  /**
   * Update status of a list of user accounts
   *
   * @param listIdUser List of user accounts to update
   * @param nNewStatus New status of the user
   * @param plugin The plugin
   */
  public static void updateUserStatus(List<Integer> listIdUser, int nNewStatus, Plugin plugin) {
    _dao.updateUserStatus(listIdUser, nNewStatus, plugin);
  }

  /**
   * Increment the number of alert send to users by 1
   *
   * @param listIdUser The list of users to update
   * @param plugin The plugin
   */
  public static void updateNbAlert(List<Integer> listIdUser, Plugin plugin) {
    _dao.updateNbAlert(listIdUser, plugin);
  }

  /**
   * Set the "change password" flag of users to true
   *
   * @param listIdUser The list of users to update
   * @param plugin The plugin
   */
  public static void updateChangePassword(List<Integer> listIdUser, Plugin plugin) {
    _dao.updateChangePassword(listIdUser, plugin);
  }

  /**
   * Update the user expiration date with the new values. Also update his alert account to 0
   *
   * @param nIdUser Id of the user to update
   * @param newExpirationDate Id of the user to update
   * @param plugin The plugin
   */
  public static void updateUserExpirationDate(
      int nIdUser, Timestamp newExpirationDate, Plugin plugin) {
    _dao.updateUserExpirationDate(nIdUser, newExpirationDate, plugin);
  }

  /**
   * Get the number of notification send to a user to warn him about the expiration of his account
   *
   * @param nIdUser Id of the user
   * @param plugin The plugin
   * @return The number of notification send to the user
   */
  public static int getNbAccountLifeTimeNotification(int nIdUser, Plugin plugin) {
    return _dao.getNbAccountLifeTimeNotification(nIdUser, plugin);
  }

  /**
   * Update a user last login date
   *
   * @param strLogin Login of the user to update
   * @param dateLastLogin date of the last login of the user
   * @param plugin The plugin
   */
  public static void updateUserLastLoginDate(String strLogin, Date dateLastLogin, Plugin plugin) {
    _dao.updateUserLastLoginDate(strLogin, new java.sql.Timestamp(dateLastLogin.getTime()), plugin);
  }
}
 /**
  * Get the instance of the service
  *
  * @return the instance of the service
  */
 public static DirectoryParameterService getService() {
   return SpringContextService.getBean(BEAN_DIRECTORY_PARAMETER_SERVICE);
 }
Esempio n. 11
0
  /**
   * Returns the mail queue
   *
   * @return the mail queue
   */
  public static IMailQueue getQueue() {
    IMailQueue queue = (IMailQueue) SpringContextService.getBean(BEAN_MAIL_QUEUE);

    return queue;
  }