Skip to content

Commit

Permalink
#47 TransacionService list with filter for createdAt doesn't work.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoloff committed Apr 9, 2014
1 parent c95bcaf commit 97572cc
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 76 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3</version>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/com/paymill/models/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,35 @@ public Client.Filter byOfferId( final String offerId ) {
return this;
}

public Client.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Client.Filter} object with populated filter for createdAt.
*/
public Client.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}

public Client.Filter byUpdatedAt( final Date startUpdatedAt, final Date endUpdatedAt ) {
this.updatedAt = String.valueOf( startUpdatedAt.getTime() ) + "-" + String.valueOf( endUpdatedAt.getTime() );
/**
* Creates filter for updatedAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Client.Filter} object with populated filter for updatedAt.
*/
public Client.Filter byUpdatedAt( final Date date, final Date endDate ) {
this.updatedAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/paymill/models/DateRangeBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.paymill.models;

import java.util.Date;

final class DateRangeBuilder {

private final static int OFFSET = 1000;

final static String execute( final Date startDate, final Date endDate ) {
if( startDate == null )
throw new IllegalArgumentException( "Start date can not be null" );

String range = String.valueOf( startDate.getTime() / DateRangeBuilder.OFFSET );
if( endDate != null ) {
range += "-" + String.valueOf( endDate.getTime() / DateRangeBuilder.OFFSET );
}

return range;
}

}
30 changes: 26 additions & 4 deletions src/main/java/com/paymill/models/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,35 @@ public Offer.Filter byAmountLessThan( final int amount ) {
return this;
}

public Offer.Filter byCreatedAt( Date startCreatedAt, Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Offer.Filter} object with populated filter for createdAt.
*/
public Offer.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}

public Offer.Filter byUpdatedAt( Date startUpdatedAt, Date endUpdatedAt ) {
this.updatedAt = String.valueOf( startUpdatedAt.getTime() ) + "-" + String.valueOf( endUpdatedAt.getTime() );
/**
* Creates filter for updatedAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Offer.Filter} object with populated filter for updatedAt.
*/
public Offer.Filter byUpdatedAt( Date date, Date endDate ) {
this.updatedAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/paymill/models/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand Down Expand Up @@ -423,8 +424,19 @@ public Payment.Filter byCardType( final Payment.CardType cardType ) {
return this;
}

public Payment.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Payment.Filter} object with populated filter for createdAt.
*/
public Payment.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/paymill/models/Preauthorization.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand All @@ -183,7 +184,8 @@ public void setUpdatedAt( final Date updatedAt ) {
* Last update representation is seconds.
*/
public void setUpdatedAt( final long seconds ) {
this.updatedAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.updatedAt = new Date( seconds * 1000 );
}

public enum Status {
Expand Down Expand Up @@ -262,8 +264,19 @@ public Preauthorization.Filter byAmountLessThan( final int amount ) {
return this;
}

public Preauthorization.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Preauthorization.Filter} object with populated filter for createdAt.
*/
public Preauthorization.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/paymill/models/Refund.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand All @@ -173,7 +174,8 @@ public void setUpdatedAt( final Date updatedAt ) {
* Last update representation is seconds.
*/
public void setUpdatedAt( final long seconds ) {
this.updatedAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.updatedAt = new Date( seconds * 1000 );
}

public static Refund.Filter createFilter() {
Expand Down Expand Up @@ -227,8 +229,19 @@ public Refund.Filter byAmountLessThan( final int amount ) {
return this;
}

public Refund.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Refund.Filter} object with populated filter for createdAt.
*/
public Refund.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/paymill/models/Subscription.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand All @@ -289,7 +290,8 @@ public void setUpdatedAt( final Date updatedAt ) {
* Last update representation is seconds.
*/
public void setUpdatedAt( final long seconds ) {
this.updatedAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.updatedAt = new Date( seconds * 1000 );
}

public static Subscription.Filter createFilter() {
Expand Down Expand Up @@ -317,8 +319,19 @@ public Subscription.Filter byOfferId( final String offerId ) {
return this;
}

public Subscription.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Subscription.Filter} object with populated filter for createdAt.
*/
public Subscription.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}

Expand Down
36 changes: 30 additions & 6 deletions src/main/java/com/paymill/models/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand All @@ -260,7 +261,8 @@ public void setUpdatedAt( final Date updatedAt ) {
* Last update representation is seconds.
*/
public void setUpdatedAt( final long seconds ) {
this.updatedAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.updatedAt = new Date( seconds * 1000 );
}

public static Transaction.Filter createFilter() {
Expand Down Expand Up @@ -328,13 +330,35 @@ public Transaction.Filter byDescription( final String description ) {
return this;
}

public Transaction.Filter byCreatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Transaction.Filter} object with populated filter for createdAt.
*/
public Transaction.Filter byCreatedAt( final Date date, final Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}

public Transaction.Filter byUpdatedAt( final Date startCreatedAt, final Date endCreatedAt ) {
this.updatedAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for updatedAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Transaction.Filter} object with populated filter for updatedAt.
*/
public Transaction.Filter byUpdatedAt( final Date date, final Date endDate ) {
this.updatedAt = DateRangeBuilder.execute( date, endDate );
return this;
}

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/paymill/models/Webhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public void setCreatedAt( final Date createdAt ) {
* Creation date representation is seconds.
*/
public void setCreatedAt( final long seconds ) {
this.createdAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.createdAt = new Date( seconds * 1000 );
}

/**
Expand All @@ -203,7 +204,8 @@ public void setUpdatedAt( final Date updatedAt ) {
* Last update representation is seconds.
*/
public void setUpdatedAt( final long seconds ) {
this.updatedAt = new Date( seconds * 1000 );
if( seconds > 0 )
this.updatedAt = new Date( seconds * 1000 );
}

public static Webhook.Filter createFilter() {
Expand Down Expand Up @@ -239,8 +241,19 @@ public Webhook.Filter byEmail( String email ) {
return this;
}

public Webhook.Filter byCreatedAt( Date startCreatedAt, Date endCreatedAt ) {
this.createdAt = String.valueOf( startCreatedAt.getTime() ) + "-" + String.valueOf( endCreatedAt.getTime() );
/**
* Creates filter for createdAt date. If endDate is given the filter is set for range from date to endDate. If endDate is
* <code>null</code> the filter search for exact match.
* @param date
* Start or exact date
* @param endDate
* End date for the period or <code>null</code>.
* @throws IllegalArgumentException
* When date is <code>null</code>.
* @return {@link Webhook.Filter} object with populated filter for createdAt.
*/
public Webhook.Filter byCreatedAt( Date date, Date endDate ) {
this.createdAt = DateRangeBuilder.execute( date, endDate );
return this;
}
}
Expand Down
Loading

0 comments on commit 97572cc

Please sign in to comment.