5
5
6
6
import com .cronos .onlinereview .Constants ;
7
7
import com .cronos .onlinereview .dataaccess .DeliverableDataAccess ;
8
- import com .cronos .onlinereview .dataaccess .ProjectDataAccess ;
9
8
import com .cronos .onlinereview .dataaccess .ProjectPhaseDataAccess ;
10
9
import com .cronos .onlinereview .util .ActionsHelper ;
11
10
import com .cronos .onlinereview .util .AuthorizationHelper ;
12
11
import com .cronos .onlinereview .util .Comparators ;
13
12
import com .cronos .onlinereview .util .ConfigHelper ;
14
- import com .cronos .onlinereview .util .CorrectnessCheckResult ;
15
- import com .cronos .onlinereview .util .EJBLibraryServicesLocator ;
16
13
import com .cronos .onlinereview .util .LoggingHelper ;
17
- import com .cronos .onlinereview .util .LookupHelper ;
18
14
19
15
import com .opensymphony .xwork2 .TextProvider ;
20
16
27
23
import com .topcoder .management .project .Project ;
28
24
import com .topcoder .management .project .ProjectCategory ;
29
25
import com .topcoder .management .project .ProjectManager ;
30
- import com .topcoder .management .project .ProjectPropertyType ;
31
26
import com .topcoder .management .project .ProjectStatus ;
32
27
import com .topcoder .management .project .ProjectType ;
33
28
import com .topcoder .management .resource .Resource ;
@@ -108,9 +103,10 @@ public String execute() throws BaseException {
108
103
scope = "my" ;
109
104
}
110
105
106
+ boolean isUserLoggedIn = AuthorizationHelper .isUserLoggedIn (request );
111
107
// If the user is trying to access pages he doesn't have permission to view,
112
108
// redirect him to scope-all page, where public projects are listed
113
- if (scope .equalsIgnoreCase ("my" ) && !AuthorizationHelper . isUserLoggedIn ( request ) ) {
109
+ if (scope .equalsIgnoreCase ("my" ) && !isUserLoggedIn ) {
114
110
return "all" ;
115
111
}
116
112
@@ -144,8 +140,6 @@ public String execute() throws BaseException {
144
140
request .setAttribute ("projectTypes" , projectTypes );
145
141
request .setAttribute ("projectCategories" , projectCategories );
146
142
147
- ProjectPropertyType [] projectInfoTypes = manager .getAllProjectPropertyTypes ();
148
-
149
143
int [] typeCounts = new int [projectTypes .length ];
150
144
int [] categoryCounts = new int [projectCategories .length ];
151
145
String [] categoryIconNames = new String [projectCategories .length ];
@@ -167,25 +161,34 @@ public String execute() throws BaseException {
167
161
String [][] myDeliverables = (myProjects ) ? new String [projectCategories .length ][] : null ;
168
162
169
163
// Fetch projects from the database. These projects will require further grouping
170
- ProjectStatus draftStatus = LookupHelper .getProjectStatus ("Draft" );
171
- ProjectStatus activeStatus = LookupHelper .getProjectStatus ("Active" );
172
164
long userId = AuthorizationHelper .getLoggedInUserId (request );
173
165
Project [] ungroupedProjects ;
174
- ProjectDataAccess projectDataAccess = new ProjectDataAccess ();
175
166
ProjectStatus [] projectStatuses = manager .getAllProjectStatuses ();
167
+ ProjectStatus draftStatus = Arrays .stream (projectStatuses ).filter (x -> "Draft" .equals (x .getName ()))
168
+ .findFirst ().get ();
169
+ ProjectStatus activeStatus = Arrays .stream (projectStatuses ).filter (x -> "Active" .equals (x .getName ()))
170
+ .findFirst ().get ();
171
+
172
+ boolean hasManagerRole = false ;
173
+ if (isUserLoggedIn ) {
174
+ hasManagerRole = AuthorizationHelper .hasUserRole (request , Constants .GLOBAL_MANAGER_ROLE_NAME );
175
+ }
176
176
177
- if (activeTab != 1 ) {
178
- if (activeTab == 4 ) {
179
- ungroupedProjects = projectDataAccess .searchDraftProjects (projectStatuses , projectCategories ,
180
- projectInfoTypes );
177
+ if (activeTab == 1 ) {
178
+ // user projects
179
+ ungroupedProjects = manager .getAllProjects (userId , activeStatus , projectCategories , true , hasManagerRole );
180
+ } else if (activeTab == 2 ) {
181
+ if (isUserLoggedIn ) {
182
+ ungroupedProjects = manager .getAllProjects (userId , activeStatus , projectCategories , false , hasManagerRole );
181
183
} else {
182
- ungroupedProjects = projectDataAccess .searchActiveProjects (projectStatuses , projectCategories ,
183
- projectInfoTypes );
184
+ ungroupedProjects = manager .getAllProjects (null , activeStatus , projectCategories , false , hasManagerRole );
184
185
}
185
186
} else {
186
- // user projects
187
- ungroupedProjects = projectDataAccess .searchUserActiveProjects (userId , projectStatuses , projectCategories ,
188
- projectInfoTypes );
187
+ if (isUserLoggedIn ) {
188
+ ungroupedProjects = manager .getAllProjects (userId , draftStatus , projectCategories , false , hasManagerRole );
189
+ } else {
190
+ ungroupedProjects = manager .getAllProjects (null , draftStatus , projectCategories , false , hasManagerRole );
191
+ }
189
192
}
190
193
191
194
// Sort fetched projects. Currently sorting is done by projects' names only, in ascending order
@@ -198,26 +201,12 @@ public String execute() throws BaseException {
198
201
}
199
202
200
203
Resource [] allMyResources = null ;
201
- if (ungroupedProjects .length != 0 && AuthorizationHelper . isUserLoggedIn ( request ) ) {
204
+ if (ungroupedProjects .length != 0 && isUserLoggedIn ) {
202
205
if (activeTab == 1 ) { // My projects
203
206
allMyResources = ActionsHelper .searchUserResources (userId , activeStatus );
204
- } else if (activeTab == 2 ) { // Active projects
205
- allMyResources = ActionsHelper .searchUserResources (userId , activeStatus );
206
- } else if (activeTab == 4 ) { // Draft projects
207
- allMyResources = ActionsHelper .searchUserResources (userId , draftStatus );
208
207
}
209
208
}
210
209
211
- // new eligibility constraints
212
- // if the user is not a global manager and is seeing all projects eligibility checks need to be performed
213
- if (!AuthorizationHelper .hasUserRole (request , Constants .GLOBAL_MANAGER_ROLE_NAME ) &&
214
- (scope .equalsIgnoreCase ("all" ) || scope .equalsIgnoreCase ("draft" )) && projectFilters .size () > 0 ) {
215
-
216
- // remove those projects that the user can't see
217
- ungroupedProjects = filterUsingEligibilityConstraints (
218
- ungroupedProjects , projectFilters , allMyResources );
219
- }
220
-
221
210
// Obtain an instance of Phase Manager
222
211
PhaseManager phMgr = ActionsHelper .createPhaseManager (false );
223
212
@@ -390,62 +379,6 @@ public String execute() throws BaseException {
390
379
return SUCCESS ;
391
380
}
392
381
393
- /**
394
- * This method will return an array of <code>Project</code> with those projects the user can see taking into
395
- * consideration eligibility constraints.
396
- *
397
- * The user can see all those "public" (no eligibility constraints) projects plus those non-public projects where
398
- * he is assigned as a resource.
399
- *
400
- * @param ungroupedProjects all project to be displayed
401
- * @param projectFilters all project ids to be displayed
402
- * @param allMyResources all resources the user has for the projects to be displayed
403
- *
404
- * @return a <code>Project[]</code> with those projects that the user can see.
405
- *
406
- * @throws BaseException if any error occurs during eligibility services call
407
- */
408
- private Project [] filterUsingEligibilityConstraints (Project [] ungroupedProjects , List <Long > projectFilters ,
409
- Resource [] allMyResources ) throws BaseException {
410
- // check which projects have eligibility constraints
411
- Set <Long > projectsWithEligibilityConstraints ;
412
-
413
- try {
414
- projectsWithEligibilityConstraints =
415
- EJBLibraryServicesLocator .getContestEligibilityService ().haveEligibility (
416
- projectFilters .toArray (new Long [projectFilters .size ()]), false );
417
- } catch (Exception e ) {
418
- addActionError (getText (ACTION_ERROR_LIST_PROJECTS ));
419
- throw new BaseException ("It was not possible to retrieve eligibility constraints" , e );
420
- }
421
-
422
- // create a set of projects where the user is a resource
423
- Set <Long > resourceProjects = new HashSet <Long >();
424
-
425
- if (allMyResources != null ) {
426
- for (Resource r : allMyResources ) {
427
- resourceProjects .add (r .getProject ());
428
- }
429
- }
430
-
431
- // user can see those projects with eligibility constraints where he is a resource, so remove these
432
- // from the projectsWithEligibilityConstraints set
433
- projectsWithEligibilityConstraints .removeAll (resourceProjects );
434
-
435
- // finally remove those projects left in projectsWithEligibilityConstraints from ungroupedProjects
436
- List <Project > visibleProjects = new ArrayList <Project >();
437
-
438
- for (Project p : ungroupedProjects ) {
439
- if (!projectsWithEligibilityConstraints .contains (p .getId ())) {
440
- visibleProjects .add (p );
441
- }
442
- }
443
-
444
- ungroupedProjects = visibleProjects .toArray (new Project [visibleProjects .size ()]);
445
-
446
- return ungroupedProjects ;
447
- }
448
-
449
382
/**
450
383
* This static method performs a search for all outstanding deliverables. The list of these
451
384
* deliverables is returned as is, i.e. as one-dimensional array, and will require further
0 commit comments