-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5999] Timeouts in session closing and closed reminders
- Loading branch information
1 parent
6d3ed47
commit 2a67b0a
Showing
10 changed files
with
265 additions
and
81 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...client/java/teammates/client/scripts/DataMigrationForSentClosingEmailFieldInSessions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package teammates.client.scripts; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.jdo.PersistenceManager; | ||
import javax.jdo.Query; | ||
|
||
import teammates.client.remoteapi.RemoteApiClient; | ||
import teammates.common.datatransfer.FeedbackSessionAttributes; | ||
import teammates.common.datatransfer.FeedbackSessionType; | ||
import teammates.common.util.Const.SystemParams; | ||
import teammates.logic.api.Logic; | ||
import teammates.storage.datastore.Datastore; | ||
import teammates.storage.entity.FeedbackSession; | ||
|
||
public class DataMigrationForSentClosingEmailFieldInSessions extends RemoteApiClient { | ||
|
||
private static final Logic logic = new Logic(); | ||
|
||
private boolean isPreview = true; | ||
|
||
public static void main(String[] args) throws IOException { | ||
new DataMigrationForSentClosingEmailFieldInSessions().doOperationRemotely(); | ||
} | ||
|
||
@Override | ||
protected void doOperation() { | ||
Datastore.initialize(); | ||
|
||
List<FeedbackSessionAttributes> sessions = getNonPrivateFeedbackSessions(); | ||
for (FeedbackSessionAttributes session : sessions) { | ||
populateClosingEmailField(session); | ||
} | ||
} | ||
|
||
private void populateClosingEmailField(FeedbackSessionAttributes session) { | ||
session.setSentClosedEmail(session.isClosed()); | ||
session.setSentClosingEmail( | ||
session.isClosed() | ||
|| !session.isClosedAfter(SystemParams.NUMBER_OF_HOURS_BEFORE_CLOSING_ALERT)); | ||
|
||
if (isPreview) { | ||
System.out.println("sentClosingEmail and sentClosedEmail for " + session.getSessionName() | ||
+ " in course " + session.getCourseId() + " to be set to " + session.isClosed()); | ||
return; | ||
} | ||
|
||
try { | ||
logic.updateFeedbackSession(session); | ||
} catch (Exception e) { | ||
System.out.println("Failed to set attribute sentClosingEmail and sentClosedEmail for session " | ||
+ session.getSessionName() + " in course " + session.getCourseId() + "."); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private List<FeedbackSessionAttributes> getNonPrivateFeedbackSessions() { | ||
List<FeedbackSessionAttributes> sessions = new ArrayList<FeedbackSessionAttributes>(); | ||
List<FeedbackSession> sessionEntities = getNonPrivateFeedbackSessionEntities(); | ||
for (FeedbackSession sessionEntity : sessionEntities) { | ||
sessions.add(new FeedbackSessionAttributes(sessionEntity)); | ||
} | ||
return sessions; | ||
} | ||
|
||
private PersistenceManager getPm() { | ||
return Datastore.getPersistenceManager(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private List<FeedbackSession> getNonPrivateFeedbackSessionEntities() { | ||
Query q = getPm().newQuery(FeedbackSession.class); | ||
q.declareParameters("Enum private"); | ||
q.setFilter("feedbackSessionType != private"); | ||
|
||
return (List<FeedbackSession>) q.execute(FeedbackSessionType.PRIVATE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.