Search in sources :

Example 11 with Strategy

use of org.simpleframework.xml.strategy.Strategy 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 12 with Strategy

use of org.simpleframework.xml.strategy.Strategy 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 13 with Strategy

use of org.simpleframework.xml.strategy.Strategy 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 14 with Strategy

use of org.simpleframework.xml.strategy.Strategy 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)

Example 15 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.

the class BackupImport method importCalendars.

/*
	 * ##################### Import Calendars
	 */
private void importCalendars(File f) throws Exception {
    log.info("Chat messages import complete, starting calendar import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    List<OmCalendar> list = readList(serializer, f, "calendars.xml", "calendars", OmCalendar.class, true);
    for (OmCalendar c : list) {
        Long id = c.getId();
        c.setId(null);
        c = calendarDao.update(c);
        calendarMap.put(id, c.getId());
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)34 Strategy (org.simpleframework.xml.strategy.Strategy)34 Registry (org.simpleframework.xml.convert.Registry)33 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)33 Serializer (org.simpleframework.xml.Serializer)31 UserConverter (org.apache.openmeetings.backup.converter.UserConverter)9 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)7 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)5 Room (org.apache.openmeetings.db.entity.room.Room)4 FileItem (org.apache.openmeetings.db.entity.file.FileItem)3 IOException (java.io.IOException)2 GroupConverter (org.apache.openmeetings.backup.converter.GroupConverter)2 ChatMessage (org.apache.openmeetings.db.entity.basic.ChatMessage)2 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)2 OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 Recording (org.apache.openmeetings.db.entity.record.Recording)2 RoomFile (org.apache.openmeetings.db.entity.room.RoomFile)2 RoomPoll (org.apache.openmeetings.db.entity.room.RoomPoll)2 PrivateMessage (org.apache.openmeetings.db.entity.user.PrivateMessage)2