44import java .util .List ;
55import java .util .Map ;
66import java .util .Set ;
7+ import java .util .logging .Logger ;
78
89import javax .servlet .ServletException ;
910
1617import com .lambdatest .jenkins .credential .MagicPlugCredentialsImpl ;
1718import com .lambdatest .jenkins .freestyle .api .Constant ;
1819import com .lambdatest .jenkins .freestyle .api .service .CapabilityService ;
20+ import com .lambdatest .jenkins .freestyle .data .AppAutomationCapabilityRequest ;
21+ import com .lambdatest .jenkins .freestyle .api .service .AppAutomationCapabilityService ;
1922
2023import hudson .Extension ;
2124import hudson .model .AbstractProject ;
2730@ Extension
2831public class MagicPlugDescriptor extends BuildWrapperDescriptor {
2932
33+ private final static Logger logger = Logger .getLogger (MagicPlugDescriptor .class .getName ());
34+
3035 @ Override
3136 public boolean isApplicable (AbstractProject <?, ?> item ) {
3237 return true ;
@@ -43,7 +48,7 @@ public MagicPlugDescriptor() {
4348 }
4449
4550 public FormValidation doPing () throws IOException , ServletException {
46- System . out . println ("doPing" );
51+ logger . info ("doPing" );
4752 if (new CapabilityService ().ping ()) {
4853 return FormValidation .ok ("Ping Successful" );
4954 } else {
@@ -72,7 +77,7 @@ public ListBoxModel doFillBrowserNameItems(@QueryParameter String operatingSyste
7277 items .add (Constant .DEFAULT_BROWSER_NAME_VALUE , Constant .EMPTY );
7378 return items ;
7479 }
75- System . out . println ( operatingSystem );
80+ logger . info ( "operatingSystem : +" + operatingSystem );
7681 Set <String > supportedBrowsers = CapabilityService .getBrowserNames (operatingSystem );
7782 if (!CollectionUtils .isEmpty (supportedBrowsers )) {
7883 supportedBrowsers .forEach (br -> {
@@ -85,10 +90,10 @@ public ListBoxModel doFillBrowserNameItems(@QueryParameter String operatingSyste
8590 public ListBoxModel doFillBrowserVersionItems (@ QueryParameter String operatingSystem ,
8691 @ QueryParameter String browserName ) {
8792 ListBoxModel items = new ListBoxModel ();
88- System . out . println (operatingSystem + "::" + browserName );
93+ logger . info (operatingSystem + "::" + browserName );
8994 if (!StringUtils .isBlank (operatingSystem ) && StringUtils .isBlank (browserName )) {
9095 browserName = "Chrome" ;
91- System . out . println ("Chrome added" );
96+ logger . info ("Chrome added" );
9297 } else if (StringUtils .isBlank (operatingSystem ) || StringUtils .isBlank (browserName )) {
9398 items .add (Constant .DEFAULT_BROWSER_VERSION_VALUE , Constant .EMPTY );
9499 return items ;
@@ -108,7 +113,7 @@ public ListBoxModel doFillResolutionItems(@QueryParameter String operatingSystem
108113 items .add (Constant .DEFAULT_RESOLUTION_VALUE , Constant .EMPTY );
109114 return items ;
110115 }
111- System . out . println ( operatingSystem );
116+ logger . info ( "operatingSystem : " + operatingSystem );
112117 List <String > supportedBrowsers = CapabilityService .getResolutions (operatingSystem );
113118 if (!CollectionUtils .isEmpty (supportedBrowsers )) {
114119 supportedBrowsers .forEach (br -> {
@@ -120,9 +125,9 @@ public ListBoxModel doFillResolutionItems(@QueryParameter String operatingSystem
120125
121126 public ListBoxModel doFillCredentialsIdItems (@ QueryParameter String credentialsId ) {
122127 if (!StringUtils .isBlank (credentialsId )) {
123- System . out . println (credentialsId );
128+ logger . info (credentialsId );
124129 } else {
125- System . out . println ("Not Found" );
130+ logger . info ("Not Found" );
126131 }
127132 return new ListBoxModel ();
128133 }
@@ -131,4 +136,81 @@ public ListBoxModel doFillCredentialsIdItems(ItemGroup context) {
131136 return new StandardListBoxModel ().withEmptySelection ().withMatching (CredentialsMatchers .always (),
132137 MagicPlugCredentialsImpl .all (context ));
133138 }
139+
140+ public ListBoxModel doFillPlatformNameItems () {
141+ Map <String , String > supportedPlatforms = AppAutomationCapabilityService .getPlatformNames ();
142+ logger .info ("OS triggered : " + supportedPlatforms );
143+ ListBoxModel items = new ListBoxModel ();
144+ items .add (Constant .DEFAULT_PLATFORM_NAME_VALUE , Constant .EMPTY );
145+ supportedPlatforms .forEach ((key , value ) -> {
146+ items .add (value , key );
147+ });
148+ return items ;
149+ }
150+
151+ public ListBoxModel doFillBrandNameItems (@ QueryParameter String platformName ) {
152+ ListBoxModel items = new ListBoxModel ();
153+ if (StringUtils .isBlank (platformName )) {
154+ items .add (Constant .DEFAULT_BRAND_NAME_VALUE , Constant .EMPTY );
155+ return items ;
156+ }
157+ logger .info ("platformName : " + platformName );
158+ Set <String > supportedBrands = AppAutomationCapabilityService .getBrandNames (platformName );
159+ logger .info ("Brand Names triggered : " + supportedBrands );
160+ if (!CollectionUtils .isEmpty (supportedBrands )) {
161+ supportedBrands .forEach (br -> {
162+ items .add (br , br );
163+ });
164+ }
165+ return items ;
166+ }
167+
168+ public ListBoxModel doFillDeviceNameItems (@ QueryParameter String platformName , @ QueryParameter String brandName ) {
169+ ListBoxModel items = new ListBoxModel ();
170+ logger .info (platformName + "::" + brandName );
171+ if (!StringUtils .isBlank (platformName ) && StringUtils .isBlank (brandName )) {
172+ brandName = "Asus" ;
173+ logger .info ("Asus added" );
174+ } else if (StringUtils .isBlank (platformName ) || StringUtils .isBlank (brandName )) {
175+ items .add (Constant .DEFAULT_DEVICE_NAME_VALUE , Constant .EMPTY );
176+ return items ;
177+ }
178+ logger .info ("platformName : " + platformName + "\n " + "brandName : " + brandName );
179+ Set <String > supportedDevices = AppAutomationCapabilityService .getDeviceNames (platformName , brandName );
180+ logger .info ("Device Names triggered : " + supportedDevices );
181+ if (!CollectionUtils .isEmpty (supportedDevices )) {
182+ supportedDevices .forEach (br -> {
183+ items .add (br , br );
184+ });
185+ }
186+ return items ;
187+ }
188+
189+ public ListBoxModel doFillDeviceVersionItems (@ QueryParameter String platformName ,
190+ @ QueryParameter String deviceName ) {
191+ ListBoxModel items = new ListBoxModel ();
192+ logger .info (platformName + "::" + deviceName );
193+ if (!StringUtils .isBlank (platformName ) && StringUtils .isBlank (deviceName )) {
194+ deviceName = "Zenfone 6" ;
195+ logger .info ("Zenfone 6 added" );
196+ } else if (StringUtils .isBlank (platformName ) || StringUtils .isBlank (deviceName )) {
197+ items .add (Constant .DEFAULT_DEVICE_VERSION_VALUE , Constant .EMPTY );
198+ return items ;
199+ }
200+ Set <String > supportedDeviceVersions = AppAutomationCapabilityService .getDeviceVersions (platformName , deviceName );
201+ logger .info ("Device Versions triggered : " + supportedDeviceVersions );
202+ if (!CollectionUtils .isEmpty (supportedDeviceVersions )) {
203+ supportedDeviceVersions .forEach (ver -> {
204+ items .add (ver , ver );
205+ });
206+ }
207+ return items ;
208+ }
209+
210+ public ListBoxModel doFillAppId () {
211+ ListBoxModel items = new ListBoxModel ();
212+ items .add (Constant .DEFAULT_APP_ID , Constant .EMPTY );
213+ return items ;
214+ }
215+
134216}
0 commit comments