Search in sources :

Example 86 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class UpdateJobImportServlet method setUpServlet.

private void setUpServlet(Trigger trigger) throws Exception {
    FormProcessor fp2 = new FormProcessor(request);
    request.setAttribute(CreateJobImportServlet.JOB_NAME, trigger.getName());
    request.setAttribute(CreateJobImportServlet.JOB_DESC, trigger.getDescription());
    dataMap = trigger.getJobDataMap();
    String contactEmail = dataMap.getString(ImportSpringJob.EMAIL);
    logger.debug("found email: " + contactEmail);
    int userId = dataMap.getInt(ImportSpringJob.USER_ID);
    int hours = dataMap.getInt(CreateJobImportServlet.HOURS);
    int minutes = dataMap.getInt(CreateJobImportServlet.MINUTES);
    String directory = dataMap.getString(ImportSpringJob.DIRECTORY);
    String studyName = dataMap.getString(ImportSpringJob.STUDY_NAME);
    request.setAttribute(ImportSpringJob.EMAIL, contactEmail);
    request.setAttribute(ImportSpringJob.STUDY_NAME, studyName);
    request.setAttribute("filePath", directory);
    request.setAttribute("firstFilePath", IMPORT_DIR);
    request.setAttribute("hours", new Integer(hours).toString());
    request.setAttribute("minutes", new Integer(minutes).toString());
    Date jobDate = trigger.getNextFireTime();
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    // ArrayList studies = udao.findStudyByUser(ub.getName(), (ArrayList)
    // sdao.findAll());
    // request.setAttribute("studies", studies);
    ArrayList<StudyBean> all = (ArrayList<StudyBean>) sdao.findAll();
    ArrayList<StudyBean> finalList = new ArrayList<StudyBean>();
    for (StudyBean sb : all) {
        if (!(sb.getParentStudyId() > 0)) {
            finalList.add(sb);
            // System.out.println("found study name: " + sb.getName());
            finalList.addAll(sdao.findAllByParent(sb.getId()));
        }
    }
    // System.out.println("found list of studies: " + finalList.toString());
    addEntityList("studies", finalList, respage.getString("a_user_cannot_be_created_no_study_as_active"), Page.ADMIN_SYSTEM);
// tbh >>
// HashMap presetValues = new HashMap();
// Calendar calendar = new GregorianCalendar();
// calendar.setTime(jobDate);
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Hour",
// calendar.get(Calendar.HOUR_OF_DAY));
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Minute",
// calendar.get(Calendar.MINUTE));
// // TODO this will have to match l10n formatting
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Date",
// (calendar.get(Calendar.MONTH) + 1) + "/" +
// calendar.get(Calendar.DATE) + "/"
// + calendar.get(Calendar.YEAR));
// fp2.setPresetValues(presetValues);
// setPresetValues(fp2.getPresetValues());
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Date(java.util.Date)

Example 87 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class UnLockUserServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int userId = fp.getInt(ARG_USERID);
    UserAccountBean u = (UserAccountBean) udao.findByPK(userId);
    String message;
    if (!u.isActive() || u.getAccountNonLocked()) {
        message = respage.getString("the_specified_user_not_exits");
    } else {
        u.setUpdater(ub);
        SecurityManager sm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
        String password = sm.genPassword();
        if (!u.isLdapUser()) {
            String passwordHash = sm.encrytPassword(password, getUserDetails());
            u.setPasswd(passwordHash);
        }
        u.setPasswdTimestamp(null);
        u.setAccountNonLocked(Boolean.TRUE);
        u.setStatus(Status.AVAILABLE);
        u.setLockCounter(0);
        udao.update(u);
        if (udao.isQuerySuccessful()) {
            message = respage.getString("the_user_has_been_unlocked");
            try {
                if (!u.isLdapUser()) {
                    sendRestoreEmail(u, password);
                }
            } catch (Exception e) {
                e.printStackTrace();
                message += respage.getString("however_was_error_sending_user_email_regarding");
            }
        } else {
            message = respage.getString("the_user_could_not_be_deleted_due_database_error");
        }
    }
    addPageMessage(message);
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
Also used : SecurityManager(org.akaza.openclinica.core.SecurityManager) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException)

Example 88 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class EditUserAccountServlet method isApiKeyExist.

