List of usage examples for org.apache.commons.transaction.util FileHelper copy
public static long copy(InputStream in, OutputStream out) throws IOException
InputStream
to an OutputStream
using a local internal buffer for performance. From source file:com.bhbsoft.videoconference.record.convert.util.FlvFileHelper.java
public static void copyFile(String sourceFile, String targetFile) throws IOException { FileHelper.copy(new File(sourceFile), new File(targetFile)); }
From source file:com.bhbsoft.videoconference.record.convert.util.FlvFileHelper.java
public static void copyFile(File f1, OutputStream out) throws IOException { InputStream in = null;/*from w w w .ja v a 2 s . co m*/ try { in = new FileInputStream(f1); FileHelper.copy(in, out); log.debug("File copied."); } catch (Exception e) { log.error("[copyfile(File, File)]", e); } finally { if (in != null) { in.close(); } } }
From source file:org.apache.openmeetings.backup.BackupImport.java
private static File unzip(InputStream is) throws IOException { File f = OmFileHelper.getNewDir(OmFileHelper.getUploadImportDir(), "import_" + CalendarPatterns.getTimeForStreamId(new Date())); log.debug("##### EXTRACTING BACKUP TO: " + f); try (ZipInputStream zis = new ZipInputStream(is)) { ZipEntry zipentry = null; while ((zipentry = zis.getNextEntry()) != null) { // for each entry to be extracted File fentry = validate(zipentry.getName(), f); File dir = zipentry.isDirectory() ? fentry : fentry.getParentFile(); if (!dir.exists()) { if (!dir.mkdirs()) { log.warn("Failed to create folders: " + dir); }/* w ww . j a v a 2 s . c o m*/ } if (!fentry.isDirectory()) { FileHelper.copy(zis, fentry); zis.closeEntry(); } } } return f; }
From source file:org.apache.openmeetings.converter.GenerateImage.java
public ConverterProcessResultList convertImageUserProfile(File file, Long users_id, boolean skipConvertion) throws Exception { ConverterProcessResultList returnMap = new ConverterProcessResultList(); // User Profile Update for (File f : getUploadProfilesUserDir(users_id).listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(JPG_EXTENTION); }//from w w w. java 2 s . co m })) { FileHelper.removeRec(f); } File destinationFile = OmFileHelper.getNewFile(getUploadProfilesUserDir(users_id), profileFileName, JPG_EXTENTION); if (!skipConvertion) { returnMap.addItem("processJPG", convertSingleJpg(file.getCanonicalPath(), destinationFile)); } else { FileHelper.copy(file, destinationFile); } returnMap.addItem("processThumb1", generateThumbs.generateThumb(chatImagePrefix, destinationFile, 40)); returnMap.addItem("processThumb2", generateThumbs.generateThumb(profileImagePrefix, destinationFile, 126)); returnMap.addItem("processThumb3", generateThumbs.generateThumb(bigImagePrefix, destinationFile, 240)); if (!skipConvertion) { // Delete old one file.delete(); } String pictureuri = destinationFile.getName(); User us = usersDao.get(users_id); us.setUpdatetime(new java.util.Date()); us.setPictureuri(pictureuri); usersDao.update(us, users_id); //FIXME: After uploading a new picture all other clients should refresh //scopeApplicationAdapter.updateUserSessionObject(users_id, pictureuri); return returnMap; }
From source file:org.apache.openmeetings.core.converter.GenerateImage.java
public ConverterProcessResultList convertImageUserProfile(File file, Long userId, boolean skipConvertion) throws Exception { ConverterProcessResultList returnMap = new ConverterProcessResultList(); // User Profile Update File[] files = getUploadProfilesUserDir(userId).listFiles(new FileFilter() { @Override/* w w w .jav a2 s . com*/ public boolean accept(File pathname) { return pathname.getName().endsWith(JPG_EXTENSION); } }); if (files != null) { for (File f : files) { FileHelper.removeRec(f); } } File destinationFile = OmFileHelper.getNewFile(getUploadProfilesUserDir(userId), profileFileName, JPG_EXTENSION); if (!skipConvertion) { returnMap.addItem("processJPG", convertSingleJpg(file.getCanonicalPath(), destinationFile)); } else { FileHelper.copy(file, destinationFile); } returnMap.addItem("processThumb1", generateThumbs.generateThumb(chatImagePrefix, destinationFile, 40)); returnMap.addItem("processThumb2", generateThumbs.generateThumb(profileImagePrefix, destinationFile, 126)); returnMap.addItem("processThumb3", generateThumbs.generateThumb(bigImagePrefix, destinationFile, 240)); if (!skipConvertion) { // Delete old one file.delete(); } String pictureuri = destinationFile.getName(); User us = userDao.get(userId); us.setUpdated(new java.util.Date()); us.setPictureuri(pictureuri); userDao.update(us, userId); //FIXME: After uploading a new picture all other clients should refresh //scopeApplicationAdapter.updateUserSessionObject(userId, pictureuri); return returnMap; }
From source file:org.apache.openmeetings.core.data.file.FileProcessor.java
public ConverterProcessResultList processFile(Long userId, FileExplorerItem f, InputStream is) throws Exception { ConverterProcessResultList returnError = new ConverterProcessResultList(); // Generate a random string to prevent any problems with // foreign characters and duplicates String hash = UUID.randomUUID().toString(); String ext = getExt(f);//w w w. ja v a2s . c o m String extDot = String.format(".%s", ext); log.debug("file extension: " + ext); StoredFile storedFile = new StoredFile(hash, ext); // Check variable to see if this file is a presentation // check if this is a a file that can be converted by // openoffice-service boolean canBeConverted = storedFile.isConvertable(); boolean isPdf = storedFile.isPdf(); boolean isImage = storedFile.isImage(); boolean isChart = storedFile.isChart(); boolean isAsIs = storedFile.isAsIs(); boolean isVideo = storedFile.isVideo(); log.debug("isAsIs: " + isAsIs); // add outputfolders for profiles // if it is a presenation it will be copied to another place if (!(canBeConverted || isPdf || isImage || isVideo || isAsIs)) { returnError.addItem("wrongType", new ConverterProcessResult("The file type cannot be converted")); return returnError; } File completeName = new File(isAsIs ? getUploadFilesDir() : getUploadTempFilesDir(), hash + extDot); log.debug("writing file to: " + completeName); FileHelper.copy(is, completeName); is.close(); if (isImage) { f.setType(Type.Image); } else if (isVideo) { f.setType(Type.Video); } else if (isChart) { f.setType(Type.PollChart); } else if (isPdf || canBeConverted) { f.setType(Type.Presentation); } f.setHash(hash); f = fileDao.update(f); log.debug("fileId: " + f.getId()); log.debug("canBeConverted: " + canBeConverted); if (canBeConverted) { // convert to pdf, thumbs, swf and xml-description returnError = generatePDF.convertPDF(hash, "files", true, completeName); } else if (isPdf) { // convert to thumbs, swf and xml-description returnError = generatePDF.convertPDF(hash, "files", false, completeName); } else if (isChart) { log.debug("uploaded chart file"); } else if (isImage && !isAsIs) { // convert it to JPG log.debug("##### convert it to JPG: "); returnError = generateImage.convertImage(hash, extDot, "files"); } else if (isAsIs) { ConverterProcessResult processThumb = generateThumbs.generateThumb(thumbImagePrefix, completeName, 50); returnError.addItem("processThumb", processThumb); } else if (isVideo) { List<ConverterProcessResult> returnList = flvExplorerConverter.startConversion(f.getId(), completeName.getCanonicalPath()); int i = 0; for (ConverterProcessResult returnMap : returnList) { returnError.addItem("processFLV " + i, returnMap); } } // has to happen at the end, otherwise it will be overwritten //cause the variable is new initialized returnError.setCompleteName(completeName.getName()); returnError.setFileExplorerItemId(f.getId()); return returnError; }
From source file:org.apache.openmeetings.core.remote.ConferenceLibrary.java
/** * @param SID/*from w w w .java 2s. co m*/ * @param fileId * @return 1 in case of success, -1 otherwise */ public Long copyFileToCurrentRoom(String SID, Long fileId) { try { Long users_id = sessionDao.check(SID); if (AuthLevelUtil.hasUserLevel(userDao.getRights(users_id))) { IConnection current = Red5.getConnectionLocal(); String streamid = current.getClient().getId(); Client currentClient = sessionManager.getClientByStreamId(streamid, null); Long roomId = currentClient.getRoomId(); if (roomId != null) { File outputFullFlvFile = new File(OmFileHelper.getStreamsHibernateDir(), WB_VIDEO_FILE_PREFIX + fileId + MP4_EXTENSION); File targetFolder = OmFileHelper.getStreamsSubDir(roomId); File targetFullFlvFile = new File(targetFolder, WB_VIDEO_FILE_PREFIX + fileId + MP4_EXTENSION); if (outputFullFlvFile.exists() && !targetFullFlvFile.exists()) { FileHelper.copy(outputFullFlvFile, targetFullFlvFile); } return 1L; } } } catch (Exception err) { log.error("[copyFileToCurrentRoom] ", err); } return -1L; }
From source file:org.apache.openmeetings.data.file.FileProcessor.java
public ConverterProcessResultList processFile(Long userId, Long room_id, boolean isOwner, InputStream is, Long parentFolderId, String fileSystemName, Long externalFileId, String externalType) throws Exception { ConverterProcessResultList returnError = new ConverterProcessResultList(); int dotidx = fileSystemName.lastIndexOf('.'); // Generate a random string to prevent any problems with // foreign characters and duplicates Date d = new Date(); String newFileSystemName = MD5.do_checksum("FILE_" + d.getTime()); String newFileExtDot = fileSystemName.substring(dotidx, fileSystemName.length()).toLowerCase(); String newFileExt = newFileExtDot.substring(1); log.debug("newFileExt: " + newFileExt); StoredFile storedFile = new StoredFile(newFileSystemName, newFileExt); // Check variable to see if this file is a presentation // check if this is a a file that can be converted by // openoffice-service boolean canBeConverted = storedFile.isConvertable(); boolean isPdf = storedFile.isPdf(); boolean isImage = storedFile.isImage(); boolean isChart = storedFile.isChart(); boolean isAsIs = storedFile.isAsIs(); boolean isVideo = storedFile.isVideo(); log.debug("isAsIs: " + isAsIs); // add outputfolders for profiles // if it is a presenation it will be copied to another place if (!(canBeConverted || isPdf || isImage || isVideo || isAsIs)) { returnError.addItem("wrongType", new ConverterProcessResult("The file type cannot be converted")); return returnError; }/* w w w.j a v a2 s. c o m*/ File completeName = new File( isAsIs ? OmFileHelper.getUploadFilesDir() : OmFileHelper.getUploadTempFilesDir(), newFileSystemName + newFileExtDot); log.debug("writing file to: " + completeName); FileHelper.copy(is, completeName); is.close(); Long ownerId = null; if (parentFolderId == -2) { parentFolderId = 0L; ownerId = userId; } if (isOwner) { ownerId = userId; } String fileHashName = newFileSystemName + newFileExtDot; Boolean isPresentation = false; if (canBeConverted || isPdf) { // In case of a presentation the hash is a folder-name fileHashName = newFileSystemName; isPresentation = true; } if (isImage) { fileHashName = newFileSystemName + ".jpg"; } if (isVideo) { fileHashName = newFileSystemName + ".flv"; } FileExplorerItem fileExplorerItem = fileExplorerItemDao.getFileExplorerItemsById(parentFolderId); if (fileExplorerItem != null) { if (fileExplorerItem.getIsFolder() == null || !fileExplorerItem.getIsFolder()) { parentFolderId = 0L; } } Long fileExplorerItemId = fileExplorerItemDao.add(fileSystemName, fileHashName, // The Hashname of the file parentFolderId, ownerId, room_id, userId, false, // isFolder isImage, isPresentation, "", false, isChart, externalFileId, externalType); log.debug("fileExplorerItemId: " + fileExplorerItemId); log.debug("canBeConverted: " + canBeConverted); if (canBeConverted) { // convert to pdf, thumbs, swf and xml-description returnError = generatePDF.convertPDF(newFileSystemName, "files", true, completeName); } else if (isPdf) { // convert to thumbs, swf and xml-description returnError = generatePDF.convertPDF(newFileSystemName, "files", false, completeName); } else if (isChart) { log.debug("uploaded chart file"); } else if (isImage && !isAsIs) { // convert it to JPG log.debug("##### convert it to JPG: "); returnError = generateImage.convertImage(newFileSystemName, newFileExtDot, "files", newFileSystemName, false); } else if (isAsIs) { ConverterProcessResult processThumb = generateThumbs.generateThumb("_thumb_", completeName, 50); returnError.addItem("processThumb", processThumb); } else if (isVideo) { List<ConverterProcessResult> returnList = flvExplorerConverter.startConversion(fileExplorerItemId, completeName.getCanonicalPath()); int i = 0; for (ConverterProcessResult returnMap : returnList) { returnError.addItem("processFLV " + i, returnMap); } } // has to happen at the end, otherwise it will be overwritten //cause the variable is new initialized returnError.setCompleteName(completeName.getName()); returnError.setFileExplorerItemId(fileExplorerItemId); return returnError; }
From source file:org.apache.openmeetings.remote.ConferenceLibrary.java
/** * @param SID//w ww . j a v a 2s .c om * @param flvFileExplorerId * @return 1 in case of success, -1 otherwise */ public Long copyFileToCurrentRoom(String SID, Long flvFileExplorerId) { try { Long users_id = sessiondataDao.checkSession(SID); Long user_level = userManager.getUserLevelByID(users_id); if (authLevelUtil.checkUserLevel(user_level)) { IConnection current = Red5.getConnectionLocal(); String streamid = current.getClient().getId(); Client currentClient = this.sessionManager.getClientByStreamId(streamid, null); Long room_id = currentClient.getRoom_id(); if (room_id != null) { File outputFullFlvFile = new File(OmFileHelper.getStreamsHibernateDir(), "UPLOADFLV_" + flvFileExplorerId + ".flv"); File targetFolder = OmFileHelper.getStreamsSubDir(room_id); File targetFullFlvFile = new File(targetFolder, "UPLOADFLV_" + flvFileExplorerId + ".flv"); if (outputFullFlvFile.exists() && !targetFullFlvFile.exists()) { FileHelper.copy(outputFullFlvFile, targetFullFlvFile); } return 1L; } } } catch (Exception err) { log.error("[copyFileToCurrentRoom] ", err); } return -1L; }
From source file:org.apache.openmeetings.servlet.outputhandler.BackupImportController.java
public void performImport(InputStream is) throws Exception { File working_dir = OmFileHelper.getUploadImportDir(); if (!working_dir.exists()) { working_dir.mkdir();/* w w w. j av a 2s.c om*/ } File f = OmFileHelper.getNewDir(working_dir, "import_" + CalendarPatterns.getTimeForStreamId(new Date())); log.debug("##### WRITE FILE TO: " + f); ZipInputStream zipinputstream = new ZipInputStream(is); ZipEntry zipentry = zipinputstream.getNextEntry(); while (zipentry != null) { String fName = zipentry.getName(); if (File.pathSeparatorChar != '\\' && fName.indexOf('\\') > -1) { fName = fName.replace('\\', '/'); } // for each entry to be extracted File fentry = new File(f, fName); File dir = fentry.isDirectory() ? fentry : fentry.getParentFile(); dir.mkdirs(); if (fentry.isDirectory()) { zipentry = zipinputstream.getNextEntry(); continue; } FileHelper.copy(zipinputstream, fentry); zipinputstream.closeEntry(); zipentry = zipinputstream.getNextEntry(); } zipinputstream.close(); /* * ##################### Import Organizations */ Serializer simpleSerializer = new Persister(); { List<Organisation> list = readList(simpleSerializer, f, "organizations.xml", "organisations", Organisation.class); for (Organisation o : list) { long oldId = o.getOrganisation_id(); o.setOrganisation_id(null); Long newId = organisationManager.addOrganisationObj(o); organisationsMap.put(oldId, newId); } } log.info("Organizations import complete, starting user import"); /* * ##################### Import Users */ { List<User> list = readUserList(f, "users.xml", "users"); for (User u : list) { OmTimeZone tz = u.getOmTimeZone(); if (tz == null || tz.getJname() == null) { String jNameTimeZone = configurationDao.getConfValue("default.timezone", String.class, "Europe/Berlin"); OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone); u.setOmTimeZone(omTimeZone); u.setForceTimeZoneCheck(true); } else { u.setForceTimeZoneCheck(false); } u.setStarttime(new Date()); long userId = u.getUser_id(); u.setUser_id(null); if (u.getSipUser() != null && u.getSipUser().getId() != 0) { u.getSipUser().setId(0); } usersDao.update(u, -1L); usersMap.put(userId, u.getUser_id()); } } log.info("Users import complete, starting room import"); /* * ##################### Import Rooms */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions Serializer serializer = new Persister(strategy, matcher); matcher.bind(Long.class, LongTransform.class); matcher.bind(Integer.class, IntegerTransform.class); registry.bind(User.class, new UserConverter(usersDao, usersMap)); registry.bind(RoomType.class, new RoomTypeConverter(roomManager)); List<Room> list = readList(serializer, f, "rooms.xml", "rooms", Room.class); for (Room r : list) { Long roomId = r.getRooms_id(); // We need to reset ids as openJPA reject to store them otherwise r.setRooms_id(null); if (r.getModerators() != null) { for (Iterator<RoomModerator> i = r.getModerators().iterator(); i.hasNext();) { RoomModerator rm = i.next(); if (rm.getUser().getUser_id() == null) { i.remove(); } } } r = roomDao.update(r, null); roomsMap.put(roomId, r.getRooms_id()); } } log.info("Room import complete, starting room organizations import"); /* * ##################### Import Room Organisations */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(Organisation.class, new OrganisationConverter(orgDao, organisationsMap)); registry.bind(Room.class, new RoomConverter(roomDao, roomsMap)); List<RoomOrganisation> list = readList(serializer, f, "rooms_organisation.xml", "room_organisations", RoomOrganisation.class); for (RoomOrganisation ro : list) { if (!ro.getDeleted()) { // We need to reset this as openJPA reject to store them otherwise ro.setRooms_organisation_id(null); roomManager.addRoomOrganisation(ro); } } } log.info("Room organizations import complete, starting appointement import"); /* * ##################### Import Appointements */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(AppointmentCategory.class, new AppointmentCategoryConverter(appointmentCategoryDaoImpl)); registry.bind(User.class, new UserConverter(usersDao, usersMap)); registry.bind(AppointmentReminderTyps.class, new AppointmentReminderTypeConverter(appointmentReminderTypDaoImpl)); registry.bind(Room.class, new RoomConverter(roomDao, roomsMap)); registry.bind(Date.class, DateConverter.class); List<Appointment> list = readList(serializer, f, "appointements.xml", "appointments", Appointment.class); for (Appointment a : list) { Long appId = a.getAppointmentId(); // We need to reset this as openJPA reject to store them otherwise a.setAppointmentId(null); if (a.getUserId() != null && a.getUserId().getUser_id() == null) { a.setUserId(null); } Long newAppId = appointmentDao.addAppointmentObj(a); appointmentsMap.put(appId, newAppId); } } log.info("Appointement import complete, starting meeting members import"); /* * ##################### Import MeetingMembers * * Reminder Invitations will be NOT send! */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(User.class, new UserConverter(usersDao, usersMap)); registry.bind(Appointment.class, new AppointmentConverter(appointmentDao, appointmentsMap)); List<MeetingMember> list = readList(serializer, f, "meetingmembers.xml", "meetingmembers", MeetingMember.class); for (MeetingMember ma : list) { if (ma.getUserid() != null && ma.getUserid().getUser_id() == null) { ma.setUserid(null); } if (!ma.getDeleted()) { // We need to reset this as openJPA reject to store them otherwise ma.setMeetingMemberId(null); meetingMemberDao.addMeetingMemberByObject(ma); } } } log.info("Meeting members import complete, starting ldap config import"); /* * ##################### Import LDAP Configs */ { List<LdapConfig> list = readList(simpleSerializer, f, "ldapconfigs.xml", "ldapconfigs", LdapConfig.class, true); for (LdapConfig c : list) { ldapConfigDao.addLdapConfigByObject(c); } } log.info("Ldap config import complete, starting recordings import"); /* * ##################### Import Recordings */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions Serializer serializer = new Persister(strategy, matcher); matcher.bind(Long.class, LongTransform.class); matcher.bind(Integer.class, IntegerTransform.class); registry.bind(Date.class, DateConverter.class); List<FlvRecording> list = readList(serializer, f, "flvRecordings.xml", "flvrecordings", FlvRecording.class, true); for (FlvRecording fr : list) { fr.setFlvRecordingId(0); if (fr.getRoom_id() != null) { fr.setRoom_id(roomsMap.get(fr.getRoom_id())); } if (fr.getOwnerId() != null) { fr.setOwnerId(usersMap.get(fr.getOwnerId())); } if (fr.getFlvRecordingMetaData() != null) { for (FlvRecordingMetaData meta : fr.getFlvRecordingMetaData()) { meta.setFlvRecordingMetaDataId(0); meta.setFlvRecording(fr); } } flvRecordingDao.addFlvRecordingObj(fr); } } log.info("FLVrecording import complete, starting private message folder import"); /* * ##################### Import Private Message Folders */ { List<PrivateMessageFolder> list = readList(simpleSerializer, f, "privateMessageFolder.xml", "privatemessagefolders", PrivateMessageFolder.class, true); for (PrivateMessageFolder p : list) { Long folderId = p.getPrivateMessageFolderId(); PrivateMessageFolder storedFolder = privateMessageFolderDao.getPrivateMessageFolderById(folderId); if (storedFolder == null) { p.setPrivateMessageFolderId(0); Long newFolderId = privateMessageFolderDao.addPrivateMessageFolderObj(p); messageFoldersMap.put(folderId, newFolderId); } } } log.info("Private message folder import complete, starting user contacts import"); /* * ##################### Import User Contacts */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(User.class, new UserConverter(usersDao, usersMap)); List<UserContact> list = readList(serializer, f, "userContacts.xml", "usercontacts", UserContact.class, true); for (UserContact uc : list) { Long ucId = uc.getUserContactId(); UserContact storedUC = userContactsDao.getUserContacts(ucId); if (storedUC == null && uc.getContact() != null && uc.getContact().getUser_id() != null) { uc.setUserContactId(0); Long newId = userContactsDao.addUserContactObj(uc); userContactsMap.put(ucId, newId); } } } log.info("Usercontact import complete, starting private messages item import"); /* * ##################### Import Private Messages */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(User.class, new UserConverter(usersDao, usersMap)); registry.bind(Room.class, new RoomConverter(roomDao, roomsMap)); registry.bind(Date.class, DateConverter.class); List<PrivateMessage> list = readList(serializer, f, "privateMessages.xml", "privatemessages", PrivateMessage.class, true); for (PrivateMessage p : list) { p.setPrivateMessageId(0); p.setPrivateMessageFolderId(getNewId(p.getPrivateMessageFolderId(), Maps.MESSAGEFOLDERS)); p.setUserContactId(getNewId(p.getUserContactId(), Maps.USERCONTACTS)); if (p.getRoom() != null && p.getRoom().getRooms_id() == null) { p.setRoom(null); } if (p.getTo() != null && p.getTo().getUser_id() == null) { p.setTo(null); } if (p.getFrom() != null && p.getFrom().getUser_id() == null) { p.setFrom(null); } if (p.getOwner() != null && p.getOwner().getUser_id() == null) { p.setOwner(null); } privateMessagesDao.addPrivateMessageObj(p); } } log.info("Private message import complete, starting file explorer item import"); /* * ##################### Import File-Explorer Items */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions Serializer serializer = new Persister(strategy, matcher); matcher.bind(Long.class, LongTransform.class); matcher.bind(Integer.class, IntegerTransform.class); registry.bind(Date.class, DateConverter.class); List<FileExplorerItem> list = readList(serializer, f, "fileExplorerItems.xml", "fileExplorerItems", FileExplorerItem.class, true); for (FileExplorerItem file : list) { // We need to reset this as openJPA reject to store them otherwise file.setFileExplorerItemId(0); Long roomId = file.getRoom_id(); file.setRoom_id(roomsMap.containsKey(roomId) ? roomsMap.get(roomId) : null); fileExplorerItemDao.addFileExplorerItem(file); } } log.info("File explorer item import complete, starting file poll import"); /* * ##################### Import Room Polls */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); Serializer serializer = new Persister(strategy); registry.bind(User.class, new UserConverter(usersDao, usersMap)); registry.bind(Room.class, new RoomConverter(roomDao, roomsMap)); registry.bind(PollType.class, new PollTypeConverter(pollManager)); registry.bind(Date.class, DateConverter.class); List<RoomPoll> list = readList(serializer, f, "roompolls.xml", "roompolls", RoomPoll.class, true); for (RoomPoll rp : list) { pollManager.savePollBackup(rp); } } log.info("Poll import complete, starting configs import"); /* * ##################### Import Configs */ { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); RegistryMatcher matcher = new RegistryMatcher(); //TODO need to be removed in the later versions Serializer serializer = new Persister(strategy, matcher); matcher.bind(Long.class, LongTransform.class); registry.bind(Date.class, DateConverter.class); registry.bind(User.class, new UserConverter(usersDao, usersMap)); List<Configuration> list = readList(serializer, f, "configs.xml", "configs", Configuration.class, true); for (Configuration c : list) { Configuration cfg = configurationDao.get(c.getConf_key()); c.setConfiguration_id(cfg == null ? null : cfg.getConfiguration_id()); if (c.getUser() != null && c.getUser().getUser_id() == null) { c.setUser(null); } if ("crypt_ClassName".equals(c.getConf_key())) { try { Class.forName(c.getConf_value()); } catch (ClassNotFoundException e) { c.setConf_value(MD5Implementation.class.getCanonicalName()); } } configurationDao.update(c, -1L); } } log.info("Configs import complete, starting copy of files and folders"); /* * ##################### Import real files and folders */ importFolders(f); log.info("File explorer item import complete, clearing temp files"); FileHelper.removeRec(f); }