Search in sources :

Example 61 with UserAccountBean

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

the class UserAccountController method getUserAccount.

private UserAccountBean getUserAccount(String userName) {
    udao = new UserAccountDAO(dataSource);
    UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(userName);
    return userAccountBean;
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 62 with UserAccountBean

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

the class UserAccountController method buildUserAccount.

private UserAccountBean buildUserAccount(String username, String fName, String lName, String password, String institution, StudyBean study, UserAccountBean ownerUserAccount, String email, String passwordHash, Boolean authorizeSoap, Role roleName, UserType userType) throws Exception {
    UserAccountBean createdUserAccountBean = new UserAccountBean();
    createdUserAccountBean.setName(username);
    createdUserAccountBean.setFirstName(fName);
    createdUserAccountBean.setLastName(lName);
    createdUserAccountBean.setEmail(username);
    createdUserAccountBean.setInstitutionalAffiliation(institution);
    createdUserAccountBean.setLastVisitDate(null);
    createdUserAccountBean.setActiveStudyId(study.getId());
    createdUserAccountBean.setPasswdTimestamp(null);
    createdUserAccountBean.setPasswdChallengeQuestion("");
    createdUserAccountBean.setPasswdChallengeAnswer("");
    createdUserAccountBean.setOwner(ownerUserAccount);
    createdUserAccountBean.setRunWebservices(false);
    createdUserAccountBean.setPhone("");
    createdUserAccountBean.setAccessCode("");
    createdUserAccountBean.setPasswd(password);
    createdUserAccountBean.setEmail(email);
    createdUserAccountBean.setEnableApiKey(true);
    createdUserAccountBean.setPasswd(passwordHash);
    createdUserAccountBean.setRunWebservices(authorizeSoap);
    String apiKey = null;
    do {
        apiKey = getRandom32ChApiKey();
    } while (isApiKeyExist(apiKey));
    createdUserAccountBean.setApiKey(apiKey);
    createdUserAccountBean = addActiveStudyRole(createdUserAccountBean, study.getId(), roleName, ownerUserAccount);
    createdUserAccountBean.addUserType(userType);
    authoritiesDao.saveOrUpdate(new AuthoritiesBean(createdUserAccountBean.getName()));
    return createdUserAccountBean;
}
Also used : AuthoritiesBean(org.akaza.openclinica.domain.user.AuthoritiesBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Example 63 with UserAccountBean

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

the class UserAccountTable method showRow.

@Override
public String showRow(EntityBean e) {
    UserAccountBean u = (UserAccountBean) e;
    Status s = u.getStatus();
    // do the first row, just the "flat" properties
    String row = "<tr>\n";
    // username
    String colorOn = s.equals(Status.AVAILABLE) ? "" : "<font color='gray'>";
    String colorOff = s.equals(Status.AVAILABLE) ? "" : "</font>";
    row += "<td>" + colorOn + u.getName() + colorOff + "</td>\n";
    row += "<td>" + u.getFirstName() + "</td>\n";
    row += "<td>" + u.getLastName() + "</td>\n";
    // status
    row += "<td>" + s.getName() + "</td>\n";
    // actions
    row += "<td>";
    if (!s.equals(Status.DELETED)) {
        String confirmQuestion = "Are you sure you want to delete " + u.getName() + "?";
        String onClick = "onClick=\"return confirm('" + confirmQuestion + "');\"";
        row += "<a href='" + ViewUserAccountServlet.getLink(u.getId()) + "'>view</a>";
        row += " <a href='" + EditUserAccountServlet.getLink(u.getId()) + "'>edit</a>";
        row += " <a href='" + DeleteUserServlet.getLink(u, EntityAction.DELETE) + "'" + onClick + ">delete</a>";
    } else {
        String confirmQuestion = "Are you sure you want to restore " + u.getName() + "?";
        String onClick = "onClick=\"return confirm('" + confirmQuestion + "');\"";
        row += " <a href='" + DeleteUserServlet.getLink(u, EntityAction.RESTORE) + "'" + onClick + ">restore</a>";
    }
    row += "</td>\n";
    row += "</tr>\n";
    // do the next row, with the user's roles
    row += "<tr>\n";
    row += "<td>&nbsp;</td>\n";
    ArrayList userRoles = u.getRoles();
    // study user roles cell
    row += "<td colspan='3'>";
    if (userRoles.size() <= 0) {
        row += "<i>No roles assigned</i>";
    }
    for (int i = 0; i < userRoles.size(); i++) {
        StudyUserRoleBean sur = (StudyUserRoleBean) userRoles.get(i);
        colorOn = sur.getStatus().equals(Status.AVAILABLE) ? "" : "<font color='gray'>";
        colorOff = sur.getStatus().equals(Status.AVAILABLE) ? "" : "</font>";
        String studyName = getStudyName(sur);
        row += studyName + " - " + colorOn + sur.getRole().getDescription() + colorOff + "<br/>\n";
    }
    row += "</td>\n";
    // actions on the study user roles
    row += "<td>";
    for (int i = 0; i < userRoles.size(); i++) {
        StudyUserRoleBean sur = (StudyUserRoleBean) userRoles.get(i);
        if (!sur.getStatus().equals(Status.DELETED)) {
            String studyName = getStudyName(sur);
            String confirmQuestion = "Are you sure you want to delete the " + sur.getRole().getDescription() + " role for " + u.getName() + " in " + studyName + "?";
            row += " <a href='" + EditStudyUserRoleServlet.getLink(sur, u) + "'>edit role</a>";
            row += " <a href='" + DeleteStudyUserRoleServlet.getLink(u.getName(), sur.getStudyId(), EntityAction.DELETE) + "' onClick='return confirm(\"" + confirmQuestion + "\");'>delete role</a>";
        } else {
            String confirmQuestion = "Are you sure you want to restore the " + sur.getRole().getDescription() + " role for " + u.getName() + " in Study " + sur.getStudyId() + "?";
            row += " <a href='" + DeleteStudyUserRoleServlet.getLink(u.getName(), sur.getStudyId(), EntityAction.RESTORE) + "' onClick=\"return confirm('" + confirmQuestion + "');\">restore role</a>";
        }
        row += "<br/>\n";
    }
    row += "</td>\n";
    row += "<tr>\n";
    row += "</tr>\n";
    return row;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ArrayList(java.util.ArrayList)

Example 64 with UserAccountBean

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

the class ImportSpringJob method executeInternalInTransaction.

protected void executeInternalInTransaction(JobExecutionContext context) {
    locale = new Locale("en-US");
    ResourceBundleProvider.updateLocale(locale);
    respage = ResourceBundleProvider.getPageMessagesBundle();
    resword = ResourceBundleProvider.getWordsBundle();
    triggerService = new TriggerService();
    JobDataMap dataMap = context.getMergedJobDataMap();
    SimpleTrigger trigger = (SimpleTrigger) context.getTrigger();
    TriggerBean triggerBean = new TriggerBean();
    triggerBean.setFullName(trigger.getKey().getName());
    String contactEmail = dataMap.getString(EMAIL);
    logger.debug("=== starting to run trigger " + trigger.getKey().getName() + " ===");
    try {
        ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
        dataSource = (DataSource) appContext.getBean("dataSource");
        mailSender = (OpenClinicaMailSender) appContext.getBean("openClinicaMailSender");
        RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) appContext.getBean("ruleSetService");
        itemDataDao = new ItemDataDAO(dataSource);
        eventCrfDao = new EventCRFDAO(dataSource);
        auditEventDAO = new AuditEventDAO(dataSource);
        int userId = dataMap.getInt(USER_ID);
        UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
        UserAccountBean ub = (UserAccountBean) userAccountDAO.findByPK(userId);
        triggerBean.setUserAccount(ub);
        String directory = dataMap.getString(DIRECTORY);
        String studyName = dataMap.getString(STUDY_NAME);
        String studyOid = dataMap.getString(STUDY_OID);
        String localeStr = dataMap.getString(ExampleSpringJob.LOCALE);
        if (localeStr != null) {
            locale = new Locale(localeStr);
            ResourceBundleProvider.updateLocale(locale);
            respage = ResourceBundleProvider.getPageMessagesBundle();
            resword = ResourceBundleProvider.getWordsBundle();
        }
        StudyDAO studyDAO = new StudyDAO(dataSource);
        StudyBean studyBean;
        if (studyOid != null) {
            studyBean = studyDAO.findByOid(studyOid);
        } else {
            studyBean = (StudyBean) studyDAO.findByName(studyName);
        }
        // might also need study id here for the data service?
        File fileDirectory = new File(SQLInitServlet.getField("filePath") + DIR_PATH + File.separator);
        // File fileDirectory = new File(IMPORT_DIR);
        if ("".equals(directory)) {
        // avoid NPEs
        // do nothing here?
        } else {
            // there is a separator at the end of IMPORT_DIR already...
            // fileDirectory = new File(IMPORT_DIR + directory +
            // File.separator);
            fileDirectory = new File(SQLInitServlet.getField("filePath") + DIR_PATH + File.separator + directory + File.separator);
        }
        if (!fileDirectory.isDirectory()) {
            fileDirectory.mkdirs();
        }
        // this is necessary the first time this is run, tbh
        // File destDirectory = new File(IMPORT_DIR_2);
        File destDirectory = new File(SQLInitServlet.getField("filePath") + DEST_DIR + File.separator);
        if (!destDirectory.isDirectory()) {
            destDirectory.mkdirs();
        }
        // look at directory, if there are new files, move them over and
        // read them
        // File fileDirectory = new File(directory);
        String[] files = fileDirectory.list();
        logger.debug("found " + files.length + " files under directory " + SQLInitServlet.getField("filePath") + DIR_PATH + File.separator + directory);
        File[] target = new File[files.length];
        File[] destination = new File[files.length];
        for (int i = 0; i < files.length; i++) {
            // hmm
            if (!new File(fileDirectory + File.separator + files[i]).isDirectory()) {
                File f = new File(fileDirectory + File.separator + files[i]);
                if (f == null || f.getName() == null) {
                    logger.debug("found a null file");
                } else if (f.getName().indexOf(".xml") < 0 && f.getName().indexOf(".XML") < 0) {
                    logger.debug("does not seem to be an xml file");
                // we need a place holder to avoid 'gaps' in the file
                // list
                } else {
                    logger.debug("adding: " + f.getName());
                    // new File(IMPORT_DIR +
                    target[i] = f;
                    // directory +
                    // File.separator + files[i]);
                    // destination[i] = new File(IMPORT_DIR_2 + files[i]);
                    destination[i] = new File(SQLInitServlet.getField("filePath") + DEST_DIR + File.separator + files[i]);
                }
            }
        }
        if (target.length > 0 && destination.length > 0) {
            cutAndPaste(target, destination);
            // @pgawade 28-June-2012: Fix for issue #13964 - Remove the null
            // elements from destination array of files
            // which might be created because of presense of sub-directories
            // or non-xml files under scheduled_data_import directory
            // which are non-usable files for import.
            destination = removeNullElements(destination);
            // do everything else here with 'destination'
            ArrayList<String> auditMessages = processData(destination, dataSource, respage, resword, ub, studyBean, destDirectory, triggerBean, ruleSetService);
            auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessages.get(1));
            try {
                if (contactEmail != null && !"".equals(contactEmail)) {
                    mailSender.sendEmail(contactEmail, respage.getString("job_ran_for") + " " + triggerBean.getFullName(), generateMsg(auditMessages.get(0), contactEmail), true);
                    logger.debug("email body: " + auditMessages.get(1));
                }
            } catch (OpenClinicaSystemException e) {
                // Do nothing
                logger.error("=== throw an ocse === " + e.getMessage());
                e.printStackTrace();
            }
        } else {
            logger.debug("no real files found");
            auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, respage.getString("job_ran_but_no_files"));
        // no email here, tbh
        }
    // use the business logic to go through each one and import that
    // data
    // check to see if they were imported before?
    // using the four methods:
    // importCRFDataServce.validateStudyMetadata,
    // service.lookupValidationErrors, service.fetchEventCRFBeans(?),
    // and
    // service.generateSummaryStatsBean(for the email we send out later)
    } catch (Exception e) {
        // more detailed reporting here
        logger.error("found a fail exception: " + e.getMessage());
        e.printStackTrace();
        auditEventDAO.createRowForExtractDataJobFailure(triggerBean, e.getMessage());
        try {
            mailSender.sendEmail(contactEmail, respage.getString("job_failure_for") + " " + triggerBean.getFullName(), e.getMessage(), true);
        } catch (OpenClinicaSystemException ose) {
            // Do nothing
            logger.error("=== throw an ocse: " + ose.getMessage());
        }
    }
}
Also used : Locale(java.util.Locale) JobDataMap(org.quartz.JobDataMap) TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) JobExecutionException(org.quartz.JobExecutionException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) RuleSetServiceInterface(org.akaza.openclinica.service.rule.RuleSetServiceInterface) ApplicationContext(org.springframework.context.ApplicationContext) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SimpleTrigger(org.quartz.SimpleTrigger) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) File(java.io.File) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 65 with UserAccountBean

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

the class UserAccountRow method compareColumn.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.core.EntityBeanRow#compareColumn(java.lang.Object,
     *      int)
     */
@Override
protected int compareColumn(Object row, int sortingColumn) {
    if (!row.getClass().equals(UserAccountRow.class)) {
        return 0;
    }
    UserAccountBean thisAccount = (UserAccountBean) bean;
    UserAccountBean argAccount = (UserAccountBean) ((UserAccountRow) row).bean;
    int answer = 0;
    switch(sortingColumn) {
        case COL_USERNAME:
            answer = thisAccount.getName().toLowerCase().compareTo(argAccount.getName().toLowerCase());
            break;
        case COL_FIRSTNAME:
            answer = thisAccount.getFirstName().toLowerCase().compareTo(argAccount.getFirstName().toLowerCase());
            break;
        case COL_LASTNAME:
            answer = thisAccount.getLastName().toLowerCase().compareTo(argAccount.getLastName().toLowerCase());
            break;
        case COL_STATUS:
            answer = thisAccount.getStatus().compareTo(argAccount.getStatus());
            break;
    }
    return answer;
}
Also used : 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