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:com.framework.reporter.ScenarioListenerAdapter.java

License:MIT License

/**
 * Invoked after the test class is instantiated and before any configuration method is called.
 *///from  w  w  w .  j  a v a 2s  .  c o m
@Override
public void onStart(final ITestContext testContext) {
    logger.info(TextArt.getTestStart(testContext.getName()));

    TestContext testContextManager = new TestContext(DateTime.now(), testContext,
            scenarioManager.getCurrentSuite());
    scenarioManager.pushTestContext(testContextManager);
    logger.debug("new Test-Context manager created -> {}", testContextManager);

    final String MSG = "Configurations were uploaded successfully. current configuration is -> < '{}' >";
    logger.info(MSG, Configurations.getInstance().toString());
}

From source file:com.freedomotic.plugins.devices.twilight.Twilight.java

License:Open Source License

@Override
protected void onRun() {
    EventTemplate ev = TLU.prepareEvent(DateTime.now());
    LOG.info(ev.getPayload().toString().replace("\n", " "));
    notifyEvent(ev);//from   w  ww  .j  av a 2 s  .  c o  m

}

From source file:com.fusesource.examples.horo.web.HoroscopeService.java

License:Apache License

private List<Horoscope> getHoroscopes(StarSign starSign) {
    Horoscope horoscope = new Horoscope();
    horoscope.setEntry("Your future has cake");
    horoscope.setPredictsFor(DateTime.now());
    horoscope.setStarSign(starSign);/* ww w  .j  ava2  s.co m*/
    Feed feed = new Feed();
    feed.setName("com.astrology");
    horoscope.setFeed(feed);

    List<Horoscope> horoscopes = new ArrayList<Horoscope>();
    horoscopes.add(horoscope);
    // and again
    horoscopes.add(horoscope);
    return horoscopes;
}

From source file:com.garethahealy.duneworld.sandworms.services.SandwormService.java

License:Apache License

public SandwormService(ArrakisService arrakisService) {
    this.arrakisService = arrakisService;
    this.worms = new ArrayList<Sandworm>();
    this.wormSelectorRand = new Random(DateTime.now().getMillis());
}

From source file:com.getperka.client.AuthUtils.java

License:Apache License

private void executeTokenRequest(String payload) throws IOException, StatusCodeException {
    TokenRequest req = new TokenRequest(api, payload);
    JsonElement elt = req.execute();//from ww  w . j av  a 2  s. c  o m
    if (elt != null && elt.isJsonObject()) {
        JsonObject obj = elt.getAsJsonObject();

        int statusCode = obj.get("status_code").getAsInt();
        if (200 != statusCode) {
            StatusCodeException sce = new StatusCodeException(statusCode, null);
            sce.setJsonElement(obj);
            throw sce;
        }

        String expires = getOrNull(obj, "expires_in");
        if (expires != null) {
            setAccessExpiration(DateTime.now().plusSeconds(Integer.valueOf(expires)));
        }
        setAccessToken(getOrNull(obj, "access_token"));
        setRefreshToken(getOrNull(obj, "refresh_token"));
        String uuid = getOrNull(obj, "uuid");
        if (uuid != null) {
            setUserUuid(UUID.fromString(uuid));
        }
    }
}

From source file:com.github.blacklocus.rdsecho.EchoNew.java

License:Open Source License

