Skip to content

Commit 83fe527

Browse files
authored
Merge pull request #158 from eisbilir/fix/list-projects
fix list projects action
2 parents f654f56 + 00261cb commit 83fe527

File tree

1 file changed

+24
-91
lines changed

1 file changed

+24
-91
lines changed

src/main/java/com/cronos/onlinereview/actions/project/ListProjectsAction.java

Lines changed: 24 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

66
import com.cronos.onlinereview.Constants;
77
import com.cronos.onlinereview.dataaccess.DeliverableDataAccess;
8-
import com.cronos.onlinereview.dataaccess.ProjectDataAccess;
98
import com.cronos.onlinereview.dataaccess.ProjectPhaseDataAccess;
109
import com.cronos.onlinereview.util.ActionsHelper;
1110
import com.cronos.onlinereview.util.AuthorizationHelper;
1211
import com.cronos.onlinereview.util.Comparators;
1312
import com.cronos.onlinereview.util.ConfigHelper;
14-
import com.cronos.onlinereview.util.CorrectnessCheckResult;
15-
import com.cronos.onlinereview.util.EJBLibraryServicesLocator;
1613
import com.cronos.onlinereview.util.LoggingHelper;
17-
import com.cronos.onlinereview.util.LookupHelper;
1814

1915
import com.opensymphony.xwork2.TextProvider;
2016

@@ -27,7 +23,6 @@
2723
import com.topcoder.management.project.Project;
2824
import com.topcoder.management.project.ProjectCategory;
2925
import com.topcoder.management.project.ProjectManager;
30-
import com.topcoder.management.project.ProjectPropertyType;
3126
import com.topcoder.management.project.ProjectStatus;
3227
import com.topcoder.management.project.ProjectType;
3328
import com.topcoder.management.resource.Resource;
@@ -108,9 +103,10 @@ public String execute() throws BaseException {
108103
scope = "my";
109104
}
110105

106+
boolean isUserLoggedIn = AuthorizationHelper.isUserLoggedIn(request);
111107
// If the user is trying to access pages he doesn't have permission to view,
112108
// 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) {
114110
return "all";
115111
}
116112

@@ -144,8 +140,6 @@ public String execute() throws BaseException {
144140
request.setAttribute("projectTypes", projectTypes);
145141
request.setAttribute("projectCategories", projectCategories);
146142

147-
ProjectPropertyType[] projectInfoTypes = manager.getAllProjectPropertyTypes();
148-
149143
int[] typeCounts = new int[projectTypes.length];
150144
int[] categoryCounts = new int[projectCategories.length];
151145
String[] categoryIconNames = new String[projectCategories.length];
@@ -167,25 +161,34 @@ public String execute() throws BaseException {
167161
String[][] myDeliverables = (myProjects) ? new String[projectCategories.length][] : null;
168162

169163
// Fetch projects from the database. These projects will require further grouping
170-
ProjectStatus draftStatus = LookupHelper.getProjectStatus("Draft");
171-
ProjectStatus activeStatus = LookupHelper.getProjectStatus("Active");
172164
long userId = AuthorizationHelper.getLoggedInUserId(request);
173165
Project[] ungroupedProjects;
174-
ProjectDataAccess projectDataAccess = new ProjectDataAccess();
175166
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+
}
176176

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);
181183
} else {
182-
ungroupedProjects = projectDataAccess.searchActiveProjects(projectStatuses, projectCategories,
183-
projectInfoTypes);
184+
ungroupedProjects = manager.getAllProjects(null, activeStatus, projectCategories, false, hasManagerRole);
184185
}
185186
} 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+
}
189192
}
190193

191194
// Sort fetched projects. Currently sorting is done by projects' names only, in ascending order
@@ -198,26 +201,12 @@ public String execute() throws BaseException {
198201
}
199202

200203
Resource[] allMyResources = null;
201-
if (ungroupedProjects.length != 0 && AuthorizationHelper.isUserLoggedIn(request)) {
204+
if (ungroupedProjects.length != 0 && isUserLoggedIn) {
202205
if (activeTab == 1) { // My projects
203206
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);
208207
}
209208
}
210209

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-
221210
// Obtain an instance of Phase Manager
222211
PhaseManager phMgr = ActionsHelper.createPhaseManager(false);
223212

@@ -390,62 +379,6 @@ public String execute() throws BaseException {
390379
return SUCCESS;
391380
}
392381

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-
449382
/**
450383
* This static method performs a search for all outstanding deliverables. The list of these
451384
* deliverables is returned as is, i.e. as one-dimensional array, and will require further

0 commit comments

Comments
 (0)