Search in sources :

Example 91 with UserAccountBean

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

the class CreateJobExportServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    // TODO multi stage servlet which will create export jobs
    // will accept, create, and return the ViewJob servlet
    FormProcessor fp = new FormProcessor(request);
    TriggerService triggerService = new TriggerService();
    scheduler = getScheduler();
    String action = fp.getString("action");
    ExtractUtils extractUtils = new ExtractUtils();
    if (StringUtil.isBlank(action)) {
        // set up list of data sets
        // select by ... active study
        setUpServlet();
        forwardPage(Page.CREATE_JOB_EXPORT);
    } else if ("confirmall".equalsIgnoreCase(action)) {
        // collect form information
        Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals("DEFAULT"));
        String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
        HashMap errors = validateForm(fp, request, triggerNames, "");
        if (!errors.isEmpty()) {
            // set errors to request
            request.setAttribute("formMessages", errors);
            logger.info("has validation errors in the first section");
            logger.info("errors found: " + errors.toString());
            setUpServlet();
            forwardPage(Page.CREATE_JOB_EXPORT);
        } else {
            logger.info("found no validation errors, continuing");
            StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
            DatasetDAO datasetDao = new DatasetDAO(sm.getDataSource());
            UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
            CoreResources cr = new CoreResources();
            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());
            // set the job in motion
            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];
            // need to set the dataset path here, tbh
            // next, can already run jobs, translations, and then add a message to be notified later
            //JN all the properties need to have the variables...
            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 = getEndFilePath(epBean.getPostProcExportName(),dsBean,sdfDir);
                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", xsltService.getTriggerGroupNameForExportJobs());
            //Updating the original trigger with user given inputs
            trigger.getTriggerBuilder().withSchedule(simpleSchedule().withRepeatCount(64000).withIntervalInSeconds(new Integer(period).intValue()).withMisfireHandlingInstructionNextWithExistingCount()).startAt(startDateTime).forJob(jobName).withDescription(jobDesc);
            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);
            trigger.getJobDataMap().put("job_type", "exportJob");
            JobDetailFactoryBean JobDetailFactoryBean = new JobDetailFactoryBean();
            JobDetailFactoryBean.setGroup(xsltService.getTriggerGroupNameForExportJobs());
            JobDetailFactoryBean.setName(trigger.getKey().getName());
            JobDetailFactoryBean.setJobClass(org.akaza.openclinica.job.XsltStatefulJob.class);
            JobDetailFactoryBean.setJobDataMap(trigger.getJobDataMap());
            // need durability?
            JobDetailFactoryBean.setDurability(true);
            // set to the scheduler
            try {
                Date dateStart = scheduler.scheduleJob(JobDetailFactoryBean.getObject(), trigger);
                logger.info("== found job date: " + dateStart.toString());
            // set a success message here
            } catch (SchedulerException se) {
                se.printStackTrace();
                setUpServlet();
                addPageMessage("Error creating Job.");
                forwardPage(Page.VIEW_JOB_SERVLET);
                return;
            }
            setUpServlet();
            addPageMessage("You have successfully created a new job: " + jobName + " which is now set to run at the time you specified.");
            forwardPage(Page.VIEW_JOB_SERVLET);
        }
    } else {
        forwardPage(Page.ADMIN_SYSTEM);
    // forward to form
    // should we even get to this part?
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) CoreResources(org.akaza.openclinica.dao.core.CoreResources) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) TriggerService(org.akaza.openclinica.web.job.TriggerService) 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) SimpleTrigger(org.quartz.SimpleTrigger) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat) JobDetailFactoryBean(org.springframework.scheduling.quartz.JobDetailFactoryBean)

Example 92 with UserAccountBean

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

the class CreateUserAccountServlet 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 93 with UserAccountBean

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

