openmeetings-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From solo...@apache.org
Subject svn commit: r1436494 - in /incubator/openmeetings/trunk/singlewebapp: WebContent/WEB-INF/ src/META-INF/ src/org/apache/openmeetings/data/chat/ src/org/apache/openmeetings/persistence/beans/chat/ src/org/apache/openmeetings/web/components/user/
Date Mon, 21 Jan 2013 17:17:53 GMT
Author: solomax
Date: Mon Jan 21 17:17:53 2013
New Revision: 1436494

URL: http://svn.apache.org/viewvc?rev=1436494&view=rev
Log:
Wicket: basic websocket-based chat messages are added

Added:
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/ChatDao.java
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/ChatMessage.java
Modified:
    incubator/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
    incubator/openmeetings/trunk/singlewebapp/src/META-INF/db2_persistence.xml
    incubator/openmeetings/trunk/singlewebapp/src/META-INF/derby_persistence.xml
    incubator/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml
    incubator/openmeetings/trunk/singlewebapp/src/META-INF/oracle_persistence.xml
    incubator/openmeetings/trunk/singlewebapp/src/META-INF/postgres_persistence.xml
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.html
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.java

Modified: incubator/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
(original)
+++ incubator/openmeetings/trunk/singlewebapp/WebContent/WEB-INF/openmeetings-applicationContext.xml
Mon Jan 21 17:17:53 2013
@@ -238,6 +238,7 @@
 	<bean id="userContactsDao" class="org.apache.openmeetings.data.user.dao.UserContactsDao"
/>
 	<bean id="usersDao" class="org.apache.openmeetings.data.user.dao.UsersDao" />
 	<bean id="serverDao" class="org.apache.openmeetings.data.basic.dao.ServerDao" />
+	<bean id="chatDao" class="org.apache.openmeetings.data.chat.ChatDao" />
 
 	<!-- No Interface -->
 	<bean id="manageCryptStyle" class="org.apache.openmeetings.utils.crypt.ManageCryptStyle"
/>

Modified: incubator/openmeetings/trunk/singlewebapp/src/META-INF/db2_persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/META-INF/db2_persistence.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/META-INF/db2_persistence.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/META-INF/db2_persistence.xml Mon Jan 21
17:17:53 2013
@@ -38,6 +38,7 @@
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentCategory</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentReminderTyps</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.MeetingMember</class>
+		<class>org.apache.openmeetings.persistence.beans.chat.ChatMessage</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation_Users</class>
 		<class>org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording</class>

Modified: incubator/openmeetings/trunk/singlewebapp/src/META-INF/derby_persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/META-INF/derby_persistence.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/META-INF/derby_persistence.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/META-INF/derby_persistence.xml Mon Jan 21
17:17:53 2013
@@ -38,6 +38,7 @@
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentCategory</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentReminderTyps</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.MeetingMember</class>
+		<class>org.apache.openmeetings.persistence.beans.chat.ChatMessage</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation_Users</class>
 		<class>org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording</class>

Modified: incubator/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml Mon Jan 21
17:17:53 2013
@@ -38,6 +38,7 @@
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentCategory</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentReminderTyps</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.MeetingMember</class>
+		<class>org.apache.openmeetings.persistence.beans.chat.ChatMessage</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation_Users</class>
 		<class>org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording</class>

Modified: incubator/openmeetings/trunk/singlewebapp/src/META-INF/oracle_persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/META-INF/oracle_persistence.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/META-INF/oracle_persistence.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/META-INF/oracle_persistence.xml Mon Jan
21 17:17:53 2013
@@ -38,6 +38,7 @@
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentCategory</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentReminderTyps</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.MeetingMember</class>
+		<class>org.apache.openmeetings.persistence.beans.chat.ChatMessage</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation_Users</class>
 		<class>org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording</class>

Modified: incubator/openmeetings/trunk/singlewebapp/src/META-INF/postgres_persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/META-INF/postgres_persistence.xml?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/META-INF/postgres_persistence.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/META-INF/postgres_persistence.xml Mon Jan
21 17:17:53 2013
@@ -38,6 +38,7 @@
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentCategory</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.AppointmentReminderTyps</class>
 		<class>org.apache.openmeetings.persistence.beans.calendar.MeetingMember</class>
+		<class>org.apache.openmeetings.persistence.beans.chat.ChatMessage</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation</class>
 		<class>org.apache.openmeetings.persistence.beans.domain.Organisation_Users</class>
 		<class>org.apache.openmeetings.persistence.beans.flvrecord.FlvRecording</class>