public Boolean isApiKeyExist(String uuid) {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean uBean = (UserAccountBean) udao.findByApiKey(uuid);
    if (uBean == null || !uBean.isActive()) {
        return false;
    } else {
        return true;
    }
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 89 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class EditUserAccountServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // because we need to use this in the confirmation and error parts too
    ArrayList studies = getAllStudies();
    request.setAttribute("studies", studies);
    int userId = fp.getInt(ARG_USERID);
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean user = (UserAccountBean) udao.findByPK(userId);
    techAdminProtect(user);
    int stepNum = fp.getInt(ARG_STEPNUM);
    if (!fp.isSubmitted()) {
        addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
        loadPresetValuesFromBean(fp, user);
        fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
        setPresetValues(fp.getPresetValues());
        // addEntityList("userTypes", getUserTypes(),
        // "The user could not be edited because there are no user types
        // available.",
        // Page.ADMIN_SYSTEM);
        request.setAttribute("userName", user.getName());
        forwardPage(Page.EDIT_ACCOUNT);
    } else if (stepNum == EDIT_STEP) {
        Validator v = new Validator(request);
        v.addValidation(INPUT_FIRST_NAME, Validator.NO_BLANKS);
        v.addValidation(INPUT_LAST_NAME, Validator.NO_BLANKS);
        v.addValidation(INPUT_FIRST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
        v.addValidation(INPUT_LAST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
        v.addValidation(INPUT_EMAIL, Validator.NO_BLANKS);
        v.addValidation(INPUT_EMAIL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 120);
        v.addValidation(INPUT_EMAIL, Validator.IS_A_EMAIL);
        v.addValidation(INPUT_INSTITUTION, Validator.NO_BLANKS);
        v.addValidation(INPUT_INSTITUTION, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
        HashMap errors = v.validate();
        if (errors.isEmpty()) {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, CONFIRM_STEP);
            setPresetValues(fp.getPresetValues());
            request.setAttribute("userName", user.getName());
            forwardPage(Page.EDIT_ACCOUNT_CONFIRM);
        } else {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
            setInputMessages(errors);
            setPresetValues(fp.getPresetValues());
            addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
            addPageMessage(respage.getString("there_were_some_errors_submission") + respage.getString("see_below_for_details"));
            forwardPage(Page.EDIT_ACCOUNT);
        }
    } else if (stepNum == CONFIRM_STEP) {
        String button = fp.getString(INPUT_CONFIRM_BUTTON);
        if (button.equals(resword.getString("back"))) {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
            addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
            setPresetValues(fp.getPresetValues());
            request.setAttribute("userName", user.getName());
            forwardPage(Page.EDIT_ACCOUNT);
        } else if (button.equals(resword.getString("confirm"))) {
            user.setFirstName(fp.getString(INPUT_FIRST_NAME));
            user.setLastName(fp.getString(INPUT_LAST_NAME));
            user.setEmail(fp.getString(INPUT_EMAIL));
            user.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
            user.setUpdater(ub);
            user.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
            user.setEnableApiKey(true);
            String apiKey = null;
            do {
                apiKey = getRandom32ChApiKey();
            } while (isApiKeyExist(apiKey));
            user.setApiKey(apiKey);
            UserType ut = UserType.get(fp.getInt(INPUT_USER_TYPE));
            if (ut.equals(UserType.SYSADMIN)) {
                user.addUserType(ut);
            } else if (ut.equals(UserType.TECHADMIN)) {
                user.addUserType(ut);
            } else {
                user.addUserType(UserType.USER);
            }
            if (fp.getBoolean(INPUT_RESET_PASSWORD)) {
                SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
                String password = sm.genPassword();
                String passwordHash = sm.encrytPassword(password, getUserDetails());
                user.setPasswd(passwordHash);
                user.setPasswdTimestamp(null);
                udao.update(user);
                if ("no".equalsIgnoreCase(fp.getString(INPUT_DISPLAY_PWD))) {
                    logger.info("displayPwd is no");
                    try {
                        sendResetPasswordEmail(user, password);
                    } catch (Exception e) {
                        addPageMessage(respage.getString("there_was_an_error_sending_reset_email_try_reset"));
                    }
                } else {
                    addPageMessage(respage.getString("new_user_password") + ":<br/> " + password + "<br/>" + respage.getString("please_write_down_the_password_and_provide"));
                }
            } else {
                udao.update(user);
            }
            addPageMessage(respage.getString("the_user_account") + " \"" + user.getName() + "\" " + respage.getString("was_updated_succesfully"));
            forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        } else {
            throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_submit_button_was_clicked"));
        }
    } else {
        throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_step_was_specified"));
    }
}
Also used : SecurityManager(org.akaza.openclinica.core.SecurityManager) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) UserType(org.akaza.openclinica.bean.core.UserType) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Validator(org.akaza.openclinica.control.form.Validator) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException)

Example 90 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class EnterDataForStudyEventServlet method populateUncompletedCRFsWithAnOwner.

private void populateUncompletedCRFsWithAnOwner(List<DisplayEventDefinitionCRFBean> displayEventDefinitionCRFBeans) {
    if (displayEventDefinitionCRFBeans == null || displayEventDefinitionCRFBeans.isEmpty()) {
        return;
    }
    UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
    UserAccountBean userAccountBean;
    EventCRFBean eventCRFBean;
    EventDefinitionCRFBean eventDefinitionCRFBean;
    for (DisplayEventDefinitionCRFBean dedcBean : displayEventDefinitionCRFBeans) {
        eventCRFBean = dedcBean.getEventCRF();
        if (eventCRFBean != null && eventCRFBean.getOwner() == null && eventCRFBean.getOwnerId() > 0) {
            userAccountBean = (UserAccountBean) userAccountDAO.findByPK(eventCRFBean.getOwnerId());
            eventCRFBean.setOwner(userAccountBean);
        }
        // EventDefinitionCRFBean
        if (eventCRFBean != null && eventCRFBean.getOwner() == null) {
            int ownerId = dedcBean.getEdc().getOwnerId();
            if (ownerId > 0) {
                userAccountBean = (UserAccountBean) userAccountDAO.findByPK(ownerId);
                eventCRFBean.setOwner(userAccountBean);
            }
        }
    }
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Aggregations

UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)101 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)69 ArrayList (java.util.ArrayList)44 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)43 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)42 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)24 Date (java.util.Date)23 HashMap (java.util.HashMap)21 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)18 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)16 Locale (java.util.Locale)15 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)14 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)14 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)13 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)12 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)10