Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.math.BigDecimal;
import java.util.Objects;

import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_ONLY;

@ApiModel( description = "A billed unit" )
public class OrderLineDTO implements Line
{
Expand Down Expand Up @@ -45,11 +47,11 @@ public class OrderLineDTO implements Line
@ApiModelProperty( "If this is a one-off cost" )
private boolean setup;

@ApiModelProperty( value = "Discount percentage if this line is relative to a coupon", example = "20", readOnly = true )
@ApiModelProperty( value = "Discount percentage if this line is relative to a coupon", example = "20", accessMode = READ_ONLY )
private BigDecimal discount;

@ApiModelProperty( value = "Requested billing item maximum quantity", example = "15", readOnly = true )
private Integer maximum;
@ApiModelProperty( value = "Requested billing item maximum quantity", example = "15.00", accessMode = READ_ONLY )
private BigDecimal maximum;

@ApiModelProperty( "Custom billing identifier" )
private String identifier;
Expand Down Expand Up @@ -79,7 +81,7 @@ public BigDecimal getPriceExcludingVAT()
return getSubtotal();
}

@ApiModelProperty( readOnly = true )
@ApiModelProperty( accessMode = READ_ONLY )
public BigDecimal getSubtotal()
{
if ( price == null || price.getPrice() == null ) return BigDecimal.ZERO;
Expand All @@ -89,7 +91,7 @@ public BigDecimal getSubtotal()
.setScale( MathConfiguration.DEFAULT_PRECISION, MathConfiguration.ROUNDING_MODE );
}

@ApiModelProperty( value = "VAT total amount", readOnly = true )
@ApiModelProperty( value = "VAT total amount", accessMode = READ_ONLY )
@JsonProperty( value = "vatSpunOff" )
public BigDecimal getVATSpunOff()
{
Expand Down Expand Up @@ -197,12 +199,12 @@ public void setDiscount( BigDecimal discount )
this.discount = discount;
}

public Integer getMaximum()
public BigDecimal getMaximum()
{
return maximum;
}

public void setMaximum( Integer maximum )
public void setMaximum( BigDecimal maximum )
{
this.maximum = maximum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.util.Objects;

import static com.liberologico.cloudesire.common.MathConfiguration.DAY_SCALE_PRECISION;
import static com.liberologico.cloudesire.common.MathConfiguration.ROUNDING_MODE;

public class SubscriptionBillingItemDTO extends DTO
{
private UrlEntityDTO billingItem;

@ApiModelProperty( "The chosen value for this billing item" )
private Integer value;
@ApiModelProperty( "The current value for this billing item" )
private BigDecimal value;

@ApiModelProperty( "Whether the billing item has been already bought for the Subscription" )
private Boolean bought;
Expand All @@ -25,7 +29,7 @@ public class SubscriptionBillingItemDTO extends DTO
public SubscriptionBillingItemDTO( UrlEntityDTO billingItem, Integer value, boolean bought )
{
this.billingItem = billingItem;
this.value = value;
this.value = new BigDecimal( value ).setScale( DAY_SCALE_PRECISION, ROUNDING_MODE );
this.bought = bought;
}

Expand All @@ -48,12 +52,12 @@ public void setBillingItem( UrlEntityDTO billingItem )
this.billingItem = billingItem;
}

public Integer getValue()
public BigDecimal getValue()
{
return value;
}

public void setValue( Integer value )
public void setValue( BigDecimal value )
{
this.value = value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.cloudesire.platform.apiclient.dto.model.dto;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class SubscriptionV1DTO extends BaseSubscriptionDTO
{
private Map<UrlEntityDTO, Integer> billingItems = new HashMap<>();
private Map<UrlEntityDTO, BigDecimal> billingItems = new HashMap<>();

public Map<UrlEntityDTO, Integer> getBillingItems()
public Map<UrlEntityDTO, BigDecimal> getBillingItems()
{
return billingItems;
}

public SubscriptionV1DTO setBillingItems( Map<String, Integer> billingItems )
public SubscriptionV1DTO setBillingItems( Map<String, BigDecimal> billingItems )
{
if ( billingItems == null ) return this;

this.billingItems = new HashMap<>();

for ( Map.Entry<String, Integer> entry : billingItems.entrySet() )
for ( Map.Entry<String, BigDecimal> entry : billingItems.entrySet() )
{
this.billingItems.put( new UrlEntityDTO( entry.getKey() ), entry.getValue() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public static BigDecimal addPercentage( BigDecimal base, BigDecimal pct )
return base.add( percentage( base, pct, MathConfiguration.COMPUTATION_PRECISION ) );
}

public static boolean isBetween( BigDecimal number, int min, int max )
{
return isBetween( number, new BigDecimal( min ), new BigDecimal( max ) );
}

public static boolean isBetween( BigDecimal number, BigDecimal min, BigDecimal max )
{
return min.compareTo( number ) <= 0 && number.compareTo( max ) <= 0;
}

public static BigDecimal subtractPercentage( BigDecimal base, BigDecimal pct )
{
if ( base == null ) return BigDecimal.ZERO;
Expand Down Expand Up @@ -114,6 +124,11 @@ public static BigDecimal bytesToGigabytes( BigDecimal bytes )
return bytes.divide( rescale, computationMathContext() );
}

public static boolean equalsByComparing( BigDecimal a, long b )
{
return equalsByComparing( a, new BigDecimal( b ) );
}

public static boolean equalsByComparing( BigDecimal a, BigDecimal b )
{
if ( a == null ) return b == null;
Expand Down