Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:app.service.AuthService.java

License:Apache License

public String checkIfAuthBind(CryptoToken cryptoToken) {
    AccountSession expireSession = getSessionWithCheck(cryptoToken, true);
    if (expireSession == null) {
        return null;
    }/*from   w  w  w . j av  a2s  . c o m*/

    DateTime now = DateTime.now();
    DateTime deadline = new DateTime(expireSession.getExpireTime());
    if (now.isBefore(deadline) || now.isEqual(deadline)) {
        return expireSession.getUserId();
    }

    return null;
}

From source file:app.service.AuthService.java

License:Apache License

public int refreshExpireToken(CryptoToken cryptoToken, AccessResponse accessResponse) {
    AccountSession refreshSession = getSessionWithCheck(cryptoToken, false);
    if (refreshSession == null) {
        return ResultCode.INVALID_TOKEN;
    }//ww  w  .  java2  s .c  om

    // ? refreshToken
    DateTime now = DateTime.now();
    DateTime deadline = new DateTime(refreshSession.getRefreshTime());
    if (now.isAfter(deadline)) {
        return ResultCode.OVERDUE_TOKEN;
    }

    //  expireToken
    final long expireTime = now.plusHours(EXPIRE_TIME).getMillis();
    refreshSession.setExpireTime(expireTime);
    CryptoToken expireToken = newSessionToken(refreshSession, true);
    if (expireToken == null) {
        return ResultCode.ENCRYPT_TOKEN_FAILED;
    }

    accessResponse.setExpireTime(expireTime);
    accessResponse.setExpireToken(expireToken);
    return BaseResponse.COMMON_SUCCESS;
}

From source file:app.service.AuthService.java

License:Apache License

protected int refreshAccessResponse(String userId, AccessResponse accessResponse) {
    DateTime now = DateTime.now();
    final long expireTime = now.plusHours(EXPIRE_TIME).getMillis();
    final long refreshTime = now.plusDays(REFRESH_TIME).getMillis();

    AccountSession session = new AccountSession();
    session.setUserId(userId);//w w w.j a  va2s .  c o  m
    session.setExpireTime(expireTime);
    session.setRefreshTime(refreshTime);

    CryptoToken expireToken = newSessionToken(session, true);
    if (expireToken == null) {
        return ResultCode.ENCRYPT_TOKEN_FAILED;
    }

    CryptoToken refreshToken = newSessionToken(session, false);
    if (refreshToken == null) {
        return ResultCode.ENCRYPT_TOKEN_FAILED;
    }

    accessResponse.setExpireTime(expireTime);
    accessResponse.setExpireToken(expireToken);
    accessResponse.setRefreshTime(refreshTime);
    accessResponse.setRefreshToken(refreshToken);
    return BaseResponse.COMMON_SUCCESS;
}

From source file:app.service.CollectionService.java

License:Apache License

@Transactional
public void postCollection(String uid, Collection col) {
    // region: update collection
    User user = prepareUser(uid);//from  w w w.j  ava 2 s .  c  o  m
    col.setUser(user);

    Link link = prepareAndSaveLink(col.getLink());
    col.setLink(link);

    Collection old = mColRepo.findOneByUserAndLink(user, link);
    if (old == null) {
        col.setCreateDate(DateTime.now().toDate());
    } else {
        col.setId(old.getId());
        col.setCreateDate(old.getCreateDate());
    }
    col.setUpdateDate(DateTime.now().toDate());
    mColRepo.save(col);
    // endregion

    // region: update collection binding
    mColBindingRepo.updateTags(col.getId(), col.getTags());
    CollectionBinding.Data favor = new CollectionBinding.Data();
    favor.uid = uid;
    favor.date = DateTime.now().toDate();
    mColBindingRepo.addFavor(col.getId(), uid, favor);
    // endregion
}

From source file:app.service.PinService.java

License:Apache License

