Search in sources :

Example 6 with UserAccountDAO

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

the class XsltTransformJob method initDependencies.

/**
     * Initializes the dependencies of this job with the components from the Spring application context.
     *
     * @param scheduler
     */
private void initDependencies(Scheduler scheduler) {
    try {
        ApplicationContext ctx = (ApplicationContext) scheduler.getContext().get("applicationContext");
        DataSource dataSource = ctx.getBean(DataSource.class);
        mailSender = ctx.getBean(OpenClinicaMailSender.class);
        auditEventDAO = ctx.getBean(AuditEventDAO.class);
        datasetDao = ctx.getBean(DatasetDAO.class);
        userAccountDao = ctx.getBean(UserAccountDAO.class);
        studyDao = new StudyDAO(dataSource);
        archivedDatasetFileDao = ctx.getBean(ArchivedDatasetFileDAO.class);
        generateFileService = ctx.getBean(GenerateExtractFileService.class);
        odmFileCreation = ctx.getBean(OdmFileCreation.class);
    } catch (SchedulerException e) {
        throw new IllegalStateException("Could not load dependencies from scheduler context", e);
    }
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) ApplicationContext(org.springframework.context.ApplicationContext) GenerateExtractFileService(org.akaza.openclinica.service.extract.GenerateExtractFileService) SchedulerException(org.quartz.SchedulerException) OpenClinicaMailSender(org.akaza.openclinica.core.OpenClinicaMailSender) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) OdmFileCreation(org.akaza.openclinica.service.extract.OdmFileCreation) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DataSource(javax.sql.DataSource)

Example 7 with UserAccountDAO

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

