} else {
// profile picture
int lastDot = fileName.lastIndexOf('.');
String fullName = lastDot < 0 ? fileName : fileName.substring(0, lastDot);
try {
final ProfilePictureData profilePicture = ProfilePictureData.getProfilePicture(IOUtils.toByteArray(zipFile));
msg.add("Read profile picture for " + fileName);
profilePics.put(fullName, profilePicture);
} catch (RuntimeException e) {
msg.add("Failed to read profile picture for " + fileName + ": " + e.getMessage());
}
}
}
if (rows == null)
return rawStringUtf8("No 'Users.csv' in zip file");
List<User> users = Funcs.map(rows, new Func<String, User>() {
@Override public User call(String row) {
List<String> cells = Strings.split(row, "\t");
final String firstName = notNull("First name", row, strip(cells.get(0)));
final String lastName = notNull("Last name", row, strip(cells.get(1)));
final String email = notNull("Email", row, strip(cells.get(2)));
final Gender gender = notNull("Gender", row, Gender.parse(strip(cells.get(3))));
final boolean disableEmail = cells.size() > 4 && Boolean.valueOf(strip(cells.get(4)).toLowerCase());
final boolean admin = cells.size() > 5 && Boolean.valueOf(strip(cells.get(5)).toLowerCase());
return new KTrans<User>(pm) {
@Override protected User call() {
User u = QueryBuilder.begin(pm, User.class).getSingleByField("email", email);
if (u == null) {
u = User.newUser(groupKey);
u.setEmail(email);
}
u.setFirstName(firstName);
u.setLastName(lastName);
u.setGender(gender);
u.setDisableEmail(disableEmail);
u.setAdmin(admin);
ProfilePictureData profilePicture = profilePics.get(u.getFullName());
if (profilePicture != null)
u.setProfilePictureInfo(profilePicture);
pm.makePersistent(u);