Added: incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/ChatDao.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/ChatDao.java?rev=1436494&view=auto
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/ChatDao.java
(added)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/chat/ChatDao.java
Mon Jan 21 17:17:53 2013
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.data.chat;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.openmeetings.persistence.beans.chat.ChatMessage;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ChatDao {
+	@PersistenceContext
+	private EntityManager em;
+
+	public ChatMessage get(long id) {
+		return em.createNamedQuery("getChatMessageById", ChatMessage.class)
+				.setParameter("id", id)
+				.getSingleResult();
+	}
+
+	//TODO additional methods should be added to get messages by external email
+	public List<ChatMessage> get(long userId, int start, int count) {
+		return em.createNamedQuery("getChatMessagesByUser", ChatMessage.class)
+				.setParameter("userId", userId)
+				.setFirstResult(start)
+				.setMaxResults(count)
+				.getResultList();
+	}
+
+	public List<ChatMessage> get(int start, int count) {
+		return em.createNamedQuery("getGlobalChatMessages", ChatMessage.class)
+				.setFirstResult(start)
+				.setMaxResults(count)
+				.getResultList();
+	}
+
+	public ChatMessage update(ChatMessage entity) {
+		entity.setSent(new Date());
+		if (entity.getId() == 0) {
+			em.persist(entity);
+		}
+		return entity;
+	}
+
+	public void delete(ChatMessage entity, long userId) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

Added: incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/ChatMessage.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/ChatMessage.java?rev=1436494&view=auto
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/ChatMessage.java
(added)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/chat/ChatMessage.java
Mon Jan 21 17:17:53 2013
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.persistence.beans.chat;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+import org.apache.openmeetings.persistence.beans.IDataProviderEntity;
+import org.apache.openmeetings.persistence.beans.rooms.Rooms;
+import org.apache.openmeetings.persistence.beans.user.Users;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+
+@Entity
+@NamedQueries({
+	@NamedQuery(name = "getChatMessageById", query = "SELECT c FROM ChatMessage c WHERE c.id
= :id")
+	, @NamedQuery(name = "getChatMessagesByUser", query = "SELECT DISTINCT c FROM ChatMessage
c WHERE c.fromUser.user_id = :userId OR c.toUser.user_id = :userId ORDER BY c.sent DESC")
+	, @NamedQuery(name = "getGlobalChatMessages", query = "SELECT DISTINCT c FROM ChatMessage
c WHERE c.toUser IS NULL ORDER BY c.sent DESC")
+})@Table(name = "chat")
+@Root(name = "ChatMessage")
+public class ChatMessage implements Serializable, IDataProviderEntity {
+	private static final long serialVersionUID = 4248081997318897605L;
+
+	@Id
+	@GeneratedValue(strategy = GenerationType.IDENTITY)
+	@Column(name = "id")
+	@Element(name = "id", data = true)
+	private long id;
+
+	@ManyToOne
+	@JoinColumn(name = "from_user_id")
+	@Element(name = "fromUserId", data = true, required = false)
+	private Users fromUser;
+	
+	// necessary to hold messages from external guests enters by invitation hash
+	@Column(name = "from_email")
+	@Element(name = "fromEmail", data = true, required = false)
+	private String fromEmail;
+	
+	@Column(name = "from_name")
+	@Element(name = "fromName", data = true, required = false)
+	private String fromName;
+	
+	@ManyToOne
+	@JoinColumn(name = "to_room_id")
+	@Element(name = "toRoomId", data = true, required = false)
+	private Rooms toRoom;
+	
+	@ManyToOne
+	@JoinColumn(name = "to_user_id")
+	@Element(name = "toUserId", data = true, required = false)
+	private Users toUser;
+
+	// necessary to hold messages to external guests enters by invitation hash
+	@Column(name = "to_email")
+	@Element(name = "toEmail", data = true, required = false)
+	private String toEmail;
+
+	@Column(name = "to_name")
+	@Element(name = "toName", data = true, required = false)
+	private String toName;
+	
+	@Column(name = "message")
+	@Element(name = "message", data = true, required = false)
+	private String message;
+	
+	@Column(name = "sent")
+	@Element(name = "sent", data = true, required = false)
+	private Date sent;
+
+	public long getId() {
+		return id;
+	}
+
+	public void setId(long id) {
+		this.id = id;
+	}
+
+	public Users getFromUser() {
+		return fromUser;
+	}
+
+	public void setFromUser(Users fromUser) {
+		this.fromUser = fromUser;
+	}
+
+	public String getFromEmail() {
+		return fromEmail;
+	}
+
+	public void setFromEmail(String fromEmail) {
+		this.fromEmail = fromEmail;
+	}
+
+	public String getFromName() {
+		return fromName;
+	}
+
+	public void setFromName(String fromName) {
+		this.fromName = fromName;
+	}
+
+	public Rooms getToRoom() {
+		return toRoom;
+	}
+
+	public void setToRoom(Rooms toRoom) {
+		this.toRoom = toRoom;
+	}
+
+	public Users getToUser() {
+		return toUser;
+	}
+
+	public void setToUser(Users toUser) {
+		this.toUser = toUser;
+	}
+
+	public String getToEmail() {
+		return toEmail;
+	}
+
+	public void setToEmail(String toEmail) {
+		this.toEmail = toEmail;
+	}
+
+	public String getToName() {
+		return toName;
+	}
+
+	public void setToName(String toName) {
+		this.toName = toName;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+
+	public void setMessage(String message) {
+		this.message = message;
+	}
+
+	public Date getSent() {
+		return sent;
+	}
+
+	public void setSent(Date sent) {
+		this.sent = sent;
+	}
+}

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.html
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.html?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.html
(original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.html
Mon Jan 21 17:17:53 2013
@@ -28,8 +28,13 @@
 					.addClass('ui-icon-carat-1-' + (chat.height() < 20 ? 's' : 'n'));
 				chat.animate({ height: chat.height() < 20 ? "300px" : "16px" }, 1000);
 			}
-			Wicket.Event.subscribe("/websocket/message", function(jqEvent, message) {
-				$('#messageArea').append('<div>' + message + '</div>'); 
+			function addChatMessage(m) {
+				if (m && m.type == "chat") {
+					$('#messageArea').append('<div>' + m.msg.message + '</div>');
+				}
+			}
+			Wicket.Event.subscribe("/websocket/message", function(jqEvent, msg) {
+				addChatMessage(jQuery.parseJSON(msg)); 
 			});
 		</script>
 	</wicket:head>

Modified: incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.java?rev=1436494&r1=1436493&r2=1436494&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.java
(original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/web/components/user/ChatPanel.java
Mon Jan 21 17:17:53 2013
@@ -18,10 +18,23 @@
  */
 package org.apache.openmeetings.web.components.user;
 
+import java.util.Date;
+
 import org.apache.openmeetings.OpenmeetingsVariables;
+import org.apache.openmeetings.data.chat.ChatDao;
+import org.apache.openmeetings.data.user.dao.UsersDao;
+import org.apache.openmeetings.persistence.beans.chat.ChatMessage;
+import org.apache.openmeetings.web.app.Application;
+import org.apache.openmeetings.web.app.WebSession;
 import org.apache.openmeetings.web.components.UserPanel;
+import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
+import org.apache.wicket.ajax.json.JSONException;
+import org.apache.wicket.ajax.json.JSONObject;
+import org.apache.wicket.behavior.Behavior;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.form.Button;
 import org.apache.wicket.markup.html.form.Form;
@@ -38,11 +51,40 @@ public class ChatPanel extends UserPanel
 	private static final long serialVersionUID = -9144707674886211557L;
 	private String message;
 	
+	private JSONObject getMessage(ChatMessage m) throws JSONException {
+		return new JSONObject()
+			.put("type", "chat")
+			.put("msg", new JSONObject()
+				.put("id", m.getId())
+				.put("message", m.getMessage())
+			);
+	}
+
 	public ChatPanel(String id) {
 		super(id);
 		setOutputMarkupId(true);
 		setMarkupId(id);
-		
+
+		add(new Behavior() {
+			private static final long serialVersionUID = -2205036360048419129L;
+
+			@Override
+			public void renderHead(Component component, IHeaderResponse response) {
+				ChatDao dao = Application.getBean(ChatDao.class);
+				try {				
+					StringBuilder sb = new StringBuilder();
+					for (ChatMessage m : dao.get(0, Integer.MAX_VALUE)) {
+						sb.append("addChatMessage(").append(getMessage(m).toString()).append(");");
+					}
+					if (sb.length() > 0) {
+						response.render(OnDomReadyHeaderItem.forScript(sb.toString()));
+					}
+				} catch (JSONException e) {
+					
+				}
+				super.renderHead(component, response);
+			}
+		});
 		add(new WebMarkupContainer("messages").setMarkupId("messageArea"));
 		final Form<Void> f = new Form<Void>("sendForm");
 		f.add(new TextArea<String>("message", new PropertyModel<String>(ChatPanel.this,
"message")).setOutputMarkupId(true));
@@ -50,11 +92,16 @@ public class ChatPanel extends UserPanel
 			private static final long serialVersionUID = -3746739738826501331L;
 			
 			protected void onSubmit(AjaxRequestTarget target) {
-				//Application.getBean(ChatService) sendMessageToOverallChat
+				ChatDao dao = Application.getBean(ChatDao.class);
+				ChatMessage m = new ChatMessage();
+				m.setMessage(message);
+				m.setSent(new Date());
+				m.setFromUser(Application.getBean(UsersDao.class).get(WebSession.getUserId()));
+				dao.update(m);
 				IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();
 				for (IWebSocketConnection c : reg.getConnections(getApplication())) {
 					try {
-						c.sendMessage(message);
+						c.sendMessage(getMessage(m).toString());
 					} catch(Exception e) {
 						log.error("Error while sending message", e);
 					}



Mime
View raw message