the class DeleteUserServlet 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);
    int action = fp.getInt(ARG_ACTION);
    UserAccountBean u = (UserAccountBean) udao.findByPK(userId);
    String message;
    if (!u.isActive()) {
        message = respage.getString("the_specified_user_not_exits");
    } else if (!EntityAction.contains(action)) {
        message = respage.getString("the_specified_action_on_the_user_is_invalid");
    } else if (!EntityAction.get(action).equals(EntityAction.DELETE) && !EntityAction.get(action).equals(EntityAction.RESTORE)) {
        message = respage.getString("the_specified_action_is_not_allowed");
    } else {
        EntityAction desiredAction = EntityAction.get(action);
        u.setUpdater(ub);
        if (desiredAction.equals(EntityAction.DELETE)) {
            udao.delete(u);
            if (udao.isQuerySuccessful()) {
                message = respage.getString("the_user_has_been_removed_successfully");
            // YW 07-31-2007 << for feature that deletion doesn't need
            // email the deleted user.
            /*
                     * //YW 07-26-2007 << catch exception (eg. timeout) and
                     * inform users. try { sendDeleteEmail(u); } catch
                     * (Exception e) { message += " However, there has been an
                     * error sending the user an email regarding this
                     * deletion."; }
                     */
            // YW >>
            } else {
                message = respage.getString("the_user_could_not_be_deleted_due_database_error");
            }
        } else {
            SecurityManager sm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
            String password = sm.genPassword();
            String passwordHash = sm.encrytPassword(password, getUserDetails());
            if (!u.isLdapUser()) {
                u.setPasswd(passwordHash);
                u.setPasswdTimestamp(null);
            }
            udao.restore(u);
            if (udao.isQuerySuccessful()) {
                message = respage.getString("the_user_has_been_restored");
                try {
                    if (!u.isLdapUser()) {
                        sendRestoreEmail(u, password);
                    }
                } catch (Exception e) {
                    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 : EntityAction(org.akaza.openclinica.bean.core.EntityAction) 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 8 with UserAccountDAO

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

the class EditStudyUserRoleServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt(ARG_STUDY_ID);
    String uName = fp.getString(ARG_USER_NAME);
    StudyUserRoleBean studyUserRole = udao.findRoleByUserNameAndStudyId(uName, studyId);
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudyBean sb = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
    if (sb != null) {
        studyUserRole.setStudyName(sb.getName());
    }
    if (!studyUserRole.isActive()) {
        String message = respage.getString("the_user_has_no_role_in_study");
        addPageMessage(message);
        forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
    } else {
        Map roleMap = new LinkedHashMap();
        for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
            Role role = (Role) it.next();
            roleMap.put(role.getId(), role.getDescription());
        }
        roleMap = new LinkedHashMap();
        ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
        StudyBean study = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
        if (study.getParentStudyId() == 0) {
            for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    case 2:
                        roleMap.put(role.getId(), resterm.getString("Study_Coordinator").trim());
                        break;
                    case 3:
                        roleMap.put(role.getId(), resterm.getString("Study_Director").trim());
                        break;
                    case 4:
                        roleMap.put(role.getId(), resterm.getString("Investigator").trim());
                        break;
                    case 5:
                        roleMap.put(role.getId(), resterm.getString("Data_Entry_Person").trim());
                        break;
                    case 6:
                        roleMap.put(role.getId(), resterm.getString("Monitor").trim());
                        break;
                    default:
                }
            }
        } else {
            for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    //                            break;
                    case 4:
                        roleMap.put(role.getId(), resterm.getString("site_investigator").trim());
                        break;
                    case 5:
                        roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person").trim());
                        break;
                    case 6:
                        roleMap.put(role.getId(), resterm.getString("site_monitor").trim());
                        break;
                    case 7:
                        roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person2").trim());
                        break;
                    default:
                }
            }
        }
        if (study.getParentStudyId() > 0) {
            roleMap.remove(Role.COORDINATOR.getId());
            roleMap.remove(Role.STUDYDIRECTOR.getId());
        }
        // send the user to the right place..
        if (!fp.isSubmitted()) {
            request.setAttribute("userName", uName);
            request.setAttribute("studyUserRole", studyUserRole);
            request.setAttribute("roles", roleMap);
            request.setAttribute("chosenRoleId", new Integer(studyUserRole.getRole().getId()));
            forwardPage(Page.EDIT_STUDY_USER_ROLE);
        } else // process the form
        {
            Validator v = new Validator(request);
            v.addValidation(INPUT_ROLE, Validator.IS_VALID_TERM, TermType.ROLE);
            HashMap errors = v.validate();
            if (errors.isEmpty()) {
                int roleId = fp.getInt(INPUT_ROLE);
                Role r = Role.get(roleId);
                studyUserRole.setRoleName(r.getName());
                studyUserRole.setUpdater(ub);
                udao.updateStudyUserRole(studyUserRole, uName);
                String message = respage.getString("the_user_in_study_has_been_updated");
                addPageMessage(message);
                forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
            } else {
                String message = respage.getString("the_role_choosen_was_invalid_choose_another");
                addPageMessage(message);
                request.setAttribute("userName", uName);
                request.setAttribute("studyUserRole", studyUserRole);
                request.setAttribute("chosenRoleId", new Integer(fp.getInt(INPUT_ROLE)));
                request.setAttribute("roles", roleMap);
                forwardPage(Page.EDIT_STUDY_USER_ROLE);
            }
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Role(org.akaza.openclinica.bean.core.Role) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 9 with UserAccountDAO

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

the class AdminSystemServlet method processRequest.

// < ResourceBundleresword,resexception;
/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // find last 5 modifed studies
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    ArrayList studies = (ArrayList) sdao.findAllByLimit(true);
    request.setAttribute("studies", studies);
    ArrayList allStudies = (ArrayList) sdao.findAll();
    request.setAttribute("allStudyNumber", new Integer(allStudies.size()));
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList users = (ArrayList) udao.findAllByLimit(true);
    request.setAttribute("users", users);
    ArrayList allUsers = (ArrayList) udao.findAll();
    request.setAttribute("allUserNumber", new Integer(allUsers.size()));
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    ArrayList subjects = (ArrayList) subdao.findAllByLimit(true);
    request.setAttribute("subjects", subjects);
    ArrayList allSubjects = (ArrayList) subdao.findAll();
    request.setAttribute("allSubjectNumber", new Integer(allSubjects.size()));
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    ArrayList crfs = (ArrayList) cdao.findAllByLimit(true);
    request.setAttribute("crfs", crfs);
    ArrayList allCrfs = (ArrayList) cdao.findAll();
    request.setAttribute("allCrfNumber", new Integer(allCrfs.size()));
    resetPanel();
    panel.setOrderedData(true);
    setToPanel(resword.getString("in_the_application"), "");
    if (allSubjects.size() > 0) {
        setToPanel(resword.getString("subjects"), new Integer(allSubjects.size()).toString());
    }
    if (allUsers.size() > 0) {
        setToPanel(resword.getString("users"), new Integer(allUsers.size()).toString());
    }
    if (allStudies.size() > 0) {
        setToPanel(resword.getString("studies"), new Integer(allStudies.size()).toString());
    }
    if (allCrfs.size() > 0) {
        setToPanel(resword.getString("CRFs"), new Integer(allCrfs.size()).toString());
    }
    panel.setStudyInfoShown(false);
    forwardPage(Page.ADMIN_SYSTEM);
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 10 with UserAccountDAO

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

the class CreateJobImportServlet method setUpServlet.

/*
     * Find all the form items and re-populate as necessary
     */
private void setUpServlet() throws Exception {
    String directory = SQLInitServlet.getField("filePath") + DIR_PATH + File.separator;
    logger.debug("found directory: " + directory);
    // find all the form items and re-populate them if necessary
    FormProcessor fp2 = new FormProcessor(request);
    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);
    // tbh, replacing the above with another version, 06/2009
    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);
    // YW >>
    // << tbh
    request.setAttribute("filePath", directory);
    // request.setAttribute("activeStudy", activeStudy);
    request.setAttribute(JOB_NAME, fp2.getString(JOB_NAME));
    request.setAttribute(JOB_DESC, fp2.getString(JOB_DESC));
    request.setAttribute(EMAIL, fp2.getString(EMAIL));
    request.setAttribute(HOURS, new Integer(fp2.getInt(HOURS)).toString());
    request.setAttribute(MINUTES, new Integer(fp2.getInt(MINUTES)).toString());
}
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)

Aggregations

UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)92 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)64 ArrayList (java.util.ArrayList)42 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)42 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)39 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 Date (java.util.Date)23 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)22 HashMap (java.util.HashMap)21 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)17 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)16 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)14 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)14 Locale (java.util.Locale)13 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 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10