Search in sources :

Example 21 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class UpdateJobExportServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    TriggerService triggerService = new TriggerService();
    String action = fp.getString("action");
    String triggerName = fp.getString("tname");
    scheduler = getScheduler();
    ExtractUtils extractUtils = new ExtractUtils();
    Trigger updatingTrigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), XsltTriggerService.TRIGGER_GROUP_NAME));
    if (StringUtil.isBlank(action)) {
        setUpServlet(updatingTrigger);
        forwardPage(Page.UPDATE_JOB_EXPORT);
    } else if ("confirmall".equalsIgnoreCase(action)) {
        // change and update trigger here
        // validate first
        // then update or send back
        String name = XsltTriggerService.TRIGGER_GROUP_NAME;
        Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(name));
        String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
        HashMap errors = validateForm(fp, request, triggerNames, updatingTrigger.getKey().getName());
        if (!errors.isEmpty()) {
            // send back
            addPageMessage("Your modifications caused an error, please see the messages for more information.");
            setUpServlet(updatingTrigger);
            logger.error("errors : " + errors.toString());
            forwardPage(Page.UPDATE_JOB_EXPORT);
        } else {
            // change trigger, update in database
            StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
            StudyBean study = (StudyBean) studyDAO.findByPK(sm.getUserBean().getActiveStudyId());
            DatasetDAO datasetDao = new DatasetDAO(sm.getDataSource());
            CoreResources cr = new CoreResources();
            UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
            int datasetId = fp.getInt(DATASET_ID);
            String period = fp.getString(PERIOD);
            String email = fp.getString(EMAIL);
            String jobName = fp.getString(JOB_NAME);
            String jobDesc = fp.getString(JOB_DESC);
            Date startDateTime = fp.getDateTime(DATE_START_JOB);
            Integer exportFormatId = fp.getInt(FORMAT_ID);
            ExtractPropertyBean epBean = cr.findExtractPropertyBeanById(exportFormatId, "" + datasetId);
            DatasetBean dsBean = (DatasetBean) datasetDao.findByPK(new Integer(datasetId).intValue());
            String[] files = epBean.getFileName();
            String exportFileName;
            int fileSize = files.length;
            int cnt = 0;
            dsBean.setName(dsBean.getName().replaceAll(" ", "_"));
            String[] exportFiles = epBean.getExportFileName();
            String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator;
            SimpleDateFormat sdfDir = new SimpleDateFormat(pattern);
            int i = 0;
            String[] temp = new String[exportFiles.length];
            //JN: The following logic is for comma separated variables, to avoid the second file be treated as a old file and deleted.
            String datasetFilePath = SQLInitServlet.getField("filePath") + "datasets";
            while (i < exportFiles.length) {
                temp[i] = extractUtils.resolveVars(exportFiles[i], dsBean, sdfDir, datasetFilePath);
                i++;
            }
            epBean.setDoNotDelFiles(temp);
            epBean.setExportFileName(temp);
            XsltTriggerService xsltService = new XsltTriggerService();
            String generalFileDir = SQLInitServlet.getField("filePath");
            generalFileDir = generalFileDir + "datasets" + File.separator + dsBean.getId() + File.separator + sdfDir.format(new java.util.Date());
            exportFileName = epBean.getExportFileName()[cnt];
            String xsltPath = SQLInitServlet.getField("filePath") + "xslt" + File.separator + files[cnt];
            String endFilePath = epBean.getFileLocation();
            endFilePath = extractUtils.getEndFilePath(endFilePath, dsBean, sdfDir, datasetFilePath);
            //  exportFileName = resolveVars(exportFileName,dsBean,sdfDir);
            if (epBean.getPostProcExportName() != null) {
                String preProcExportPathName = extractUtils.resolveVars(epBean.getPostProcExportName(), dsBean, sdfDir, datasetFilePath);
                epBean.setPostProcExportName(preProcExportPathName);
            }
            if (epBean.getPostProcLocation() != null) {
                String prePocLoc = extractUtils.getEndFilePath(epBean.getPostProcLocation(), dsBean, sdfDir, datasetFilePath);
                epBean.setPostProcLocation(prePocLoc);
            }
            extractUtils.setAllProps(epBean, dsBean, sdfDir, datasetFilePath);
            SimpleTrigger trigger = null;
            trigger = xsltService.generateXsltTrigger(scheduler, xsltPath, // xml_file_path
            generalFileDir, endFilePath + File.separator, exportFileName, dsBean.getId(), epBean, userBean, LocaleResolver.getLocale(request).getLanguage(), cnt, SQLInitServlet.getField("filePath") + "xslt", TRIGGER_GROUP_JOB);
            //Updating the original trigger with user given inputs
            trigger.getTriggerBuilder().withDescription(jobDesc).startAt(startDateTime).forJob(jobName).withSchedule(simpleSchedule().withIntervalInSeconds(new Long(XsltTriggerService.getIntervalTime(period)).intValue()).withRepeatCount(64000).withMisfireHandlingInstructionNextWithExistingCount());
            trigger.getJobDataMap().put(XsltTriggerService.EMAIL, email);
            trigger.getJobDataMap().put(XsltTriggerService.PERIOD, period);
            trigger.getJobDataMap().put(XsltTriggerService.EXPORT_FORMAT, epBean.getFiledescription());
            trigger.getJobDataMap().put(XsltTriggerService.EXPORT_FORMAT_ID, exportFormatId);
            trigger.getJobDataMap().put(XsltTriggerService.JOB_NAME, jobName);
            JobDetailFactoryBean JobDetailFactoryBean = new JobDetailFactoryBean();
            JobDetailFactoryBean.setGroup(xsltService.TRIGGER_GROUP_NAME);
            JobDetailFactoryBean.setName(trigger.getKey().getName());
            JobDetailFactoryBean.setJobClass(org.akaza.openclinica.job.XsltStatefulJob.class);
            JobDetailFactoryBean.setJobDataMap(trigger.getJobDataMap());
            // need durability?
            JobDetailFactoryBean.setDurability(true);
            try {
                // scheduler.unscheduleJob(triggerName, "DEFAULT");
                scheduler.deleteJob(new JobKey(triggerName, XsltTriggerService.TRIGGER_GROUP_NAME));
                Date dataStart = scheduler.scheduleJob(JobDetailFactoryBean.getObject(), trigger);
                // Date dateStart = scheduler.rescheduleJob(triggerName,
                // "DEFAULT", trigger);
                // scheduler.rescheduleJob(triggerName, groupName,
                // newTrigger)
                addPageMessage("Your job has been successfully modified.");
                forwardPage(Page.VIEW_JOB_SERVLET);
            } catch (SchedulerException se) {
                se.printStackTrace();
                // set a message here with the exception message
                setUpServlet(trigger);
                addPageMessage("There was an unspecified error with your creation, please contact an administrator.");
                forwardPage(Page.UPDATE_JOB_EXPORT);
            }
        }
    }
}
Also used : CoreResources(org.akaza.openclinica.dao.core.CoreResources) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ExtractUtils(org.akaza.openclinica.service.extract.ExtractUtils) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ExtractPropertyBean(org.akaza.openclinica.bean.extract.ExtractPropertyBean) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) TriggerService(org.akaza.openclinica.web.job.TriggerService) SimpleDateFormat(java.text.SimpleDateFormat) JobDetailFactoryBean(org.springframework.scheduling.quartz.JobDetailFactoryBean)