public int updatePin(String uid, List<PinData> pinDatas) {
    if (pinDatas.size() > PIN_LIMIT) {
        return ResultCode.PIN_DATA_TOO_MUCH;
    }/*  ww  w  .  j  av a2 s  .  c o m*/

    // get old pin-data' id
    User user = new User();
    user.setUid(uid);
    Pin old = mPinRepo.findByUser(user);

    List<Long> ids = new ArrayList<>(5);
    if (old != null && !StringUtils.isEmpty(old.getPins())) {
        try {
            String pins = old.getPins();
            List<PinData> list = mObjectMapper.readValue(pins, new TypeReference<List<PinData>>() {
            });
            for (PinData pinData : list) {
                long colId = pinData.getCollection().getId();
                ids.add(colId);
            }
        } catch (IOException e) {
            // for writing, ignore because we will overwrite it
            logger.info("parse list-pinData -> object failure", e);
        }
    }

    // prepare new pin-data
    for (PinData pinData : pinDatas) {
        long id = pinData.getCollection().getId();
        if (!mColService.isExistCollection(id)) {
            return ResultCode.COLLECTION_NOT_EXIST;
        }
        Collection collection = new Collection();
        collection.setId(id);
        pinData.setCollection(collection);

        // update pin-data' Date
        if (!ids.contains(id)) {
            pinData.setPinDate(DateTime.now().toDate());
        }
    }

    try {
        String json = mObjectMapper.writeValueAsString(pinDatas);
        Pin pin = new Pin();
        pin.setUser(user);
        pin.setPins(json);
        if (old != null) {
            pin.setId(old.getId());
        }
        mPinRepo.save(pin);
    } catch (JsonProcessingException e) {
        logger.info("parse list-pinData -> string failure", e);
        return ResultCode.PARSE_PIN_DATA_FAILED;
    }

    return BaseResponse.COMMON_SUCCESS;
}

From source file:ar.laboratorio.software.jbom.domain.JBomCore.java

public void comenzarJuego() {
    jBomGUI.mostrarMensaje("Todo listo, comenzando el juego");
    startTime = DateTime.now();
    endTime = startTime.plusMinutes(/*from w  w  w  .  j  a  v  a2 s  .com*/
            Integer.valueOf(jBomGUI.getPantallaInicial().getInputTiempoDeJuego().getText().split(":")[0]));
    jBomGUI.getPantallaJuego().getTiempoDeJuego().setText(startTime.toString("mm:ss"));
    jBomGUI.getPantallaJuego().setNumeroDeRonda(currentRound);
    this.setUserWithBomb();
    jBomCoreState.changeState();
}

From source file:ar.laboratorio.software.jbom.domain.JBomCore.java

public void comenzarContadorNuevaRonda() {
    jBomGUI.mostrarMensaje("Nueva Ronda");
    startTime = DateTime.now();
    endTime = startTime.plusMinutes(//w w w  . j  a  v  a 2 s  .  c  o  m
            Integer.valueOf(jBomGUI.getPantallaInicial().getInputTiempoDeJuego().getText().split(":")[0]));
    jBomGUI.getPantallaJuego().setNumeroDeRonda(currentRound);
    this.setUserWithBomb();
}

From source file:ar.laboratorio.software.jbom.domain.JBomCore.java

public void comenzarNuevaRonda() {
    jBomGUI.mostrarMensaje("Ronda finalizada");
    startTime = DateTime.now();
    endTime = startTime.plusSeconds(10);
    jBomGUI.getPantallaJuego().getTiempoDeJuego().setText(startTime.toString("mm:ss"));
    jBomGUI.getPantallaJuego().setNumeroDeRonda(currentRound);
    this.explodeBoom();
}

From source file:ar.laboratorio.software.jbom.domain.JBomCore.java

public void updatePlaying() {
    currentTime = DateTime.now();
    jBomGUI.getPantallaJuego().getTiempoDeJuego()
            .setText(endTime.minus(currentTime.getMillis()).toString("mm:ss"));
    if (endTime.minus(currentTime.getMillis()).getMillis() <= 0.0)
        jBomCoreState.changeState();//www.  j  av a2s  .  co  m
}

From source file:ar.laboratorio.software.jbom.domain.JBomCore.java

public void updateWaitingNewRound() {
    currentTime = DateTime.now();
    jBomGUI.getPantallaJuego().getTiempoDeJuego()
            .setText(endTime.minus(currentTime.getMillis()).toString("mm:ss"));
    if (endTime.minus(currentTime.getMillis()).getMillis() <= 0.0)
        jBomCoreState.changeState();//www .  ja  va  2 s .c o m
}