Search in sources :

Example 1 with UserConverter

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);
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) Configuration(org.apache.openmeetings.db.entity.basic.Configuration) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) IOException(java.io.IOException) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 2 with UserConverter

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());
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 3 with UserConverter

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());
    }
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) OmCalendarConverter(org.apache.openmeetings.backup.converter.OmCalendarConverter) UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 4 with UserConverter

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());
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RoomModerator(org.apache.openmeetings.db.entity.room.RoomModerator) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Room(org.apache.openmeetings.db.entity.room.Room) Serializer(org.simpleframework.xml.Serializer)

Example 5 with UserConverter

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);
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) PrivateMessage(org.apache.openmeetings.db.entity.user.PrivateMessage) Serializer(org.simpleframework.xml.Serializer)

Aggregations

UserConverter (org.apache.openmeetings.backup.converter.UserConverter)9 Serializer (org.simpleframework.xml.Serializer)9 Registry (org.simpleframework.xml.convert.Registry)9 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)9 Persister (org.simpleframework.xml.core.Persister)9 Strategy (org.simpleframework.xml.strategy.Strategy)9 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)4 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)3 IOException (java.io.IOException)1 AppointmentConverter (org.apache.openmeetings.backup.converter.AppointmentConverter)1 OmCalendarConverter (org.apache.openmeetings.backup.converter.OmCalendarConverter)1 ChatMessage (org.apache.openmeetings.db.entity.basic.ChatMessage)1 Configuration (org.apache.openmeetings.db.entity.basic.Configuration)1 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)1 MeetingMember (org.apache.openmeetings.db.entity.calendar.MeetingMember)1 OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)1 Room (org.apache.openmeetings.db.entity.room.Room)1 RoomModerator (org.apache.openmeetings.db.entity.room.RoomModerator)1 RoomPoll (org.apache.openmeetings.db.entity.room.RoomPoll)1 RoomPollAnswer (org.apache.openmeetings.db.entity.room.RoomPollAnswer)1