Example 22 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class ResetPasswordServlet method processRequest.

/**
     * Tasks include:
     * <ol>
     * <li>Validation:
     * <ol>
     * <li>1. old password match database record
     * <li>2. new password is follows requirements
     * <li>4. two times entered passwords are same
     * <li>5. all required fields are filled
     * </ol>
     * <li>Update ub - UserAccountBean - in session and database
     * </ol>
     */
@Override
public void processRequest() throws Exception {
    logger.info("Change expired password");
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    Validator v = new Validator(request);
    errors.clear();
    FormProcessor fp = new FormProcessor(request);
    String mustChangePwd = request.getParameter("mustChangePwd");
    String newPwd = fp.getString("passwd").trim();
    String passwdChallengeQ = fp.getString("passwdChallengeQ");
    String passwdChallengeA = fp.getString("passwdChallengeA");
    if ("yes".equalsIgnoreCase(mustChangePwd)) {
        addPageMessage(respage.getString("your_password_has_expired_must_change"));
    } else {
        addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
    }
    request.setAttribute("mustChangePass", mustChangePwd);
    String oldPwd = fp.getString("oldPasswd").trim();
    // user bean from web
    UserAccountBean ubForm = new UserAccountBean();
    // form
    ubForm.setPasswd(oldPwd);
    ubForm.setPasswdChallengeQuestion(passwdChallengeQ);
    ubForm.setPasswdChallengeAnswer(passwdChallengeA);
    request.setAttribute("userBean1", ubForm);
    SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
    if (!sm.isPasswordValid(ub.getPasswd(), oldPwd, getUserDetails())) {
        Validator.addError(errors, "oldPasswd", resexception.getString("wrong_old_password"));
        request.setAttribute("formMessages", errors);
        forwardPage(Page.RESET_PASSWORD);
    } else {
        if (mustChangePwd.equalsIgnoreCase("yes")) {
            v.addValidation("passwd", Validator.NO_BLANKS);
            v.addValidation("passwd1", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeQ", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeA", Validator.NO_BLANKS);
            v.addValidation("passwd", Validator.CHECK_DIFFERENT, "oldPasswd");
        }
        String newDigestPass = sm.encrytPassword(newPwd, getUserDetails());
        List<String> pwdErrors = new ArrayList<String>();
        if (!StringUtils.isEmpty(newPwd)) {
            v.addValidation("passwd", Validator.IS_A_PASSWORD);
            v.addValidation("passwd1", Validator.CHECK_SAME, "passwd");
            ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
            PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
            Locale locale = LocaleResolver.getLocale(request);
            ResourceBundle resexception = ResourceBundleProvider.getExceptionsBundle(locale);
            pwdErrors = PasswordValidator.validatePassword(passwordRequirementsDao, udao, ub.getId(), newPwd, newDigestPass, resexception);
        }
        errors = v.validate();
        for (String err : pwdErrors) {
            v.addError(errors, "passwd", err);
        }
        if (!errors.isEmpty()) {
            logger.info("ResetPassword page has validation errors");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.RESET_PASSWORD);
        } else {
            logger.info("ResetPassword page has no errors");
            if (!StringUtils.isBlank(newPwd)) {
                ub.setPasswd(newDigestPass);
                ub.setPasswdTimestamp(new Date());
            } else if ("no".equalsIgnoreCase(mustChangePwd)) {
                ub.setPasswdTimestamp(new Date());
            }
            ub.setOwner(ub);
            // when update ub, updator id is required
            ub.setUpdater(ub);
            ub.setPasswdChallengeQuestion(passwdChallengeQ);
            ub.setPasswdChallengeAnswer(passwdChallengeA);
            udao.update(ub);
            ArrayList<String> pageMessages = new ArrayList<String>();
            request.setAttribute(PAGE_MESSAGE, pageMessages);
            addPageMessage(respage.getString("your_expired_password_reset_successfully"));
            ub.incNumVisitsToMainMenu();
            forwardPage(Page.MENU_SERVLET);
        }
    }
}
Also used : Locale(java.util.Locale) ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) SecurityManager(org.akaza.openclinica.core.SecurityManager) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ResourceBundle(java.util.ResourceBundle) PasswordRequirementsDao(org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao) Validator(org.akaza.openclinica.control.form.Validator)

