Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixes for comparing date types #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.tennaito</groupId>
<artifactId>rsql-jpa</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.5-SNAPSHOT</version>
<packaging>jar</packaging>

<!--//////////////////// ABOUT ////////////////////-->
Expand Down
585 changes: 334 additions & 251 deletions src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -72,6 +73,7 @@ public <T> T parse(String argument, Class<T> type)
if (type.equals(Float.class) || type.equals(float.class)) return (T) Float.valueOf(argument);
if (type.equals(Double.class) || type.equals(double.class)) return (T) Double.valueOf(argument);
if (type.equals(Long.class) || type.equals(long.class)) return (T) Long.valueOf(argument);
if (type.equals(BigDecimal.class)) return (T) new BigDecimal(argument);
} catch (IllegalArgumentException ex) {
throw new ArgumentFormatException(argument, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class SimpleMapper implements Mapper {

private static final Logger LOG = Logger.getLogger(DefaultArgumentParser.class.getName());
private static final Logger LOG = Logger.getLogger(SimpleMapper.class.getName());

private Map<Class<?>, Map<String, String>> mapping;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.github.tennaito.rsql.jpa;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -34,6 +36,7 @@
import com.github.tennaito.rsql.jpa.entity.CourseDetails;
import com.github.tennaito.rsql.jpa.entity.Department;
import com.github.tennaito.rsql.jpa.entity.Person;
import com.github.tennaito.rsql.jpa.entity.Teacher;
import com.github.tennaito.rsql.jpa.entity.Title;

/**
Expand Down Expand Up @@ -81,14 +84,27 @@ public static void setUpBefore() throws Exception {
department.setHead(head);
entityManager.persist(department);

Teacher teacher = new Teacher();
teacher.setId(23L);
teacher.setSpecialtyDescription("Maths");
entityManager.persist(teacher);

Course c = new Course();
c.setId(1L);
c.setCode("MI-MDW");
c.setActive(true);
c.setCredits(10);
c.setName("Testing Course");
c.setDepartment(department);
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR_OF_DAY);
cal.clear(Calendar.AM_PM);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
c.setDate(cal.getTime());
c.setDetails(CourseDetails.of("test"));
c.getDetails().setTeacher(teacher);
entityManager.persist(c);

entityManager.getTransaction().commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.util.Date;
import java.util.GregorianCalendar;

Expand Down Expand Up @@ -143,6 +144,11 @@ public void testParseArgument() throws Exception {
assertEquals(Date.class, e.getPropertyType());
}

argument = "1235.2232";
expected = new BigDecimal("1235.2232");
actual = instance.parse(argument, BigDecimal.class);
assertEquals(expected, actual);

argument = "foo";
expected = new MockValueOfType();
actual = instance.parse(argument, MockValueOfType.class);
Expand Down
Loading