use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.
the class BackupImport method importFiles.
/*
* ##################### Import File-Explorer Items
*/
private List<FileItem> importFiles(File f) throws Exception {
log.info("Private message import complete, starting file explorer item import");
List<FileItem> result = new ArrayList<>();
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
RegistryMatcher matcher = new RegistryMatcher();
Serializer ser = new Persister(strategy, matcher);
matcher.bind(Long.class, LongTransform.class);
matcher.bind(Integer.class, IntegerTransform.class);
registry.bind(Date.class, DateConverter.class);
List<FileItem> list = readList(ser, f, "fileExplorerItems.xml", "fileExplorerItems", FileItem.class);
for (FileItem file : list) {
Long fId = file.getId();
// We need to reset this as openJPA reject to store them otherwise
file.setId(null);
Long roomId = file.getRoomId();
file.setRoomId(roomMap.containsKey(roomId) ? roomMap.get(roomId) : null);
if (file.getOwnerId() != null) {
file.setOwnerId(userMap.get(file.getOwnerId()));
}
if (file.getParentId() != null && file.getParentId().longValue() <= 0L) {
file.setParentId(null);
}
if (Strings.isEmpty(file.getHash())) {
file.setHash(UUID.randomUUID().toString());
}
file = fileItemDao.update(file);
result.add(file);
fileItemMap.put(fId, file.getId());
}
return result;
}
use of org.simpleframework.xml.strategy.Strategy in project syncany by syncany.
the class ConfigTO method save.
public void save(File file) throws ConfigException {
try {
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass()));
new Persister(strategy).write(this, file);
} catch (Exception e) {
throw new ConfigException("Cannot write config to file " + file, e);
}
}
use of org.simpleframework.xml.strategy.Strategy in project syncany by syncany.
the class ConfigTO method load.
public static ConfigTO load(File file) throws ConfigException {
try {
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
registry.bind(String.class, new EncryptedTransferSettingsConverter());
return new Persister(strategy).read(ConfigTO.class, file);
} catch (ClassNotFoundException ex) {
// Ugly hack to catch common case of non-existing plugin
String message = ex.getMessage();
if (!message.startsWith("org.syncany.plugins.")) {
// Apparently there are other ClassNotFoundExceptions possible.
throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
}
message = message.replaceFirst("org.syncany.plugins.", "");
message = message.replaceAll("\\..*", "");
throw new ConfigException("Is the " + message + " plugin installed?");
} catch (Exception ex) {
throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
}
}
use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.
the class BackupImport method performImport.
public void performImport(InputStream is) throws Exception {
userMap.clear();
groupMap.clear();
calendarMap.clear();
appointmentMap.clear();
roomMap.clear();
messageFolderMap.clear();
userContactMap.clear();
fileMap.clear();
messageFolderMap.put(INBOX_FOLDER_ID, INBOX_FOLDER_ID);
messageFolderMap.put(SENT_FOLDER_ID, SENT_FOLDER_ID);
messageFolderMap.put(TRASH_FOLDER_ID, TRASH_FOLDER_ID);
File f = unzip(is);
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
RegistryMatcher matcher = new RegistryMatcher();
Serializer simpleSerializer = new Persister(strategy, matcher);
matcher.bind(Long.class, LongTransform.class);
registry.bind(Date.class, DateConverter.class);
BackupVersion ver = getVersion(simpleSerializer, f);
importConfigs(f);
importGroups(f, simpleSerializer);
Long defaultLdapId = importLdap(f, simpleSerializer);
importOauth(f, simpleSerializer);
importUsers(f, defaultLdapId);
importRooms(f);
importRoomGroups(f);
importChat(f);
importCalendars(f);
importAppointments(f);
importMeetingMembers(f);
importRecordings(f);
importPrivateMsgFolders(f, simpleSerializer);
importContacts(f);
importPrivateMsgs(f);
List<FileItem> files = importFiles(f);
importPolls(f);
importRoomFiles(f);
log.info("Room files import complete, starting copy of files and folders");
/*
* ##################### Import real files and folders
*/
importFolders(f);
if (ver.compareTo(BackupVersion.get("4.0.0")) < 0) {
for (BaseFileItem bfi : files) {
if (bfi.isDeleted()) {
continue;
}
if (BaseFileItem.Type.Presentation == bfi.getType()) {
convertOldPresentation((FileItem) bfi);
fileItemDao._update(bfi);
}
if (BaseFileItem.Type.WmlFile == bfi.getType()) {
try {
Whiteboard wb = WbConverter.convert((FileItem) bfi);
wb.save(bfi.getFile().toPath());
} catch (Exception e) {
log.error("Unexpected error while converting WB", e);
}
}
}
}
log.info("File explorer item import complete, clearing temp files");
FileUtils.deleteDirectory(f);
}
use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.
the class BackupImport method importPolls.
/*
* ##################### Import Room Polls
*/
private void importPolls(File f) throws Exception {
log.info("File explorer item import complete, starting room poll import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
RegistryMatcher matcher = new RegistryMatcher();
Serializer serializer = new Persister(strategy, matcher);
matcher.bind(Integer.class, IntegerTransform.class);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(RoomPoll.Type.class, PollTypeConverter.class);
registry.bind(Date.class, DateConverter.class);
List<RoomPoll> list = readList(serializer, f, "roompolls.xml", "roompolls", RoomPoll.class);
for (RoomPoll rp : list) {
rp.setId(null);
if (rp.getRoom() == null || rp.getRoom().getId() == null) {
// room was deleted
continue;
}
if (rp.getCreator() == null || rp.getCreator().getId() == null) {
rp.setCreator(null);
}
for (RoomPollAnswer rpa : rp.getAnswers()) {
if (rpa.getVotedUser() == null || rpa.getVotedUser().getId() == null) {
rpa.setVotedUser(null);
}
}
pollDao.update(rp);
}
}
Aggregations