@Override
public Boolean call() throws Exception {

    // Do some sanity checks to make sure we aren't generating a bunch of trouble in RDS

    String tagEchoManaged = echo.getTagEchoManaged();

    LOG.info("Checking to see if current echo-created instance (tagged {}) was created less than 24 hours ago. "
            + "If so this operation will not continue.", tagEchoManaged);
    Optional<DBInstance> newestInstanceOpt = echo.lastEchoInstance();
    if (newestInstanceOpt.isPresent()) {

        if (new DateTime(newestInstanceOpt.get().getInstanceCreateTime()).plusHours(24)
                .isAfter(DateTime.now())) {
            LOG.info("  Last echo-created RDS instance {} was created less than 24 hours ago. Aborting.",
                    tagEchoManaged);//from w w  w  . j  ava  2 s.  com
            return false;

        } else {
            LOG.info("  Last echo-created RDS instance {} was created more than 24 hours ago. Proceeding.",
                    tagEchoManaged);
        }

    } else {
        LOG.info("  No prior echo-created instance found with tag {}. Proceeding.", tagEchoManaged);
    }

    // Locate a suitable snapshot to be the basis of the new instance

    LOG.info("Locating latest snapshot from {}", cfg.snapshotDbInstanceIdentifier());
    Optional<DBSnapshot> dbSnapshotOpt = echo.latestSnapshot();
    if (dbSnapshotOpt.isPresent()) {
        DBSnapshot snapshot = dbSnapshotOpt.get();
        LOG.info("  Located snapshot {} completed on {}", snapshot.getDBSnapshotIdentifier(),
                new DateTime(snapshot.getSnapshotCreateTime()).toDateTimeISO().toString());

    } else {
        LOG.info("  Could not locate a suitable snapshot. Cannot continue.");
        return false;
    }

    // Info summary

    String dbSnapshotIdentifier = dbSnapshotOpt.get().getDBSnapshotIdentifier();
    String newDbInstanceIdentifier = cfg.name() + '-' + DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd");
    LOG.info(
            "Proposed new db instance...\n" + "  engine           : {}\n" + "  license model    : {}\n"
                    + "  db instance class: {}\n" + "  multi az         : {}\n" + "  storage type     : {}\n"
                    + "  iops             : {}\n" + "  db snapshot id   : {}\n" + "  db instance id   : {}\n"
                    + "  port             : {}\n" + "  option group name: {}\n" + "  auto minor ver up: {}",
            cfg.newEngine(), cfg.newLicenseModel(), cfg.newDbInstanceClass(), cfg.newMultiAz(),
            cfg.newStorageType(), cfg.newIops(), dbSnapshotIdentifier, newDbInstanceIdentifier, cfg.newPort(),
            cfg.newOptionGroupName(), cfg.newAutoMinorVersionUpgrade());

    // Interactive user confirmation

    if (cfg.interactive()) {
        String format = "Proceed to create a new DB instance from this snapshot? Input %s to confirm.";
        if (!EchoUtil.prompt(newDbInstanceIdentifier, format, newDbInstanceIdentifier)) {
            LOG.info("User declined to proceed. Exiting.");
            return false;
        }
    }

    // Create the new database

    LOG.info("Creating new DB instance. Hold on to your butts.");
    RestoreDBInstanceFromDBSnapshotRequest request = new RestoreDBInstanceFromDBSnapshotRequest()
            .withEngine(cfg.newEngine()).withLicenseModel(cfg.newLicenseModel())
            .withDBInstanceClass(cfg.newDbInstanceClass()).withMultiAZ(cfg.newMultiAz())
            .withStorageType(cfg.newStorageType()).withIops(cfg.newIops())
            .withDBSnapshotIdentifier(dbSnapshotIdentifier).withDBInstanceIdentifier(newDbInstanceIdentifier)
            .withPort(cfg.newPort()).withOptionGroupName(cfg.newOptionGroupName())
            .withAutoMinorVersionUpgrade(cfg.newAutoMinorVersionUpgrade())
            .withTags(new Tag().withKey(echo.getTagEchoManaged()).withValue("true"),
                    new Tag().withKey(echo.getTagEchoStage()).withValue(EchoConst.STAGE_NEW));
    DBInstance restoredInstance = rds.restoreDBInstanceFromDBSnapshot(request);

    Optional<String[]> newTags = cfg.newTags();
    if (newTags.isPresent()) {
        List<Tag> tags = EchoUtil.parseTags(newTags.get());
        if (tags.size() > 0) {
            LOG.info("Applying tags on create new: {}", Arrays.asList(tags));
            AddTagsToResourceRequest tagsRequest = new AddTagsToResourceRequest()
                    .withResourceName(RdsFind.instanceArn(cfg.region(), cfg.accountNumber(),
                            restoredInstance.getDBInstanceIdentifier()));
            tagsRequest.setTags(tags);
            rds.addTagsToResource(tagsRequest);
        }
    }

    LOG.info("Created new DB instance. \n"
            + "  https://console.aws.amazon.com/rds/home?region={}#dbinstance:id={}\n"
            + "Additional preparation of the instance will continue once the instance becomes available.",
            cfg.region(), newDbInstanceIdentifier);

    return true;
}

