removed private messages
This commit is contained in:
parent
60f5287b2c
commit
ad467083ae
resources/db_update_scripts
src
main/java/se/su/dsv/scipro
SciProApplication.java
data
dao
interfaces
jpa
dataobjects
json/pages
JsonDeletePrivateMessagePage.javaJsonDeleteRecipientPage.javaJsonKeyAuthPage.javaJsonLoginPage.javaJsonMessagePage.javaJsonMessagePageCountUnread.javaJsonNewMessagePage.javaJsonProjectForSupervisorPage.javaJsonSentMessagePage.javaJsonSetReadPage.javaJsonSetStatusPage.javaJsonStatusPage.java
jsonobjects
JsonDeletePrivateMessage.javaJsonKeyAuth.javaJsonLogin.javaJsonPrivateMessage.javaJsonRecipient.javaJsonStatus.java
message
test/java/se/su/dsv/scipro
@ -150,4 +150,6 @@ INSERT INTO `FinalSeminarSettings_punishMails` (`FinalSeminarSettings_id`, `puni
|
||||
-- Constraints for table `FinalSeminarSettings_punishMails`
|
||||
--
|
||||
ALTER TABLE `FinalSeminarSettings_punishMails`
|
||||
ADD CONSTRAINT `FK373B1D06BB47DEDF` FOREIGN KEY (`FinalSeminarSettings_id`) REFERENCES `FinalSeminarSettings` (`id`);
|
||||
ADD CONSTRAINT `FK373B1D06BB47DEDF` FOREIGN KEY (`FinalSeminarSettings_id`) REFERENCES `FinalSeminarSettings` (`id`);
|
||||
|
||||
DROP TABLE `private_message`, `recipient`;
|
@ -32,14 +32,12 @@ import se.su.dsv.scipro.examiner.pages.ExaminerReviewPage;
|
||||
import se.su.dsv.scipro.exceptions.RenderingSafeException;
|
||||
import se.su.dsv.scipro.forum.pages.ProjectForumPage;
|
||||
import se.su.dsv.scipro.forum.pages.SupervisorForumPage;
|
||||
import se.su.dsv.scipro.json.pages.*;
|
||||
import se.su.dsv.scipro.landingpages.FinalSeminarLandingPage;
|
||||
import se.su.dsv.scipro.landingpages.NewIdeaLandingPage;
|
||||
import se.su.dsv.scipro.landingpages.PeerRequestLandingPage;
|
||||
import se.su.dsv.scipro.landingpages.ProjectLandingPage;
|
||||
import se.su.dsv.scipro.loginlogout.pages.*;
|
||||
import se.su.dsv.scipro.match.dataobject.NewIdea;
|
||||
import se.su.dsv.scipro.message.pages.PrivateMessagesPage;
|
||||
import se.su.dsv.scipro.mockup.ForumPage;
|
||||
import se.su.dsv.scipro.notifications.NotificationLoader;
|
||||
import se.su.dsv.scipro.notifications.pages.NotificationsPage;
|
||||
@ -126,7 +124,7 @@ public class SciProApplication extends RepositoryApplication implements IThemabl
|
||||
/*
|
||||
* Unknown pages
|
||||
*/
|
||||
mountBookmarkablePage("inbox", PrivateMessagesPage.class);
|
||||
// mountBookmarkablePage("inbox", PrivateMessagesPage.class);
|
||||
mountBookmarkablePage("repository/download", RepositoryDownloadPage.class);
|
||||
|
||||
/*
|
||||
@ -170,17 +168,17 @@ public class SciProApplication extends RepositoryApplication implements IThemabl
|
||||
/*
|
||||
* JSON pages
|
||||
*/
|
||||
mountBookmarkablePage("json/project", JsonProjectForSupervisorPage.class);
|
||||
mountBookmarkablePage("json/message", JsonMessagePage.class);
|
||||
mountBookmarkablePage("json/message/unread", JsonMessagePageCountUnread.class);
|
||||
mountBookmarkablePage("json/message/setread", JsonSetReadPage.class);
|
||||
mountBookmarkablePage("json/message/deleterecipient", JsonDeleteRecipientPage.class);
|
||||
mountBookmarkablePage("json/message/deleteprivatemessage", JsonDeletePrivateMessagePage.class);
|
||||
mountBookmarkablePage("json/message/newmessage", JsonNewMessagePage.class);
|
||||
mountBookmarkablePage("json/message/sentmessages", JsonSentMessagePage.class);
|
||||
mountBookmarkablePage("json/login", JsonLoginPage.class);
|
||||
mountBookmarkablePage("json/status", JsonStatusPage.class);
|
||||
mountBookmarkablePage("json/setstatus", JsonSetStatusPage.class);
|
||||
// mountBookmarkablePage("json/project", JsonProjectForSupervisorPage.class);
|
||||
// mountBookmarkablePage("json/message", JsonMessagePage.class);
|
||||
// mountBookmarkablePage("json/message/unread", JsonMessagePageCountUnread.class);
|
||||
// mountBookmarkablePage("json/message/setread", JsonSetReadPage.class);
|
||||
// mountBookmarkablePage("json/message/deleterecipient", JsonDeleteRecipientPage.class);
|
||||
// mountBookmarkablePage("json/message/deleteprivatemessage", JsonDeletePrivateMessagePage.class);
|
||||
// mountBookmarkablePage("json/message/newmessage", JsonNewMessagePage.class);
|
||||
// mountBookmarkablePage("json/message/sentmessages", JsonSentMessagePage.class);
|
||||
// mountBookmarkablePage("json/login", JsonLoginPage.class);
|
||||
// mountBookmarkablePage("json/status", JsonStatusPage.class);
|
||||
// mountBookmarkablePage("json/setstatus", JsonSetStatusPage.class);
|
||||
|
||||
/*
|
||||
* Admin pages
|
||||
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.dao.interfaces;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
|
||||
public interface PrivateMessageDao extends LazyDeleteDao<PrivateMessage> {
|
||||
|
||||
public List<PrivateMessage> getPrivateMessagesFromUser(final User user);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.dao.interfaces;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public interface RecipientDao extends LazyDeleteDao<Recipient>{
|
||||
public List<Recipient> getRecipientsByUser(final User user);
|
||||
public List<Recipient> getRecipientsByUser(final User user, final Integer limit);
|
||||
public List<Recipient> getUnreadMessagesForUser(final User user);
|
||||
public int getNumberOfUnreadMessagesForUser(final User user);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import org.springframework.orm.jpa.JpaCallback;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository("privateMessageDao")
|
||||
public class PrivateMessageDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<PrivateMessage> implements PrivateMessageDao {
|
||||
|
||||
public PrivateMessageDaoJPAImp() {
|
||||
super(PrivateMessage.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PrivateMessage> getPrivateMessagesFromUser(final User user) {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<PrivateMessage>>() {
|
||||
public List<PrivateMessage> doInJpa(EntityManager em)
|
||||
throws PersistenceException {
|
||||
String q = "select p " +
|
||||
"from PrivateMessage p " +
|
||||
"where p.fromUser = :user AND p.deleted = false ";
|
||||
|
||||
|
||||
q += "order by p.dateCreated DESC";
|
||||
|
||||
TypedQuery<PrivateMessage> query = em.createQuery(q, PrivateMessage.class);
|
||||
query.setParameter("user", user);
|
||||
|
||||
|
||||
try {
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e) {
|
||||
return new ArrayList<PrivateMessage>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import org.springframework.orm.jpa.JpaCallback;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository("recipientDao")
|
||||
public class RecipientDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Recipient>
|
||||
implements RecipientDao {
|
||||
|
||||
public RecipientDaoJPAImp() {
|
||||
super(Recipient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Recipient> getRecipientsByUser(final User user,
|
||||
final Integer limit) {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<Recipient>>() {
|
||||
@Override
|
||||
public List<Recipient> doInJpa(EntityManager em)
|
||||
throws PersistenceException {
|
||||
String q = "select R " + "from Recipient r "
|
||||
+ "where r.toUser = :user AND r.deleted = false ";
|
||||
|
||||
q += "order by r.dateCreated DESC";
|
||||
|
||||
TypedQuery<Recipient> query = em
|
||||
.createQuery(q, Recipient.class);
|
||||
query.setParameter("user", user);
|
||||
|
||||
if (limit != null) {
|
||||
query.setMaxResults(limit);
|
||||
}
|
||||
try {
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e) {
|
||||
return new ArrayList<Recipient>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Recipient> getRecipientsByUser(final User user) {
|
||||
return getRecipientsByUser(user, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Recipient> getUnreadMessagesForUser(final User user) {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<Recipient>>() {
|
||||
@Override
|
||||
public List<Recipient> doInJpa(EntityManager em)
|
||||
throws PersistenceException {
|
||||
String q = "select R "
|
||||
+ "from Recipient r "
|
||||
+ "where r.toUser = :user AND r.deleted = false AND r.dateRead = null ";
|
||||
|
||||
q += "order by r.dateCreated DESC";
|
||||
|
||||
TypedQuery<Recipient> query = em
|
||||
.createQuery(q, Recipient.class);
|
||||
query.setParameter("user", user);
|
||||
|
||||
try {
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e) {
|
||||
return new ArrayList<Recipient>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int getNumberOfUnreadMessagesForUser(final User user) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||
@Override
|
||||
public Integer doInJpa(EntityManager em)
|
||||
throws PersistenceException {
|
||||
String q = "select count(R) "
|
||||
+ "from Recipient r "
|
||||
+ "where r.toUser = :user AND r.deleted = false AND r.dateRead = null ";
|
||||
|
||||
TypedQuery<Long> query = em.createQuery(q, Long.class);
|
||||
query.setParameter("user", user);
|
||||
|
||||
return (query.getSingleResult()).intValue();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.dataobjects;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@Table(name="private_message")
|
||||
@Cacheable(true)
|
||||
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
public class PrivateMessage extends LazyDeletableDomainObject{
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Lob
|
||||
private String subject;
|
||||
|
||||
@Lob
|
||||
private String message;
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
private User fromUser;
|
||||
|
||||
@OneToMany(mappedBy="privateMessage")
|
||||
private List<Recipient> recipientList = new ArrayList<Recipient>();
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public User getFromUser() {
|
||||
return fromUser;
|
||||
}
|
||||
|
||||
|
||||
public void setFromUser(User fromUser) {
|
||||
this.fromUser = fromUser;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Recipient> getRecipientList() {
|
||||
return recipientList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PrivateMessage other = (PrivateMessage) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.data.dataobjects;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="recipient")
|
||||
@Cacheable(true)
|
||||
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
public class Recipient extends LazyDeletableDomainObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
private User toUser;
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
private PrivateMessage privateMessage;
|
||||
|
||||
private Date dateRead;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Date getDateRead() {
|
||||
return dateRead;
|
||||
}
|
||||
|
||||
public void setDateRead(Date dateRead) {
|
||||
this.dateRead = dateRead;
|
||||
}
|
||||
|
||||
public User getToUser() {
|
||||
return toUser;
|
||||
}
|
||||
|
||||
public void setToUser(User toUser) {
|
||||
this.toUser = toUser;
|
||||
}
|
||||
|
||||
public PrivateMessage getPrivateMessage() {
|
||||
return privateMessage;
|
||||
}
|
||||
|
||||
public void setPrivateMessage(PrivateMessage privateMessage) {
|
||||
this.privateMessage = privateMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Recipient other = (Recipient) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.*;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonDeletePrivateMessage;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonDeletePrivateMessagePage extends WebPage {
|
||||
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
PrivateMessageDao privateMessageDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonDeletePrivateMessagePage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
|
||||
String loginString = pp.getString("json");
|
||||
JsonDeletePrivateMessage jsonDeletePrivateMessage = gson.fromJson(loginString, JsonDeletePrivateMessage.class);
|
||||
long userid = jsonDeletePrivateMessage.userid;
|
||||
String apikey = jsonDeletePrivateMessage.apikey;
|
||||
apikey = apikey.replace(" ", "+");
|
||||
User user = userDao.load(userid);
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
PrivateMessage privateMessage = privateMessageDao.load(jsonDeletePrivateMessage.id);
|
||||
privateMessage.setDeleted(true);
|
||||
privateMessage = privateMessageDao.save(privateMessage);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonRecipient;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonDeleteRecipientPage extends WebPage {
|
||||
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonDeleteRecipientPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
|
||||
String loginString = pp.getString("json");
|
||||
JsonRecipient jsonRecipient = gson.fromJson(loginString, JsonRecipient.class);
|
||||
long userid = jsonRecipient.userid;
|
||||
String apikey = jsonRecipient.apikey;
|
||||
User user = userDao.load(userid);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
Recipient recipient = recipientDao.load(jsonRecipient.id);
|
||||
recipient.setDeleted(true);
|
||||
recipient = recipientDao.save(recipient);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.protocol.http.WebResponse;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonKeyAuth;
|
||||
|
||||
public class JsonKeyAuthPage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
public UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonKeyAuthPage(PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
String authJson = pp.getString("json");
|
||||
|
||||
JsonKeyAuth jsonLogin = gson.fromJson(authJson, JsonKeyAuth.class);
|
||||
|
||||
if (jsonLogin != null) {
|
||||
String loginUsername = jsonLogin.username;
|
||||
//@ToDo Fix the apple-app to support non hard-coded realm
|
||||
User user = userDao.getUserByUsername(loginUsername,"DSV.SU.SE");
|
||||
|
||||
if (user == null) {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
jsonOutput.addProperty("reason", "User missing");
|
||||
loginUsername = null;
|
||||
}
|
||||
|
||||
if (loginUsername != null) {
|
||||
|
||||
String apikey = jsonLogin.apikey;
|
||||
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
|
||||
if (userSettings.getApiKey() == null || userSettings.getApiKey().equals("")) {
|
||||
// throw new FailedLoginException("API key missing");
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
jsonOutput.addProperty("reason", "API key missing");
|
||||
} else if (userSettings.getApiKey().equals(apikey)) {
|
||||
jsonOutput.addProperty("authenticated", true);
|
||||
jsonOutput.addProperty("apikey", apikey);
|
||||
jsonOutput.addProperty("userid", user.getId());
|
||||
} else {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
jsonOutput.addProperty("reason", "API key not matching");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.wicket.markup.html.WebPage#setHeaders(org.apache.wicket.protocol.http.WebResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void setHeaders(WebResponse response) {
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store");
|
||||
super.setHeaders(response);
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RoleDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonLogin;
|
||||
import se.su.dsv.scipro.security.auth.Authenticator;
|
||||
import se.su.dsv.scipro.util.LoginUtils;
|
||||
|
||||
import javax.security.auth.login.FailedLoginException;
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonLoginPage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
@SpringBean
|
||||
RoleDao roleDao;
|
||||
|
||||
public JsonLoginPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
String loginString = pp.getString("json");
|
||||
JsonLogin jsonLogin = gson.fromJson(loginString, JsonLogin.class);
|
||||
Authenticator authenticator = new Authenticator();
|
||||
|
||||
String loginUsername = null;
|
||||
if (jsonLogin.username.equals("hhansson") && jsonLogin.password.equals("AppleDEMO_2011")) {
|
||||
loginUsername = "hhansson";
|
||||
} else {
|
||||
try {
|
||||
loginUsername = authenticator.authenticate(jsonLogin.username, jsonLogin.password, "ThesisJaasUser");
|
||||
} catch (FailedLoginException fle) {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
|
||||
} catch (LoginException e) {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
} catch (NullPointerException e) {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (loginUsername != null) {
|
||||
String username = jsonLogin.username;
|
||||
//@ToDo Fix the apple-app to support non hard-coded realm
|
||||
User user = userDao.getUserByUsername(username,"DSV.SU.SE");
|
||||
if (roleDao.isEmployee(user)) {
|
||||
jsonOutput.addProperty("authenticated", true);
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
}
|
||||
String apikey = LoginUtils.apiKeyGen(username);
|
||||
jsonOutput.addProperty("apikey", apikey);
|
||||
jsonOutput.addProperty("userid", user.getId());
|
||||
jsonOutput.addProperty("name", user.getFirstName() + " " + user.getLastName());
|
||||
userSettings.setApiKey(apikey);
|
||||
userSettings.setiPhoneId(jsonLogin.iPhoneId);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
} else {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
jsonOutput.addProperty("notEmployee", true);
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonOutput.addProperty("authenticated", false);
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType("application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static String hash(String plaintext) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||
md.update(plaintext.getBytes("UTF-8"));
|
||||
|
||||
return String.valueOf(Base64Coder.encode(md.digest()));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new Error("SHA-1 support is required.");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new Error("Unexpected exception", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonMessagePage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonMessagePage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
String apikey = pp.getString("apikey");
|
||||
long userid = pp.getLong("userid");
|
||||
User user = userDao.load(userid);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
List<Recipient> recipientList = recipientDao
|
||||
.getRecipientsByUser(user);
|
||||
JsonArray messageArray = new JsonArray();
|
||||
for (Recipient r : recipientList) {
|
||||
JsonObject jsonMessage = new JsonObject();
|
||||
jsonMessage.addProperty("message", r.getPrivateMessage()
|
||||
.getMessage());
|
||||
jsonMessage.addProperty("subject", r.getPrivateMessage()
|
||||
.getSubject());
|
||||
jsonMessage.addProperty("date", new DateFormatter(DateStyle.DATETIME).createFormattedString(r.getDateCreated()));
|
||||
jsonMessage.addProperty("id", r.getId());
|
||||
boolean read = false;
|
||||
if(r.getDateRead() != null){
|
||||
read = true;
|
||||
}
|
||||
jsonMessage.addProperty("read", read);
|
||||
JsonObject jsonUser = new JsonObject();
|
||||
jsonUser.addProperty("id", r.getPrivateMessage().getFromUser()
|
||||
.getId());
|
||||
jsonUser.addProperty("name", r.getPrivateMessage()
|
||||
.getFromUser().getFirstName()
|
||||
+ " "
|
||||
+ r.getPrivateMessage().getFromUser().getLastName());
|
||||
jsonMessage.add("from", jsonUser);
|
||||
messageArray.add(jsonMessage);
|
||||
}
|
||||
jsonOutput.add("messageArray", messageArray);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonMessagePageCountUnread extends WebPage{
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonMessagePageCountUnread(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
String apikey = pp.getString("apikey");
|
||||
long userid = pp.getLong("userid");
|
||||
User user = userDao.load(userid);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
int unreadMessages = recipientDao.getNumberOfUnreadMessagesForUser(user);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
jsonOutput.addProperty("unreadmess", unreadMessages);
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.*;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonPrivateMessage;
|
||||
import se.su.dsv.scipro.util.PushApple;
|
||||
|
||||
public class JsonNewMessagePage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
PrivateMessageDao privateMessageDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonNewMessagePage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
String loginString = pp.getString("json");
|
||||
JsonPrivateMessage jsonPrivateMessage = gson
|
||||
.fromJson(loginString, JsonPrivateMessage.class);
|
||||
long userId = jsonPrivateMessage.userid;
|
||||
String apikey = jsonPrivateMessage.apikey;
|
||||
User user = userDao.load(userId);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
PrivateMessage pm = new PrivateMessage();
|
||||
pm.setFromUser(user);
|
||||
pm.setMessage(jsonPrivateMessage.message);
|
||||
pm.setSubject(jsonPrivateMessage.subject);
|
||||
pm = privateMessageDao.save(pm);
|
||||
for (Long id : jsonPrivateMessage.toUserIdArray) {
|
||||
Recipient rec = new Recipient();
|
||||
User selectedUser = userDao.load(id);
|
||||
rec.setToUser(selectedUser);
|
||||
rec.setPrivateMessage(pm);
|
||||
rec = recipientDao.save(rec);
|
||||
}
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType("application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
for (Long id : jsonPrivateMessage.toUserIdArray) {
|
||||
User selectedUser = userDao.load(id);
|
||||
if (userSettingsDao.getUserSettings(selectedUser) != null) {
|
||||
|
||||
PushApple.sendPushMessage(userSettingsDao.getUserSettings(selectedUser)
|
||||
.getiPhoneId(),
|
||||
recipientDao.getNumberOfUnreadMessagesForUser(selectedUser),
|
||||
"New message received");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FinalSeminarDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.*;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||
import se.su.dsv.scipro.data.enums.ProjectTeamMemberRoles;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonProjectForSupervisorPage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
FinalSeminarDao finalSeminarDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonProjectForSupervisorPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
long userid = pp.getLong("userid");
|
||||
User user = userDao.load(userid);
|
||||
String apikey = pp.getString("apikey");
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if(userSettings == null){
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
List<Project> projectList = projectDao.getProjectsByHeadSupervisor(
|
||||
user, ProjectStatus.ACTIVE);
|
||||
JsonArray jProjectArray = new JsonArray();
|
||||
|
||||
for (Project project : projectList) {
|
||||
JsonObject jsonProject = new JsonObject();
|
||||
jsonProject.addProperty("title", project.getTitle());
|
||||
jsonProject.addProperty("status", project.getStateOfMind()
|
||||
.toString());
|
||||
jsonProject.addProperty("statusMessage",
|
||||
project.getStatusMessage());
|
||||
jsonProject.addProperty("level", project.getProjectClass()
|
||||
.toString());
|
||||
JsonArray jStudentArray = new JsonArray();
|
||||
for (Student student : project.getProjectParticipants()) {
|
||||
JsonObject jsonStudent = new JsonObject();
|
||||
jsonStudent.addProperty("id", student.getUser().getId());
|
||||
jsonStudent.addProperty("name", student.getUser()
|
||||
.getFirstName()
|
||||
+ " "
|
||||
+ student.getUser().getLastName());
|
||||
jStudentArray.add(jsonStudent);
|
||||
}
|
||||
jsonProject.add("projectMembers", jStudentArray);
|
||||
|
||||
JsonArray jReviewerArray = new JsonArray();
|
||||
for (ProjectFollower projectFollower : project
|
||||
.getProjectFollowers()) {
|
||||
JsonObject jsonFollower = new JsonObject();
|
||||
if (projectFollower.getProjectRole().equals(
|
||||
ProjectTeamMemberRoles.REVIEWER)) {
|
||||
jsonFollower.addProperty("id", projectFollower
|
||||
.getFollower().getUser().getId());
|
||||
jsonFollower.addProperty("name", projectFollower
|
||||
.getFollower().getUser().getFirstName()
|
||||
+ " "
|
||||
+ projectFollower.getFollower().getUser()
|
||||
.getLastName());
|
||||
jReviewerArray.add(jsonFollower);
|
||||
}
|
||||
}
|
||||
JsonArray coSupervisorArray = new JsonArray();
|
||||
for (ProjectFollower projectFollower : project
|
||||
.getProjectFollowers()) {
|
||||
|
||||
JsonObject jsonFollower = new JsonObject();
|
||||
if (projectFollower.getProjectRole().equals(
|
||||
ProjectTeamMemberRoles.CO_SUPERVISOR)) {
|
||||
jsonFollower.addProperty("id", projectFollower
|
||||
.getFollower().getUser().getId());
|
||||
jsonFollower.addProperty("name", projectFollower
|
||||
.getFollower().getUser().getFirstName()
|
||||
+ " "
|
||||
+ projectFollower.getFollower().getUser()
|
||||
.getLastName());
|
||||
coSupervisorArray.add(jsonFollower);
|
||||
}
|
||||
|
||||
}
|
||||
jsonProject.add("projectMembers", jStudentArray);
|
||||
jsonProject.add("projectReviewers", jReviewerArray);
|
||||
jsonProject.add("projectCosupervisors", coSupervisorArray);
|
||||
|
||||
JsonArray finalSeminars = new JsonArray();
|
||||
|
||||
for (FinalSeminar finalSeminar : finalSeminarDao
|
||||
.findFinalSeminarsByProject(project)) {
|
||||
JsonObject finalSeminarObject = new JsonObject();
|
||||
|
||||
finalSeminar.getStartDate();
|
||||
finalSeminar.getEndDate();
|
||||
finalSeminarObject.addProperty("room",
|
||||
finalSeminar.getRoom());
|
||||
|
||||
String date = new DateFormatter(DateStyle.DATETIME).createFormattedString(finalSeminar.getStartDate())
|
||||
+ "-" + new DateFormatter(DateStyle.TIME).createFormattedString(finalSeminar.getEndDate());
|
||||
finalSeminarObject.addProperty("date", date);
|
||||
|
||||
JsonArray activeListeners = new JsonArray();
|
||||
for (FinalSeminarActiveParticipation fs: finalSeminar.getActiveParticipations()) {
|
||||
JsonObject activeParticipant = new JsonObject();
|
||||
activeParticipant.addProperty("id", fs.getUser().getId());
|
||||
activeParticipant.addProperty("name", fs
|
||||
.getUser().getFirstName()
|
||||
+ " "
|
||||
+ fs.getUser()
|
||||
.getLastName());
|
||||
activeListeners.add(activeParticipant);
|
||||
|
||||
}
|
||||
JsonArray opponents = new JsonArray();
|
||||
for (FinalSeminarOpposition fs: finalSeminar.getOppositions()) {
|
||||
JsonObject activeParticipant = new JsonObject();
|
||||
activeParticipant.addProperty("id", fs.getOpponent().getUser().getId());
|
||||
activeParticipant.addProperty("name", fs
|
||||
.getOpponent().getUser().getFirstName()
|
||||
+ " "
|
||||
+ fs.getOpponent().getUser()
|
||||
.getLastName());
|
||||
opponents.add(activeParticipant);
|
||||
|
||||
}
|
||||
finalSeminarObject.add("active", activeListeners);
|
||||
finalSeminarObject.add("opponents", opponents);
|
||||
finalSeminars.add(finalSeminarObject);
|
||||
}
|
||||
jsonProject.add("finalSeminars", finalSeminars);
|
||||
jProjectArray.add(jsonProject);
|
||||
|
||||
}
|
||||
jsonOutput.add("projectArray", jProjectArray);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.*;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonSentMessagePage extends WebPage {
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
PrivateMessageDao privateMessageDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonSentMessagePage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
String apikey = pp.getString("apikey");
|
||||
long userid = pp.getLong("userid");
|
||||
User user = userDao.load(userid);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
List<PrivateMessage> recipientList = privateMessageDao.getPrivateMessagesFromUser(user);
|
||||
JsonArray messageArray = new JsonArray();
|
||||
for (PrivateMessage r : recipientList) {
|
||||
JsonObject jsonMessage = new JsonObject();
|
||||
jsonMessage.addProperty("message", r
|
||||
.getMessage());
|
||||
jsonMessage.addProperty("subject", r.
|
||||
getSubject());
|
||||
jsonMessage.addProperty("date", new DateFormatter(DateStyle.DATETIME).createFormattedString(r.getDateCreated()));
|
||||
jsonMessage.addProperty("id", r.getId());
|
||||
|
||||
JsonArray userArray = new JsonArray();
|
||||
for(Recipient r2: r.getRecipientList()){
|
||||
JsonObject jsonUser = new JsonObject();
|
||||
jsonUser.addProperty("id", r2.getToUser()
|
||||
.getId());
|
||||
jsonUser.addProperty("name", r2.getToUser().getFirstName()
|
||||
+ " "
|
||||
+ r2.getToUser().getLastName());
|
||||
userArray.add(jsonUser);
|
||||
}
|
||||
jsonMessage.add("toUsers", userArray);
|
||||
messageArray.add(jsonMessage);
|
||||
}
|
||||
jsonOutput.add("messageArray", messageArray);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonRecipient;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonSetReadPage extends WebPage {
|
||||
|
||||
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonSetReadPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
|
||||
String loginString = pp.getString("json");
|
||||
JsonRecipient jsonRecipient = gson.fromJson(loginString, JsonRecipient.class);
|
||||
String apikey = jsonRecipient.apikey;
|
||||
long userId= jsonRecipient.userid;
|
||||
User user = userDao.load(userId);
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
Recipient recipient = recipientDao.load(jsonRecipient.id);
|
||||
recipient.setDateRead(new Date());
|
||||
recipient = recipientDao.save(recipient);
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
import se.su.dsv.scipro.jsonobjects.JsonStatus;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonSetStatusPage extends WebPage{
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonSetStatusPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
String loginString = pp.getString("json");
|
||||
JsonStatus jsonStatus = gson.fromJson(loginString, JsonStatus.class);
|
||||
String apikey = jsonStatus.apikey;
|
||||
long userId= jsonStatus.userid;
|
||||
User user = userDao.load(userId);
|
||||
|
||||
apikey = apikey.replace(" ", "+");
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
userSettings.setAvailable(jsonStatus.available);
|
||||
userSettings.setStatusMessage(jsonStatus.status);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.json.pages;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.wicket.IRequestTarget;
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.UserSettings;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonStatusPage extends WebPage{
|
||||
@SpringBean
|
||||
UserDao userDao;
|
||||
|
||||
@SpringBean
|
||||
ProjectDao projectDao;
|
||||
|
||||
@SpringBean
|
||||
RecipientDao recipientDao;
|
||||
|
||||
@SpringBean
|
||||
UserSettingsDao userSettingsDao;
|
||||
|
||||
public JsonStatusPage(final PageParameters pp) {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject jsonOutput = new JsonObject();
|
||||
|
||||
String apikey = pp.getString("apikey");
|
||||
long userid = pp.getLong("userid");
|
||||
apikey = apikey.replace(" ", "+");
|
||||
User user = userDao.load(userid);
|
||||
UserSettings userSettings = userSettingsDao.getUserSettings(user);
|
||||
if (userSettings == null) {
|
||||
userSettings = new UserSettings(user);
|
||||
userSettings = userSettingsDao.save(userSettings);
|
||||
}
|
||||
if (userSettings.getApiKey() != null && userSettings.getApiKey().equals(apikey)) {
|
||||
jsonOutput.addProperty("apikey", "success");
|
||||
jsonOutput.addProperty("status", userSettings.isAvailable());
|
||||
jsonOutput.addProperty("statusmessage", userSettings.getStatusMessage());
|
||||
} else {
|
||||
jsonOutput.addProperty("apikey", "fail");
|
||||
}
|
||||
getRequestCycle().setRequestTarget(new IRequestTarget() {
|
||||
|
||||
public void detach(RequestCycle requestCycle) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
public void respond(RequestCycle requestCycle) {
|
||||
// Add JSON-encoded string to the response.
|
||||
requestCycle.getResponse().setContentType(
|
||||
"application/json; charset=UTF-8");
|
||||
requestCycle.getResponse().setCharacterEncoding("UTF-8");
|
||||
requestCycle.getResponse().write(gson.toJson(jsonOutput));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonDeletePrivateMessage {
|
||||
public long id;
|
||||
public long userid;
|
||||
public String apikey;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
public class JsonKeyAuth {
|
||||
public String username;
|
||||
public String apikey;
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonLogin {
|
||||
public String username;
|
||||
public String password;
|
||||
public String iPhoneId;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonPrivateMessage {
|
||||
|
||||
public long userid;
|
||||
public String apikey;
|
||||
public String subject;
|
||||
public String message;
|
||||
public LinkedList<Long> toUserIdArray;
|
||||
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonRecipient {
|
||||
public long id;
|
||||
public long userid;
|
||||
public String apikey;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.jsonobjects;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
public class JsonStatus {
|
||||
public String status;
|
||||
public boolean available;
|
||||
public long userid;
|
||||
public String apikey;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package se.su.dsv.scipro.message.models;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
import org.apache.wicket.injection.web.InjectorHolder;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessageListModel implements IClusterable {
|
||||
|
||||
private static final long serialVersionUID = 2508705612579433562L;
|
||||
|
||||
@SpringBean
|
||||
private RecipientDao recipientDao;
|
||||
@SpringBean
|
||||
private PrivateMessageDao privateMessageDao;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private List<Recipient> privateMessages;
|
||||
@SuppressWarnings("unused")
|
||||
private List<PrivateMessage> sentMessages;
|
||||
@SuppressWarnings("unused")
|
||||
private List<Recipient> newMessages;
|
||||
private User user;
|
||||
@SuppressWarnings("unused")
|
||||
private int count;
|
||||
|
||||
public MessageListModel(User user) {
|
||||
InjectorHolder.getInjector().inject(this);
|
||||
|
||||
this.user = user;
|
||||
updatePrivateMessages();
|
||||
}
|
||||
|
||||
public void updatePrivateMessages() {
|
||||
privateMessages = recipientDao.getRecipientsByUser(user);
|
||||
newMessages = recipientDao.getUnreadMessagesForUser(user);
|
||||
}
|
||||
|
||||
public List<Recipient> getPrivateMessages() {
|
||||
return recipientDao.getRecipientsByUser(user);
|
||||
}
|
||||
|
||||
public List<PrivateMessage> getSentMessages() {
|
||||
return privateMessageDao.getPrivateMessagesFromUser(user);
|
||||
}
|
||||
|
||||
public List<Recipient> getNewMessages() {
|
||||
return recipientDao.getUnreadMessagesForUser(user);
|
||||
}
|
||||
|
||||
public void removeMessage(PrivateMessage privateMessage) {
|
||||
privateMessage = privateMessageDao.reLoad(privateMessage);
|
||||
privateMessageDao.lazyDelete(privateMessage);
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package se.su.dsv.scipro.message.models;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
import org.apache.wicket.injection.web.InjectorHolder;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class PrivateMessageModel implements IClusterable {
|
||||
|
||||
private static final long serialVersionUID = 1008022850115673161L;
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
@SpringBean
|
||||
private PrivateMessageDao privateMessageDao;
|
||||
@SpringBean
|
||||
private RecipientDao recipientDao;
|
||||
|
||||
private String subject;
|
||||
private String textMessage;
|
||||
private List<User> userList = new ArrayList<User>();
|
||||
private String userSearchText;
|
||||
private List<User> userFinder = new ArrayList<User>();
|
||||
private Collection<User> selectedUserList;
|
||||
|
||||
private final static String relativePath = "inbox/";
|
||||
|
||||
public PrivateMessageModel() {
|
||||
InjectorHolder.getInjector().inject(this);
|
||||
}
|
||||
|
||||
public void sendMessage() {
|
||||
List<User> users = userFinder;
|
||||
if (users.size() > 0) {
|
||||
PrivateMessage pm = new PrivateMessage();
|
||||
pm.setFromUser(SciProSession.get().getUser());
|
||||
pm.setMessage(textMessage);
|
||||
pm.setSubject(subject);
|
||||
pm = privateMessageDao.save(pm);
|
||||
for (User selectedUser : users) {
|
||||
Recipient rec = new Recipient();
|
||||
selectedUser = userDao.reLoad(selectedUser);
|
||||
rec.setToUser(selectedUser);
|
||||
rec.setPrivateMessage(pm);
|
||||
rec = recipientDao.save(rec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package se.su.dsv.scipro.message.models;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
import org.apache.wicket.injection.web.InjectorHolder;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
public class ReplyMessageModel implements IClusterable {
|
||||
|
||||
private static final long serialVersionUID = -1616138704355671880L;
|
||||
|
||||
@SpringBean
|
||||
private PrivateMessageDao pmDao;
|
||||
@SpringBean
|
||||
private RecipientDao recipientDao;
|
||||
|
||||
private PrivateMessage originalMessage;
|
||||
|
||||
private User replyToUser;
|
||||
private String replySubject;
|
||||
private String replyText;
|
||||
|
||||
public ReplyMessageModel() {
|
||||
InjectorHolder.getInjector().inject(this);
|
||||
replySubject = "";
|
||||
replyText = "";
|
||||
}
|
||||
|
||||
public ReplyMessageModel(PrivateMessage originalMessage) {
|
||||
this();
|
||||
this.originalMessage = pmDao.reLoad(originalMessage);
|
||||
setReplyToUser(originalMessage.getFromUser());
|
||||
setReplySubject("Re: " + originalMessage.getSubject());
|
||||
setReplyText("\n\n\n-------\n" + originalMessage.getMessage());
|
||||
}
|
||||
|
||||
public User getReplyToUser() {
|
||||
return replyToUser;
|
||||
}
|
||||
|
||||
public void setReplyToUser(User user) {
|
||||
replyToUser = user;
|
||||
}
|
||||
|
||||
public String getReplyToUserString() {
|
||||
return replyToUser == null ? "" : replyToUser.getFirstName() + " " + replyToUser.getLastName();
|
||||
}
|
||||
|
||||
public String getReplySubject() {
|
||||
return replySubject;
|
||||
}
|
||||
|
||||
public void setReplySubject(String subject) {
|
||||
replySubject = subject;
|
||||
}
|
||||
|
||||
public String getReplyText() {
|
||||
return replyText;
|
||||
}
|
||||
|
||||
public void setReplyText(String text) {
|
||||
replyText = text;
|
||||
}
|
||||
|
||||
public void sendMessage() {
|
||||
|
||||
PrivateMessage pm = new PrivateMessage();
|
||||
pm.setFromUser(SciProSession.get().getUser());
|
||||
pm.setMessage(getReplyText());
|
||||
pm.setSubject(getReplySubject());
|
||||
pm = pmDao.save(pm);
|
||||
Recipient r = new Recipient();
|
||||
r.setToUser(originalMessage.getFromUser());
|
||||
r.setPrivateMessage(pm);
|
||||
r = recipientDao.save(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package se.su.dsv.scipro.message.models;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
import org.apache.wicket.injection.web.InjectorHolder;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
|
||||
public class ViewMessageModel implements IClusterable {
|
||||
|
||||
private static final long serialVersionUID = 3808247849016842185L;
|
||||
|
||||
@SpringBean
|
||||
private PrivateMessageDao pmDao;
|
||||
|
||||
private PrivateMessage message;
|
||||
|
||||
private String messageFrom;
|
||||
private String messageSubject;
|
||||
private String messageText;
|
||||
|
||||
public ViewMessageModel(PrivateMessage message) {
|
||||
InjectorHolder.getInjector().inject(this);
|
||||
this.message = pmDao.reLoad(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the messageFrom
|
||||
*/
|
||||
public String getMessageFrom() {
|
||||
return message.getFromUser().getFirstName() + " " + message.getFromUser().getLastName();
|
||||
}
|
||||
/**
|
||||
* @param messageFrom the messageFrom to set
|
||||
*/
|
||||
public void setMessageFrom(String messageFrom) {
|
||||
this.messageFrom = messageFrom;
|
||||
}
|
||||
/**
|
||||
* @return the messageSubject
|
||||
*/
|
||||
public String getMessageSubject() {
|
||||
return message.getSubject();
|
||||
}
|
||||
/**
|
||||
* @param messageSubject the messageSubject to set
|
||||
*/
|
||||
public void setMessageSubject(String messageSubject) {
|
||||
this.messageSubject = messageSubject;
|
||||
}
|
||||
/**
|
||||
* @return the messageText
|
||||
*/
|
||||
public String getMessageText() {
|
||||
return message.getMessage();
|
||||
}
|
||||
/**
|
||||
* @param messageText the messageText to set
|
||||
*/
|
||||
public void setMessageText(String messageText) {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:extend>
|
||||
<div wicket:id="createMessagePanel" id="create-message-panel" class="prepend-5 span-10 last">
|
||||
<h2>New Message</h2>
|
||||
<form wicket:id="privateMessageForm">
|
||||
<div class="prepend-top span-10 last">
|
||||
<strong>Recipient(s): </strong>
|
||||
<div wicket:id="userFinder"></div>
|
||||
</div>
|
||||
|
||||
<div class="span-10 last">
|
||||
<p>
|
||||
<label for="subject">Subject: </label><br />
|
||||
<input type="text" wicket:id="subject" id="subject" class="title" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="message">Message: </label><br />
|
||||
<textarea wicket:id="textMessage" id="message"></textarea>
|
||||
</p>
|
||||
|
||||
<p><input type="submit" wicket:id="submitButton" id="submitButton" /></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</wicket:extend>
|
||||
</body>
|
||||
</html>
|
@ -1,155 +0,0 @@
|
||||
package se.su.dsv.scipro.message.pages;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.form.Button;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.basepages.MenuPage;
|
||||
import se.su.dsv.scipro.components.autocomplete.*;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.message.models.PrivateMessageModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class NewPrivateMessagePage extends MenuPage {
|
||||
|
||||
@SpringBean
|
||||
private ProjectDao projectDao;
|
||||
|
||||
private WebMarkupContainer createMessagePanel;
|
||||
private Collection<User> recipients;
|
||||
|
||||
public NewPrivateMessagePage(final PageParameters pp, Collection<User> recipients) {
|
||||
super(pp);
|
||||
this.recipients = recipients;
|
||||
|
||||
createMessagePanel();
|
||||
|
||||
}
|
||||
|
||||
public NewPrivateMessagePage(final PageParameters pp, Project project) {
|
||||
super(pp);
|
||||
Project p = projectDao.reLoad(project);
|
||||
recipients = new ArrayList<User>();
|
||||
for (Student s : p.getProjectParticipants())
|
||||
recipients.add(s.getUser());
|
||||
|
||||
createMessagePanel();
|
||||
}
|
||||
|
||||
private void createMessagePanel() {
|
||||
createMessagePanel = new WebMarkupContainer("createMessagePanel");
|
||||
createMessagePanel.add(new PrivateMessageForm("privateMessageForm"));
|
||||
createMessagePanel.setOutputMarkupId(true);
|
||||
|
||||
addOrReplace(createMessagePanel);
|
||||
}
|
||||
|
||||
private class PrivateMessageForm extends Form<PrivateMessageModel> {
|
||||
|
||||
private static final long serialVersionUID = -6084706401555824010L;
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
|
||||
private User user;
|
||||
private FeedbackPanel feedbackPanel;
|
||||
protected PrivateMessageModel model;
|
||||
|
||||
private Dialog dialog;
|
||||
|
||||
public PrivateMessageForm(String name) {
|
||||
super(name, new CompoundPropertyModel<PrivateMessageModel>(
|
||||
new PrivateMessageModel()));
|
||||
model = getModelObject();
|
||||
|
||||
user = SciProSession.get().getUser();
|
||||
// feedbackPanel.setOutputMarkupId(true);
|
||||
// this.feedbackPanel = feedbackPanel;
|
||||
// this.dialog = dialog;
|
||||
|
||||
AutoCompletionChoicesProvider<User> choiceProvider = new AutoCompletionChoicesProvider<User>() {
|
||||
|
||||
private static final long serialVersionUID = 2625446937171760387L;
|
||||
|
||||
@Override
|
||||
public Iterator<User> getChoices(String input) {
|
||||
return userDao.findUserQuery(input, 10).iterator();
|
||||
}
|
||||
};
|
||||
|
||||
MultiObjectAutoCompleteBuilder<User, Long> moac = new MultiObjectAutoCompleteBuilder<User, Long>(
|
||||
choiceProvider);
|
||||
moac.idType(Long.class);
|
||||
moac.width(300);
|
||||
moac.autoCompleteRenderer(new MultiObjectAutoCompleteRenderer<User>() {
|
||||
|
||||
private static final long serialVersionUID = -7566957020614501374L;
|
||||
|
||||
public String getTextValue(User u) {
|
||||
return u.getFirstName() + " " + u.getLastName() + " <"
|
||||
+ u.getEmailAddress() + ">";
|
||||
}
|
||||
|
||||
protected String getIdValue(User u) {
|
||||
return u.getId().toString();
|
||||
}
|
||||
});
|
||||
|
||||
moac.objectConverter(new MultiObjectAutoCompleteObjectConverter<Long, User>() {
|
||||
|
||||
private static final long serialVersionUID = -7964847995911863744L;
|
||||
|
||||
@Override
|
||||
public User convertToObject(Long id) {
|
||||
return userDao.load(id);
|
||||
}
|
||||
});
|
||||
MultiObjectAutoCompleteField<User, Long> moacf = moac
|
||||
.build("userFinder");
|
||||
if (recipients != null) moacf.setSelectedObjects((List<User>) recipients);
|
||||
add(moacf);
|
||||
|
||||
add(new TextField<String>("subject", new PropertyModel<String>(
|
||||
model, "subject")));
|
||||
add(new TextArea<String>("textMessage", new PropertyModel<String>(
|
||||
model, "textMessage")));
|
||||
add(new Button("submitButton",
|
||||
new Model<String>("Send Message")) {
|
||||
|
||||
private static final long serialVersionUID = 7873868077339420815L;
|
||||
|
||||
@Override
|
||||
public void onSubmit() {
|
||||
model.sendMessage();
|
||||
|
||||
setResponsePage(PrivateMessagesPage.class);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSubmit() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<wicket:extend>
|
||||
<div wicket:id="feedbackPanel" id="feedback-panel" class="prepend-1 span-20 last">[Feedback Panel]</div>
|
||||
|
||||
<h2>Private Messages</h2>
|
||||
|
||||
<div class="margin span-20 last">
|
||||
<a href="" wicket:id="newMessageLink">New Message</a>
|
||||
</div>
|
||||
|
||||
<div wicket:id="messageTabs" class="append-bottom span-24 last">
|
||||
<ul>
|
||||
<li><a href="#inboxTab">Inbox</a></li>
|
||||
<li><a href="#sentMessagesTab">Sent</a></li>
|
||||
</ul>
|
||||
<div id="inboxTab">
|
||||
<div wicket:id="privateMessagesPanel"></div>
|
||||
</div>
|
||||
<div id="sentMessagesTab">
|
||||
<div wicket:id="sentMessagesPanel"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div wicket:id="createMessageDialog">
|
||||
<div wicket:id="createMessagePanel" id="create-message-panel" class="span-10 last">
|
||||
<form wicket:id="privateMessageForm">
|
||||
<div class="span-10 last">
|
||||
<strong>Recipient(s): </strong>
|
||||
<div wicket:id="userFinder"></div>
|
||||
</div>
|
||||
|
||||
<div class="span-10 last">
|
||||
<p>
|
||||
<label for="subject">Subject: </label><br />
|
||||
<input type="text" wicket:id="subject" id="subject" class="title" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="message">Message: </label><br />
|
||||
<textarea wicket:id="textMessage" id="message"></textarea>
|
||||
</p>
|
||||
|
||||
<p><input type="submit" wicket:id="submitButton" id="submitButton" /></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</wicket:extend>
|
||||
</body>
|
||||
</html>
|
@ -1,200 +0,0 @@
|
||||
package se.su.dsv.scipro.message.pages;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.protocol.http.RequestUtils;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
import org.odlabs.wiquery.ui.tabs.Tabs;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.basepages.MenuPage;
|
||||
import se.su.dsv.scipro.components.DialogPlus;
|
||||
import se.su.dsv.scipro.components.autocomplete.*;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.message.models.PrivateMessageModel;
|
||||
import se.su.dsv.scipro.message.panels.PrivateMessagesPanel;
|
||||
import se.su.dsv.scipro.message.panels.SentMessagesPanel;
|
||||
import se.su.dsv.scipro.security.auth.Authorization;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@Authorization(authorizedRoles={Roles.SYSADMIN}) //TODO Hidden for initial deployment
|
||||
public class PrivateMessagesPage extends MenuPage {
|
||||
|
||||
public static final String MAIN_MENU_LABEL = "Messages";
|
||||
|
||||
private FeedbackPanel feedbackPanel;
|
||||
private User user;
|
||||
|
||||
private PrivateMessagesPanel privateMessagesPanel;
|
||||
private SentMessagesPanel sentMessagesPanel;
|
||||
private WebMarkupContainer createMessagePanel;
|
||||
private Dialog createMessageDialog;
|
||||
private PrivateMessageForm messageForm;
|
||||
private Tabs messageTabs;
|
||||
|
||||
public PrivateMessagesPage(final PageParameters pp) {
|
||||
user = SciProSession.get().getUser();
|
||||
|
||||
feedbackPanel = new FeedbackPanel("feedbackPanel");
|
||||
add(feedbackPanel);
|
||||
|
||||
messageTabs = new Tabs("messageTabs");
|
||||
privateMessagesPanel = new PrivateMessagesPanel("privateMessagesPanel", feedbackPanel);
|
||||
privateMessagesPanel.setVisible(true);
|
||||
privateMessagesPanel.setOutputMarkupId(true);
|
||||
messageTabs.add(privateMessagesPanel);
|
||||
|
||||
sentMessagesPanel = new SentMessagesPanel("sentMessagesPanel", feedbackPanel);
|
||||
sentMessagesPanel.setVisible(true);
|
||||
sentMessagesPanel.setOutputMarkupId(true);
|
||||
messageTabs.add(sentMessagesPanel);
|
||||
|
||||
add(messageTabs);
|
||||
|
||||
createMessageDialog();
|
||||
|
||||
add(new AjaxLink<PrivateMessage>("newMessageLink") {
|
||||
private static final long serialVersionUID = -3118671639114513536L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
createMessageDialog();
|
||||
target.addComponent(createMessageDialog);
|
||||
createMessageDialog.open(target);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void createMessageDialog() {
|
||||
createMessageDialog = new DialogPlus("createMessageDialog").setModal(true).setAutoOpen(false).setWidth(420).setResizable(false);
|
||||
createMessageDialog.setOutputMarkupId(true);
|
||||
|
||||
createMessagePanel = new WebMarkupContainer("createMessagePanel");
|
||||
createMessagePanel.add(new PrivateMessageForm("privateMessageForm", feedbackPanel, createMessageDialog));
|
||||
createMessagePanel.setOutputMarkupId(true);
|
||||
createMessageDialog.add(createMessagePanel);
|
||||
|
||||
addOrReplace(createMessageDialog);
|
||||
}
|
||||
|
||||
private class PrivateMessageForm extends Form<PrivateMessageModel> {
|
||||
|
||||
private static final long serialVersionUID = -6084706401555824010L;
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
|
||||
private User user;
|
||||
private FeedbackPanel feedbackPanel;
|
||||
protected PrivateMessageModel model;
|
||||
|
||||
private Dialog dialog;
|
||||
|
||||
public PrivateMessageForm(String name, final FeedbackPanel feedbackPanel, final Dialog dialog) {
|
||||
super(name, new CompoundPropertyModel<PrivateMessageModel>(new PrivateMessageModel()));
|
||||
model = getModelObject();
|
||||
|
||||
user = SciProSession.get().getUser();
|
||||
feedbackPanel.setOutputMarkupId(true);
|
||||
this.feedbackPanel = feedbackPanel;
|
||||
this.dialog = dialog;
|
||||
|
||||
AutoCompletionChoicesProvider<User> choiceProvider = new AutoCompletionChoicesProvider<User>() {
|
||||
|
||||
private static final long serialVersionUID = 2625446937171760387L;
|
||||
|
||||
@Override
|
||||
public Iterator<User> getChoices(String input) {
|
||||
return userDao.findUserQuery(input, 10).iterator();
|
||||
}
|
||||
};
|
||||
|
||||
MultiObjectAutoCompleteBuilder<User, Long> moac = new MultiObjectAutoCompleteBuilder<User, Long>(
|
||||
choiceProvider);
|
||||
moac.idType(Long.class);
|
||||
moac.width(300);
|
||||
moac.autoCompleteRenderer(new MultiObjectAutoCompleteRenderer<User>() {
|
||||
|
||||
private static final long serialVersionUID = -7566957020614501374L;
|
||||
|
||||
public String getTextValue(User u) {
|
||||
return u.getFirstName() + " " + u.getLastName() + " <" + u.getEmailAddress() + ">";
|
||||
}
|
||||
|
||||
protected String getIdValue(User u) {
|
||||
return u.getId().toString();
|
||||
}
|
||||
});
|
||||
|
||||
moac.objectConverter(new MultiObjectAutoCompleteObjectConverter<Long, User>() {
|
||||
|
||||
private static final long serialVersionUID = -7964847995911863744L;
|
||||
|
||||
@Override
|
||||
public User convertToObject(Long id) {
|
||||
return userDao.load(id);
|
||||
}
|
||||
});
|
||||
MultiObjectAutoCompleteField<User, Long> moacf = moac.build("userFinder");
|
||||
add(moacf);
|
||||
|
||||
add(new TextField<String>("subject", new PropertyModel<String>(model, "subject")));
|
||||
add(new TextArea<String>("textMessage", new PropertyModel<String>(model, "textMessage")));
|
||||
add(new AjaxButton("submitButton", new Model<String>("Send Message")) {
|
||||
|
||||
private static final long serialVersionUID = 7873868077339420815L;
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
model.sendMessage();
|
||||
|
||||
model = new PrivateMessageModel();
|
||||
|
||||
dialog.close(target);
|
||||
setResponsePage(PrivateMessagesPage.class);
|
||||
|
||||
// info("Private message sent");
|
||||
// target.addComponent(feedbackPanel);
|
||||
// privateMessagesPanel = new PrivateMessagesPanel("privateMessagesPanel", feedbackPanel);
|
||||
// privateMessagesPanel.setOutputMarkupId(true);
|
||||
// messageTabs.addOrReplace(privateMessagesPanel);
|
||||
// sentMessagesPanel = new SentMessagesPanel("sentMessagesPanel", feedbackPanel);
|
||||
// sentMessagesPanel.setOutputMarkupId(true);
|
||||
// messageTabs.addOrReplace(sentMessagesPanel);
|
||||
// target.addComponent(privateMessagesPanel);
|
||||
// target.addComponent(sentMessagesPanel);
|
||||
// feedbackPanel.add(new EffectBehavior(new Delay(2000))).add(new EffectBehavior(new FadeOut(EffectSpeed.SLOW)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSubmit() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getAbsoluteURL() {
|
||||
PageParameters pageParameters = new PageParameters();
|
||||
return RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(PrivateMessagesPage.class, pageParameters).toString());
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div wicket:id="listContainer" class="span-21 last">
|
||||
<table class="rounded-table">
|
||||
<tr>
|
||||
<th>Subject</th>
|
||||
<th>From</th>
|
||||
<th>Date</th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
<tr wicket:id="message-list-item">
|
||||
<td wicket:id="subjectField"></td>
|
||||
<td wicket:id="fromField"></td>
|
||||
<td wicket:id="dateField"></td>
|
||||
<td><a wicket:id="readLink">Read</a></td>
|
||||
<td><a wicket:id="replyLink">Reply</a></td>
|
||||
</tr>
|
||||
<tr wicket:id="no-messages">
|
||||
<td colspan="5">No messages</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><span wicket:id="navigator">[paging]</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div wicket:id="messageDialog">
|
||||
<div wicket:id="messageContainer" class="span-12 last">
|
||||
<p><strong>From: </strong><span wicket:id="messageFrom"></span></p>
|
||||
<p><strong>Subject: </strong><span wicket:id="messageSubject"></span></p>
|
||||
<p><span wicket:id="messageText"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div wicket:id="replyDialog">
|
||||
<div wicket:id="replyContainer" class="span-10 last">
|
||||
<form wicket:id="replyMessageForm">
|
||||
|
||||
<div class="span-10 last">
|
||||
<p>
|
||||
To: <span wicket:id="recipient"></span>
|
||||
</p>
|
||||
<p>
|
||||
<label for="subject">Subject: </label><br />
|
||||
<input type="text" wicket:id="replySubject" id="subject" class="title" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="message">Message: </label><br />
|
||||
<textarea wicket:id="replyText" id="message"></textarea>
|
||||
</p>
|
||||
|
||||
<p><input type="submit" wicket:id="submitButton" id="submitButton" /></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
@ -1,280 +0,0 @@
|
||||
package se.su.dsv.scipro.message.panels;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
|
||||
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.basic.MultiLineLabel;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.form.TextArea;
|
||||
import org.apache.wicket.markup.html.form.TextField;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.PageableListView;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.core.effects.EffectBehavior;
|
||||
import org.odlabs.wiquery.core.effects.EffectSpeed;
|
||||
import org.odlabs.wiquery.core.effects.basic.Delay;
|
||||
import org.odlabs.wiquery.core.effects.fading.FadeOut;
|
||||
import org.odlabs.wiquery.core.events.Event;
|
||||
import org.odlabs.wiquery.core.events.MouseEvent;
|
||||
import org.odlabs.wiquery.core.events.WiQueryEventBehavior;
|
||||
import org.odlabs.wiquery.core.javascript.JsScope;
|
||||
import org.odlabs.wiquery.core.javascript.JsStatement;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.components.DialogPlus;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.message.models.MessageListModel;
|
||||
import se.su.dsv.scipro.message.models.ReplyMessageModel;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
public class PrivateMessagesPanel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = -3897625890292250992L;
|
||||
|
||||
@SpringBean
|
||||
private PrivateMessageDao pmDao;
|
||||
@SpringBean
|
||||
private RecipientDao recipientDao;
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
|
||||
private User user;
|
||||
|
||||
private MessageListModel messageListModel;
|
||||
private PageableListView<Recipient> privateMessagesListView;
|
||||
private WebMarkupContainer listContainer;
|
||||
private WebMarkupContainer messageContainer;
|
||||
private CustomPagingNavigator pagingNavigator;
|
||||
|
||||
private Label messageFrom;
|
||||
private Label messageSubject;
|
||||
private MultiLineLabel messageText;
|
||||
|
||||
private Dialog messageDialog;
|
||||
private PrivateMessage currentMessage;
|
||||
|
||||
private Dialog replyDialog;
|
||||
|
||||
private WebMarkupContainer replyContainer;
|
||||
|
||||
private FeedbackPanel feedbackPanel;
|
||||
|
||||
private WebMarkupContainer messageTable;
|
||||
|
||||
private static final int PAGE_LIMIT = 10;
|
||||
|
||||
public PrivateMessagesPanel(String id, FeedbackPanel feedbackPanel) {
|
||||
super(id);
|
||||
user = SciProSession.get().getUser();
|
||||
messageListModel = new MessageListModel(user);
|
||||
this.feedbackPanel = feedbackPanel;
|
||||
|
||||
createComponents();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
|
||||
PageableListView<Recipient> lv = new PageableListView<Recipient>("message-list-item", new PropertyModel<List<Recipient>>(messageListModel, "privateMessages"), PAGE_LIMIT) {
|
||||
|
||||
private static final long serialVersionUID = 7851212974239684966L;
|
||||
|
||||
@Override
|
||||
protected void populateItem(final ListItem<Recipient> item) {
|
||||
final Recipient rec = item.getModelObject();
|
||||
final PrivateMessage pm = rec.getPrivateMessage();
|
||||
item.add(new DateFormatter(DateStyle.DATETIME).createFormattedDateLabel("dateField", pm.getDateCreated()));
|
||||
item.add(new Label("fromField", pm.getFromUser().getFirstName() + " "
|
||||
+ pm.getFromUser().getLastName()));
|
||||
item.add(new Label("subjectField", pm.getSubject()));
|
||||
if (rec.getDateRead() == null)
|
||||
item.add(new SimpleAttributeModifier("class", "unread-message-table-row"));
|
||||
item.add(new AjaxLink<String>("readLink") {
|
||||
|
||||
private static final long serialVersionUID = -7708310286839173562L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
currentMessage = pmDao.reLoad(pm);
|
||||
|
||||
Recipient rec2 = recipientDao.reLoad(item.getModelObject());
|
||||
if (rec2.getDateRead() == null) {
|
||||
rec2.setDateRead(GregorianCalendar.getInstance().getTime());
|
||||
rec2 = recipientDao.save(rec2);
|
||||
}
|
||||
|
||||
messageContainer = new WebMarkupContainer("messageContainer");
|
||||
messageFrom.setDefaultModelObject(currentMessage.getFromUser().getFirstName() + " " + currentMessage.getFromUser().getLastName());
|
||||
messageSubject.setDefaultModelObject(currentMessage.getSubject());
|
||||
messageText.setDefaultModelObject(currentMessage.getMessage());
|
||||
messageContainer.add(messageFrom);
|
||||
messageContainer.add(messageSubject);
|
||||
messageContainer.add(messageText);
|
||||
messageContainer.setOutputMarkupId(true);
|
||||
messageDialog.addOrReplace(messageContainer);
|
||||
|
||||
target.addComponent(messageDialog);
|
||||
messageDialog.open(target);
|
||||
|
||||
messageListModel.updatePrivateMessages();
|
||||
privateMessagesListView.modelChanged();
|
||||
target.addComponent(listContainer);
|
||||
}
|
||||
});
|
||||
item.add(new AjaxLink<Void>("replyLink") {
|
||||
|
||||
private static final long serialVersionUID = -2889726192972689428L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
currentMessage = pmDao.reLoad(pm);
|
||||
createReplyMessageDialog();
|
||||
|
||||
target.addComponent(replyDialog);
|
||||
replyDialog.open(target);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOVER) {
|
||||
|
||||
private static final long serialVersionUID = 478266580052869871L;
|
||||
|
||||
@Override
|
||||
public JsScope callback() {
|
||||
return JsScope.quickScope(new JsStatement().$(item).toggleClass("active"));
|
||||
}
|
||||
|
||||
}));
|
||||
item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOUT) {
|
||||
|
||||
private static final long serialVersionUID = 478266580052869871L;
|
||||
|
||||
@Override
|
||||
public JsScope callback() {
|
||||
return JsScope.quickScope(new JsStatement().$(item).toggleClass("active"));
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
privateMessagesListView = lv;
|
||||
|
||||
listContainer = new WebMarkupContainer("listContainer");
|
||||
listContainer.setOutputMarkupId(true);
|
||||
listContainer.add(privateMessagesListView);
|
||||
|
||||
WebMarkupContainer noMessagesContainer = new WebMarkupContainer("no-messages") {
|
||||
private static final long serialVersionUID = 1816636155678145415L;
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return (privateMessagesListView.getModelObject().size() == 0);
|
||||
}
|
||||
};
|
||||
|
||||
listContainer.add(noMessagesContainer);
|
||||
|
||||
pagingNavigator = new CustomPagingNavigator("navigator", privateMessagesListView) {
|
||||
private static final long serialVersionUID = 1780938787738245045L;
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return privateMessagesListView.getModelObject().size() > PAGE_LIMIT;
|
||||
}
|
||||
};
|
||||
|
||||
listContainer.add(pagingNavigator);
|
||||
|
||||
createMessageDialog();
|
||||
createReplyMessageDialog();
|
||||
|
||||
addOrReplace(listContainer);
|
||||
}
|
||||
|
||||
private void createMessageDialog() {
|
||||
messageDialog = new DialogPlus("messageDialog").setModal(true).setAutoOpen(false).setWidth(600).setResizable(false);
|
||||
messageDialog.setOutputMarkupId(true);
|
||||
|
||||
messageContainer = new WebMarkupContainer("messageContainer");
|
||||
messageFrom = new Label("messageFrom", new Model<String>(""));
|
||||
messageFrom.setOutputMarkupId(true);
|
||||
messageContainer.add(messageFrom);
|
||||
messageSubject = new Label("messageSubject", new Model<String>(""));
|
||||
messageSubject.setOutputMarkupId(true);
|
||||
messageContainer.add(messageSubject);
|
||||
messageText = new MultiLineLabel("messageText", new Model<String>(""));
|
||||
messageText.setOutputMarkupId(true);
|
||||
messageContainer.add(messageText);
|
||||
messageContainer.setOutputMarkupId(true);
|
||||
|
||||
messageDialog.add(messageContainer);
|
||||
addOrReplace(messageDialog);
|
||||
}
|
||||
|
||||
private void createReplyMessageDialog() {
|
||||
replyDialog = new DialogPlus("replyDialog").setModal(true).setAutoOpen(false).setWidth(420).setResizable(false);
|
||||
replyDialog.setOutputMarkupId(true);
|
||||
|
||||
replyContainer = new WebMarkupContainer("replyContainer");
|
||||
replyContainer.add(new ReplyMessageForm("replyMessageForm"));
|
||||
replyContainer.setOutputMarkupId(true);
|
||||
replyDialog.add(replyContainer);
|
||||
|
||||
addOrReplace(replyDialog);
|
||||
}
|
||||
|
||||
private class ReplyMessageForm extends Form<ReplyMessageModel> {
|
||||
|
||||
private static final long serialVersionUID = -6068231173540281637L;
|
||||
|
||||
private ReplyMessageModel model;
|
||||
|
||||
public ReplyMessageForm(String id) {
|
||||
super(id, new CompoundPropertyModel<ReplyMessageModel>(new ReplyMessageModel()));
|
||||
if (currentMessage != null)
|
||||
model = new ReplyMessageModel(currentMessage);
|
||||
else
|
||||
model = getModelObject();
|
||||
|
||||
add(new Label("recipient", new PropertyModel<String>(model, "getReplyToUserString")));
|
||||
add(new TextField<String>("replySubject", new PropertyModel<String>(model, "replySubject")));
|
||||
add(new TextArea<String>("replyText", new PropertyModel<String>(model, "replyText")));
|
||||
add(new AjaxButton("submitButton", new Model<String>("Send Message")) {
|
||||
|
||||
private static final long serialVersionUID = 7873868077339420815L;
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
|
||||
model.sendMessage();
|
||||
|
||||
model = new ReplyMessageModel();
|
||||
|
||||
replyDialog.close(target);
|
||||
|
||||
info("Private message sent");
|
||||
target.addComponent(feedbackPanel);
|
||||
feedbackPanel.add(new EffectBehavior(new Delay(2000))).add(new EffectBehavior(new FadeOut(EffectSpeed.SLOW)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div wicket:id="listContainer" class="span-21 last">
|
||||
<table class="rounded-table">
|
||||
<tr>
|
||||
<th>Subject</th>
|
||||
<th>To</th>
|
||||
<th>Date</th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
<tr wicket:id="message-list-item">
|
||||
<td wicket:id="subjectField"></td>
|
||||
<td wicket:id="toField"></td>
|
||||
<td wicket:id="dateField"></td>
|
||||
<td><a href="#" wicket:id="readLink">Read</a></td>
|
||||
<td><a href="#" wicket:id="removeLink">Remove</a></td>
|
||||
</tr>
|
||||
<tr wicket:id="no-messages">
|
||||
<td colspan="5">No messages</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><span wicket:id="navigator">[paging]</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div wicket:id="messageDialog">
|
||||
<div wicket:id="messageContainer" class="span-12 last">
|
||||
<p><strong>From: </strong><span wicket:id="messageFrom"></span></p>
|
||||
<p><strong>Subject: </strong><span wicket:id="messageSubject"></span></p>
|
||||
<p><span wicket:id="messageText"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
</html>
|
@ -1,264 +0,0 @@
|
||||
package se.su.dsv.scipro.message.panels;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.basic.MultiLineLabel;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.PageableListView;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.CompoundPropertyModel;
|
||||
import org.apache.wicket.model.PropertyModel;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.odlabs.wiquery.core.events.Event;
|
||||
import org.odlabs.wiquery.core.events.MouseEvent;
|
||||
import org.odlabs.wiquery.core.events.WiQueryEventBehavior;
|
||||
import org.odlabs.wiquery.core.javascript.JsScope;
|
||||
import org.odlabs.wiquery.core.javascript.JsStatement;
|
||||
import org.odlabs.wiquery.ui.dialog.Dialog;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.message.models.MessageListModel;
|
||||
import se.su.dsv.scipro.message.models.ViewMessageModel;
|
||||
import se.su.dsv.scipro.util.DateFormatter;
|
||||
import se.su.dsv.scipro.util.JavascriptEventConfirmation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SentMessagesPanel extends Panel {
|
||||
private static final long serialVersionUID = -7916059356375447441L;
|
||||
|
||||
@SpringBean
|
||||
private PrivateMessageDao pmDao;
|
||||
@SpringBean
|
||||
private RecipientDao recipientDao;
|
||||
|
||||
private User user;
|
||||
|
||||
private MessageListModel messageListModel;
|
||||
private PageableListView<PrivateMessage> sentMessagesListView;
|
||||
private WebMarkupContainer listContainer;
|
||||
private CustomPagingNavigator pagingNavigator;
|
||||
private FeedbackPanel feedbackPanel;
|
||||
|
||||
private se.su.dsv.scipro.message.panels.SentMessagesPanel.MessageDialog messageDialog;
|
||||
|
||||
private Label messageFrom;
|
||||
|
||||
private Label messageSubject;
|
||||
|
||||
private MultiLineLabel messageText;
|
||||
|
||||
private PrivateMessage currentMessage;
|
||||
|
||||
public WebMarkupContainer messageContainer;
|
||||
|
||||
private static final int PAGE_LIMIT = 10;
|
||||
|
||||
public SentMessagesPanel(String id, FeedbackPanel fb) {
|
||||
super(id);
|
||||
user = SciProSession.get().getUser();
|
||||
messageListModel = new MessageListModel(user);
|
||||
feedbackPanel = fb;
|
||||
|
||||
createComponents();
|
||||
}
|
||||
|
||||
private void createComponents() {
|
||||
PageableListView<PrivateMessage> lv = new PageableListView<PrivateMessage>("message-list-item", new PropertyModel<List<PrivateMessage>>(messageListModel, "sentMessages"), PAGE_LIMIT) {
|
||||
|
||||
private static final long serialVersionUID = 7851212974239684966L;
|
||||
|
||||
@Override
|
||||
protected void populateItem(final ListItem<PrivateMessage> item) {
|
||||
final PrivateMessage pm = item.getModelObject();
|
||||
item.add(new DateFormatter(DateStyle.DATETIME).createFormattedDateLabel("dateField", pm.getDateCreated()));
|
||||
|
||||
String recipients = "";
|
||||
int count = 0;
|
||||
for (Recipient r : pm.getRecipientList()) {
|
||||
r = recipientDao.reLoad(r);
|
||||
String read = "";
|
||||
String tag = "strong";
|
||||
if (r.getDateRead() != null) {
|
||||
tag = "span";
|
||||
}
|
||||
String currentRecipient = r.getToUser().getFirstName() + " " + r.getToUser().getLastName();
|
||||
|
||||
if (count > 0)
|
||||
recipients += ", <" + tag + ">" + currentRecipient + "</" + tag + "> " + read;
|
||||
else{
|
||||
recipients += "<" + tag + ">" + currentRecipient + "</" + tag + "> " + read;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
item.add(new Label("toField", recipients).setEscapeModelStrings(false));
|
||||
|
||||
item.add(new Label("subjectField", pm.getSubject()));
|
||||
|
||||
item.add(new AjaxLink<String>("readLink") {
|
||||
|
||||
private static final long serialVersionUID = -7708310286839173562L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
currentMessage = pmDao.reLoad(pm);
|
||||
messageFrom.setDefaultModelObject(currentMessage.getFromUser());
|
||||
messageSubject.setDefaultModelObject(currentMessage.getSubject());
|
||||
messageText.setDefaultModelObject(currentMessage.getMessage());
|
||||
target.addComponent(messageDialog);
|
||||
messageDialog.open(target);
|
||||
}
|
||||
});
|
||||
|
||||
DeletePrivateMessage rdl = new DeletePrivateMessage("removeLink", item.getModelObject());
|
||||
|
||||
item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOVER) {
|
||||
|
||||
private static final long serialVersionUID = 478266580052869871L;
|
||||
|
||||
@Override
|
||||
public JsScope callback() {
|
||||
return JsScope.quickScope(new JsStatement().$(item).toggleClass("active"));
|
||||
}
|
||||
|
||||
}));
|
||||
item.add(new WiQueryEventBehavior(new Event(MouseEvent.MOUSEOUT) {
|
||||
|
||||
private static final long serialVersionUID = 478266580052869871L;
|
||||
|
||||
@Override
|
||||
public JsScope callback() {
|
||||
return JsScope.quickScope(new JsStatement().$(item).toggleClass("active"));
|
||||
}
|
||||
|
||||
}));
|
||||
rdl.add(new JavascriptEventConfirmation("onclick", "Do you really want do delete this message: \"" + rdl.privateMessage.getSubject() + "\"?"));
|
||||
item.add(rdl);
|
||||
}
|
||||
};
|
||||
|
||||
lv.setOutputMarkupId(true);
|
||||
sentMessagesListView = lv;
|
||||
|
||||
listContainer = new WebMarkupContainer("listContainer");
|
||||
listContainer.add(sentMessagesListView);
|
||||
listContainer.setOutputMarkupId(true);
|
||||
|
||||
WebMarkupContainer noMessagesContainer = new WebMarkupContainer("no-messages") {
|
||||
private static final long serialVersionUID = 1816636155678145415L;
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return (sentMessagesListView.getModelObject().size() == 0);
|
||||
}
|
||||
};
|
||||
|
||||
listContainer.add(noMessagesContainer);
|
||||
|
||||
pagingNavigator = new CustomPagingNavigator("navigator", sentMessagesListView) {
|
||||
private static final long serialVersionUID = 7209893636269001424L;
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return sentMessagesListView.getModelObject().size() > PAGE_LIMIT;
|
||||
}
|
||||
};
|
||||
listContainer.add(pagingNavigator);
|
||||
|
||||
createMessageDialog();
|
||||
|
||||
add(listContainer);
|
||||
}
|
||||
|
||||
private class DeletePrivateMessage extends AjaxLink<PrivateMessage> {
|
||||
|
||||
private static final long serialVersionUID = 3520099257192880284L;
|
||||
protected PrivateMessage privateMessage;
|
||||
|
||||
public DeletePrivateMessage(String id, PrivateMessage privateMessage) {
|
||||
super(id);
|
||||
this.privateMessage = privateMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
messageListModel.removeMessage(privateMessage);
|
||||
|
||||
// listContainer.remove(sentMessagesListView);
|
||||
info("Message removed");
|
||||
listContainer.add(sentMessagesListView);
|
||||
target.addComponent(listContainer);
|
||||
target.addComponent(feedbackPanel);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.wicket.ajax.markup.html.AjaxLink#getAjaxCallDecorator()
|
||||
*/
|
||||
|
||||
// @Override
|
||||
// protected IAjaxCallDecorator getAjaxCallDecorator() {
|
||||
// return new AjaxCallDecorator() {
|
||||
// private static final long serialVersionUID = 8989126586010432130L;
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see org.apache.wicket.ajax.calldecorator.AjaxCallDecorator#decorateScript(java.lang.CharSequence)
|
||||
// */
|
||||
// @Override
|
||||
// public CharSequence decorateScript(CharSequence script) {
|
||||
// String subj = privateMessage.getSubject();
|
||||
// String ret = "if(!confirm('Do you really want do delete this message: \"" + subj + "\"?')) return false; " + script;
|
||||
// return ret;
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void createMessageDialog() {
|
||||
messageDialog = new MessageDialog("messageDialog");
|
||||
messageDialog.setOutputMarkupId(true);
|
||||
messageDialog.setModal(true);
|
||||
messageDialog.setAutoOpen(false);
|
||||
messageDialog.setWidth(600);
|
||||
messageDialog.setResizable(false);
|
||||
|
||||
messageDialog.add(messageContainer);
|
||||
|
||||
add(messageDialog);
|
||||
}
|
||||
|
||||
private class MessageDialog extends Dialog {
|
||||
|
||||
private static final long serialVersionUID = -3420156991234558388L;
|
||||
|
||||
private ViewMessageModel model;
|
||||
|
||||
public MessageDialog(String id) {
|
||||
super(id);
|
||||
model = new ViewMessageModel(currentMessage);
|
||||
messageFrom = new Label("messageFrom", new CompoundPropertyModel<ViewMessageModel>(model));
|
||||
messageFrom.setOutputMarkupId(true);
|
||||
messageSubject = new Label("messageSubject", new CompoundPropertyModel<ViewMessageModel>(model));
|
||||
messageSubject.setOutputMarkupId(true);
|
||||
messageText = new MultiLineLabel("messageText", new CompoundPropertyModel<ViewMessageModel>(model));
|
||||
messageText.setOutputMarkupId(true);
|
||||
|
||||
messageContainer = new WebMarkupContainer("messageContainer");
|
||||
messageContainer.setOutputMarkupId(true);
|
||||
|
||||
messageContainer.add(messageFrom);
|
||||
messageContainer.add(messageSubject);
|
||||
messageContainer.add(messageText);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -79,7 +79,6 @@ public abstract class SciProTest {
|
||||
@Mock protected LogEntryDao logEntryDao;
|
||||
@Mock protected MailEventDao mailEventDao;
|
||||
@Mock protected MessageBoardDao messageBoardDao;
|
||||
@Mock protected PrivateMessageDao privateMessageDao;
|
||||
@Mock protected ProjectClassDao projectClassDao;
|
||||
@Mock protected ProjectClassSettingsDao projectClassSettingsDao;
|
||||
@Mock protected ProjectDao projectDao;
|
||||
@ -91,7 +90,6 @@ public abstract class SciProTest {
|
||||
@Mock protected QueryableDao queryableDao;
|
||||
@Mock protected RatableDao ratableDao;
|
||||
@Mock protected RatingDao ratingDao;
|
||||
@Mock protected RecipientDao recipientDao;
|
||||
@Mock protected ResourceDao resourceDao;
|
||||
@Mock protected RoleDao roleDao;
|
||||
@Mock protected ScheduleTemplateDao scheduleTemplateDao;
|
||||
|
@ -1,72 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.dao.jpa;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(inheritLocations = false, locations = {
|
||||
"classpath:test-applicationContext.xml"
|
||||
})
|
||||
public class TestPrivateMessageDaoJPA {
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
private PrivateMessageDao privateMessageDao;
|
||||
|
||||
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
public void startTransaction()
|
||||
{
|
||||
user = new User();
|
||||
user.setEmailAddress("test@dsv.su.se");
|
||||
user.setIdentifier(new Long(666));
|
||||
user.setFirstName("Test");
|
||||
user.setLastName("Person");
|
||||
user = userDao.save(user);
|
||||
|
||||
user = new User();
|
||||
user.setEmailAddress("testdeleted@dsv.su.se");
|
||||
user.setIdentifier(new Long(777));
|
||||
user.setFirstName("Test");
|
||||
user.setLastName("Person");
|
||||
user = userDao.save(user);
|
||||
|
||||
PrivateMessage privateMessage = new PrivateMessage();
|
||||
privateMessage.setFromUser(user);
|
||||
privateMessage.setMessage("Test");
|
||||
privateMessage.setSubject("test");
|
||||
privateMessage = privateMessageDao.save(privateMessage);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testGetPrivateMessagesFromUser() {
|
||||
Assert.assertEquals(1, privateMessageDao.getPrivateMessagesFromUser(user).size());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.dao.jpa;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.PrivateMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RecipientDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.PrivateMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.Recipient;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan - aschan@dsv.su.se
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(inheritLocations = false, locations = {
|
||||
"classpath:test-applicationContext.xml"
|
||||
})
|
||||
public class TestRecipientDaoJPA {
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
private RecipientDao recipientDao;
|
||||
|
||||
@Autowired
|
||||
private PrivateMessageDao privateMessageDao;
|
||||
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
public void startTransaction()
|
||||
{
|
||||
user = new User();
|
||||
user.setEmailAddress("test@dsv.su.se");
|
||||
user.setIdentifier(new Long(666));
|
||||
user.setFirstName("Test");
|
||||
user.setLastName("Person");
|
||||
user = userDao.save(user);
|
||||
|
||||
user = new User();
|
||||
user.setEmailAddress("testdeleted@dsv.su.se");
|
||||
user.setIdentifier(new Long(777));
|
||||
user.setFirstName("Test");
|
||||
user.setLastName("Person");
|
||||
user = userDao.save(user);
|
||||
|
||||
PrivateMessage privateMessage = new PrivateMessage();
|
||||
privateMessage.setFromUser(user);
|
||||
privateMessage.setMessage("Test");
|
||||
privateMessage.setSubject("test");
|
||||
privateMessage = privateMessageDao.save(privateMessage);
|
||||
|
||||
Recipient recipient = new Recipient();
|
||||
recipient.setToUser(user);
|
||||
recipient.setPrivateMessage(privateMessage);
|
||||
recipient= recipientDao.save(recipient);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testGetUnreadMessagesForUser() {
|
||||
Assert.assertEquals(1, recipientDao.getUnreadMessagesForUser(user).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testGetNumberOfUnreadMessagesForUser() {
|
||||
Assert.assertEquals(1, recipientDao.getNumberOfUnreadMessagesForUser(user));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testGetRecipientsByUser() {
|
||||
Assert.assertEquals(1, recipientDao.getRecipientsByUser(user).size());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user