use of org.apache.openmeetings.db.entity.user.GroupUser in project openmeetings by apache.
the class AppointmentDialog method onSubmit.
@Override
protected void onSubmit(AjaxRequestTarget target) {
Appointment a = form.getModelObject();
a.setRoom(form.createRoom ? form.appRoom : form.groom.getModelObject());
final List<MeetingMember> mms = a.getMeetingMembers() == null ? new ArrayList<>() : a.getMeetingMembers();
Set<Long> currentIds = new HashSet<>();
List<User> users = new ArrayList<>();
if (InviteeType.group == rdi.getModelObject()) {
// lets iterate through all group users
for (Group g : groups.getModelObject()) {
for (GroupUser gu : groupUserDao.get(g.getId(), 0, Integer.MAX_VALUE)) {
User u = gu.getUser();
if (!currentIds.contains(u.getId())) {
users.add(u);
currentIds.add(u.getId());
}
}
}
} else {
users = new ArrayList<>(attendees.getModelObject());
for (User u : users) {
if (u.getId() != null) {
currentIds.add(u.getId());
}
}
}
// remove users
for (Iterator<MeetingMember> i = mms.iterator(); i.hasNext(); ) {
MeetingMember m = i.next();
if (!currentIds.contains(m.getUser().getId())) {
i.remove();
}
}
Set<Long> originalIds = new HashSet<>();
for (MeetingMember m : mms) {
originalIds.add(m.getUser().getId());
}
// add users
for (User u : users) {
if (u.getId() == null || !originalIds.contains(u.getId())) {
MeetingMember mm = new MeetingMember();
mm.setUser(u);
mm.setDeleted(false);
mm.setInserted(a.getInserted());
mm.setUpdated(a.getUpdated());
mm.setAppointment(a);
mms.add(mm);
}
}
a.setMeetingMembers(mms);
a.setStart(getDate(form.start.getModelObject()));
a.setEnd(getDate(form.end.getModelObject()));
a.setCalendar(form.cals.getModelObject());
apptDao.update(a, getUserId());
if (a.getCalendar() != null) {
calendarPanel.updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
}
target.add(feedback);
calendarPanel.refresh(target);
}
use of org.apache.openmeetings.db.entity.user.GroupUser in project openmeetings by apache.
the class GeneralUserForm method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
add(email);
email.setLabel(Model.of(getString("119")));
email.add(RfcCompliantEmailAddressValidator.getInstance());
add(new DropDownChoice<>("salutation", Arrays.asList(Salutation.values()), new ChoiceRenderer<Salutation>() {
private static final long serialVersionUID = 1L;
@Override
public Object getDisplayValue(Salutation object) {
return getString("user.salutation." + object.name());
}
@Override
public String getIdValue(Salutation object, int index) {
return object.name();
}
}));
add(new TextField<String>("firstname"));
add(new TextField<String>("lastname"));
add(new DropDownChoice<>("timeZoneId", AVAILABLE_TIMEZONES));
add(new LanguageDropDown("languageId"));
add(new TextField<String>("address.phone"));
add(new CheckBox("sendSMS"));
add(new AjaxDatePicker("age", new PropertyModel<LocalDate>(this, "age"), WebSession.get().getLocale()) {
private static final long serialVersionUID = 1L;
@Override
public void onValueChanged(IPartialPageRequestHandler target) {
User u = GeneralUserForm.this.getModelObject();
u.setAge(CalendarHelper.getDate(age, u.getTimeZoneId()));
}
});
add(new TextField<String>("address.street"));
add(new TextField<String>("address.additionalname"));
add(new TextField<String>("address.zip"));
add(new TextField<String>("address.town"));
add(new CountryDropDown("address.country"));
add(new TextArea<String>("address.comment"));
add(new Select2MultiChoice<>("groupUsers", null, new RestrictiveChoiceProvider<GroupUser>() {
private static final long serialVersionUID = 1L;
@Override
public String getDisplayValue(GroupUser choice) {
return choice.getGroup().getName();
}
@Override
public String toId(GroupUser choice) {
Long id = choice.getGroup().getId();
return id == null ? null : "" + id;
}
@Override
public void query(String term, int page, Response<GroupUser> response) {
for (GroupUser ou : grpUsers) {
if (Strings.isEmpty(term) || ou.getGroup().getName().contains(term)) {
response.add(ou);
}
}
}
@Override
public GroupUser fromId(String _id) {
Long id = Long.parseLong(_id);
User u = GeneralUserForm.this.getModelObject();
Group g = groupDao.get(id);
GroupUser gu = new GroupUser(g, u);
int idx = grpUsers.indexOf(gu);
return idx < 0 ? gu : grpUsers.get(idx);
}
}).setLabel(Model.of(getString("161"))).setRequired(isAdminForm && hasGroupAdminLevel(getRights())).setEnabled(isAdminForm));
}
use of org.apache.openmeetings.db.entity.user.GroupUser in project openmeetings by apache.
the class ImportInitvalues method loadInitUserAndGroup.
public void loadInitUserAndGroup(InstallationConfig cfg) throws Exception {
// Add default group
Group org = new Group();
org.setName(cfg.getGroup());
org.setInsertedby(1L);
org.setDeleted(false);
org.setInserted(new Date());
org = groupDao.update(org, null);
User u = userDao.getNewUserInstance(null);
u.setType(User.Type.user);
u.getRights().add(Right.Admin);
u.getRights().add(Right.Soap);
u.setLogin(cfg.getUsername());
u.setFirstname("firstname");
u.setLastname("lastname");
u.getAddress().setEmail(cfg.getEmail());
u.getGroupUsers().add(new GroupUser(org, u));
u = userDao.update(u, cfg.getPassword(), -1L);
log.debug("Installation - User Added user-Id " + u.getId());
if (u.getId() == null) {
throw new InstallException("Unable to add user");
}
}
use of org.apache.openmeetings.db.entity.user.GroupUser in project openmeetings by apache.
the class GroupForm method onSaveSubmit.
@Override
protected void onSaveSubmit(AjaxRequestTarget target, Form<?> form) {
Group o = getModelObject();
o = groupDao.update(o, getUserId());
setModelObject(o);
for (GroupUser grpUser : usersPanel.getUsers2add()) {
usersPanel.update(grpUser);
}
hideNewRecord();
updateView(target);
}
use of org.apache.openmeetings.db.entity.user.GroupUser in project openmeetings by apache.
the class UserManager method loginOAuth.
@Override
public User loginOAuth(OAuthUser user, long serverId) throws IOException, NoSuchAlgorithmException {
if (!userDao.validLogin(user.getUid())) {
log.error("Invalid login, please check parameters");
return null;
}
User u = userDao.getByLogin(user.getUid(), Type.oauth, serverId);
if (!userDao.checkEmail(user.getEmail(), Type.oauth, serverId, u == null ? null : u.getId())) {
log.error("Another user with the same email exists");
return null;
}
// generate random password
SecureRandom rnd = new SecureRandom();
byte[] rawPass = new byte[25];
rnd.nextBytes(rawPass);
String pass = Base64.encodeBase64String(rawPass);
// check if the user already exists and register new one if it's needed
if (u == null) {
u = userDao.getNewUserInstance(null);
u.setType(Type.oauth);
u.getRights().remove(Right.Login);
u.setDomainId(serverId);
u.getGroupUsers().add(new GroupUser(groupDao.get(cfgDao.getLong(CONFIG_DEFAULT_GROUP_ID, null)), u));
u.setLogin(user.getUid());
u.setShowContactDataToContacts(true);
u.setLastname(user.getLastName());
u.setFirstname(user.getFirstName());
u.getAddress().setEmail(user.getEmail());
String picture = user.getPicture();
if (picture != null) {
u.setPictureuri(picture);
}
String locale = user.getLocale();
if (locale != null) {
Locale loc = Locale.forLanguageTag(locale);
if (loc != null) {
u.setLanguageId(getLanguage(loc));
u.getAddress().setCountry(loc.getCountry());
}
}
}
u.setLastlogin(new Date());
u = userDao.update(u, pass, Long.valueOf(-1));
return u;
}
Aggregations