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.github.tetravex_android.data.HiScoreManager.java

License:Open Source License

/**
 * Add a new score to the high scores database
 * @param boardSize the size of the game board in [2..5]
 * @param elapsed the time retrieved from the Chronometer view
 *//*from   ww w  . jav a 2s .  c om*/
public void addScore(int boardSize, String elapsed) {
    Score achievedScore = new Score(boardSize, elapsed, DateTime.now());

    // update the DB on a separate thread
    this.execute(achievedScore);
}

From source file:com.github.vase4kin.teamcityapp.utils.DateUtils.java

License:Apache License

/**
 * Parse date/*from www . j a v  a2  s. c  om*/
 *
 * @param date - Date to parse
 * @return Date
 */
private static Date parseDate(String date) {
    SimpleDateFormat df = DateUtils.getSimpleDateFormat(DATE_PARSE_PATTERN);
    try {
        return df.parse(date);
    } catch (ParseException e) {
        // Just return today time
        return DateTime.now().toDate();
    }
}

From source file:com.github.wxiaoqi.oss.cloud.CloudStorageService.java

License:Open Source License

/**
 * //w  ww  . j a  va 2s.  com
 * @param prefix ?
 * @param suffix ?
 * @return 
 */
public String getPath(String prefix, String suffix) {
    //?uuid
    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    //
    String path = DateTime.now().toString("yyyyMMdd") + "/" + uuid;
    if (StringUtils.isNotBlank(prefix)) {
        path = prefix + "/" + path;
    }

    return path + suffix;
}

From source file:com.github.xdev.MigrationsPluginMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    getLog().info("Migrations location is " + migrationsDirectory.getAbsolutePath());
    if (!migrationsDirectory.exists()) {
        getLog().info("Migrations location not found. Creating migrations directory");
        migrationsDirectory.mkdirs();/*www  .  ja v  a 2s .  c  o  m*/
    }

    name = name.replaceAll("\\s", "_").toLowerCase();
    String timeStamp = DateTime.now().toString(VERSION_PATTERN);
    String migrationName = MessageFormat.format(FLYWAY_DB_MIGRATION_PATTERN, timeStamp, name);
    getLog().info("Creating new migration: " + migrationName);

    FileWriter writer = null;
    try {
        File migration = new File(migrationsDirectory, migrationName);
        writer = new FileWriter(migration);
        //Write name comment
        writer.write("# " + name);

        getLog().info("Migration created " + migration.getAbsolutePath());
    } catch (IOException ex) {
        throw new MojoExecutionException("Error creating new migration file", ex);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ex) {
                //Ignore
            }
        }
    }
}

From source file:com.gooddata.warehouse.WarehouseServiceIT.java

License:Open Source License

@BeforeClass
public void setUp() throws Exception {
    pollingTask = readObjectFromResource(TASK_POLL, WarehouseTask.class);
    finishedTask = readObjectFromResource(TASK_DONE, WarehouseTask.class);
    warehouse = readObjectFromResource(WAREHOUSE, Warehouse.class);
    warehouseSchema = readObjectFromResource(WAREHOUSE_SCHEMA, WarehouseSchema.class);
    s3Credentials = new WarehouseS3Credentials(REGION, ACCESS_KEY, SECRET_KEY);
    s3CredentialsWithLinks = new WarehouseS3Credentials(REGION, ACCESS_KEY, SECRET_KEY, DateTime.now(), LINKS);
}

From source file:com.goodhuddle.huddle.domain.Petition.java

License:Open Source License

public Petition(Huddle huddle, String name, String description, String subject, String content,
        String petitionEmailTemplate, String thankyouEmailTemplate, String adminEmailAddresses,
        String adminEmailTemplate, Member createdBy) {
    super(huddle);
    this.name = name;
    this.description = description;
    this.subject = subject;
    this.content = content;
    this.petitionEmailTemplate = petitionEmailTemplate;
    this.thankyouEmailTemplate = thankyouEmailTemplate;
    this.adminEmailAddresses = adminEmailAddresses;
    this.adminEmailTemplate = adminEmailTemplate;
    this.createdBy = createdBy;
    this.createdOn = DateTime.now();
}

From source file:com.goodhuddle.huddle.domain.Subscription.java

License:Open Source License

