99import com .codedx .client .api .Project ;
1010import com .codedx .client .api .ProjectsApi ;
1111import org .apache .commons .lang .StringUtils ;
12+ import org .apache .log4j .Logger ;
1213
1314import javax .ws .rs .ProcessingException ;
1415import java .util .ArrayList ;
1718
1819public class CodeDxScanTaskConfigurator extends AbstractTaskConfigurator {
1920
21+ private static final Logger _logger = Logger .getLogger (CodeDxScanTaskConfigurator .class );
22+
2023 // Since much work was done surrounding saving invalid configs, lets keep the code and toggle it with a flag.
2124 private static final boolean ALLOW_SAVE_INVALID_CONFIG = true ;
2225
@@ -61,6 +64,8 @@ public Map<String, String> generateTaskConfigMap(final ActionParametersMap param
6164
6265 final Map <String , String > config = super .generateTaskConfigMap (params , previousTaskDefinition );
6366
67+ _logger .info ("generateTaskConfigMap(...) called" );
68+
6469 // Save succeeded. Set this back to false.
6570 this .failedSave = null ;
6671
@@ -84,6 +89,8 @@ public void validate(final ActionParametersMap params, final ErrorCollection err
8489
8590 super .validate (params , errorCollection );
8691
92+ _logger .info ("validate(...) called" );
93+
8794 if (ALLOW_SAVE_INVALID_CONFIG ) {
8895 return ;
8996 }
@@ -94,16 +101,19 @@ public void validate(final ActionParametersMap params, final ErrorCollection err
94101 final String analysisName = params .getString ("analysisName" );
95102 if (StringUtils .isEmpty (analysisName )) {
96103 errorCollection .addError ("analysisName" , "Missing analysis name" );
104+ _logger .error ("Missing analysis name" );
97105 }
98106
99107 final String selectedProjectId = params .getString ("selectedProjectId" );
100108 if (StringUtils .isEmpty (selectedProjectId )) {
101109 errorCollection .addError ("selectedProjectId" , "Missing selected project" );
110+ _logger .error ("Missing selected project" );
102111 }
103112
104113 final String includePaths = params .getString ("includePaths" );
105114 if (StringUtils .isEmpty (includePaths )) {
106115 errorCollection .addError ("includePaths" , "Missing source and binary files" );
116+ _logger .error ("Missing source and binary files" );
107117 }
108118
109119 final String useDefaults = params .getString ("useDefaults" );
@@ -114,20 +124,25 @@ public void validate(final ActionParametersMap params, final ErrorCollection err
114124 // Make sure the URL is valid
115125 if (!ServerConfigManager .isURLValid (url )) {
116126 errorCollection .addError ("url" , "Malformed URL" );
127+ _logger .error ("Malformed URL" );
117128 }
118129 } else {
119130 errorCollection .addError ("url" , "Missing Code Dx URL" );
131+ _logger .error ("Missing Code Dx URL" );
120132 }
121133
122134 final String apiKey = params .getString ("apiKey" );
123135 if (StringUtils .isEmpty (apiKey )) {
124136 errorCollection .addError ("apiKey" , "Missing Code Dx API key" );
137+ _logger .error ("Missing Code Dx API key" );
125138 }
126139 }
127140 }
128141
129142 private static List <Project > getProjectList (Map <String , Object > context ) {
130143
144+ _logger .info ("getProjectList(...) called" );
145+
131146 String url = null ;
132147 String apiKey = null ;
133148 String fingerprint = null ;
@@ -144,6 +159,7 @@ private static List<Project> getProjectList(Map<String, Object> context) {
144159 }
145160
146161 if (url == null || apiKey == null || url .isEmpty () || apiKey .isEmpty ()) {
162+ _logger .info ("Code Dx URL and API key are not configured" );
147163 context .put ("reachabilityMessage" , "Code Dx URL and API key are not configured" );
148164 return new ArrayList <Project >();
149165 }
@@ -158,10 +174,13 @@ private static List<Project> getProjectList(Map<String, Object> context) {
158174
159175 } catch (IllegalArgumentException e ) {
160176 e .printStackTrace ();
177+ _logger .error (e .toString ());
161178 } catch (ApiException e ) {
162179 e .printStackTrace ();
180+ _logger .error (e .toString ());
163181 } catch (ProcessingException e ) {
164182 context .put ("reachabilityMessage" , "Connection refused. Please confirm that the URL is correct and that the Code Dx server is running." );
183+ _logger .error (e .toString ());
165184 }
166185
167186 return new ArrayList <Project >();
@@ -172,6 +191,8 @@ public void populateContextForCreate(final Map<String, Object> context) {
172191
173192 super .populateContextForCreate (context );
174193
194+ _logger .info ("populateContextForCreate(...) called" );
195+
175196 boolean defaultsSet = ServerConfigManager .getDefaultsSet ();
176197 context .put ("defaultsSet" , String .valueOf (defaultsSet ));
177198 context .put ("failedSave" , String .valueOf (failedSave ));
@@ -182,10 +203,12 @@ public void populateContextForCreate(final Map<String, Object> context) {
182203
183204 context .put ("useDefaults" , String .valueOf (defaultsSet ));
184205 if (defaultsSet ) {
206+ _logger .info ("User has default Code Dx credentials saved" );
185207 context .put ("url" , defaultUrl );
186208 context .put ("apiKey" , defaultApiKey );
187209 context .put ("fingerprint" , defaultFingerprint );
188210 } else {
211+ _logger .info ("User does not have default Code Dx credentials saved" );
189212 context .put ("url" , "" );
190213 context .put ("apiKey" , "" );
191214 context .put ("fingerprint" , "" );
@@ -218,6 +241,8 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
218241
219242 super .populateContextForEdit (context , taskDefinition );
220243
244+ _logger .info ("populateContextForEdit(...) called" );
245+
221246 // Get saved user config
222247 Map <String , String > config = taskDefinition .getConfiguration ();
223248
@@ -250,6 +275,7 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
250275
251276 if (failedSave != null ) {
252277
278+ _logger .info ("Failed save exists" );
253279 failedSave .setContext (context );
254280
255281 } else {
@@ -261,10 +287,12 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
261287
262288 // We check defaultsSet in case the defaults were erased. In that case we have what they used to be in the task configuration.
263289 if (useDefaults && defaultsSet ) {
290+ _logger .info ("User has default Code Dx credentials saved" );
264291 context .put ("url" , defaultUrl );
265292 context .put ("apiKey" , defaultApiKey );
266293 context .put ("fingerprint" , defaultFingerprint );
267294 } else {
295+ _logger .info ("User does not have default Code Dx credentials saved" );
268296 context .put ("url" , config .get ("url" ));
269297 context .put ("apiKey" , config .get ("apiKey" ));
270298 context .put ("fingerprint" , config .get ("fingerprint" ));
@@ -278,13 +306,15 @@ public void populateContextForEdit(Map<String, Object> context, TaskDefinition t
278306
279307 if (selectedProjectId != null && !selectedProjectId .isEmpty () && projectList .size () == 0 && (failedSave == null || !failedSave .missingSelectedProject )) {
280308 // Case where user already selected a project, but we can't communicate with CodeDx for the name. Just use a generic "name".
309+ _logger .info ("User already selected a project, but we can't communicate with CodeDx for the name. using a generic name." );
281310 Project p = new Project ();
282311 p .setId (Integer .parseInt (selectedProjectId ));
283312 p .setName ("Project Id: " + selectedProjectId );
284313 projectList .add (p );
285314
286315 // We get here if the previously selected project is not found
287316 if (context .get ("reachabilityMessage" ) == null ) {
317+ _logger .info ("Unable to access previously selected project from Code Dx" );
288318 context .put ("reachabilityMessage" , "Unable to access previously selected project from Code Dx" );
289319 }
290320 }
0 commit comments