Skip to content

Commit

Permalink
#288 weekly digest
Browse files Browse the repository at this point in the history
  • Loading branch information
Titogelo committed Mar 22, 2017
1 parent 9d16768 commit 8fb6118
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/celstec/arlearn2/api/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public String sendMessage(@HeaderParam("Authorization") String token,
@POST
@Path("/send/email")
public String sendReminder(@HeaderParam("Authorization") String token,
@PathParam("account") String account, @DefaultValue("application/json") @HeaderParam("Accept") String accept) {
@PathParam("account") String account,
@DefaultValue("application/json") @HeaderParam("Accept") String accept) {
if (!validCredentials(token))
return serialise(getInvalidCredentialsBean(), accept);

MailDelegator md = new MailDelegator(token);

String tomail = "[email protected]";
md.sendReminders();

return null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/celstec/arlearn2/api/NotificationAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public String testAPN(@PathParam("token") String account, @PathParam("apns") Str
@POST
@Path("/reminders")
public String sendReminder(@HeaderParam("Authorization") String token,
@PathParam("account") String account, @DefaultValue("application/json") @HeaderParam("Accept") String accept) {
@PathParam("account") String account,
@DefaultValue("application/json") @HeaderParam("Accept") String accept) {
if (!validCredentials(token))
return serialise(getInvalidCredentialsBean(), accept);
MailDelegator md = new MailDelegator(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public class MailDelegator extends GoogleDelegator {

private static final Logger logger = Logger.getLogger(ActionDelegator.class.getName());
private static final long MILLIS_PER_DAY = 1 * 5 * 60 * 1000L; // 5 minutes

public MailDelegator(String authtoken) {
super(authtoken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import org.celstec.arlearn2.jdo.manager.MessageManager;
import org.celstec.arlearn2.jdo.manager.ThreadManager;

import java.util.logging.Logger;

public class MessageDelegator extends GoogleDelegator {
private static final Logger logger = Logger.getLogger(MessageDelegator.class.getName());
private static final long MILLIS_PER_DAY = 1 * 5 * 60 * 1000L; // 1 minute

public MessageDelegator(Service service) {
super(service);
Expand All @@ -26,9 +30,37 @@ public Message createMessage(Message message) {
}
Message returnMessage = MessageManager.createMessage(message);

/*
* Angel
*
* Added task which starts a timer of 1 minutes.
* If five minutes have passed after the last message the task will send and email
* to all the account that participate in the inquiry that did not login in the
* last 1 minutes.
* */

// Queue q = QueueFactory.getDefaultQueue();
//// Queue q = QueueFactory.getQueue(String.valueOf(message.getRunId()));
// q.purge();
//
//// q.deleteTask(String.valueOf(message.getRunId()));
//
//
//
// q.add(TaskOptions.Builder.withUrl("/setTimerEmailNotification").countdownMillis(MILLIS_PER_DAY)
// .param("token", this.getAuthToken())
// .param("name", String.valueOf(message.getRunId())));

RunAccessDelegator rad = new RunAccessDelegator(this);
NotificationDelegator nd = new NotificationDelegator(this);
for (RunAccess ra : rad.getRunAccess(message.getRunId()).getRunAccess()) {

/*
* 1) new message is created
* 2) create a task, which sends an email after 2 hours
* 3) send the email only for users that did not login in the last two hours
* */

nd.broadcast(returnMessage, ra.getAccount());
}

Expand Down
54 changes: 44 additions & 10 deletions src/main/java/org/celstec/arlearn2/tasks/TimerSendEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,66 @@
******************************************************************************/
package org.celstec.arlearn2.tasks;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.celstec.arlearn2.beans.account.Account;
import org.celstec.arlearn2.beans.run.RunAccess;
import org.celstec.arlearn2.delegators.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.celstec.arlearn2.tasks.beans.GenericBean;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;


public class TimerSendEmail extends HttpServlet {

private static final Logger log = Logger.getLogger(TimerSendEmail.class.getName());
private static final long MILLIS_PER_DAY = 1 * 1 * 60 * 1000L; // 1 minute
private static String token;
private static Long runId;
private static final Logger logger = Logger.getLogger(TimerSendEmail.class.getName());


protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
try {
BeanDeserialiser bd = new BeanDeserialiser(request);
GenericBean gb = bd.deserialize();
gb.run();

token = request.getParameter("token");
runId = Long.parseLong(request.getParameter("name"));

RunAccessDelegator rad = new RunAccessDelegator(token);
AccountDelegator ad = new AccountDelegator(token);
NotificationDelegator nd = new NotificationDelegator(token);
MailDelegator md = new MailDelegator(token);

for(RunAccess ra: rad.getRunAccess(runId).getRunAccess()) {

Account account1 = ad.getContactDetails(ra.getAccount());

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date)); //2016/11/16 12:08:43

md.sendReminders();

// if(Math.abs(account1.getLastModificationDate() - date.getTime()) < MILLIS_PER_DAY){
// System.out.print("["+account1.getEmail()+"] "+account1.getName()+" login less than 1 minutes ago");
// }else{
// System.out.print("["+account1.getEmail()+"] "+account1.getName()+" login more than 1 minutes ago");
// }
}


} catch (Exception e) {
log.log(Level.SEVERE, e.getMessage(), e);
logger.log(Level.SEVERE, e.getMessage(), e);
}
}



protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
Expand Down

3 comments on commit 8fb6118

@Titogelo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was not good

@rafaelklaessen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just being curious, what do you mean by that?

@Titogelo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weekly email with a summary of the contributions you've missed that week

Please sign in to comment.