8000 NLIC-2227: Allow custom properties for auto-created licensee · Labs64/NetLicensingClient-java@3943cdc · GitHub
[go: up one dir, main page]

Skip to content

Commit 3943cdc

Browse files
authored
NLIC-2227: Allow custom properties for auto-created licensee
* allow custom properties for auto-created licensee * allow custom properties for auto-created licensee * cleanup
1 parent 55386a4 commit 3943cdc

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6+
import com.labs64.netlicensing.domain.Constants;
7+
68
public class ValidationParameters {
79

810
private String productNumber;
9-
private String licenseeName;
10-
private String licenseeSecret;
11+
private Map<String, String> licenseeProperties;
1112
private Boolean dryRun;
1213
private Boolean forOfflineUse;
1314
private Map<String, Map<String, String>> parameters;
@@ -26,6 +27,18 @@ public String getProductNumber() {
2627
return productNumber;
2728
}
2829

30+
public Map<String, String> getLicenseeProperties() {
31+
if (licenseeProperties == null) {
32+
licenseeProperties = new HashMap<>();
33+
}
34+
return licenseeProperties;
35+
}
36+
37+
public void setLicenseeProperty(final String key, final String value) {
38+
getLicenseeProperties().put(key, value);
39+
}
40+
41+
2942
/**
3043
* Sets the name for the new licensee
3144
*
@@ -35,11 +48,11 @@ public String getProductNumber() {
3548
* 1000 characters.
3649
*/
3750
public void setLicenseeName(final String licenseeName) {
38-
this.licenseeName = licenseeName;
51+
setLicenseeProperty(Constants.Licensee.PROP_LICENSEE_NAME, licenseeName);
3952
}
4053

4154
public String getLicenseeName() {
42-
return licenseeName;
55+
return getLicenseeProperties().get(Constants.Licensee.PROP_LICENSEE_NAME);
4356
}
4457

4558
/**
@@ -49,13 +62,14 @@ public String getLicenseeName() {
4962
* licensee secret stored on the client side. Refer to Licensee Secret documentation for details.
5063
*/
5164
public void setLicenseeSecret(final String licenseeSecret) {
52-
this.licenseeSecret = licenseeSecret;
65+
setLicenseeProperty(Constants.Licensee.PROP_LICENSEE_SECRET, licenseeSecret);
5366
}
5467

5568
public String getLicenseeSecret() {
56-
return licenseeSecret;
69+
return getLicenseeProperties().get(Constants.Licensee.PROP_LICENSEE_SECRET);
5770
}
5871

72+
5973
/**
6074
* Sets the "dry run" mode
6175
*

NetLicensingClient/src/main/java/com/labs64/netlicensing/service/ValidationService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ private static Form convertValidationParameters(final ValidationParameters valid
108108
if (StringUtils.isNotBlank(validationParameters.getProductNumber())) {
109109
form.param(Constants.Product.PRODUCT_NUMBER, validationParameters.getProductNumber());
110110
}
111-
if (StringUtils.isNotBlank(validationParameters.getLicenseeName())) {
112-
form.param(Constants.Licensee.PROP_LICENSEE_NAME, validationParameters.getLicenseeName());
113-
}
114-
if (StringUtils.isNotBlank(validationParameters.getLicenseeSecret())) {
115-
form.param(Constants.Licensee.PROP_LICENSEE_SECRET, validationParameters.getLicenseeSecret());
116-
}
111+
112+
validationParameters.getLicenseeProperties()
113+
.forEach((k, v) -> {
114+
if (StringUtils.isNotBlank(k)) {
115+
form.param(k, v);
116+
}
117+
});
118+
117119
if (Boolean.TRUE.equals(validationParameters.isDryRun())) {
118120
form.param(Constants.Validation.DRY_RUN, Boolean.TRUE.toString());
119121
}

NetLicensingClient/src/test/java/com/labs64/netlicensing/service/LicenseeServiceTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public void testValidate() throws Exception {
154154
final ValidationParameters validationParameters = new ValidationParameters();
155155
validationParameters.setLicenseeName("Test Licensee");
156156
validationParameters.setProductNumber(productNumber);
157+
validationParameters.setLicenseeProperty("customProperty", "Licensee Custom Property");
157158
final ValidationResult result = LicenseeService.validate(context, licenseeNumber, validationParameters);
158159

159160
assertNotNull(result);
@@ -237,7 +238,8 @@ public Response delete(final String licenseeNumber, final UriInfo uriInfo) {
237238
@Path("{licenseeNumber}/validate")
238239
public Response validateLicensee(@PathParam("licenseeNumber") final String licenseeNumber,
239240
@FormParam("productNumber") final String productNumber,
240-
@FormParam("licenseeName") final String licenseeName) {
241+
@FormParam("licenseeName") final String licenseeName,
242+
@FormParam("customProperty") final String licenseeCustomProperty) {
241243

242244
if (!productNumber.equals(productNumber)) {
243245
return unexpectedValueErrorResponse("productNumber");
@@ -246,6 +248,10 @@ public Response validateLicensee(@PathParam("licenseeNumber") final String licen
246248
return unexpectedValueErrorResponse("licenseeName");
247249
}
248250

251+
if (!"Licensee Custom Property".equals(licenseeCustomProperty)) {
252+
return unexpectedValueErrorResponse("customProperty");
253+
}
254+
249255
final Netlicensing netlicensing = JAXBUtils.readObject(TEST_CASE_BASE
250256
+ "netlicensing-licensee-validate.xml", Netlicensing.class);
251257
return Response.ok(netlicensing).build();

0 commit comments

Comments
 (0)
0