Example 23 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class UpdateProfileServlet method processRequest.

@Override
public void processRequest() throws Exception {
    // action sent by user
    String action = request.getParameter("action");
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean userBean1 = (UserAccountBean) udao.findByUserName(ub.getName());
    Collection studies = sdao.findAllByUser(ub.getName());
    if (StringUtils.isBlank(action)) {
        request.setAttribute("studies", studies);
        session.setAttribute("userBean1", userBean1);
        forwardPage(Page.UPDATE_PROFILE);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            logger.info("confirm");
            request.setAttribute("studies", studies);
            confirmProfile(userBean1, udao);
        } else if ("submit".equalsIgnoreCase(action)) {
            logger.info("submit");
            submitProfile(udao);
            addPageMessage(respage.getString("profile_updated_succesfully"));
            ub.incNumVisitsToMainMenu();
            forwardPage(Page.MENU_SERVLET);
        }
    }
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Collection(java.util.Collection) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 24 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class AssignUserToStudyServlet method findUsers.

/**
     * Find all users in the system
     * 
     * @return
     */
private ArrayList findUsers() {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userList = (ArrayList) udao.findAll();
    ArrayList userAvailable = new ArrayList();
    for (int i = 0; i < userList.size(); i++) {
        UserAccountBean u = (UserAccountBean) userList.get(i);
        int activeStudyId = currentStudy.getId();
        StudyUserRoleBean sub = udao.findRoleByUserNameAndStudyId(u.getName(), activeStudyId);
        if (!sub.isActive()) {
            // doesn't have a role in the current study
            sub.setRole(Role.RESEARCHASSISTANT);
            sub.setStudyId(activeStudyId);
            u.setActiveStudyId(activeStudyId);
            u.addRole(sub);
            u.setStatus(Status.AVAILABLE);
            // try to find whether this user has role in site or parent
            if (currentStudy.getParentStudyId() > 0) {
                // this is a site
                StudyUserRoleBean subParent = udao.findRoleByUserNameAndStudyId(u.getName(), currentStudy.getParentStudyId());
                if (subParent.isActive()) {
                    u.setNotes(subParent.getRole().getDescription() + " " + respage.getString("in_parent_study"));
                }
            } else {
                // find all the sites for this top study
                StudyDAO sdao = new StudyDAO(sm.getDataSource());
                ArrayList sites = (ArrayList) sdao.findAllByParent(currentStudy.getId());
                String notes = "";
                for (int j = 0; j < sites.size(); j++) {
                    StudyBean site = (StudyBean) sites.get(j);
                    StudyUserRoleBean subSite = udao.findRoleByUserNameAndStudyId(u.getName(), site.getId());
                    if (subSite.isActive()) {
                        notes = notes + subSite.getRole().getDescription() + respage.getString("in_site") + ":" + site.getName() + "; ";
                    }
                }
                u.setNotes(notes);
            }
        } else {
            // already have a role in the current study
            sub.setStudyId(activeStudyId);
            u.setActiveStudyId(activeStudyId);
            u.addRole(sub);
            u.setStatus(Status.UNAVAILABLE);
        }
        userAvailable.add(u);
    }
    return userAvailable;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 25 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.

the class RequestAccountServlet method getUserBean.

/**
     * Constructs userbean from request
     *
     * @param request
     * @return
     */
private UserAccountBean getUserBean() {
    FormProcessor fp = new FormProcessor(request);
    UserAccountBean ubForm = new UserAccountBean();
    ubForm.setName(fp.getString("name"));
    ubForm.setFirstName(fp.getString("firstName"));
    ubForm.setLastName(fp.getString("lastName"));
    ubForm.setEmail(fp.getString("email"));
    ubForm.setInstitutionalAffiliation(fp.getString("institutionalAffiliation"));
    ubForm.setActiveStudyId(fp.getInt("activeStudyId"));
    StudyUserRoleBean uRole = new StudyUserRoleBean();
    uRole.setStudyId(fp.getInt("activeStudyId"));
    uRole.setRole(Role.get(fp.getInt("activeStudyRole")));
    ubForm.addRole(uRole);
    return ubForm;
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Aggregations

UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)152 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)64 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)56 ArrayList (java.util.ArrayList)52 HashMap (java.util.HashMap)38 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)36 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)35 Date (java.util.Date)32 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)32 Locale (java.util.Locale)30 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)18 Iterator (java.util.Iterator)16 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)16 ResponseEntity (org.springframework.http.ResponseEntity)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)15 Validator (org.akaza.openclinica.control.form.Validator)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Role (org.akaza.openclinica.bean.core.Role)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)10