Skip to content

Commit 143877c

Browse files
committed
update resource change analyzer
1 parent 8a9d033 commit 143877c

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed

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

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -415,22 +415,22 @@ public String execute() throws BaseException {
415415
getProjectPrizesToBeUpdated(request, project, createdPrize, updatedPrize, removedPrize);
416416

417417
Phase[] projectPhases;
418-
boolean updated = false;
419418
boolean phaseUpdated = false;
420419
boolean resourceUpdated = false;
421420
boolean prizeUpdated = false;
422421
boolean submissionUpdated = false;
423422
if (!ActionsHelper.isErrorsPresent(request)) {
424423
// Save the project phases
425424
projectPhases = saveProjectPhases(newProject, request, project, phasesJsMap, phasesToDelete);
426-
phaseUpdated = true;
425+
if (!ActionsHelper.isErrorsPresent(request)) {
426+
phaseUpdated = true;
427+
}
427428
} else {
428429
// Retrieve and sort project phases
429430
projectPhases = ActionsHelper.getPhasesForProject(ActionsHelper.createPhaseManager(false), project);
430431
Arrays.sort(projectPhases, new Comparators.ProjectPhaseComparer());
431432
}
432433
if (!ActionsHelper.isErrorsPresent(request)) {
433-
updated = true;
434434
// The project has been saved, so pre-populate last modification timestamp
435435
getModel().set("last_modification_time",
436436
ActionsHelper.getLastModificationTime(project, projectPhases).getTime());
@@ -439,8 +439,7 @@ public String execute() throws BaseException {
439439
// resources must be saved even if there are validation errors to validate resources
440440
if (!ActionsHelper.isErrorsPresent(request)) {
441441
// Save the project resources
442-
saveResources(request, project, projectPhases, phasesJsMap);
443-
resourceUpdated = true;
442+
resourceUpdated = saveResources(request, project, projectPhases, phasesJsMap);
444443
}
445444

446445
if (!ActionsHelper.isErrorsPresent(request)) {
@@ -476,11 +475,9 @@ public String execute() throws BaseException {
476475
prizeUpdated = true;
477476
}
478477
}
479-
if (updated) {
480-
GrpcHelper.getSyncServiceRpc().saveProjectSync(project.getId(), statusHasChanged, categoryHasChanged,
481-
externalRefIdHasChanged, directProjectIdHasChanged, phaseUpdated, resourceUpdated, prizeUpdated,
482-
submissionUpdated);
483-
}
478+
GrpcHelper.getSyncServiceRpc().saveProjectSync(project.getId(), statusHasChanged, categoryHasChanged,
479+
externalRefIdHasChanged, directProjectIdHasChanged, phaseUpdated, resourceUpdated, prizeUpdated,
480+
submissionUpdated);
484481
// Check if there are any validation errors and return appropriate forward
485482
if (ActionsHelper.isErrorsPresent(request)) {
486483
// Check if the form is really for new project
@@ -1521,7 +1518,7 @@ private boolean checkUserChallengeEligibility(HttpServletRequest request, int re
15211518
* @param phasesJsMap the phasesJsMap
15221519
* @throws BaseException if any error occurs
15231520
*/
1524-
private void saveResources(HttpServletRequest request,
1521+
private boolean saveResources(HttpServletRequest request,
15251522
Project project, Phase[] projectPhases, Map<Object, Phase> phasesJsMap) throws BaseException {
15261523
// Obtain the instance of the User Retrieval
15271524
UserRetrieval userRetrieval = ActionsHelper.createUserRetrieval(request);
@@ -1532,19 +1529,21 @@ private void saveResources(HttpServletRequest request,
15321529
String[] resourceNames = (String[]) getModel().get("resources_name");
15331530

15341531
// HashSet used to identify resource of new user
1535-
Set<Long> newUsers = new HashSet<Long>();
1536-
Set<Long> newModerators = new HashSet<Long>();
1537-
Set<Long> oldUsers = new HashSet<Long>();
1538-
Set<Long> deletedUsers = new HashSet<Long>();
1532+
//Set<Long> newUsers = new HashSet<Long>();
1533+
//Set<Long> newModerators = new HashSet<Long>();
1534+
//Set<Long> oldUsers = new HashSet<Long>();
1535+
//Set<Long> deletedUsers = new HashSet<Long>();
15391536
Set<Long> newSubmitters = new HashSet<Long>();
1540-
Set<Long> newUsersForumWatch = new HashSet<Long>();
1537+
//Set<Long> newUsersForumWatch = new HashSet<Long>();
15411538

15421539
Set<Long> newUsersForNotification = new HashSet<Long>();
15431540
Set<Long> deletedUsersForNotification = new HashSet<Long>();
1544-
Set<Long> deletedUsersForForumWatch = new HashSet<Long>();
1541+
//Set<Long> deletedUsersForForumWatch = new HashSet<Long>();
1542+
boolean resourcesUpdated = false;
15451543

15461544
// 0-index resource is skipped as it is a "dummy" one
15471545
boolean allResourcesValid = true;
1546+
ExternalUser[] externalUsers = new ExternalUser[resourceNames.length];
15481547
for (int i = 1; i < resourceNames.length; i++) {
15491548

15501549
if (resourceNames[i] == null || resourceNames[i].trim().length() == 0) {
@@ -1556,6 +1555,7 @@ private void saveResources(HttpServletRequest request,
15561555

15571556
// Get info about user with the specified handle
15581557
ExternalUser user = userRetrieval.retrieveUser(resourceNames[i]);
1558+
externalUsers[i] = user;
15591559

15601560
// If there is no user with such handle, indicate an error
15611561
if (user == null) {
@@ -1568,7 +1568,7 @@ private void saveResources(HttpServletRequest request,
15681568
// validate resources have correct terms of use
15691569
try {
15701570
allResourcesValid = allResourcesValid && validateResourceTermsOfUse(request, project, userRetrieval, resourceNames);
1571-
allResourcesValid = allResourcesValid && validateResourceEligibility(request, project, userRetrieval, resourceNames);
1571+
allResourcesValid = allResourcesValid && validateResourceEligibility(request, project, userRetrieval, resourceNames, externalUsers);
15721572
} catch (ContestEligibilityValidatorException e) {
15731573
throw new BaseException(e);
15741574
}
@@ -1798,14 +1798,14 @@ private void saveResources(HttpServletRequest request,
17981798

17991799
// No resources are updated if at least one of them is incorrect.
18001800
if (!allResourcesValid) {
1801-
return;
1801+
return resourcesUpdated;
18021802
}
18031803

18041804
// 0-index resource is skipped as it is a "dummy" one
18051805
for (int i = 1; i < resourceNames.length; i++) {
18061806

18071807
// Get info about user with the specified handle
1808-
ExternalUser user = userRetrieval.retrieveUser(resourceNames[i]);
1808+
ExternalUser user = externalUsers[i];
18091809

18101810
Resource resource;
18111811

@@ -1818,7 +1818,8 @@ private void saveResources(HttpServletRequest request,
18181818

18191819
resource.setProperty("Registration Date", DATE_FORMAT.format(new Date()));
18201820

1821-
newUsers.add(user.getId());
1821+
//newUsers.add(user.getId());
1822+
resourcesUpdated = true;
18221823

18231824
ResourceRole role = LookupHelper.getResourceRole((Long) getModel().get("resources_role", i));
18241825
if (!role.getName().equals("Observer") || Boolean.parseBoolean(retrieveUserPreference(user.getId(), GLOBAL_TIMELINE_NOTIFICATION))) {
@@ -1832,20 +1833,20 @@ private void saveResources(HttpServletRequest request,
18321833
if (resourceId != -1) {
18331834
// Retrieve the resource with the specified id
18341835
resource = resourceManager.getResource(resourceId);
1835-
oldUsers.add(user.getId());
1836+
//oldUsers.add(user.getId());
18361837
//System.out.println("REMOVE:" + user.getId());
18371838
} else {
18381839
// -1 value as id marks the resources that were't persisted in DB yet
18391840
// and so should be skipped for actions other then "add"
1840-
oldUsers.add(user.getId());
1841+
//oldUsers.add(user.getId());
18411842
//System.out.println("REMOVE:" + user.getId());
18421843
continue;
18431844
}
18441845
}
18451846

18461847
// If action is "delete", delete the resource and proceed to the next one
18471848
if ("delete".equals(resourceAction)) {
1848-
deletedUsers.add(user.getId());
1849+
//deletedUsers.add(user.getId());
18491850

18501851
// delete project payments
18511852
for (ProjectPayment payment : allPayments) {
@@ -1884,13 +1885,13 @@ private void saveResources(HttpServletRequest request,
18841885
}
18851886

18861887
if (!Boolean.parseBoolean(retrieveUserPreference(user.getId(), GLOBAL_FORUM_WATCH))) {
1887-
deletedUsersForForumWatch.add(user.getId());
1888+
//deletedUsersForForumWatch.add(user.getId());
18881889
}
18891890
}
18901891
if (resource.getResourceRole().getName().equals("Observer")) {
18911892
// change from observer to other role
18921893
// add forum watch & notification anyway
1893-
newUsersForumWatch.add(user.getId());
1894+
//newUsersForumWatch.add(user.getId());
18941895
newUsersForNotification.add(user.getId());
18951896
}
18961897
}
@@ -1933,7 +1934,7 @@ private void saveResources(HttpServletRequest request,
19331934
// add "Appeals Completed Early" flag.
19341935
resource.setProperty(Constants.APPEALS_COMPLETED_EARLY_PROPERTY_KEY, Constants.NO_VALUE);
19351936
}
1936-
1937+
/*
19371938
if ("add".equals(resourceAction)) {
19381939
19391940
if (resourceRole.equals("Manager") || resourceRole.equals("Observer")
@@ -1947,22 +1948,23 @@ private void saveResources(HttpServletRequest request,
19471948
if (!resourceRole.equals("Observer")
19481949
|| Boolean.parseBoolean(retrieveUserPreference(
19491950
user.getId(), GLOBAL_FORUM_WATCH))) {
1950-
newUsersForumWatch.add(user.getId());
1951+
//newUsersForumWatch.add(user.getId());
19511952
}
19521953
}
19531954
19541955
}
19551956
}
1956-
1957+
*/
19571958
// client manager and copilot have moderator role
1959+
/*
19581960
if (resourceRole.equals("Client Manager") || resourceRole.equals("Copilot")
19591961
|| resourceRole.equals("Observer") || resourceRole.equals("Designer"))
19601962
{
1961-
newUsers.remove(user.getId());
1962-
newModerators.add(user.getId());
1963+
//newUsers.remove(user.getId());
1964+
//newModerators.add(user.getId());
19631965
19641966
}
1965-
1967+
*/
19661968
// make sure "Appeals Completed Early" flag is not set if the role is not submitter.
19671969
if (resourceRoleChanged && !resourceRole.equals(Constants.SUBMITTER_ROLE_NAME)) {
19681970
resource.setProperty(Constants.APPEALS_COMPLETED_EARLY_PROPERTY_KEY, null);
@@ -1978,7 +1980,8 @@ private void saveResources(HttpServletRequest request,
19781980

19791981
// check the list of users to delete and remove those still have other roles
19801982
Resource[] allProjectResources = ActionsHelper.getAllResourcesForProject(project);
1981-
Set<Long> usersToKeep = new HashSet<Long>();
1983+
//Set<Long> usersToKeep = new HashSet<Long>();
1984+
/*
19821985
for (Long id : deletedUsers) {
19831986
for (Resource projectResource : allProjectResources) {
19841987
Long userId = projectResource.getUserId();
@@ -1989,12 +1992,14 @@ private void saveResources(HttpServletRequest request,
19891992
}
19901993
}
19911994
}
1992-
deletedUsers.removeAll(usersToKeep);
1993-
1995+
*/
1996+
//deletedUsers.removeAll(usersToKeep);
19941997

1998+
/*
19951999
for (Long id : oldUsers) {
19962000
newUsers.remove(id);
19972001
}
2002+
*/
19982003

19992004
// Populate project_result and component_inquiry for new submitters
20002005
ActionsHelper.populateProjectResult(project, newSubmitters);
@@ -2031,6 +2036,7 @@ private void saveResources(HttpServletRequest request,
20312036
resourceManager.addNotifications(userIds, project.getId(),
20322037
timelineNotificationId, Long.toString(AuthorizationHelper.getLoggedInUserId(request)));
20332038
}
2039+
return resourcesUpdated;
20342040
}
20352041

20362042
/**
@@ -2126,7 +2132,7 @@ private boolean validateResourceTermsOfUse(HttpServletRequest request,
21262132
* @return true if all resources are valid
21272133
*/
21282134
private boolean validateResourceEligibility(HttpServletRequest request,
2129-
Project project, UserRetrieval userRetrieval, String[] resourceNames)
2135+
Project project, UserRetrieval userRetrieval, String[] resourceNames, ExternalUser[] externalUsers)
21302136
throws BaseException, ContestEligibilityValidatorException {
21312137

21322138
boolean allResourcesValid = true;
@@ -2136,7 +2142,7 @@ private boolean validateResourceEligibility(HttpServletRequest request,
21362142
// 0-index resource is skipped as it is a "dummy" one
21372143
for (int i = 1; i < resourceNames.length; i++) {
21382144
if (resourceNames[i] != null && resourceNames[i].trim().length() > 0) {
2139-
ExternalUser user = userRetrieval.retrieveUser(resourceNames[i]);
2145+
ExternalUser user = externalUsers[i];
21402146
String resourceAction = (String) getModel().get("resources_action", i);
21412147
// check for additions or modifications
21422148
if (!"delete".equals(resourceAction)) {

src/main/java/com/cronos/onlinereview/util/AuthorizationHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,18 @@ public static void removeLoginRedirect(HttpServletRequest request) {
158158
* information about the user possibly logged in.
159159
*/
160160
public static long getLoggedInUserId(HttpServletRequest request) {
161+
if (request.getAttribute("loggedInUserId") != null) {
162+
return (Long) request.getAttribute("loggedInUserId");
163+
}
161164
Long userId = null;
162165
try {
163166
userId = getSsoCookieService().getUserIdFromSSOCookie(request);
164167
} catch (Exception e) {
165168
e.printStackTrace();
166169
}
167-
return (userId != null) ? (userId) : NO_USER_LOGGED_IN_ID;
170+
userId = (userId != null) ? (userId) : NO_USER_LOGGED_IN_ID;
171+
request.setAttribute("loggedInUserId", userId);
172+
return userId;
168173
}
169174

170175
/**

0 commit comments

Comments
 (0)