From source file:com.github.cherimojava.orchidae.controller.LayoutController.java

License:Apache License

private ResponseEntity registerUser(HttpServletRequest request) {
    // TODO send messages out if something isn't right
    if (StringUtils.isEmpty(request.getParameter("username"))) {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }/*from   w w  w  . j  a  va2  s  .  c  om*/
    if (factory.load(User.class, request.getParameter("username")) != null) {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
    String pwd = request.getParameter("password");
    if (StringUtils.isNotEmpty(pwd) && pwd.equals(request.getParameter("password2"))) {
        User newUser = factory.create(User.class);
        newUser.setMemberSince(DateTime.now());
        newUser.setUsername(request.getParameter("username"));
        newUser.setPassword(pwEncoder.encode(pwd));
        newUser.setPictureCount(new AtomicInteger(0));
        newUser.save();
    }
    return new ResponseEntity(HttpStatus.NO_CONTENT);
}

From source file:com.github.cherimojava.orchidae.controller.PictureController.java

License:Apache License

/**
 * check if batching should be applied to the current picture upload
 * //from   w  ww .  j  a v  a 2s.  c  o m
 * @param pic
 * @param batchId
 */
private void checkBatch(Picture pic, String batchId) {
    if (StringUtils.isNotEmpty(batchId)) {
        if (!FileUtil.validateId(batchId)) {
            // ignore the batching if the id isn't valid
            return;
        }
        BatchUpload batch = factory.load(BatchUpload.class, batchId);
        // if the batch doesn't exist, create it
        if (batch == null) {
            batch = factory.create(BatchUpload.class);
            batch.setUploadDate(DateTime.now()).setId(batchId);
        }
        batch.addPictures(pic);
        pic.setBatchUpload(batch);
        batch.save();
    }
}

From source file:com.github.cherimojava.orchidae.hook.BasePictureInformationUploadHook.java

License:Apache License

@Override
public void upload(UploadInfo ui) {
    Picture picture = ui.pictureUploaded;
    picture.setUser(ui.uploadingUser);//www.  ja  v  a  2  s  . c  om
    picture.setTitle(StringUtils.split(ui.uploadedFile.getOriginalFilename(), ".")[0]);
    picture.setOriginalName(ui.uploadedFile.getOriginalFilename());
    picture.setUploadDate(DateTime.now());
    picture.setOrder(ui.uploadingUser.getPictureCount().incrementAndGet());
    picture.setAccess(Access.PRIVATE);// TODO for now only private access
    // read some some properties from picture
    picture.setHeight(ui.storedImage.getHeight());
    picture.setWidth(ui.storedImage.getWidth());
}

From source file:com.github.ibole.infrastructure.security.jwt.auth0.Auth0Utils.java

License:Apache License

public static String createJwtWithECKey(JwtObject claimObj, ECPublicKey publicKey, ECPrivateKey privateKey)
        throws TokenHandlingException {
    checkArgument(claimObj != null, "JwtObject cannot be null!");
    String[] roleArray = new String[claimObj.getRoles().size()];
    claimObj.getRoles().toArray(roleArray);
    String token = null;/*from ww w .j  a va 2  s.  c  o  m*/
    try {
        token = JWT.create().withSubject(claimObj.getSubject()).withAudience(claimObj.getAudience())
                .withIssuer(claimObj.getIssuer()).withArrayClaim(JwtConstant.ROLE_ID, roleArray)
                .withClaim(JwtConstant.CLIENT_ID, claimObj.getClientId())
                .withClaim(JwtConstant.LOGIN_ID, claimObj.getLoginId())
                .withExpiresAt(DateTime.now().plusSeconds(claimObj.getTtlSeconds()).toDate())
                .sign(Algorithm.ECDSA256(publicKey, privateKey));
    } catch (IllegalArgumentException | JWTCreationException ex) {
        throw new TokenHandlingException(ex);
    }
    return token;
}