use of org.apache.openmeetings.backup.converter.UserConverter in project openmeetings by apache.
the class BackupImport method importConfigs.
/*
* ##################### Import Configs
*/
private void importConfigs(File f) throws Exception {
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
RegistryMatcher matcher = new RegistryMatcher();
Serializer serializer = new Persister(strategy, matcher);
matcher.bind(Long.class, LongTransform.class);
registry.bind(Date.class, DateConverter.class);
registry.bind(User.class, new UserConverter(userDao, userMap));
List<Configuration> list = readList(serializer, f, "configs.xml", "configs", Configuration.class);
for (Configuration c : list) {
if (c.getKey() == null || c.isDeleted()) {
continue;
}
String newKey = outdatedConfigKeys.get(c.getKey());
if (newKey != null) {
c.setKey(newKey);
}
Configuration.Type type = configTypes.get(c.getKey());
if (type != null) {
c.setType(type);
if (Configuration.Type.bool == type) {
c.setValue(String.valueOf("1".equals(c.getValue()) || "yes".equals(c.getValue()) || "true".equals(c.getValue())));
}
}
Configuration cfg = cfgDao.forceGet(c.getKey());
if (cfg != null && !cfg.isDeleted()) {
log.warn("Non deleted configuration with same key is found! old value: {}, new value: {}", cfg.getValue(), c.getValue());
}
c.setId(cfg == null ? null : cfg.getId());
if (c.getUser() != null && c.getUser().getId() == null) {
c.setUser(null);
}
if (CONFIG_CRYPT.equals(c.getKey())) {
try {
Class<?> clazz = Class.forName(c.getValue());
clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.warn("Not existing Crypt class found {}, replacing with SCryptImplementation", c.getValue());
c.setValue(SCryptImplementation.class.getCanonicalName());
}
}
cfgDao.update(c, null);
}
}
use of org.apache.openmeetings.backup.converter.UserConverter in project openmeetings by apache.
the class BackupImport method importChat.
/*
* ##################### Import Chat messages
*/
private void importChat(File f) throws Exception {
log.info("Room groups import complete, starting chat messages import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(Date.class, DateConverter.class);
List<ChatMessage> list = readList(serializer, f, "chat_messages.xml", "chat_messages", ChatMessage.class);
for (ChatMessage m : list) {
m.setId(null);
if (m.getFromUser() == null || m.getFromUser().getId() == null) {
continue;
}
chatDao.update(m, m.getSent());
}
}
use of org.apache.openmeetings.backup.converter.UserConverter in project openmeetings by apache.
the class BackupImport method importAppointments.
/*
* ##################### Import Appointements
*/
private void importAppointments(File f) throws Exception {
log.info("Calendar import complete, starting appointement import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Appointment.Reminder.class, AppointmentReminderTypeConverter.class);
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(Date.class, DateConverter.class);
registry.bind(OmCalendar.class, new OmCalendarConverter(calendarDao, calendarMap));
List<Appointment> list = readList(serializer, f, "appointements.xml", "appointments", Appointment.class);
for (Appointment a : list) {
Long appId = a.getId();
// We need to reset this as openJPA reject to store them otherwise
a.setId(null);
if (a.getOwner() != null && a.getOwner().getId() == null) {
a.setOwner(null);
}
if (a.getRoom() == null || a.getRoom().getId() == null) {
log.warn("Appointment without room was found, skipping: {}", a);
continue;
}
if (a.getStart() == null || a.getEnd() == null) {
log.warn("Appointment without start/end time was found, skipping: {}", a);
continue;
}
a = appointmentDao.update(a, null, false);
appointmentMap.put(appId, a.getId());
}
}
use of org.apache.openmeetings.backup.converter.UserConverter in project openmeetings by apache.
the class BackupImport method importRooms.
/*
* ##################### Import Rooms
*/
private void importRooms(File f) throws Exception {
log.info("Users import complete, starting room import");
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(User.class, new UserConverter(userDao, userMap));
registry.bind(Room.Type.class, RoomTypeConverter.class);
registry.bind(Date.class, DateConverter.class);
List<Room> list = readList(ser, f, "rooms.xml", "rooms", Room.class);
for (Room r : list) {
Long roomId = r.getId();
// We need to reset ids as openJPA reject to store them otherwise
r.setId(null);
if (r.getModerators() != null) {
for (Iterator<RoomModerator> i = r.getModerators().iterator(); i.hasNext(); ) {
RoomModerator rm = i.next();
if (rm.getUser().getId() == null) {
i.remove();
}
}
}
r = roomDao.update(r, null);
roomMap.put(roomId, r.getId());
}
}
use of org.apache.openmeetings.backup.converter.UserConverter in project openmeetings by apache.
the class BackupImport method importPrivateMsgs.
/*
* ##################### Import Private Messages
*/
private void importPrivateMsgs(File f) throws Exception {
log.info("Usercontact import complete, starting private messages item import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(Date.class, DateConverter.class);
List<PrivateMessage> list = readList(serializer, f, "privateMessages.xml", "privatemessages", PrivateMessage.class);
boolean oldBackup = true;
for (PrivateMessage p : list) {
if (p.getFolderId() == null || p.getFolderId().longValue() < 0) {
oldBackup = false;
break;
}
}
for (PrivateMessage p : list) {
p.setId(null);
p.setFolderId(messageFolderMap.get(p.getFolderId()));
p.setUserContactId(userContactMap.get(p.getUserContactId()));
if (p.getRoom() != null && p.getRoom().getId() == null) {
p.setRoom(null);
}
if (p.getTo() != null && p.getTo().getId() == null) {
p.setTo(null);
}
if (p.getFrom() != null && p.getFrom().getId() == null) {
p.setFrom(null);
}
if (p.getOwner() != null && p.getOwner().getId() == null) {
p.setOwner(null);
}
if (oldBackup && p.getOwner() != null && p.getOwner().getId() != null && p.getFrom() != null && p.getFrom().getId() != null && p.getOwner().getId() == p.getFrom().getId()) {
p.setFolderId(SENT_FOLDER_ID);
}
privateMessageDao.update(p, null);
}
}
Aggregations