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());
}
}
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);
}
}
Aggregations