Example usage for org.apache.commons.lang.time DateUtils addMinutes

List of usage examples for org.apache.commons.lang.time DateUtils addMinutes

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils addMinutes.

Prototype

public static Date addMinutes(Date date, int amount) 

Source Link

Document

Adds a number of minutes to a date returning a new object.

Usage

From source file:com.hs.mail.imap.schedule.ScheduleUtils.java

public static Date getTimeAfter(String str, Date defaultTime) {
    if (str != null) {
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            char ch = str.charAt(i);
            if (!Character.isDigit(ch)) {
                try {
                    int amount = Integer.parseInt(str.substring(0, i));
                    switch (Character.toUpperCase(ch)) {
                    case 'H':
                        return DateUtils.addHours(new Date(), amount);
                    case 'M':
                        return DateUtils.addMinutes(new Date(), amount);
                    }//from   w  ww.  j  a  va2 s .  c  o m
                } catch (NumberFormatException e) {
                    break;
                }
            }
        }
    }
    return defaultTime;
}

From source file:ch.ksfx.model.AssetPricingTimeRange.java

@Transient
public Date getStartDate() {
    if (name.equalsIgnoreCase("max")) {
        return new Date(0l);
    }/*  w  w  w  .jav  a2 s .c om*/

    Date fromDate = new Date();

    if (offsetMin == 0) {
        fromDate = DateUtils.setMinutes(fromDate, 0);
        fromDate = DateUtils.setSeconds(fromDate, 0);
        fromDate = DateUtils.setHours(fromDate, 0);
    } else {
        fromDate = DateUtils.addMinutes(fromDate, offsetMin * -1);
    }

    return fromDate;
}

From source file:cn.vlabs.umt.services.session.impl.SessionServiceImpl.java

public void cleanSession() {
    //??
    Date time = DateUtils.addMinutes(new Date(), -timeOut);
    sd.removeTimeOutSession(time);
}

From source file:cn.vlabs.umt.services.ticket.impl.TicketServiceImpl.java

public void cleanup() {
    Date createTime = DateUtils.addMinutes(new Date(), -(lifetime + 1));//lifetime+1??Ticket
    td.removeBefore(createTime);
}

From source file:hu.holdinarms.authentication.TokenStorage.java

/**
 * Generate new token to the user. The system uses this method when the user makes the first authentication.
 * // ww w .  j av  a2 s  .c  om
 * @param userId The user id.
 * @return 
 */
public static String generateUserToken(Long userId) {
    String tokenValue = UUID.randomUUID().toString();
    Date expirationDate = DateUtils.addMinutes(new Date(), timeExtendedMinutes);
    userTokenHashMap.put(userId, new Token(tokenValue, expirationDate));

    return tokenValue;
}

From source file:cn.vlabs.umt.services.session.impl.LoginRecord.java

public void logout(Date deadline) {
    Date timeout = DateUtils.addMinutes(lastupdate, 30);
    if (timeout.before(deadline)) {
        String sessionkey = sessionkeys.get(appType);
        if (sessionkey != null) {
            GetMethod method = new GetMethod(logoutURL);
            method.setRequestHeader("Connection", "close");
            method.setRequestHeader("Cookie", sessionkey + "=" + appSessionid);
            HttpClient client = new HttpClient();
            try {
                client.executeMethod(method);
            } catch (Exception e) {

            } finally {
                client.getHttpConnectionManager().closeIdleConnections(0);
            }/*ww  w. j av  a  2s  .c om*/
        }
    }
}

From source file:hu.holdinarms.authentication.TokenStorage.java

/**
 * Extend the expiration date of token of the user.
 * // ww  w  .  j a  v  a 2  s .  co  m
 * @param userId The user id.
 */
public static void extendExpirationDate(Long userId) {
    Token token = userTokenHashMap.get(userId);
    token.setExpirationDate(DateUtils.addMinutes(token.getExpirationDate(), timeExtendedMinutes));
}

From source file:eu.domibus.ebms3.common.RetentionWorker.java

private void deleteExpiredMessages() {
    List<String> mpcs = pModeProvider.getMpcList();
    for (String mpc : mpcs) {
        int messageRetentionDownladed = pModeProvider.getRetentionDownloadedByMpcName(mpc);
        if (messageRetentionDownladed > 0) { // if -1 the messages will be kept indefinetely and if 0 it already has been deleted
            List<String> messageIds = messageLogDao.getDownloadedUserMessagesOlderThan(
                    DateUtils.addMinutes(new Date(), messageRetentionDownladed * -1), mpc);
            for (String messageId : messageIds) {
                messagingDao.delete(messageId);
            }//ww w  .  j a  va2 s  . c  om
        }
        int messageRetentionUndownladed = pModeProvider.getRetentionUndownloadedByMpcName(mpc);
        if (messageRetentionUndownladed > -1) { // if -1 the messages will be kept indefinetely and if 0, although it makes no sense, is legal
            List<String> messageIds = messageLogDao.getUndownloadedUserMessagesOlderThan(
                    DateUtils.addMinutes(new Date(), messageRetentionUndownladed * -1), mpc);
            for (String messageId : messageIds) {
                messagingDao.delete(messageId);
            }
        }
    }

}

From source file:br.interactive.ecm.gerais.service.UsuarioService.java

public LoginDTO login(LoginDTO user, HttpServletRequest request) {

    if (!StringUtil.notEmpty(user.getSenha())) {
        throw new BusinessException(new ErrorMessage("seguranca.login.naoencontrado"));
    }/*from   w  w w  .j  a va 2  s  .  c o  m*/

    //        Usuario usua = usuarioDAO.getUsuarioByLoginSenha(user.getLogin(), user.getSenha());
    // FIXME Obter usuario
    Usuario usua = new Usuario();
    Pessoa p = new Pessoa();
    p.setTxNome("Nome do Usuario");
    p.setUsuario(usua);
    usua.setPessoa(p);

    //        this.validarUsuarioParaAutenticacao(usua);
    UserSession userSession = userSessionDAO.getUserSessionLoginBrowserIp(usua.getTxLogin(),
            request.getHeader("user-agent"), request.getRemoteAddr());

    if (userSession != null) {
        userSessionDAO.remove(userSession);
    }

    String token = UUID.randomUUID().toString();
    UserSession session = new UserSession();
    session.setTxLogin(usua.getTxLogin());
    session.setTxToken(token);
    session.setDtStartOrRefreshSession(new Date());
    session.setDtExpiredSession(DateUtils.addMinutes(new Date(), 120));
    session.setTxBrowser(request.getHeader("user-agent"));
    session.setTxIpAdress(request.getRemoteAddr());
    userSessionDAO.persist(session);
    user.sethToken(token);

    usua.setNbTentativas(Short.valueOf("0"));
    usua.setDtDataAcesso(Calendar.getInstance());
    usuarioDAO.merge(usua);

    return user;
}

From source file:cn.vlabs.umt.services.session.impl.SessionServiceImpl.java

public void logout(String appname, String username, String userip, String sid) {
    if (appname != null) {
        Date lastupdate = DateUtils.addMinutes(new Date(), timeOut);
        Collection<LoginRecord> records = null;
        synchronized (sd) {
            records = sd.getAllAppSession(username, userip);
            sd.removeAllSession(username, userip);
        }/*from   w ww.  jav  a 2  s .com*/
        for (LoginRecord record : records) {
            if (!isSameSession(appname, sid, record)) {
                record.logout(lastupdate);
            }
        }
    }
}