Commit 3bb95cb6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added #creationDate and #modificationDate to MUCRoom.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@453 b35dd754-fafc-0310-a699-88a17e54d16e
parent b0afaa1e
......@@ -13,6 +13,7 @@ package org.jivesoftware.messenger.muc;
import java.util.Iterator;
import java.util.List;
import java.util.Date;
import org.jivesoftware.messenger.muc.spi.IQAdminHandler;
import org.jivesoftware.messenger.muc.spi.IQOwnerHandler;
......@@ -59,6 +60,36 @@ public interface MUCRoom extends ChatDeliverer {
*/
void setID(long roomID);
/**
* Returns the date when the room was created.
*
* @return the date when the room was created.
*/
Date getCreationDate();
/**
* Sets the date when the room was created.
*
* @param creationDate the date when the room was created.
*/
void setCreationDate(Date creationDate);
/**
* Returns the last date when the room's configuration was modified. If the room's configuration
* was never modified then the creation date will be returned.
*
* @return the last date when the room's configuration was modified.
*/
Date getModificationDate();
/**
* Sets the last date when the room's configuration was modified. If the room's configuration
* was never modified then the initial value will be the same as the creation date.
*
* @param modificationDate the last date when the room's configuration was modified.
*/
void setModificationDate(Date modificationDate);
/**
* Obtain the role of the chat server (mainly for addressing messages and presence).
*
......
......@@ -456,6 +456,10 @@ public class IQOwnerHandler {
room.setLogEnabled(("1".equals(booleanValue) ? true : false));
}
// Update the modification date to reflect the last time when the room's configuration
// was modified
room.setModificationDate(new Date());
if (room.isPersistent()) {
room.saveToDB();
}
......
......@@ -41,16 +41,16 @@ import org.jivesoftware.util.StringUtils;
public class MUCPersistenceManager {
private static final String LOAD_ROOM_SURROGATES =
"SELECT roomID, name, naturalName, description, canChangeSubject, maxUsers, " +
"moderated, invitationRequired, canInvite, " +
"SELECT roomID, creationDate, modificationDate, name, naturalName, description, " +
"canChangeSubject, maxUsers, moderated, invitationRequired, canInvite, " +
"password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE inMemory=0 and publicRoom=1";
private static final String GET_RESERVED_NAME =
"SELECT nickname FROM mucMember WHERE roomID=? AND jid=?";
private static final String LOAD_ROOM =
"SELECT roomID, naturalName, description, canChangeSubject, maxUsers, " +
"publicRoom, moderated, invitationRequired, canInvite, password, " +
"canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"SELECT roomID, creationDate, modificationDate, naturalName, description, " +
"canChangeSubject, maxUsers, publicRoom, moderated, invitationRequired, canInvite, " +
"password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE name=?";
private static final String LOAD_AFFILIATIONS =
"SELECT jid,affiliation FROM mucAffiliation WHERE roomID=?";
......@@ -106,21 +106,23 @@ public class MUCPersistenceManager {
ResultSet rs = pstmt.executeQuery();
MUCPersistentRoomSurrogate room = null;
while (rs.next()) {
room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(2), packetRouter);
room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(4), packetRouter);
room.setID(rs.getLong(1));
room.setNaturalLanguageName(rs.getString(3));
room.setDescription(rs.getString(4));
room.setCanOccupantsChangeSubject(rs.getInt(5) == 1 ? true : false);
room.setMaxUsers(rs.getInt(6));
room.setModerated(rs.getInt(7) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false);
room.setPassword(rs.getString(10));
room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false);
room.setLogEnabled(rs.getInt(12) == 1 ? true : false);
room.setSubject(rs.getString(13));
room.setCreationDate(new Date(Long.parseLong(rs.getString(2).trim()))); // creation date
room.setModificationDate(new Date(Long.parseLong(rs.getString(3).trim()))); // modification date
room.setNaturalLanguageName(rs.getString(5));
room.setDescription(rs.getString(6));
room.setCanOccupantsChangeSubject(rs.getInt(7) == 1 ? true : false);
room.setMaxUsers(rs.getInt(8));
room.setModerated(rs.getInt(9) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(10) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(11) == 1 ? true : false);
room.setPassword(rs.getString(12));
room.setCanAnyoneDiscoverJID(rs.getInt(13) == 1 ? true : false);
room.setLogEnabled(rs.getInt(14) == 1 ? true : false);
room.setSubject(rs.getString(15));
List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(14));
String roles = Integer.toBinaryString(rs.getInt(16));
if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator");
}
......@@ -200,20 +202,22 @@ public class MUCPersistenceManager {
throw new IllegalArgumentException("Room " + room.getName() + " was not found in the database.");
}
room.setID(rs.getLong(1));
room.setNaturalLanguageName(rs.getString(2));
room.setDescription(rs.getString(3));
room.setCanOccupantsChangeSubject(rs.getInt(4) == 1 ? true : false);
room.setMaxUsers(rs.getInt(5));
room.setPublicRoom(rs.getInt(6) == 1 ? true : false);
room.setModerated(rs.getInt(7) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false);
room.setPassword(rs.getString(10));
room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false);
room.setLogEnabled(rs.getInt(12) == 1 ? true : false);
room.setSubject(rs.getString(13));
room.setCreationDate(new Date(Long.parseLong(rs.getString(2).trim()))); // creation date
room.setModificationDate(new Date(Long.parseLong(rs.getString(3).trim()))); // modification date
room.setNaturalLanguageName(rs.getString(4));
room.setDescription(rs.getString(5));
room.setCanOccupantsChangeSubject(rs.getInt(6) == 1 ? true : false);
room.setMaxUsers(rs.getInt(7));
room.setPublicRoom(rs.getInt(8) == 1 ? true : false);
room.setModerated(rs.getInt(9) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(10) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(11) == 1 ? true : false);
room.setPassword(rs.getString(12));
room.setCanAnyoneDiscoverJID(rs.getInt(13) == 1 ? true : false);
room.setLogEnabled(rs.getInt(14) == 1 ? true : false);
room.setSubject(rs.getString(15));
List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(14));
String roles = Integer.toBinaryString(rs.getInt(16));
if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator");
}
......@@ -287,15 +291,13 @@ public class MUCPersistenceManager {
* @param room The room to save its configuration.
*/
public static void saveToDB(MUCRoom room) {
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
if (room.wasSavedToDB()) {
pstmt = con.prepareStatement(UPDATE_ROOM);
pstmt.setString(1, StringUtils.dateToMillis(nowDate));
pstmt.setString(1, StringUtils.dateToMillis(room.getModificationDate()));
pstmt.setString(2, room.getNaturalLanguageName());
pstmt.setString(3, room.getDescription());
pstmt.setInt(4, (room.canOccupantsChangeSubject() ? 1 : 0));
......@@ -315,8 +317,8 @@ public class MUCPersistenceManager {
else {
pstmt = con.prepareStatement(ADD_ROOM);
pstmt.setLong(1, room.getID());
pstmt.setString(2, StringUtils.dateToMillis(nowDate));
pstmt.setString(3, StringUtils.dateToMillis(nowDate));
pstmt.setString(2, StringUtils.dateToMillis(room.getCreationDate()));
pstmt.setString(3, StringUtils.dateToMillis(room.getModificationDate()));
pstmt.setString(4, room.getName());
pstmt.setString(5, room.getNaturalLanguageName());
pstmt.setString(6, room.getDescription());
......@@ -331,7 +333,7 @@ public class MUCPersistenceManager {
pstmt.setInt(15, (room.isLogEnabled() ? 1 : 0));
pstmt.setString(16, room.getSubject());
pstmt.setInt(17, marshallRolesToBroadcast(room));
pstmt.setString(18, StringUtils.dateToMillis(nowDate));
pstmt.setString(18, StringUtils.dateToMillis(new Date()));
pstmt.setInt(19, 1); // the room starts always "in memory"
pstmt.executeUpdate();
}
......@@ -400,14 +402,12 @@ public class MUCPersistenceManager {
return;
}
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_IN_MEMORY);
pstmt.setString(1, StringUtils.dateToMillis(nowDate));
pstmt.setString(1, StringUtils.dateToMillis(new Date()));
pstmt.setBoolean(2, inMemory);
pstmt.setLong(3, room.getID());
pstmt.executeUpdate();
......@@ -429,14 +429,12 @@ public class MUCPersistenceManager {
* the service is starting up (again).
*/
public static void resetRoomInMemory() {
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(RESET_IN_MEMORY);
pstmt.setString(1, StringUtils.dateToMillis(nowDate));
pstmt.setString(1, StringUtils.dateToMillis(new Date()));
pstmt.executeUpdate();
}
catch (SQLException sqle) {
......
......@@ -11,10 +11,7 @@
package org.jivesoftware.messenger.muc.spi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import org.jivesoftware.messenger.muc.*;
import org.jivesoftware.util.NotFoundException;
......@@ -141,6 +138,16 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
*/
private long roomID = -1;
/**
* The date when the room was created.
*/
private Date creationDate;
/**
* The last date when the room's configuration was modified.
*/
private Date modificationDate;
/**
* Create a new chat room.
*
......@@ -168,6 +175,22 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
this.roomID = roomID;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
public MUCRole getRole() throws UnauthorizedException {
return role;
}
......
......@@ -236,6 +236,16 @@ public class MUCRoomImpl implements MUCRoom {
*/
private long roomID = -1;
/**
* The date when the room was created.
*/
private Date creationDate;
/**
* The last date when the room's configuration was modified.
*/
private Date modificationDate;
/**
* Indicates if the room is present in the database.
*/
......@@ -255,6 +265,8 @@ public class MUCRoomImpl implements MUCRoom {
this.description = roomname;
this.router = packetRouter;
this.startTime = System.currentTimeMillis();
this.creationDate = new Date(startTime);
this.modificationDate = new Date(startTime);
// TODO Allow to set the history strategy from the configuration form?
roomHistory = new MUCRoomHistory(this, new HistoryStrategy(server.getHistoryStrategy()));
role = new RoomRole(this);
......@@ -297,6 +309,22 @@ public class MUCRoomImpl implements MUCRoom {
this.roomID = roomID;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
public MUCRole getRole() {
return role;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment