Skip to content

Commit 7b1cae6

Browse files
committed
ProductDiscount interface/implementation fixed; Added currency code 'NONE'.
1 parent 1d29f82 commit 7b1cae6

7 files changed

Lines changed: 86 additions & 42 deletions

File tree

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Product.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19-
import com.labs64.netlicensing.domain.entity.impl.ProductDiscount;
20-
2119
/**
22-
* Product entity used internally by NetLicensing.
20+
* NetLicensing Product entity.
2321
* <p/>
2422
* Properties visible via NetLicensing API:
2523
* <p/>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.labs64.netlicensing.domain.entity;
2+
3+
import java.math.BigDecimal;
4+
5+
public interface ProductDiscount extends Comparable<ProductDiscount> {
6+
7+
void setProduct(final Product product);
8+
9+
Product getProduct();
10+
11+
void setTotalPrice(final BigDecimal totalPrice);
12+
13+
BigDecimal getTotalPrice();
14+
15+
void setCurrency(final String currency);
16+
17+
String getCurrency();
18+
19+
void setAmountFix(final BigDecimal amountFix);
20+
21+
BigDecimal getAmountFix();
22+
23+
void setAmountPercent(final BigDecimal amountPercent);
24+
25+
BigDecimal getAmountPercent();
26+
27+
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/ProductDiscount.java renamed to NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/ProductDiscountImpl.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
import com.labs64.netlicensing.domain.Constants;
2121
import com.labs64.netlicensing.domain.entity.Product;
22+
import com.labs64.netlicensing.domain.entity.ProductDiscount;
2223
import com.labs64.netlicensing.domain.vo.Currency;
2324
import com.labs64.netlicensing.domain.vo.Money;
2425

2526
/**
2627
* Represents discount step as a discount amount (absolute or percentage) after total price reaches the given threshold.
2728
*/
28-
public class ProductDiscount implements Comparable<ProductDiscount>, Serializable {
29+
public class ProductDiscountImpl implements ProductDiscount, Serializable {
2930

3031
private static final long serialVersionUID = -8665112497261365879L;
3132

@@ -39,51 +40,61 @@ public class ProductDiscount implements Comparable<ProductDiscount>, Serializabl
3940

4041
private BigDecimal amountPercent;
4142

42-
public Product getProduct() {
43-
return product;
44-
}
45-
43+
@Override
4644
public void setProduct(final Product product) {
4745
this.product = product;
4846
}
4947

50-
public BigDecimal getTotalPrice() {
51-
return totalPrice;
48+
@Override
49+
public Product getProduct() {
50+
return product;
5251
}
5352

53+
@Override
5454
public void setTotalPrice(final BigDecimal totalPrice) {
5555
this.totalPrice = totalPrice;
5656
}
5757

58-
public String getCurrency() {
59-
return currency;
58+
@Override
59+
public BigDecimal getTotalPrice() {
60+
return totalPrice;
6061
}
6162

63+
@Override
6264
public void setCurrency(final String currency) {
6365
this.currency = currency;
6466
}
6567

66-
public BigDecimal getAmountFix() {
67-
return amountFix;
68+
@Override
69+
public String getCurrency() {
70+
return currency;
6871
}
6972

73+
@Override
7074
public void setAmountFix(final BigDecimal amountFix) {
7175
this.amountFix = amountFix;
7276
amountPercent = null;
7377
}
7478

75-
public BigDecimal getAmountPercent() {
76-
return amountPercent;
79+
@Override
80+
public BigDecimal getAmountFix() {
81+
return amountFix;
7782
}
7883

84+
@Override
7985
public void setAmountPercent(final BigDecimal amountPercent) {
8086
this.amountPercent = amountPercent;
8187
amountFix = null;
8288
}
8389

90+
@Override
91+
public BigDecimal getAmountPercent() {
92+
return amountPercent;
93+
}
94+
8495
/**
8596
* Gets the discount amount as string, with '%' sign at the end indicating discount is given in percent.
86-
*
97+
*
8798
* @return the string amount
8899
*/
89100
public String getStringAmount() {
@@ -98,7 +109,7 @@ public String getStringAmount() {
98109

99110
/**
100111
* Sets the discount amount from string, '%' sign at the end indicates discount is provided in percent.
101-
*
112+
*
102113
* @param amount
103114
* discount amount as string
104115
*/
@@ -145,7 +156,7 @@ public String toString() {
145156

146157
@Override
147158
public int compareTo(final ProductDiscount productDiscount) {
148-
return productDiscount.totalPrice.compareTo(totalPrice); // reverse order!
159+
return productDiscount.getTotalPrice().compareTo(totalPrice); // reverse order!
149160
}
150161

151162
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/ProductImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.labs64.netlicensing.domain.Constants;
2222
import com.labs64.netlicensing.domain.entity.Licensee;
2323
import com.labs64.netlicensing.domain.entity.Product;
24+
import com.labs64.netlicensing.domain.entity.ProductDiscount;
2425
import com.labs64.netlicensing.domain.entity.ProductModule;
2526

2627
/**

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Currency.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
*/
1313
package com.labs64.netlicensing.domain.vo;
1414

15+
import org.apache.commons.lang3.StringUtils;
16+
1517
/**
1618
* NetLicensing supported currencies.
1719
*/
1820
public enum Currency {
1921

22+
NONE(""),
23+
2024
EUR("EUR");
2125

2226
private final String value;
2327

2428
/**
2529
* Instantiates a new currency.
26-
*
30+
*
2731
* @param currency
2832
* currency value
2933
*/
@@ -33,7 +37,7 @@ public enum Currency {
3337

3438
/**
3539
* Get enum value.
36-
*
40+
*
3741
* @return enum value
3842
*/
3943
public String value() {
@@ -42,7 +46,7 @@ public String value() {
4246

4347
/*
4448
* (non-Javadoc)
45-
*
49+
*
4650
* @see java.lang.Enum#toString()
4751
*/
4852
@Override
@@ -52,7 +56,7 @@ public String toString() {
5256

5357
/**
5458
* Parse currency value to {@link Currency} enum.
55-
*
59+
*
5660
* @param value
5761
* currency value
5862
* @return {@link Currency} enum object or throws {@link IllegalArgumentException} if no corresponding
@@ -64,20 +68,23 @@ public static Currency parseValue(final String value) {
6468
return currency;
6569
}
6670
}
71+
if (value != null && StringUtils.isBlank(value)) {
72+
return NONE;
73+
}
6774
throw new IllegalArgumentException(value);
6875
}
6976

7077
/**
71-
* Gets the enum safe.
72-
*
78+
* Parse currency value to {@link Currency} enum, nothrow version.
79+
*
7380
* @param value
74-
* currency value
75-
* @return the enum safe
81+
* licenseType value as string
82+
* @return {@link Currency} enum object or {@code null} if argument doesn't match any of the enum values
7683
*/
7784
public static Currency parseValueSafe(final String value) {
7885
try {
7986
return parseValue(value);
80-
} catch (IllegalArgumentException e) {
87+
} catch (final IllegalArgumentException e) {
8188
return null;
8289
}
8390
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/LicenseType.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum LicenseType {
3333

3434
/**
3535
* Instantiates a new license type.
36-
*
36+
*
3737
* @param licenseTypeValue
3838
* licenseType value
3939
*/
@@ -43,7 +43,7 @@ public enum LicenseType {
4343

4444
/**
4545
* Get enum value.
46-
*
46+
*
4747
* @return enum value
4848
*/
4949
public String value() {
@@ -52,7 +52,7 @@ public String value() {
5252

5353
/*
5454
* (non-Javadoc)
55-
*
55+
*
5656
* @see java.lang.Enum#toString()
5757
*/
5858
@Override
@@ -62,7 +62,7 @@ public String toString() {
6262

6363
/**
6464
* Parse license type value to {@link LicenseType} enum.
65-
*
65+
*
6666
* @param value
6767
* licenseType value
6868
* @return {@link LicenseType} enum object or throws {@link IllegalArgumentException} if no corresponding
@@ -78,16 +78,16 @@ public static LicenseType parseValue(final String value) {
7878
}
7979

8080
/**
81-
* Gets the enum safe.
82-
*
83-
* @param val
84-
* the val
85-
* @return the enum safe
81+
* Parse license type value to {@link LicenseType} enum, nothrow version.
82+
*
83+
* @param value
84+
* licenseType value as string
85+
* @return {@link LicenseType} enum object or {@code null} if argument doesn't match any of the enum values
8686
*/
87-
public static LicenseType parseValueSafe(final String val) {
87+
public static LicenseType parseValueSafe(final String value) {
8888
try {
89-
return parseValue(val);
90-
} catch (IllegalArgumentException e) {
89+
return parseValue(value);
90+
} catch (final IllegalArgumentException e) {
9191
return null;
9292
}
9393
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToProductConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.labs64.netlicensing.domain.Constants;
2020
import com.labs64.netlicensing.domain.entity.Product;
21-
import com.labs64.netlicensing.domain.entity.impl.ProductDiscount;
21+
import com.labs64.netlicensing.domain.entity.impl.ProductDiscountImpl;
2222
import com.labs64.netlicensing.domain.entity.impl.ProductImpl;
2323
import com.labs64.netlicensing.domain.vo.Money;
2424
import com.labs64.netlicensing.exception.ConversionException;
@@ -46,7 +46,7 @@ public Product convert(final Item source) throws ConversionException {
4646

4747
for (final com.labs64.netlicensing.schema.context.List list : source.getList()) {
4848
if (Constants.DISCOUNT.equals(list.getName())) {
49-
final ProductDiscount productDiscount = new ProductDiscount();
49+
final ProductDiscountImpl productDiscount = new ProductDiscountImpl();
5050
final Money price = convertPrice(list.getProperty(), Constants.Product.Discount.TOTAL_PRICE);
5151
productDiscount.setTotalPrice(price.getAmount());
5252
productDiscount.setCurrency(price.getCurrencyCode());

0 commit comments

Comments
 (0)