Search in sources :

Example 26 with Strategy

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

the class BackupExport method exportRoomFile.

/*
	 * ##################### Backup Room Files
	 */
private void exportRoomFile(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(FileItem.class, BaseFileItemConverter.class);
    registry.bind(Recording.class, BaseFileItemConverter.class);
    writeList(serializer, zos, "roomFiles.xml", "RoomFiles", roomDao.getFiles());
    progressHolder.setProgress(17);
}
Also used : RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 27 with Strategy

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

the class BackupExport method exportAppointment.

/*
	 * ##################### Backup Appointments
	 */
private void exportAppointment(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<Appointment> list = appointmentDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, UserConverter.class);
    registry.bind(Appointment.Reminder.class, AppointmentReminderTypeConverter.class);
    registry.bind(Room.class, RoomConverter.class);
    bindDate(registry, list);
    writeList(serializer, zos, "appointements.xml", "appointments", list);
    progressHolder.setProgress(25);
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 28 with Strategy

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

the class BackupExport method exportRoom.

/*
	 * ##################### Backup Room
	 */
private void exportRoom(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, UserConverter.class);
    registry.bind(Room.Type.class, RoomTypeConverter.class);
    List<Room> list = roomDao.get();
    bindDate(registry, list);
    writeList(serializer, zos, "rooms.xml", "rooms", list);
    progressHolder.setProgress(15);
}
Also used : RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) 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 29 with Strategy

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

the class BackupImport method importUsers.

/*
	 * ##################### Import Users
	 */
private void importUsers(File f, Long defaultLdapId) throws Exception {
    log.info("OAuth2 servers import complete, starting user import");
    String jNameTimeZone = getDefaultTimezone();
    // add existence email from database
    List<User> users = userDao.getAllUsers();
    final Map<String, Integer> userEmailMap = new HashMap<>();
    final Map<String, Integer> userLoginMap = new HashMap<>();
    for (User u : users) {
        if (u.getAddress() == null || u.getAddress().getEmail() == null || User.Type.user != u.getType()) {
            continue;
        }
        userEmailMap.put(u.getAddress().getEmail(), Integer.valueOf(-1));
        userLoginMap.put(u.getLogin(), Integer.valueOf(-1));
    }
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer ser = new Persister(strategy);
    registry.bind(Group.class, new GroupConverter(groupDao, groupMap));
    registry.bind(Salutation.class, SalutationConverter.class);
    registry.bind(Date.class, DateConverter.class);
    List<User> list = readList(ser, f, "users.xml", "users", User.class);
    int minLoginLength = getMinLoginLength(cfgDao);
    for (User u : list) {
        if (u.getLogin() == null) {
            continue;
        }
        // check that email is unique
        if (u.getAddress() != null && u.getAddress().getEmail() != null && User.Type.user == u.getType()) {
            if (userEmailMap.containsKey(u.getAddress().getEmail())) {
                log.warn("Email is duplicated for user " + u.toString());
                String updateEmail = String.format("modified_by_import_<%s>%s", UUID.randomUUID(), u.getAddress().getEmail());
                u.getAddress().setEmail(updateEmail);
            }
            userEmailMap.put(u.getAddress().getEmail(), Integer.valueOf(userEmailMap.size()));
        }
        if (userLoginMap.containsKey(u.getLogin())) {
            log.warn("Login is duplicated for user " + u.toString());
            String updateLogin = String.format("modified_by_import_<%s>%s", UUID.randomUUID(), u.getLogin());
            u.setLogin(updateLogin);
        }
        userLoginMap.put(u.getLogin(), Integer.valueOf(userLoginMap.size()));
        if (u.getGroupUsers() != null) {
            for (GroupUser gu : u.getGroupUsers()) {
                gu.setUser(u);
            }
        }
        if (u.getType() == User.Type.contact && u.getLogin().length() < minLoginLength) {
            u.setLogin(UUID.randomUUID().toString());
        }
        String tz = u.getTimeZoneId();
        if (tz == null) {
            u.setTimeZoneId(jNameTimeZone);
            u.setForceTimeZoneCheck(true);
        } else {
            u.setForceTimeZoneCheck(false);
        }
        Long userId = u.getId();
        u.setId(null);
        if (u.getSipUser() != null && u.getSipUser().getId() != 0) {
            u.getSipUser().setId(0);
        }
        if (LDAP_EXT_TYPE.equals(u.getExternalType()) && User.Type.external != u.getType()) {
            log.warn("Found LDAP user in 'old' format, external_type == 'LDAP':: " + u);
            u.setType(User.Type.ldap);
            u.setExternalType(null);
            if (u.getDomainId() == null) {
                // domainId was not supported in old versions of OM
                u.setDomainId(defaultLdapId);
            }
        }
        if (!Strings.isEmpty(u.getExternalType())) {
            u.setType(User.Type.external);
        }
        if (AuthLevelUtil.hasLoginLevel(u.getRights()) && !Strings.isEmpty(u.getActivatehash())) {
            u.setActivatehash(null);
        }
        userDao.update(u, Long.valueOf(-1));
        userMap.put(userId, u.getId());
    }
}
Also used : GroupConverter(org.apache.openmeetings.backup.converter.GroupConverter) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) HashMap(java.util.HashMap) Registry(org.simpleframework.xml.convert.Registry) 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 30 with Strategy

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

the class BackupImport method importRecordings.

/*
	 * ##################### Import Recordings
	 */
private void importRecordings(File f) throws Exception {
    log.info("Meeting members import complete, starting recordings server 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(Date.class, DateConverter.class);
    registry.bind(Recording.Status.class, RecordingStatusConverter.class);
    List<Recording> list = readList(ser, f, "flvRecordings.xml", "flvrecordings", Recording.class);
    for (Recording r : list) {
        Long recId = r.getId();
        r.setId(null);
        if (r.getRoomId() != null) {
            r.setRoomId(roomMap.get(r.getRoomId()));
        }
        if (r.getOwnerId() != null) {
            r.setOwnerId(userMap.get(r.getOwnerId()));
        }
        if (r.getMetaData() != null) {
            for (RecordingMetaData meta : r.getMetaData()) {
                meta.setId(null);
                meta.setRecording(r);
            }
        }
        if (!Strings.isEmpty(r.getHash()) && r.getHash().startsWith(RECORDING_FILE_NAME)) {
            String name = getFileName(r.getHash());
            r.setHash(UUID.randomUUID().toString());
            fileMap.put(String.format(FILE_NAME_FMT, name, EXTENSION_JPG), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_PNG));
            fileMap.put(String.format("%s.%s.%s", name, EXTENSION_FLV, EXTENSION_MP4), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_MP4));
        }
        if (Strings.isEmpty(r.getHash())) {
            r.setHash(UUID.randomUUID().toString());
        }
        r = recordingDao.update(r);
        fileItemMap.put(recId, r.getId());
    }
}
Also used : RecordingMetaData(org.apache.openmeetings.db.entity.record.RecordingMetaData) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) 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) Recording(org.apache.openmeetings.db.entity.record.Recording) 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