Author: solomax
Date: Sat Apr 28 09:56:27 2012
New Revision: 1331735
URL: http://svn.apache.org/viewvc?rev=1331735&view=rev
Log:
OPENMEETINGS-245 implemented
Modified:
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
Modified:
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java?rev=1331735&r1=1331734&r2=1331735&view=diff
==============================================================================
---
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java
(original)
+++
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java
Sat Apr 28 09:56:27 2012
@@ -45,6 +45,7 @@ import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.openmeetings.app.OpenmeetingsVariables;
import org.openmeetings.app.data.basic.AuthLevelmanagement;
+import org.openmeetings.app.data.basic.Configurationmanagement;
import org.openmeetings.app.data.basic.Sessionmanagement;
import org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl;
import org.openmeetings.app.data.calendar.daos.AppointmentDaoImpl;
@@ -61,6 +62,7 @@ import org.openmeetings.app.data.user.da
import org.openmeetings.app.data.user.dao.PrivateMessagesDaoImpl;
import org.openmeetings.app.data.user.dao.UserContactsDaoImpl;
import org.openmeetings.app.data.user.dao.UsersDaoImpl;
+import org.openmeetings.app.persistence.beans.basic.Configuration;
import org.openmeetings.app.persistence.beans.basic.LdapConfig;
import org.openmeetings.app.persistence.beans.calendar.Appointment;
import org.openmeetings.app.persistence.beans.calendar.MeetingMember;
@@ -92,6 +94,12 @@ public class BackupExport {
private static final Logger log = Red5LoggerFactory.getLogger(
BackupExport.class,
OpenmeetingsVariables.webAppRootKey);
+ private static final String BACKUP_COMMENT =
+ "###############################################\n"
+ + "This File is auto-generated by the Backup Tool \n"
+ + "you should use the BackupPanel to modify or change
this file \n"
+ + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
+ + "###############################################";
@Autowired
private AppointmentDaoImpl appointmentDao;
@@ -127,6 +135,8 @@ public class BackupExport {
private AuthLevelmanagement authLevelManagement;
@Autowired
private PollManagement pollManagement;
+ @Autowired
+ private Configurationmanagement cfgManagement;
public void performExport(String filePath, File backup_dir,
boolean includeFiles, String omFilesDir) throws
Exception {
@@ -349,6 +359,17 @@ public class BackupExport {
this.serializetoXML(fos, "UTF-8", doc);
}
+ /*
+ * ##################### Config
+ */
+ List<Configuration> configs =
cfgManagement.getConfigurations(0, Integer.MAX_VALUE, "conf_key", true);
+ if (configs != null) {
+ Document doc = createConfigDocument(configs);
+ File aListXML = new File(backup_dir, "configs.xml");
+ FileOutputStream fos = new FileOutputStream(aListXML);
+ this.serializetoXML(fos, "UTF-8", doc);
+ }
+
if (includeFiles) {
/*
* ##################### Backup Room Files
@@ -507,13 +528,7 @@ public class BackupExport {
private Document createRoomPollDocument(List<RoomPoll> roomPollList) {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -635,21 +650,11 @@ public class BackupExport {
FileOutputStream fos) {
try {
- // FileOutputStream fos = new
- // FileOutputStream(directoryToZip.getName() + ".zip");
ZipOutputStream zos = new ZipOutputStream(fos);
for (File file : fileList) {
if (!file.isDirectory()) { // we only zip
files, not directories
addToZip(directoryToZip, file, zos);
- } else {
- // String zipFilePath =
- //
file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length()
- // + 1,
- // file.getCanonicalPath().length());
- // //log.debug("Writing '" +
zipFilePath + "' to zip file");
- // ZipEntry zipEntry = new
ZipEntry(zipFilePath);
- // zos.putNextEntry(zipEntry);
}
}
@@ -719,13 +724,7 @@ public class BackupExport {
public Document createAppointementDocument(List<Appointment> aList)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -785,46 +784,13 @@ public class BackupExport {
appointment.addElement("isPasswordProtected").addCDATA(
"" + a.getIsPasswordProtected());
appointment.addElement("password").addCDATA("" +
a.getPassword());
-
- // Separated XML File
-
- // Element meetingMembers =
- // appointment.addElement("meetingMembers");
- // //List<String> organisations = new LinkedList();
- // for (Iterator<MeetingMember> iterObj =
- // a.getMeetingMember().iterator();iterObj.hasNext(); )
{
- // MeetingMember m = iterObj.next();
- // Element meetingMember =
- // meetingMembers.addElement("meetingMember");
- //
meetingMember.addElement("meetingMemberId").addCDATA(""+m.getMeetingMemberId());
- // if (m.getUserid() != null) {
- //
meetingMember.addElement("userid").addCDATA(""+m.getUserid().getUser_id());
- // } else {
- // meetingMember.addElement("userid").addCDATA("null");
- // }
- //
meetingMember.addElement("firstname").addCDATA(""+m.getFirstname());
- //
meetingMember.addElement("lastname").addCDATA(""+m.getLastname());
- //
meetingMember.addElement("memberStatus").addCDATA(""+m.getMemberStatus());
- //
meetingMember.addElement("appointmentStatus").addCDATA(""+m.getAppointmentStatus());
- //
meetingMember.addElement("email").addCDATA(""+m.getEmail());
- //
meetingMember.addElement("deleted").addCDATA(""+m.getDeleted());
- //
meetingMember.addElement("comment").addCDATA(""+m.getComment());
- //
meetingMember.addElement("invitor").addCDATA(""+m.getInvitor());
- // }
-
}
return document;
}
public Document createRoomsDocument(List<Rooms> roomList) throws
Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -965,13 +931,7 @@ public class BackupExport {
public Document createOrgDocument(List<Organisation> orgList)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1003,13 +963,7 @@ public class BackupExport {
private Document createPrivateMessagesDocument(
List<PrivateMessages> privateMessages) throws Exception
{
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1081,13 +1035,7 @@ public class BackupExport {
private Document createFileExplorerItemDocument(
List<FileExplorerItem> fileExplorerItems) throws
Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1161,13 +1109,7 @@ public class BackupExport {
private Document createFlvRecordingDocument(List<FlvRecording>
flvRecordings)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1301,13 +1243,7 @@ public class BackupExport {
private Document createPrivateMessageFolderDocument(
List<PrivateMessageFolder> privateMessageFolders)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1335,13 +1271,7 @@ public class BackupExport {
private Document createUserContactsDocument(List<UserContacts>
userContacts)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1380,13 +1310,7 @@ public class BackupExport {
private Document createOrgRoomsDocument(List<Rooms_Organisation>
roomOrgList)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1421,13 +1345,7 @@ public class BackupExport {
private Document createMeetingMemberDocument(List<MeetingMember>
memberList)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1476,13 +1394,7 @@ public class BackupExport {
private Document createLdapConfigDocument(List<LdapConfig>
ldapConfigList)
throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1511,13 +1423,7 @@ public class BackupExport {
}
public Document createDocument(List<Users> uList) throws Exception {
- Document document = DocumentHelper.createDocument();
- document.setXMLEncoding("UTF-8");
-
document.addComment("###############################################\n"
- + "This File is auto-generated by the Backup
Tool \n"
- + "you should use the BackupPanel to modify or
change this file \n"
- + "see
http://incubator.apache.org/openmeetings/Upgrade.html for Details \n"
- +
"###############################################");
+ Document document = getDocument();
Element root = document.addElement("root");
@@ -1753,6 +1659,33 @@ public class BackupExport {
return document;
}
+ private Document getDocument() {
+ Document document = DocumentHelper.createDocument();
+ document.setXMLEncoding("UTF-8");
+ document.addComment(BACKUP_COMMENT);
+
+ return document;
+ }
+
+ private Document createConfigDocument(List<Configuration> configs) {
+ Document document = getDocument();
+ Element root = document.addElement("root");
+ Element configsElem = root.addElement("configs");
+
+ for (Configuration cfg : configs) {
+ Element cfgElem = configsElem.addElement("config");
+ cfgElem.addElement("id").addCDATA(formatString("" +
cfg.getConfiguration_id()));
+ cfgElem.addElement("comment").addCDATA(formatString(""
+ cfg.getComment()));
+
cfgElem.addElement("key").addCDATA(formatString(cfg.getConf_key()));
+
cfgElem.addElement("value").addCDATA(formatString(cfg.getConf_value()));
+
cfgElem.addElement("deleted").addCDATA(formatString(cfg.getDeleted()));
+
cfgElem.addElement("created").addCDATA(formatString(CalendarPatterns.getExportDate(cfg.getStarttime())));
+
cfgElem.addElement("updated").addCDATA(formatString(CalendarPatterns.getExportDate(cfg.getUpdatetime())));
+ cfgElem.addElement("user_id").addCDATA(formatString(""
+ cfg.getUser_id()));
+ }
+ return document;
+ }
+
public void serializetoXML(OutputStream out, String aEncodingScheme,
Document doc) throws Exception {
OutputFormat outformat = OutputFormat.createPrettyPrint();
Modified:
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
URL:
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1331735&r1=1331734&r2=1331735&view=diff
==============================================================================
---
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
(original)
+++
incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
Sat Apr 28 09:56:27 2012
@@ -43,6 +43,7 @@ import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.openmeetings.app.OpenmeetingsVariables;
+import org.openmeetings.app.data.basic.Configurationmanagement;
import org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl;
import org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl;
import org.openmeetings.app.data.calendar.daos.AppointmentCategoryDaoImpl;
@@ -136,6 +137,8 @@ public class BackupImportController exte
private ScopeApplicationAdapter scopeApplicationAdapter;
@Autowired
private PollManagement pollManagement;
+ @Autowired
+ private Configurationmanagement cfgManagement;
private final HashMap<Long, Long> usersMap = new HashMap<Long, Long>();
private final HashMap<Long, Long> organisationsMap = new HashMap<Long,
Long>();
@@ -386,7 +389,7 @@ public class BackupImportController exte
log.info("File explorer item import complete, starting file
poll import");
/*
- * ##################### Import File-Explorer Items
+ * ##################### Import Room Polls
*/
File roomPollListFile = new File(f, "roompolls.xml");
if (!roomPollListFile.exists()) {
@@ -394,8 +397,18 @@ public class BackupImportController exte
} else {
this.importRoomPolls(roomPollListFile);
}
+ log.info("Poll import complete, starting configs import");
- log.info("Poll import complete, starting copy of files and
folders");
+ /*
+ * ##################### Import Configs
+ */
+ File configsFile = new File(f, "configs.xml");
+ if (!configsFile.exists()) {
+ log.debug("configsFile missing");
+ } else {
+ importConfigs(configsFile);
+ }
+ log.info("Configs import complete, starting copy of files and
folders");
/*
* ##################### Import real files and folders
@@ -456,7 +469,35 @@ public class BackupImportController exte
}
}
+
+ private void importConfigs(File configsFile) throws Exception {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(configsFile);
+ Element root = document.getRootElement();
+ Element configs = root.element("configs");
+ for (@SuppressWarnings("unchecked")
+ Iterator<Element> iter =
configs.elementIterator("config"); iter.hasNext();) {
+
+ Element cfgElem = iter.next();
+ String key = cfgElem.elementText("key");
+ try {
+ Configuration cfg =
cfgManagement.getConfKey(3L, key);
+ if (cfg == null) {
+ cfg = new Configuration();
+ cfg.setConf_key(key);
+ }
+ cfg.setConf_value(cfgElem.elementText("value"));
+ cfg.setUpdatetime(new Date());
+ cfg.setDeleted(cfgElem.elementText("deleted"));
+ cfg.setComment(cfgElem.elementText("comment"));
+ cfgManagement.updateConfig(cfg);
+ } catch (Exception e) {
+ log.debug("failed to add/update configuration:
" + key, e);
+ }
+ }
+ }
+
@SuppressWarnings("unchecked")
private List<RoomPoll> getRoomPolls(File roomPollListFile) throws
Exception {