Search in sources :

Example 1 with GroupConverter

use of org.apache.openmeetings.backup.converter.GroupConverter 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 2 with GroupConverter

use of org.apache.openmeetings.backup.converter.GroupConverter in project openmeetings by apache.

the class BackupImport method importRoomGroups.

/*
	 * ##################### Import Room Groups
	 */
private void importRoomGroups(File f) throws Exception {
    log.info("Room import complete, starting room groups import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(Group.class, new GroupConverter(groupDao, groupMap));
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
    List<RoomGroup> list = readList(serializer, f, "rooms_organisation.xml", "room_organisations", RoomGroup.class);
    for (RoomGroup ro : list) {
        Room r = roomDao.get(ro.getRoom().getId());
        if (r == null || ro.getGroup() == null || ro.getGroup().getId() == null) {
            continue;
        }
        if (r.getGroups() == null) {
            r.setGroups(new ArrayList<>());
        }
        ro.setId(null);
        ro.setRoom(r);
        r.getGroups().add(ro);
        roomDao.update(r, null);
    }
}
Also used : GroupConverter(org.apache.openmeetings.backup.converter.GroupConverter) 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) RoomGroup(org.apache.openmeetings.db.entity.room.RoomGroup) Room(org.apache.openmeetings.db.entity.room.Room) Serializer(org.simpleframework.xml.Serializer)

Aggregations

GroupConverter (org.apache.openmeetings.backup.converter.GroupConverter)2 Serializer (org.simpleframework.xml.Serializer)2 Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Persister (org.simpleframework.xml.core.Persister)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 HashMap (java.util.HashMap)1 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)1 Room (org.apache.openmeetings.db.entity.room.Room)1 RoomGroup (org.apache.openmeetings.db.entity.room.RoomGroup)1 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)1 User (org.apache.openmeetings.db.entity.user.User)1