public void setCancelled(Member cancelledBy) {
    this.status = SubscriptionStatus.cancelled;
    this.cancelledBy = cancelledBy;
    this.cancelledOn = DateTime.now();
}

From source file:com.goodhuddle.huddle.service.impl.BlogServiceImpl.java

License:Open Source License

@Override
public BlogPostComment postComment(PostCommentRequest request)
        throws CommentsNotAllowedException, CommentsClosedException, CommentsByMembersOnlyException {

    Huddle huddle = huddleService.getHuddle();
    BlogPost blogPost = blogPostRepository.findByHuddleAndId(huddle, request.getBlogPostId());

    if (!blogPost.isCommentsOpen()) {
        throw new CommentsClosedException("Comments have been closed for blog '" + blogPost.getSlug() + "'");
    }//w  w  w . j av  a2s  . c  om

    Blog blog = blogPost.getBlog();

    Member member = null;

    switch (blog.getAllowComments()) {
    case members:
        if (member == null) {
            throw new CommentsByMembersOnlyException(
                    "Only members can comment on blog '" + blog.getSlug() + "'");
        }
        break;
    case none:
        throw new CommentsNotAllowedException("Comments are not allowed for blog '" + blog.getSlug() + "'");
    }

    boolean approved;
    switch (blog.getRequireCommentApproval()) {
    case none:
        approved = true;
        break;
    case anonymous:
        approved = (member != null);
        break;
    case all:
        approved = false;
        break;
    default:
        throw new IllegalArgumentException(
                "Unsupported comment approval type: " + blog.getRequireCommentApproval());
    }

    BlogPostComment comment = blogPostCommentRepository.save(new BlogPostComment(huddle, blogPost, member,
            DateTime.now(), request.getDisplayName(), request.getComment(), approved));
    log.info("New comment added to blog post '{}' with ID {}", blogPost.getSlug(), comment.getId());
    return comment;
}

From source file:com.goodhuddle.huddle.service.impl.MemberServiceImpl.java

License:Open Source License

@Override
@Transactional(readOnly = false)//  w  w w .j a v a  2  s .c om
public void sendPasswordResetEmail(ForgotPasswordRequest request)
        throws NoSuchMemberException, ResetPasswordFailedException, EmailsNotSetupException {

    Member member = memberRepository.findByHuddleAndEmailIgnoreCase(huddleService.getHuddle(),
            request.getEmail());
    if (member != null) {

        String resetCode = UUID.randomUUID().toString();
        member.setPasswordResetCode(resetCode);
        DateTime expiry = DateTime.now().plusDays(1);
        member.setPasswordResetExpiry(expiry);
        memberRepository.save(member);

        Huddle huddle = huddleService.getHuddle();

        String message = "<p>Hi " + member.getDisplayName() + ",</p>"
                + "<p>We received a request to reset your password for your GoodHuddle account for '"
                + huddle.getName() + "'."
                + " If this request was from you, please follow this link to set a new password:</p>"
                + "<ul><li><a href='" + huddle.getBaseUrl() + "/admin/reset/" + resetCode + "'>"
                + huddle.getBaseUrl() + "/admin/reset/" + resetCode + "</a></li></ul>"
                + "<p>If this request was not from you, please ignore this email.</p>"
                + "<p>If you have any questions or problems, please contact us at info@goodhuddle.com</p>"
                + "<p>Kind regards,<br/> The GoodHuddle Team<br/><a href='http://goodhuddle.com'>http://goodhuddle.com</a></p>";

        try {

            emailSender.sendEmail(member.getEmail(), member.getDisplayName(),
                    "Password reset for " + huddle.getName(), message, Arrays.asList(""));

        } catch (IOException | MandrillApiError e) {
            throw new ResetPasswordFailedException(
                    "Unable to send reset password email to: " + member.getEmail(), e);
        }

    } else {
        throw new NoSuchMemberException("No member found for email: " + request.getEmail());
    }
}

From source file:com.goodhuddle.huddle.service.impl.security.LoginSuccessHandler.java

License:Open Source License

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {

    Member member = securityHelper.getCurrentMember();
    member.setLastLogin(DateTime.now());
    member.setLoginAttempts(0);//from   w  ww.  j a  v a  2s  . c  o  m
    memberRepository.save(member);

    super.onAuthenticationSuccess(request, response, authentication);
}