Skip to content

Commit

Permalink
Merge branch 'master' into 6238-appveyor
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
wkurniawan07 committed Jan 17, 2017
2 parents 324bd26 + 0c82919 commit 5147f5d
Show file tree
Hide file tree
Showing 345 changed files with 45,487 additions and 45,649 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Expand Up @@ -427,6 +427,13 @@ def afterTestClosure = { descriptor, result ->
}
}

def checkConfigFailureClosure = { descriptor, result ->
if (result.exception instanceof org.gradle.messaging.remote.internal.PlaceholderException
&& result.exception.toString().startsWith("org.gradle.api.internal.tasks.testing.TestSuiteExecutionException")) {
throw new GradleException('Detected TestNG configuration failure - check src/test/testng-ci.xml')
}
}

task ciTests {
description "Runs the full test suite and retries failed test up to ${numOfTestRetries} times."
group "Test"
Expand Down Expand Up @@ -454,6 +461,8 @@ task ciTests {
}
if (isLastRetry) {
afterTest afterTestClosure
} else if (isFirstTry) {
afterSuite checkConfigFailureClosure
}
finalizedBy "killFirefox${id}"
dependsOn enhancerRun
Expand Down
Expand Up @@ -39,8 +39,8 @@ public class RepairTeamNameInStudentResponseAndCommentAttributes extends RemoteA

private StudentsDb studentsDb = new StudentsDb();
private StudentsLogic studentsLogic = StudentsLogic.inst();
private FeedbackResponsesLogic responsesLogic = new FeedbackResponsesLogic();
private CommentsLogic commentsLogic = new CommentsLogic();
private FeedbackResponsesLogic responsesLogic = FeedbackResponsesLogic.inst();
private CommentsLogic commentsLogic = CommentsLogic.inst();

public static void main(String[] args) throws IOException {
RepairTeamNameInStudentResponseAndCommentAttributes migrator =
Expand Down
@@ -1,8 +1,8 @@
package teammates.client.scripts;

import static teammates.logic.core.TeamEvalResult.NSB;
import static teammates.logic.core.TeamEvalResult.NSU;
import teammates.logic.core.TeamEvalResult;
import static teammates.common.datatransfer.TeamEvalResult.NSB;
import static teammates.common.datatransfer.TeamEvalResult.NSU;
import teammates.common.datatransfer.TeamEvalResult;

/**
* Displays the step-by-step calculations for contribution question results.
Expand Down
Expand Up @@ -73,7 +73,7 @@ public class UploadBackupData extends RemoteApiClient {
private static final FeedbackResponsesDb frDb = new FeedbackResponsesDb();
private static final FeedbackResponseCommentsDb fcDb = new FeedbackResponseCommentsDb();
private static final ProfilesDb profilesDb = new ProfilesDb();
private static final FeedbackQuestionsLogic feedbackQuestionsLogic = new FeedbackQuestionsLogic();
private static final FeedbackQuestionsLogic feedbackQuestionsLogic = FeedbackQuestionsLogic.inst();

public static void main(String[] args) throws Exception {
UploadBackupData uploadBackupData = new UploadBackupData();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/teammates/common/datatransfer/AccountAttributes.java
Expand Up @@ -65,6 +65,23 @@ public AccountAttributes(String googleId, String name, boolean isInstructor,
this.studentProfile.googleId = this.googleId;
}

/**
* Gets a deep copy of this object.
*/
public AccountAttributes getCopy() {
// toEntity() requires a non-null student profile
boolean isStudentProfileNull = this.studentProfile == null;
if (isStudentProfileNull) {
this.studentProfile = new StudentProfileAttributes();
}
AccountAttributes copy = new AccountAttributes(this.toEntity());
if (isStudentProfileNull) {
copy.studentProfile = null;
this.studentProfile = null;
}
return copy;
}

public boolean isInstructor() {
return isInstructor;
}
Expand Down
Expand Up @@ -16,7 +16,6 @@
import teammates.common.util.Templates;
import teammates.common.util.Templates.FeedbackQuestion.FormTemplates;
import teammates.common.util.Templates.FeedbackQuestion.Slots;
import teammates.logic.core.TeamEvalResult;
import teammates.ui.template.InstructorFeedbackResultsResponseRow;

public class FeedbackContributionQuestionDetails extends FeedbackQuestionDetails {
Expand Down
Expand Up @@ -6,7 +6,6 @@
import teammates.common.util.Const;
import teammates.common.util.Logger;
import teammates.common.util.Sanitizer;
import teammates.logic.core.TeamEvalResult;

public class FeedbackContributionResponseDetails extends FeedbackResponseDetails {

Expand Down
Expand Up @@ -15,7 +15,6 @@
import teammates.common.util.Logger;
import teammates.common.util.Sanitizer;
import teammates.common.util.StringHelper;
import teammates.logic.core.TeamEvalResult;

/**
* Represents detailed results for an feedback session.
Expand Down
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.common.datatransfer;

import java.util.Arrays;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/teammates/common/util/ActivityLogEntry.java
Expand Up @@ -131,7 +131,7 @@ public ActivityLogEntry(String servlet, String act, AccountAttributes acc, Strin
name = "Unknown";
email = "Unknown";

UserType userType = GateKeeper.inst().getCurrentUser();
UserType userType = new GateKeeper().getCurrentUser();
googleId = userType == null ? "Unknown" : userType.id;

} else {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/teammates/logic/api/EmailGenerator.java
Expand Up @@ -32,9 +32,10 @@

/**
* Handles operations related to generating emails to be sent from provided templates.
* @see EmailTemplates
* @see EmailType
* @see EmailWrapper
*
* @see {@link EmailTemplates}
* @see {@link EmailType}
* @see {@link EmailWrapper}
*/
public class EmailGenerator {

Expand Down
24 changes: 10 additions & 14 deletions src/main/java/teammates/logic/api/GateKeeper.java
Expand Up @@ -19,16 +19,12 @@
import com.google.appengine.api.users.UserServiceFactory;

public class GateKeeper {

private static UserService userService = UserServiceFactory.getUserService();

private static GateKeeper instance;

public static GateKeeper inst() {
if (instance == null) {
instance = new GateKeeper();
}
return instance;
}

private static final AccountsLogic accountsLogic = AccountsLogic.inst();
private static final InstructorsLogic instructorsLogic = InstructorsLogic.inst();
private static final StudentsLogic studentsLogic = StudentsLogic.inst();

public boolean isUserLoggedOn() {
return userService.getCurrentUser() != null;
Expand Down Expand Up @@ -326,19 +322,19 @@ private boolean isAdministrator() {
private boolean isInstructor() {
User user = userService.getCurrentUser();
Assumption.assertNotNull(user);
return AccountsLogic.inst().isAccountAnInstructor(user.getNickname());
return accountsLogic.isAccountAnInstructor(user.getNickname());
}

private boolean isStudent() {
User user = userService.getCurrentUser();
Assumption.assertNotNull(user);

return StudentsLogic.inst().isStudentInAnyCourse(user.getNickname());
return studentsLogic.isStudentInAnyCourse(user.getNickname());
}

public void verifyAccessibleForCurrentUserAsInstructorOrTeamMember(AccountAttributes account, String courseId,
String section, String email) {
InstructorAttributes instructor = InstructorsLogic.inst().getInstructorForGoogleId(courseId, account.googleId);
InstructorAttributes instructor = instructorsLogic.getInstructorForGoogleId(courseId, account.googleId);
if (instructor != null) {
if (!instructor.isAllowedForPrivilege(section,
Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS)) {
Expand All @@ -347,9 +343,9 @@ public void verifyAccessibleForCurrentUserAsInstructorOrTeamMember(AccountAttrib
return;
}

StudentAttributes student = StudentsLogic.inst().getStudentForCourseIdAndGoogleId(courseId, account.googleId);
StudentAttributes student = studentsLogic.getStudentForCourseIdAndGoogleId(courseId, account.googleId);
if (student != null) {
if (!StudentsLogic.inst().isStudentsInSameTeam(courseId, email, student.email)) {
if (!studentsLogic.isStudentsInSameTeam(courseId, email, student.email)) {
throw new UnauthorizedAccessException("Student does not have enough privileges to view the photo");
}
return;
Expand Down
106 changes: 67 additions & 39 deletions src/main/java/teammates/logic/api/Logic.java
Expand Up @@ -31,10 +31,10 @@
import teammates.common.datatransfer.InstructorSearchResultBundle;
import teammates.common.datatransfer.SectionDetailsBundle;
import teammates.common.datatransfer.StudentAttributes;
import teammates.common.datatransfer.StudentEnrollDetails;
import teammates.common.datatransfer.StudentProfileAttributes;
import teammates.common.datatransfer.StudentSearchResultBundle;
import teammates.common.datatransfer.TeamDetailsBundle;
import teammates.common.datatransfer.UserType;
import teammates.common.exception.EnrollException;
import teammates.common.exception.EntityAlreadyExistsException;
import teammates.common.exception.EntityDoesNotExistException;
Expand Down Expand Up @@ -67,12 +67,9 @@
*/
public class Logic {

//TODO: sanitizes values received from outside.

//TODO: remove this constant
public static final String ERROR_NULL_PARAMETER = "The supplied parameter was null\n";

protected static GateKeeper gateKeeper = GateKeeper.inst();
protected static AccountsLogic accountsLogic = AccountsLogic.inst();
protected static StudentsLogic studentsLogic = StudentsLogic.inst();
protected static InstructorsLogic instructorsLogic = InstructorsLogic.inst();
Expand All @@ -85,41 +82,6 @@ public class Logic {
protected static AdminEmailsLogic adminEmailsLogic = AdminEmailsLogic.inst();
protected static ProfilesLogic profilesLogic = ProfilesLogic.inst();

/**
* Produces the URL the user should use to login to the system
*
* @param redirectUrl
* This is the URL the user will be directed to after login.
*/
public static String getLoginUrl(String redirectUrl) {
return gateKeeper.getLoginUrl(redirectUrl);
}

/**
* Produces the URL used to logout the user
*
* @param redirectUrl
* This is the URL the user will be directed to after logout.
*/
public static String getLogoutUrl(String redirectUrl) {
return gateKeeper.getLogoutUrl(redirectUrl);
}

/**
* Verifies if the user is logged into his/her Google account
*/
public static boolean isUserLoggedIn() {
return gateKeeper.isUserLoggedOn();
}

/**
* @return Returns null if the user is not logged in.
*/
public UserType getCurrentUser() {
return gateKeeper.getCurrentUser();
}


/**
* Creates a new Account based on given values. If a profile is not given,
* a default empty profile is created for the user<br>
Expand Down Expand Up @@ -2200,6 +2162,14 @@ public CommentAttributes getComment(Long commentId) {
return commentsLogic.getComment(commentId);
}

/**
* @see {@link CommentsLogic#getComment(CommentAttributes)}.
*/
public CommentAttributes getComment(CommentAttributes comment) {
Assumption.assertNotNull(comment);
return commentsLogic.getComment(comment);
}

/**
* Create or update document for the given Comment
* @param comment to be put into documents
Expand Down Expand Up @@ -2518,4 +2488,62 @@ public List<String> getArchivedCourseIds(List<CourseAttributes> allCourses,
return coursesLogic.getArchivedCourseIds(allCourses, instructorsForCourses);
}

/**
* @see {@link FeedbackResponsesLogic#getFeedbackResponsesForSession(String, String)}
*/
public List<FeedbackResponseAttributes>
getFeedbackResponsesForSession(String feedbackSessionName, String courseId) {
Assumption.assertNotNull(feedbackSessionName);
Assumption.assertNotNull(courseId);
return feedbackResponsesLogic.getFeedbackResponsesForSession(feedbackSessionName, courseId);
}

/**
* @see {@link StudentsLogic#adjustFeedbackResponseForEnrollments(List, FeedbackResponseAttributes)}
*/
public void adjustFeedbackResponseForEnrollments(List<StudentEnrollDetails> enrollmentList,
FeedbackResponseAttributes response)
throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(enrollmentList);
Assumption.assertNotNull(response);
studentsLogic.adjustFeedbackResponseForEnrollments(enrollmentList, response);
}

/**
* @see {@link FeedbackSessionsLogic#getFeedbackSessionsClosedWithinThePastHour()}
*/
public List<FeedbackSessionAttributes> getFeedbackSessionsClosedWithinThePastHour() {
return feedbackSessionsLogic.getFeedbackSessionsClosedWithinThePastHour();
}

/**
* @see {@link FeedbackSessionsLogic#getFeedbackSessionsClosingWithinTimeLimit()}
*/
public List<FeedbackSessionAttributes> getFeedbackSessionsClosingWithinTimeLimit() {
return feedbackSessionsLogic.getFeedbackSessionsClosingWithinTimeLimit();
}

/**
* @see {@link FeedbackSessionsLogic#getFeedbackSessionsWhichNeedAutomatedPublishedEmailsToBeSent()}
*/
public List<FeedbackSessionAttributes> getFeedbackSessionsWhichNeedAutomatedPublishedEmailsToBeSent() {
return feedbackSessionsLogic.getFeedbackSessionsWhichNeedAutomatedPublishedEmailsToBeSent();
}

/**
* @see {@link FeedbackSessionsLogic#getFeedbackSessionsWhichNeedOpenEmailsToBeSent()}
*/
public List<FeedbackSessionAttributes> getFeedbackSessionsWhichNeedOpenEmailsToBeSent() {
return feedbackSessionsLogic.getFeedbackSessionsWhichNeedOpenEmailsToBeSent();
}

/**
* @see {@link StudentsLogic#getSectionForTeam(String, String)}
*/
public String getSectionForTeam(String courseId, String teamName) {
Assumption.assertNotNull(courseId);
Assumption.assertNotNull(teamName);
return studentsLogic.getSectionForTeam(courseId, teamName);
}

}

0 comments on commit 5147f5d

Please sign in to comment.