Skip to content

Commit e51fc93

Browse files
authored
Add "dry run" parameter to validate (#16)
1 parent 536d24a commit e51fc93

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ public static final class Shop {
207207
public static final String PROP_SHOPPING_CART = "shopping-cart";
208208
}
209209

210+
public static final class Validation {
211+
public static final String DRY_RUN = "dryRun";
212+
}
213+
210214
public static final class ValidationResult {
211215
public static final String VALIDATION_RESULT_TYPE = "ProductModuleValidation";
212216
public static final int DEFAULT_TTL_MINUTES = 60 * 24; // 1 day

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ValidationParameters {
88
private String productNumber;
99
private String licenseeName;
1010
private String licenseeSecret;
11+
private Boolean dryRun;
1112
private Map<String, Map<String, String>> parameters;
1213

1314
/**
@@ -26,7 +27,7 @@ public String getProductNumber() {
2627

2728
/**
2829
* Sets the name for the new licensee
29-
*
30+
*
3031
* @param licenseeName
3132
* optional human-readable licensee name in case licensee will be auto-created. This parameter must not
3233
* be the name, but can be used to store any other useful string information with new licensees, up to
@@ -42,7 +43,7 @@ public String getLicenseeName() {
4243

4344
/**
4445
* Sets the licensee secret
45-
*
46+
*
4647
* @param licenseeSecret
4748
* licensee secret stored on the client side. Refer to Licensee Secret documentation for details.
4849
*/
@@ -54,6 +55,20 @@ public String getLicenseeSecret() {
5455
return licenseeSecret;
5556
}
5657

58+
/**
59+
* Sets the "dry run" mode
60+
*
61+
* @param dryRun
62+
* if "true", validation will be executed in "dry run" mode, i.e. no modifications to any licenses.
63+
*/
64+
public void setDryRun(final Boolean dryRun) {
65+
this.dryRun = dryRun;
66+
}
67+
68+
public Boolean isDryRun() {
69+
return dryRun;
70+
}
71+
5772
public Map<String, Map<String, String>> getParameters() {
5873
if (parameters == null) {
5974
parameters = new HashMap<>();

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static ValidationResult validate(final Context context, final String numb
7676
public static Netlicensing retrieveValidationFile(final Context context, final String number,
7777
final ValidationParameters validationParameters) throws NetLicensingException {
7878
CheckUtils.paramNotEmpty(number, "number");
79-
Form form = convertValidationParameters(validationParameters);
79+
final Form form = convertValidationParameters(validationParameters);
8080
final NetLicensingService service = NetLicensingService.getInstance();
8181
return service.request(context, HttpMethod.POST,
8282
Constants.Licensee.ENDPOINT_PATH + "/" + number + "/" + Constants.Licensee.ENDPOINT_PATH_VALIDATE, form,
@@ -113,6 +113,9 @@ private static Form convertValidationParameters(final ValidationParameters valid
113113
if (StringUtils.isNotBlank(validationParameters.getLicenseeSecret())) {
114114
form.param(Constants.Licensee.PROP_LICENSEE_SECRET, validationParameters.getLicenseeSecret());
115115
}
116+
if (Boolean.TRUE.equals(validationParameters.isDryRun())) {
117+
form.param(Constants.Validation.DRY_RUN, Boolean.TRUE.toString());
118+
}
116119
int pmIndex = 0;
117120
for (final Entry<String, Map<String, String>> productModuleValidationParams : validationParameters
118121
.getParameters().entrySet()) {

0 commit comments

Comments
 (0)