8000 NLIC-1980: Group models & packages in a license bundle (#40) · Labs64/NetLicensingClient-java@34bcf7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 34bcf7f

Browse files
v-rudkovskiyViacheslav Rudkovskyi
and
Viacheslav Rudkovskyi
authored
NLIC-1980: Group models & packages in a license bundle (#40)
* add Bundle functionality * add Bundle functionality * rename "licenseTemplatesNumbers" to "licenseTemplateNumbers" * remove BundleObtainParameters.java --------- Co-authored-by: Viacheslav Rudkovskyi <viachaslau.rudkovski@labs64.de>
1 parent bd5e210 commit 34bcf7f

File tree

13 files changed

+771
-2
lines changed

13 files changed

+771
-2
lines changed

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,11 @@ public static final class Notification {
227227
public static final String PAYLOAD = "payload";
228228
}
229229

230+
public static final class Bundle {
231+
public static final String ENDPOINT_PATH = "bundle";
232+
public static final String ENDPOINT_OBTAIN_PATH = "obtain";
233+
public static final String DESCRIPTION = "description";
234+
public static final String LICENSE_TEMPLATE_NUMBERS = "licenseTemplateNumbers";
235+
}
230236
// CHECKSTYLE:ON
231237
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/EntityFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.Map;
2020

21+
import com.labs64.netlicensing.domain.entity.Bundle;
2122
import com.labs64.netlicensing.domain.entity.Country;
2223
import com.labs64.netlicensing.domain.entity.License;
2324
import com.labs64.netlicensing.domain.entity.LicenseTemplate;
@@ -39,6 +40,7 @@
3940
import com.labs64.netlicensing.schema.context.Item;
4041
import com.labs64.netlicensing.schema.context.Netlicensing;
4142
import com.labs64.netlicensing.schema.converter.Converter;
43+
import com.labs64.netlicensing.schema.converter.ItemToBundleConverter;
4244
import com.labs64.netlicensing.schema.converter.ItemToCountryConverter;
4345
import com.labs64.netlicensing.schema.converter.ItemToLicenseConverter;
4446
import com.labs64.netlicensing.schema.converter.ItemToLicenseTemplateConverter;
@@ -75,6 +77,7 @@ public class EntityFactory {
7577
entityToConverterMap.put(LicensingModelProperties.class, ItemToLicensingModelPropertiesConverter.class);
7678
entityToConverterMap.put(LicenseTypeProperties.class, ItemToLicenseTypePropertiesConverter.class);
7779
entityToConverterMap.put(Notification.class, ItemToNotificationConverter.class);
80+
entityToConverterMap.put(Bundle.class, ItemToBundleConverter.class);
7881
}
7982

8083
private Map<Class<?>, Converter<Item, ?>> convertersCache;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.labs64.netlicensing.domain.entity;
2+
3+
import java.math.BigDecimal;
4+
import java.util.List;
5+
6+
import com.labs64.netlicensing.domain.vo.Currency;
7+
8+
public interface Bundle extends BaseEntity {
9+
void setName(String name);
10+
11+
String getName();
12+
13+
void setPrice(BigDecimal price);
14+
15+
BigDecimal getPrice();
16+
17+
void setCurrency(Currency currency);
18+
19+
Currency getCurrency();
20+
21+
void setDescription(String description);
22+
23+
String getDescription();
24+
25+
void setLicenseTemplateNumbers(List<String> licenseTemplateNumbers);
26+
27+
List<String> getLicenseTemplateNumbers();
28+
29+
void addLicenseTemplateNumber(String licenseTemplateNumber);
30+
31+
void removeLicenseTemplateNumber(String licenseTemplateNumber);
32+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.labs64.netlicensing.domain.entity.impl;
2+
3+
import java.math.BigDecimal;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import javax.ws.rs.core.MultivaluedMap;
8+
9+
import com.labs64.netlicensing.domain.Constants;
10+
import com.labs64.netlicensing.domain.entity.Bundle;
11+
import com.labs64.netlicensing.domain.vo.Currency;
12+
13+
public class BundleImpl extends BaseEntityImpl implements Bundle {
14+
private String name;
15+
16+
private String description;
17+
18+
private BigDecimal price;
19+
20+
private Currency currency;
21+
22+
private List<String> licenseTemplateNumbers;
23+
24+
@Override
25+
public void setName(final String name) {
26+
this.name = name;
27+
}
28+
29+
@Override
30+
public String getName() {
31+
return name;
32+
}
33+
34+
@Override
35+
public void setPrice(final BigDecimal price) {
36+
this.price = price;
37+
}
38+
39+
@Override
40+
public BigDecimal getPrice() {
41+
return price;
42+
}
43+
44+
@Override
45+
public void setCurrency(final Currency currency) {
46+
this.currency = currency;
47+
}
48+
49+
@Override
50+
public Currency getCurrency() {
51+
return currency;
52+
}
53+
54+
@Override
55+
public void setDescription(final String description) {
56+
this.description = description;
57+
}
58+
59+
@Override
60+
public String getDescription() {
61+
return description;
62+
}
63+
64+
@Override
65+
public void setLicenseTemplateNumbers(final List<String> licenseTemplateNumbers) {
66+
this.licenseTemplateNumbers = licenseTemplateNumbers;
67+
}
68+
69+
@Override
70+
public List<String> getLicenseTemplateNumbers() {
71+
return licenseTemplateNumbers;
72+
}
73+
74+
@Override
75+
public void addLicenseTemplateNumber(final String licenseTemplateNumber) {
76+
if (getLicenseTemplateNumbers() == null) {
77+
this.licenseTemplateNumbers = new ArrayList<>();
78+
}
79+
80+
this.licenseTemplateNumbers.add(licenseTemplateNumber);
81+
}
82+
83+
@Override
84+
public void removeLicenseTemplateNumber(final String licenseTemplateNumber) {
85+
if (getLicenseTemplateNumbers() == null) {
86+
return;
87+
}
88+
89+
getLicenseTemplateNumbers().remove(licenseTemplateNumber);
90+
}
91+
92+
public static List<String> getReservedProps() {
93+
final List<String> reserved = BaseEntityImpl.getReservedProps();
94+
reserved.add(Constants.NAME);
95+
reserved.add(Constants.Bundle.DESCRIPTION);
96+
reserved.add(Constants.PRICE);
97+
reserved.add(Constants.CURRENCY);
98+
reserved.add(Constants.Bundle.LICENSE_TEMPLATE_NUMBERS);
99+
return reserved;
100+
}
101+
102+
@Override
103+
protected MultivaluedMap<String, Object> asPropertiesMap() {
104+
final MultivaluedMap<String, Object> map = super.asPropertiesMap();
105+
map.add(Constants.NAME, getName());
106+
107+
if (getDescription() != null) {
108+
map.add(Constants.Bundle.DESCRIPTION, getDescription());
109+
}
110+
111+
map.add(Constants.PRICE, getPrice());
112+
map.add(Constants.CURRENCY, getCurrency());
113+
114+
if (getLicenseTemplateNumbers() != null) {
115+
map.add(Constants.Bundle.LICENSE_TEMPLATE_NUMBERS, String.join(",", getLicenseTemplateNumbers()));
116+
}
117+
118+
return map;
119+
}
120+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ public enum TransactionSource {
6868
/**
6969
* Transaction for cancel recurring payment.
7070
*/
71-
CANCEL_RECURRING_PAYMENT
71+
CANCEL_RECURRING_PAYMENT,
72+
73+
/**
74+
* Transaction for obtain bundle.
75+
*/
76+
OBTAIN_BUNDLE;
7277
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* https://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package com.labs64.netlicensing.schema.converter;
14+
15+
import java.util.Arrays;
16+
17+
import com.labs64.netlicensing.domain.Constants;
18+
import com.labs64.netlicensing.domain.entity.Bundle;
19+
import com.labs64.netlicensing.domain.entity.impl.BundleImpl;
20+
import com.labs64.netlicensing.domain.entity.impl.LicenseTemplateImpl;
21+
import com.labs64.netlicensing.domain.vo.Currency;
22+
import com.labs64.netlicensing.domain.vo.Money;
23+
import com.labs64.netlicensing.exception.ConversionException;
24+
import com.labs64.netlicensing.schema.SchemaFunction;
25+
import com.labs64.netlicensing.schema.context.Item;
26+
import com.labs64.netlicensing.schema.context.Property;
27+
28+
/**
29+
* Convert {@link Item} entity into {@link Bundle} object.
30+
*/
31+
public class ItemToBundleConverter extends ItemToEntityBaseConverter<Bundle> {
32+
33+
@Override
34+
public Bundle convert(final Item source) throws ConversionException {
35+
final Bundle target = super.convert(source);
36+
37+
target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue());
38+
target.setDescription(SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.DESCRIPTION).getValue());
39+
if (SchemaFunction.propertyByName(source.getProperty(), Constants.PRICE).getValue() != null) {
40+
final Money price = convertPrice(source.getProperty(), Constants.PRICE);
41+
target.setPrice(price.getAmount());
42+
target.setCurrency(Currency.valueOf(price.getCurrencyCode()));
43+
}
44+
45+
final String licenseTemplateNumbers = SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.LICENSE_TEMPLATE_NUMBERS).getValue();
46+
47+
if (licenseTemplateNumbers != null) {
48+
target.setLicenseTemplateNumbers(Arrays.asList(licenseTemplateNumbers.split(",")));
49+
}
50+
51+
// Custom properties
52+
for (final Property property : source.getProperty()) {
53+
if (!LicenseTemplateImpl.getReservedProps().contains(property.getName())) {
54+
target.getProperties().put(property.getName(), property.getValue());
55+
}
56+
}
57+
58+
return target;
59+
}
60+
61+
@Override
62+
public Bundle newTarget() {
63+
return new BundleImpl();
64+
}
65+
66+
}

0 commit comments

Comments
 (0)
0