the class ViewSingleJobServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // changes to this servlet, we now look at group name too, tbh 05/2009
    String triggerName = fp.getString("tname");
    String gName = fp.getString("gname");
    String groupName = "";
    if (gName.equals("") || gName.equals("0")) {
        groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
    } else {
        // if (gName.equals("1")) {
        groupName = TRIGGER_IMPORT_GROUP;
    }
    // << tbh 09/03/2009 #4143
    scheduler = getScheduler();
    Trigger trigger = scheduler.getTrigger(new TriggerKey(triggerName, groupName));
    if (trigger == null) {
        groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
        trigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), groupName));
    }
    // << tbh 09/03/2009 #4143
    // above is a hack, if we add more trigger groups this will have
    // to be redone
    logger.debug("found trigger name: " + triggerName);
    logger.debug("found group name: " + groupName);
    TriggerBean triggerBean = new TriggerBean();
    JobDataMap dataMap = new JobDataMap();
    AuditEventDAO auditEventDAO = new AuditEventDAO(sm.getDataSource());
    try {
        triggerBean.setFullName(trigger.getKey().getName());
        triggerBean.setPreviousDate(trigger.getPreviousFireTime());
        triggerBean.setNextDate(trigger.getNextFireTime());
        // >> set active here, tbh 10/08/2009
        if (scheduler.getTriggerState(new TriggerKey(triggerName, groupName)) == Trigger.TriggerState.PAUSED) {
            triggerBean.setActive(false);
            logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
        } else {
            triggerBean.setActive(true);
            logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
        }
        // <<
        if (trigger.getDescription() != null) {
            triggerBean.setDescription(trigger.getDescription());
        }
        if (trigger.getJobDataMap().size() > 0) {
            dataMap = trigger.getJobDataMap();
            String contactEmail = dataMap.getString(XsltTriggerService.EMAIL);
            logger.debug("found email: " + contactEmail);
            // int dsId = new Integer(datasetId).intValue();
            if (gName.equals("") || gName.equals("0")) {
                String exportFormat = dataMap.getString(XsltTriggerService.EXPORT_FORMAT);
                String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
                // int userId = new Integer(userAcctId).intValue();
                int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
                triggerBean.setExportFormat(exportFormat);
                triggerBean.setPeriodToRun(periodToRun);
                DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
                DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
                triggerBean.setDataset(dataset);
            }
            int userId = dataMap.getInt(ExampleSpringJob.USER_ID);
            // need to set information, extract bean, user account bean
            UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
            triggerBean.setContactEmail(contactEmail);
            UserAccountBean userAccount = (UserAccountBean) userAccountDAO.findByPK(userId);
            triggerBean.setUserAccount(userAccount);
            ArrayList<AuditEventBean> triggerLogs = auditEventDAO.findAllByAuditTable(trigger.getKey().getName());
            // set the table for the audit event beans here
            ArrayList allRows = AuditEventRow.generateRowsFromBeans(triggerLogs);
            EntityBeanTable table = fp.getEntityBeanTable();
            String[] columns = { resword.getString("date_and_time"), resword.getString("action_message"), resword.getString("entity_operation"), // resword.getString("study_subject_ID"),
            resword.getString("changes_and_additions"), resword.getString("actions") };
            table.setColumns(new ArrayList(Arrays.asList(columns)));
            table.setAscendingSort(false);
            table.hideColumnLink(1);
            table.hideColumnLink(3);
            table.hideColumnLink(4);
            table.setQuery("ViewSingleJob?tname=" + triggerName + "&gname=" + gName, new HashMap());
            table.setRows(allRows);
            table.computeDisplay();
            request.setAttribute("table", table);
        }
    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        logger.debug(" found NPE " + e.getMessage());
        e.printStackTrace();
    }
    // need to show the extract for which this runs, which files, etc
    // in other words the job data map
    request.setAttribute("triggerBean", triggerBean);
    request.setAttribute("groupName", groupName);
    forwardPage(Page.VIEW_SINGLE_JOB);
}
Also used : TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) AuditEventBean(org.akaza.openclinica.bean.admin.AuditEventBean)

Example 94 with UserAccountBean

use of org.akaza.openclinica.bean.login.UserAccountBean 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 95 with UserAccountBean

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

the class ViewUserAccountServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int userId = fp.getInt(ARG_USER_ID, true);
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean user = getBean(udao, userId);
    if (user.isActive()) {
        request.setAttribute("user", user);
    } else {
        throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("the_user_attemping_to_view_not_exists"));
    }
    // BWP>>To provide the view with the correct date format pattern, locale
    // sensitive
    String pattn = "";
    pattn = ResourceBundleProvider.getFormatBundle().getString("date_format_string");
    request.setAttribute("dateFormatPattern", pattn);
    forwardPage(Page.VIEW_USER_ACCOUNT);
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException)

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