33import com .fasterxml .jackson .annotation .JsonIgnore ;
44import com .testdroid .api .APIEntity ;
55import com .testdroid .api .util .TimeConverter ;
6+ import jakarta .xml .bind .annotation .XmlType ;
67import org .apache .commons .lang3 .EnumUtils ;
78import org .apache .commons .lang3 .StringUtils ;
89
9- import jakarta .xml .bind .annotation .XmlType ;
1010import java .time .LocalDateTime ;
1111import java .util .Date ;
12+ import java .util .Optional ;
1213
1314import static org .apache .commons .lang3 .StringUtils .EMPTY ;
1415
@@ -46,6 +47,8 @@ public enum Status {
4647
4748 private boolean privateInstance ;
4849
50+ private boolean legacy ;
51+
4952 private Long userId ;
5053
5154 private RecorderLicense recorder ;
@@ -65,30 +68,26 @@ public APILicense() {
6568
6669 @ SuppressWarnings ("squid:S107" )
6770 public APILicense (
68- Long id , Long userId , String userEmail , boolean privateInstance , LocalDateTime activateTime ,
69- LocalDateTime expireTime , Integer androidDeviceLimit , Boolean androidEnabled , Boolean serverAndroidEnabled ,
70- Boolean uiautomatorEnabled , Boolean recorderEnabled , Integer iosProjectLimit , Boolean serverIosEnabled ,
71- Integer recorderLimit , Boolean ctsEnabled , Integer androidProjectLimit , Boolean serverEnabled ,
72- Boolean inspectorEnabled , Boolean iosEnabled , Integer iosDeviceLimit , LocalDateTime closeTime ,
73- String status , Boolean buildEnabled , Integer buildLimit , Boolean desktopEnabled ,
74- Integer desktopDeviceLimit , Integer desktopProjectLimit , Integer globalDeviceLimit ,
75- Integer globalProjectLimit ) {
71+ Long id , Long userId , String userEmail , boolean privateInstance , boolean legacy , LocalDateTime activateTime ,
72+ LocalDateTime expireTime , Integer androidDeviceLimit , Boolean androidEnabled , Boolean iosEnabled ,
73+ Integer iosDeviceLimit , LocalDateTime closeTime , String status , Boolean desktopEnabled ,
74+ Integer desktopDeviceLimit ) {
7675 super (id );
7776 this .privateInstance = privateInstance ;
77+ this .legacy = legacy ;
7878 this .activateTime = TimeConverter .toDate (activateTime );
7979 this .expireTime = TimeConverter .toDate (expireTime );
8080 this .userEmail = userEmail ;
8181 this .userId = userId ;
82- this .android = new AndroidLicense (androidDeviceLimit , androidProjectLimit ,
83- new AndroidLicense .CTSLicense (ctsEnabled ), new AndroidLicense .UIAutomatorLicense (uiautomatorEnabled ),
84- androidEnabled );
85- this .ios = new IOSLicense (iosDeviceLimit , iosProjectLimit , iosEnabled );
86- this .build = new BuildLicense (buildLimit , buildEnabled );
87- this .recorder = new RecorderLicense (recorderLimit , recorderEnabled );
88- this .server = new ServerLicense (serverAndroidEnabled , serverIosEnabled , serverEnabled );
89- this .inspector = new InspectorLicense (inspectorEnabled );
90- this .desktop = new DesktopLicense (desktopDeviceLimit , desktopProjectLimit , desktopEnabled );
91- this .global = new GlobalLicense (globalDeviceLimit , globalProjectLimit );
82+ this .android = new AndroidLicense (androidDeviceLimit , null ,
83+ new AndroidLicense .CTSLicense (true ), new AndroidLicense .UIAutomatorLicense (true ), androidEnabled );
84+ this .ios = new IOSLicense (iosDeviceLimit , null , iosEnabled );
85+ this .build = new BuildLicense (null , true );
86+ this .recorder = new RecorderLicense (null , true );
87+ this .server = new ServerLicense (true , true , true );
88+ this .inspector = new InspectorLicense (true );
89+ this .desktop = new DesktopLicense (desktopDeviceLimit , null , desktopEnabled );
90+ this .global = new GlobalLicense (null , null );
9291 this .closeTime = TimeConverter .toDate (closeTime );
9392 this .status = EnumUtils .getEnum (Status .class , status );
9493 }
@@ -111,6 +110,16 @@ public APILicense(
111110 this .global = global ;
112111 }
113112
113+ public APILicense (
114+ boolean privateInstance , LocalDateTime expireTime , AndroidLicense android , IOSLicense ios ,
115+ DesktopLicense desktop ) {
116+ this .privateInstance = privateInstance ;
117+ this .expireTime = TimeConverter .toDate (expireTime );
118+ this .android = android ;
119+ this .ios = ios ;
120+ this .desktop = desktop ;
121+ }
122+
114123 private static String getTextValue (Integer i ) {
115124 return i != null ? Integer .toString (i ) : EMPTY ;
116125 }
@@ -249,10 +258,23 @@ public void setGlobal(GlobalLicense global) {
249258 this .global = global ;
250259 }
251260
261+ public boolean isLegacy () {
262+ return legacy ;
263+ }
264+
265+ public void setLegacy (boolean legacy ) {
266+ this .legacy = legacy ;
267+ }
268+
252269 public String generateSignContent () {
253270 return StringUtils .joinWith (":" , getTextValue (privateInstance ), userEmail ,
254- StringUtils .join (android .generateSignContent (), ios .generateSignContent (),
255- recorder .generateSignContent (), server .generateSignContent ()));
271+ StringUtils .join (
272+ Optional .ofNullable (android ).map (AndroidLicense ::generateSignContent ).orElse (EMPTY ),
273+ Optional .ofNullable (ios ).map (IOSLicense ::generateSignContent ).orElse (EMPTY ),
274+ Optional .ofNullable (recorder ).map (RecorderLicense ::generateSignContent ).orElse (EMPTY ),
275+ Optional .ofNullable (server ).map (ServerLicense ::generateSignContent ).orElse (EMPTY )
276+ )
277+ );
256278 }
257279
258280 public static class GlobalLicense {
@@ -330,6 +352,11 @@ public static class AndroidLicense extends FeatureLicense {
330352 public AndroidLicense () {
331353 }
332354
355+ public AndroidLicense (boolean enabled , Integer deviceLimit ) {
356+ super (enabled );
357+ this .deviceLimit = deviceLimit ;
358+ }
359+
333360 public AndroidLicense (
334361 Integer deviceLimit , Integer projectLimit , CTSLicense cts , UIAutomatorLicense uiAutomator ,
335362 boolean enabled ) {
@@ -382,8 +409,10 @@ public boolean isProjectLimited() {
382409
383410 @ Override
384411 public String generateSignContent () {
385- return StringUtils .join (getTextValue (enabled ), getTextValue (projectLimit ),
386- getTextValue (deviceLimit ), cts .generateSignContent (), uiAutomator .generateSignContent ());
412+ return StringUtils .join (getTextValue (enabled ), getTextValue (projectLimit ), getTextValue (deviceLimit ),
413+ Optional .ofNullable (cts ).map (CTSLicense ::generateSignContent ).orElse (EMPTY ),
414+ Optional .ofNullable (uiAutomator ).map (UIAutomatorLicense ::generateSignContent ).orElse (EMPTY )
415+ );
387416 }
388417
389418 public static class CTSLicense extends FeatureLicense {
@@ -458,6 +487,11 @@ public static class IOSLicense extends FeatureLicense {
458487 public IOSLicense () {
459488 }
460489
490+ public IOSLicense (boolean enabled , Integer deviceLimit ) {
491+ super (enabled );
492+ this .deviceLimit = deviceLimit ;
493+ }
494+
461495 public IOSLicense (Integer deviceLimit , Integer projectLimit , boolean enabled ) {
462496 super (enabled );
463497 this .deviceLimit = deviceLimit ;
@@ -504,6 +538,11 @@ public static class DesktopLicense extends FeatureLicense {
504538 public DesktopLicense () {
505539 }
506540
541+ public DesktopLicense (boolean enabled , Integer deviceLimit ) {
542+ super (enabled );
543+ this .deviceLimit = deviceLimit ;
544+ }
545+
507546 public DesktopLicense (Integer deviceLimit , Integer projectLimit , boolean enabled ) {
508547 super (enabled );
509548 this .deviceLimit = deviceLimit ;
0 commit comments