Skip to content

Commit

Permalink
closes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Robbins | hybris committed Jan 13, 2016
1 parent 21d0d87 commit b2f0a84
Show file tree
Hide file tree
Showing 26 changed files with 216 additions and 210 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ gen/
gwt-unitCache/
deploy/
classes/
restygwt/
gwt-joda-time/


# Compiled source #
###################
Expand Down
4 changes: 0 additions & 4 deletions FlashCards_Client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;

public class CustomObjectMapper extends ObjectMapper {

public CustomObjectMapper() {

this.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
this.registerModule(new JodaModule());
}

public void setPrettyPrint(final boolean prettyPrint) {
Expand Down
4 changes: 2 additions & 2 deletions FlashCards_Config/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ cassandra.native_transport_port=9042
cassandra.keyspace=flashcardsapp

# Akka properties
jdbc.batchsize=1000
akka.workerCount=20
jdbc.batchsize=10000
akka.workerCount=10
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<custom-converters>
<converter
type="org.robbins.flashcards.repository.util.dozer.DateTimeConverter">
<class-a>org.joda.time.DateTime</class-a>
<class-a>java.time.LocalDateTime</class-a>
<class-b>java.util.Date</class-b>
</converter>
<converter
Expand Down
6 changes: 0 additions & 6 deletions FlashCards_Repository/FlashCards_Repository_Commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
<version>${project.version}</version>
</dependency>

<!-- Joda-Time provides a quality replacement for the Java date and time classes. -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<!-- Dozer for mapping @Entities to DTOs -->
<dependency>
<groupId>net.sf.dozer</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

package org.robbins.flashcards.repository.util.dozer;

import java.time.LocalDateTime;
import java.util.Date;

import org.dozer.CustomConverter;
import org.joda.time.DateTime;
import org.robbins.flashcards.util.DateUtils;
import org.springframework.data.mapping.model.MappingException;

public class DateTimeConverter implements CustomConverter {
Expand All @@ -22,9 +23,9 @@ public Object convert(final Object existingDestinationFieldValue,
if (sourceFieldValue instanceof Date) {
// Note that DateTime is immutable, so
// we can't do much with the existingDestinationFieldValue.
return new DateTime(sourceFieldValue);
} else if (sourceFieldValue instanceof DateTime) {
return ((DateTime) sourceFieldValue).toDate();
return DateUtils.asLocalDateTime((Date)sourceFieldValue);
} else if (sourceFieldValue instanceof LocalDateTime) {
return DateUtils.asDate((LocalDateTime) sourceFieldValue);
}

throw new MappingException("Misconfigured/unsupported mapping");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

package org.robbins.flashcards.repository.util.dozer;

import java.util.UUID;

import org.dozer.CustomConverter;
import org.joda.time.DateTime;
import org.springframework.data.mapping.model.MappingException;

import java.util.Date;
import java.util.UUID;

public class UUIDConverter implements CustomConverter {

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* [y] hybris Platform
*
* Copyright (c) 2000-2016 hybris AG
* All rights reserved.
*
* This software is the confidential and proprietary information of hybris
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with hybris.
*/
package org.robbins.flashcards.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class DateUtils
{
public static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}

public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}

public static LocalDate asLocalDate(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
}

public static LocalDateTime asLocalDateTime(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

package org.robbins.flashcards.jpa.repository;

import org.apache.commons.lang3.NotImplementedException;
import org.joda.time.DateTime;
import org.robbins.flashcards.model.common.AbstractAuditable;
import org.robbins.flashcards.repository.FlashCardsAppRepository;
import org.robbins.flashcards.repository.auditing.AuditingAwareUser;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;

import java.io.Serializable;
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;
import org.robbins.flashcards.model.common.AbstractAuditable;
import org.robbins.flashcards.repository.FlashCardsAppRepository;
import org.robbins.flashcards.repository.auditing.AuditingAwareUser;

public abstract class AbstractCrudRepositoryImpl<T extends AbstractAuditable<Long, ID>, ID extends Serializable>
implements FlashCardsAppRepository<T, ID> {
Expand All @@ -38,12 +38,12 @@ public EntityManager getEm() {
@Override
public T save(final T entity) {
entity.setLastModifiedBy(getAuditingUser());
entity.setLastModifiedDate(new DateTime());
entity.setLastModifiedDate(LocalDateTime.now());

// is it a new entity?
if (entity.getId() == null) {
entity.setCreatedBy(getAuditingUser());
entity.setCreatedDate(new DateTime());
entity.setCreatedDate(LocalDateTime.now());
getEm().persist(entity);
} // must be an update
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

package org.robbins.flashcards.jpa.repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.Query;

import org.joda.time.DateTime;
import org.robbins.flashcards.jpa.repository.util.JpqlUtil;
import org.robbins.flashcards.model.FlashCard;
import org.robbins.flashcards.model.Tag;
Expand All @@ -33,9 +33,9 @@ public FlashCard save(final FlashCard flashCard) {
flashCard.getTags().stream()
.filter(tag -> (tag.getId() == null)).forEach(tag -> {
tag.setCreatedBy(getAuditingUser());
tag.setCreatedDate(new DateTime());
tag.setCreatedDate(LocalDateTime.now());
tag.setLastModifiedBy(getAuditingUser());
tag.setLastModifiedDate(new DateTime());
tag.setLastModifiedDate(LocalDateTime.now());
});
return super.save(flashCard);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
<version>${project.version}</version>
</dependency>

<!-- Joda-Time provides a quality replacement for the Java date and time classes. -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<!-- JDBC Connection pooling -->
<dependency>
<groupId>c3p0</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

package org.robbins.flashcards.model;

import org.joda.time.DateTime;
import org.robbins.flashcards.model.common.AbstractAuditable;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.time.LocalDateTime;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.robbins.flashcards.model.common.AbstractAuditable;

@Entity
@Table(name = "user")
Expand Down Expand Up @@ -39,10 +42,8 @@ public class User extends AbstractAuditable<Long, Long> implements Serializable
@Column(name = "Language")
private String language;

// @JsonSerialize(using = CustomJsonDateSerializer.class)
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LastLoginDate", nullable = true)
private Date lastLoginDate;
private LocalDateTime lastLoginDate;

public User() {
}
Expand Down Expand Up @@ -133,12 +134,12 @@ public void setLanguage(final String language) {
this.language = language;
}

public DateTime getLastLoginDate() {
return null == lastLoginDate ? null : new DateTime(lastLoginDate);
public LocalDateTime getLastLoginDate() {
return lastLoginDate;
}

public void setLastLoginDate(final DateTime lastLoginDate) {
this.lastLoginDate = null == lastLoginDate ? null : lastLoginDate.toDate();
public void setLastLoginDate(final LocalDateTime lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}

@Override
Expand Down
Loading

0 comments on commit b2f0a84

Please sign in to comment.