Skip to content

Commit c57ee5b

Browse files
authored
Identify data objects by name + check for duplicates during creation (#16)
* Start on identification of data objects by name * More methods * Fix all methods * Add check for duplicates * Start on register event method * Add tests * Update AI.java * Update AI.java
1 parent 04b2b0e commit c57ee5b

16 files changed

+623
-11
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.cryptolens.methods;
2+
3+
import io.cryptolens.internal.BasicResult;
4+
import io.cryptolens.internal.HelperMethods;
5+
import io.cryptolens.models.RegisterEventModel;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class AI {
11+
12+
/**
13+
* <p>This method will register an event that has occured in either the client app
14+
* (eg. start of a certain feature or interaction within a feature) or in a third
15+
* party provider (eg. a payment has occured, etc).</p>
16+
* <p>Note: You can either use this method standalone (eg. by only providing a machine code/device identifier)
17+
* or together with Cryptolens Licensing module (which requires productId and optionally keyid to be set).
18+
* The more information that is provided, the better insights can be provided.</p>
19+
* @param token The access token with 'RegisterEvent' permission.
20+
* @param model The input parameters of the method.
21+
* @return
22+
*/
23+
public static BasicResult RegisterEvent(String token, RegisterEventModel model) {
24+
Map<String,String> extraParams = new HashMap<>();
25+
26+
extraParams.put("token", token);
27+
28+
return HelperMethods.SendRequestToWebAPI("AI/RegisterEvent", model, extraParams, BasicResult.class);
29+
}
30+
}

src/main/java/io/cryptolens/methods/Data.java

Lines changed: 291 additions & 2 deletions
Large diffs are not rendered by default.

src/main/java/io/cryptolens/models/AddDataObjectToKeyModel.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public class AddDataObjectToKeyModel extends ProductAndKeyModel {
1313
* A string value (text) to store. Max 10000 characters.
1414
*/
1515
public String StringValue;
16+
/**
17+
* If set to true, this method will check that no other data object with the same name exists.
18+
* Note: setting this to true may affect performance.
19+
*/
20+
public boolean CheckForDuplicates;
1621

1722
public AddDataObjectToKeyModel(int productId, String key, String name, int intValue, String stringValue) {
1823
Name = name;
@@ -21,4 +26,13 @@ public AddDataObjectToKeyModel(int productId, String key, String name, int intVa
2126
this.ProductId = productId;
2227
this.Key = key;
2328
}
29+
30+
public AddDataObjectToKeyModel(int productId, String key, String name, int intValue, String stringValue, boolean checkForDuplicates) {
31+
Name = name;
32+
StringValue = stringValue;
33+
IntValue = intValue;
34+
this.ProductId = productId;
35+
this.Key = key;
36+
this.CheckForDuplicates = checkForDuplicates;
37+
}
2438
}

src/main/java/io/cryptolens/models/AddDataObjectToMachineCodeModel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class AddDataObjectToMachineCodeModel extends ProductKeyMachineCodeModel
1414
* A string value (text) to store. Max 10000 characters.
1515
*/
1616
public String StringValue;
17+
/**
18+
* If set to true, this method will check that no other data object with the same name exists.
19+
* Note: setting this to true may affect performance.
20+
*/
21+
public boolean CheckForDuplicates;
1722

1823
public AddDataObjectToMachineCodeModel(int productId, String key, String machineCode, String name, int intValue, String stringValue) {
1924
Name = name;
@@ -23,4 +28,14 @@ public AddDataObjectToMachineCodeModel(int productId, String key, String machine
2328
this.Key = key;
2429
this.MachineCode = machineCode;
2530
}
31+
32+
public AddDataObjectToMachineCodeModel(int productId, String key, String machineCode, String name, int intValue, String stringValue, boolean checkForDuplicates) {
33+
Name = name;
34+
IntValue = intValue;
35+
StringValue = stringValue;
36+
this.ProductId = productId;
37+
this.Key = key;
38+
this.MachineCode = machineCode;
39+
this.CheckForDuplicates = checkForDuplicates;
40+
}
2641
}

src/main/java/io/cryptolens/models/DecrementIntValueToKeyModel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class DecrementIntValueToKeyModel extends ProductAndKeyModel {
77
*/
88
public long Id;
99

10+
public String Name;
11+
1012
/**
1113
* The constant int value that should be subtracted to the current IntValue of the data object. For example,
1214
* if this value is set to 5 and the old IntValue is 11, then the new IntValue will be the old one minus 5, i.e. 6.
@@ -34,5 +36,15 @@ public DecrementIntValueToKeyModel(int productId, String key, long id, int intVa
3436
this.Key = key;
3537
this.EnableBound = enableBound;
3638
this.Bound = bound;
39+
this.Name = "";
40+
}
41+
public DecrementIntValueToKeyModel(int productId, String key, String name, int intValue, boolean enableBound, int bound) {
42+
Id = 0;
43+
IntValue = intValue;
44+
this.ProductId = productId;
45+
this.Key = key;
46+
this.EnableBound = enableBound;
47+
this.Bound = bound;
48+
this.Name = name;
3749
}
3850
}

src/main/java/io/cryptolens/models/DecrementIntValueToMachineCodeModel.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class DecrementIntValueToMachineCodeModel extends ProductKeyMachineCodeMo
77
*/
88
public long Id;
99

10+
public String Name;
11+
1012
/**
1113
* The constant int value that should be subtracted to the current IntValue of the data object. For example,
1214
* if this value is set to 5 and the old IntValue is 11, then the new IntValue will be the old one minus 5, i.e. 6.
@@ -35,6 +37,18 @@ public DecrementIntValueToMachineCodeModel(int productId, String key, String mac
3537
this.EnableBound = enableBound;
3638
this.Bound = bound;
3739
this.MachineCode = machineCode;
40+
this.Name = "";
41+
}
42+
43+
public DecrementIntValueToMachineCodeModel(int productId, String key, String machineCode, String name, int intValue, boolean enableBound, int bound) {
44+
Id = 0;
45+
IntValue = intValue;
46+
this.ProductId = productId;
47+
this.Key = key;
48+
this.EnableBound = enableBound;
49+
this.Bound = bound;
50+
this.MachineCode = machineCode;
51+
this.Name = name;
3852
}
3953

4054
}

src/main/java/io/cryptolens/models/IncrementIntValueToKeyModel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class IncrementIntValueToKeyModel extends ProductAndKeyModel {
55
* The unique object id for the data object.
66
*/
77
public long Id;
8+
9+
public String Name;
810
/**
911
* The constant int (non-negative) value that should be added to the current IntValue of the data object.
1012
* For example, if this value is set to 5 and the old IntValue is 1, then the new IntValue will be the
@@ -31,5 +33,16 @@ public IncrementIntValueToKeyModel(int productId, String key, long id, int intVa
3133
this.Key = key;
3234
this.EnableBound = enableBound;
3335
this.Bound = bound;
36+
this.Name = "";
37+
}
38+
39+
public IncrementIntValueToKeyModel(int productId, String key, String name, int intValue, boolean enableBound, int bound) {
40+
this.Name = name;
41+
this.IntValue = intValue;
42+
this.ProductId = productId;
43+
this.Key = key;
44+
this.EnableBound = enableBound;
45+
this.Bound = bound;
46+
Id = 0;
3447
}
3548
}

src/main/java/io/cryptolens/models/IncrementIntValueToMachineCodeModel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class IncrementIntValueToMachineCodeModel extends ProductKeyMachineCodeMo
66
* The unique object id for the data object.
77
*/
88
public long Id;
9+
10+
public String Name;
911
/**
1012
* The constant int (non-negative) value that should be added to the current IntValue of the data object.
1113
* For example, if this value is set to 5 and the old IntValue is 1, then the new IntValue will be the
@@ -33,5 +35,16 @@ public IncrementIntValueToMachineCodeModel(int productId, String key, String mac
3335
this.EnableBound = enableBound;
3436
this.Bound = bound;
3537
this.MachineCode = machineCode;
38+
this.Name = "";
39+
}
40+
public IncrementIntValueToMachineCodeModel(int productId, String key, String machineCode, String name, int intValue, boolean enableBound, int bound) {
41+
this.IntValue = intValue;
42+
this.ProductId = productId;
43+
this.Key = key;
44+
this.EnableBound = enableBound;
45+
this.Bound = bound;
46+
this.MachineCode = machineCode;
47+
this.Name = name;
48+
Id = 0;
3649
}
3750
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.cryptolens.models;
2+
3+
public class RegisterEventModel extends ProductKeyMachineCodeModel {
4+
5+
public String FeatureName;
6+
public String EventName;
7+
public int Value;
8+
public String Currency;
9+
10+
public RegisterEventModel(int productId, String key, String machineCode, String featureName, String eventName, int value, String currency) {
11+
ProductId = productId;
12+
Key = key;
13+
MachineCode = machineCode;
14+
FeatureName = featureName;
15+
EventName = eventName;
16+
Value = value;
17+
Currency = currency;
18+
}
19+
}

src/main/java/io/cryptolens/models/RemoveDataObjectToKeyModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ public class RemoveDataObjectToKeyModel extends ProductAndKeyModel {
77
*/
88
public long Id;
99

10+
public String Name;
11+
1012
public RemoveDataObjectToKeyModel(int productId, String key, long id) {
1113
Id = id;
1214
this.ProductId = productId;
1315
this.Key = key;
16+
this.Name = "";
17+
}
18+
19+
public RemoveDataObjectToKeyModel(int productId, String key, String name) {
20+
Id = 0;
21+
this.ProductId = productId;
22+
this.Key = key;
23+
this.Name = name;
1424
}
1525
}

0 commit comments

Comments
 (0)