Search in sources :

Example 1 with GroupUser

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);
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) Group(org.apache.openmeetings.db.entity.user.Group) RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) MeetingMember(org.apache.openmeetings.db.entity.calendar.MeetingMember) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with GroupUser

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));
}
Also used : AjaxDatePicker(com.googlecode.wicket.kendo.ui.form.datetime.local.AjaxDatePicker) CountryDropDown(org.apache.openmeetings.web.util.CountryDropDown) Group(org.apache.openmeetings.db.entity.user.Group) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) PropertyModel(org.apache.wicket.model.PropertyModel) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) Salutation(org.apache.openmeetings.db.entity.user.User.Salutation) CheckBox(org.apache.wicket.markup.html.form.CheckBox) Select2MultiChoice(org.wicketstuff.select2.Select2MultiChoice) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer)

Example 3 with GroupUser

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");
    }
}
Also used : RoomGroup(org.apache.openmeetings.db.entity.room.RoomGroup) Group(org.apache.openmeetings.db.entity.user.Group) User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) Date(java.util.Date)

Example 4 with GroupUser

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);
}
Also used : Group(org.apache.openmeetings.db.entity.user.Group) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser)

Example 5 with GroupUser

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;
}
Also used : Locale(java.util.Locale) User(org.apache.openmeetings.db.entity.user.User) OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) SecureRandom(java.security.SecureRandom) Date(java.util.Date)

Aggregations

GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)28 User (org.apache.openmeetings.db.entity.user.User)19 Group (org.apache.openmeetings.db.entity.user.Group)9 Test (org.junit.Test)7 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Path (javax.ws.rs.Path)3 AbstractJUnitDefaults.createUser (org.apache.openmeetings.AbstractJUnitDefaults.createUser)3 AbstractJUnitDefaults.getUser (org.apache.openmeetings.AbstractJUnitDefaults.getUser)3 GroupDao (org.apache.openmeetings.db.dao.user.GroupDao)3 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)3 RoomGroup (org.apache.openmeetings.db.entity.room.RoomGroup)3 JSONObject (com.github.openjson.JSONObject)2 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)2 OAuthUser (org.apache.openmeetings.db.dto.user.OAuthUser)2 MeetingMember (org.apache.openmeetings.db.entity.calendar.MeetingMember)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 JSONArray (com.github.openjson.JSONArray)1