use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class ExampleSpringJob method executeInternal.
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
// need to generate a Locale so that user beans and other things will
// generate normally
Locale locale = new Locale("en-US");
ResourceBundleProvider.updateLocale(locale);
ResourceBundle pageMessages = ResourceBundleProvider.getPageMessagesBundle();
// logger.debug("--");
// logger.debug("-- executing a job " + message + " at " + new
// java.util.Date().toString());
JobDataMap dataMap = context.getMergedJobDataMap();
SimpleTrigger trigger = (SimpleTrigger) context.getTrigger();
try {
ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
String studySubjectNumber = ((CoreResources) appContext.getBean("coreResources")).getField("extract.number");
coreResources = (CoreResources) appContext.getBean("coreResources");
ruleSetRuleDao = (RuleSetRuleDao) appContext.getBean("ruleSetRuleDao");
dataSource = (DataSource) appContext.getBean("dataSource");
mailSender = (OpenClinicaMailSender) appContext.getBean("openClinicaMailSender");
AuditEventDAO auditEventDAO = new AuditEventDAO(dataSource);
// Scheduler scheduler = context.getScheduler();
// JobDetail detail = context.getJobDetail();
// jobDetailBean = (JobDetailBean) detail;
/*
* data map here should coincide with the job data map found in
* CreateJobExportServlet, with the following code: jobDataMap = new
* JobDataMap(); jobDataMap.put(DATASET_ID, datasetId);
* jobDataMap.put(PERIOD, period); jobDataMap.put(EMAIL, email);
* jobDataMap.put(TAB, tab); jobDataMap.put(CDISC, cdisc);
* jobDataMap.put(SPSS, spss);
*/
String alertEmail = dataMap.getString(EMAIL);
String localeStr = dataMap.getString(LOCALE);
if (localeStr != null) {
locale = new Locale(localeStr);
ResourceBundleProvider.updateLocale(locale);
pageMessages = ResourceBundleProvider.getPageMessagesBundle();
}
int dsId = dataMap.getInt(DATASET_ID);
String tab = dataMap.getString(TAB);
String cdisc = dataMap.getString(CDISC);
String cdisc12 = dataMap.getString(CDISC12);
if (cdisc12 == null) {
cdisc12 = "0";
}
String cdisc13 = dataMap.getString(CDISC13);
if (cdisc13 == null) {
cdisc13 = "0";
}
String cdisc13oc = dataMap.getString(CDISC13OC);
if (cdisc13oc == null) {
cdisc13oc = "0";
}
String spss = dataMap.getString(SPSS);
int userId = dataMap.getInt(USER_ID);
int studyId = dataMap.getInt(STUDY_ID);
// String datasetId = dataMap.getString(DATASET_ID);
// int dsId = new Integer(datasetId).intValue();
// String userAcctId = dataMap.getString(USER_ID);
// int userId = new Integer(userAcctId).intValue();
// why the flip-flop? if one property is set to 'true' we can
// see jobs in another screen but all properties have to be
// strings
logger.debug("-- found the job: " + dsId + " dataset id");
// for (Iterator it = dataMap.entrySet().iterator(); it.hasNext();)
// {
// java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
// Object key = entry.getKey();
// Object value = entry.getValue();
// // logger.debug("-- found datamap property: " + key.toString() +
// // " : " + value.toString());
// }
HashMap fileName = new HashMap<String, Integer>();
if (dsId > 0) {
// trying to not throw an error if there's no dataset id
DatasetDAO dsdao = new DatasetDAO(dataSource);
DatasetBean datasetBean = (DatasetBean) dsdao.findByPK(dsId);
StudyDAO studyDao = new StudyDAO(dataSource);
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
// hmm, three lines in the if block DRY?
String generalFileDir = "";
String generalFileDirCopy = "";
String exportFilePath = SQLInitServlet.getField("exportFilePath");
String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator;
SimpleDateFormat sdfDir = new SimpleDateFormat(pattern);
generalFileDir = DATASET_DIR + datasetBean.getId() + File.separator + sdfDir.format(new java.util.Date());
if (!"".equals(exportFilePath)) {
generalFileDirCopy = SQLInitServlet.getField("filePath") + exportFilePath + File.separator;
}
// logger.debug("-- created the following dir: " +
// generalFileDir);
long sysTimeBegin = System.currentTimeMillis();
// set up the user bean here, tbh
// logger.debug("-- gen tab file 00");
userBean = (UserAccountBean) userAccountDAO.findByPK(userId);
// needs to also be captured by the servlet, tbh
// logger.debug("-- gen tab file 00");
generateFileService = new GenerateExtractFileService(dataSource, coreResources, ruleSetRuleDao);
// logger.debug("-- gen tab file 00");
// tbh #5796 - covers a bug when the user changes studies, 10/2010
StudyBean activeStudy = (StudyBean) studyDao.findByPK(studyId);
StudyBean parentStudy = new StudyBean();
logger.debug("active study: " + studyId + " parent study: " + activeStudy.getParentStudyId());
if (activeStudy.getParentStudyId() > 0) {
// StudyDAO sdao = new StudyDAO(sm.getDataSource());
parentStudy = (StudyBean) studyDao.findByPK(activeStudy.getParentStudyId());
} else {
parentStudy = activeStudy;
// covers a bug in tab file creation, tbh 01/2009
}
logger.debug("-- found extract bean ");
ExtractBean eb = generateFileService.generateExtractBean(datasetBean, activeStudy, parentStudy);
MessageFormat mf = new MessageFormat("");
StringBuffer message = new StringBuffer();
StringBuffer auditMessage = new StringBuffer();
// use resource bundle page messages to generate the email, tbh
// 02/2009
// message.append(pageMessages.getString("html_email_header_1")
// + " " + alertEmail +
// pageMessages.getString("html_email_header_2") + "<br/>");
message.append("<p>" + pageMessages.getString("email_header_1") + " " + EmailEngine.getAdminEmail() + " " + pageMessages.getString("email_header_2") + " Job Execution " + pageMessages.getString("email_header_3") + "</p>");
message.append("<P>Dataset: " + datasetBean.getName() + "</P>");
message.append("<P>Study: " + activeStudy.getName() + "</P>");
message.append("<p>" + pageMessages.getString("html_email_body_1") + datasetBean.getName() + pageMessages.getString("html_email_body_2") + SQLInitServlet.getField("sysURL") + pageMessages.getString("html_email_body_3") + "</p>");
// logger.debug("-- gen tab file 00");
if ("1".equals(tab)) {
logger.debug("-- gen tab file 01");
fileName = generateFileService.createTabFile(eb, sysTimeBegin, generalFileDir, datasetBean, activeStudy.getId(), parentStudy.getId(), generalFileDirCopy, userBean);
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_tab_delimited"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your tab-delimited file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_tab_delimited") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc)) {
String odmVersion = "oc1.2";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_12"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.2 w/OpenClinica Extension XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName)
// + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_12") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc12)) {
String odmVersion = "1.2";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.2 default");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_12_xml"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// // auditMessage.append(
// "You can access your ODM 1.2 XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_12_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc13)) {
String odmVersion = "1.3";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.3");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_13"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.3 XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_13") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc13oc)) {
String odmVersion = "oc1.3";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.3 oc");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_13_xml"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.3 w/OpenClinica Extension XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName)
// + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_13_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(spss)) {
SPSSReportBean answer = new SPSSReportBean();
fileName = generateFileService.createSPSSFile(datasetBean, eb, activeStudy, parentStudy, sysTimeBegin, generalFileDir, answer, generalFileDirCopy, userBean);
logger.debug("-- gen spss file");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_spss"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your SPSS files <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_spss") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
// wrap up the message, and send the email
message.append("<p>" + pageMessages.getString("html_email_body_5") + "</P><P>" + pageMessages.getString("email_footer"));
try {
mailSender.sendEmail(alertEmail.trim(), pageMessages.getString("job_ran_for") + " " + datasetBean.getName(), message.toString(), true);
} catch (OpenClinicaSystemException ose) {
// Do Nothing, In the future we might want to have an email
// status added to system.
}
TriggerBean triggerBean = new TriggerBean();
triggerBean.setDataset(datasetBean);
triggerBean.setUserAccount(userBean);
triggerBean.setFullName(trigger.getKey().getName());
auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessage.toString());
} else {
TriggerBean triggerBean = new TriggerBean();
// triggerBean.setDataset(datasetBean);
triggerBean.setUserAccount(userBean);
triggerBean.setFullName(trigger.getKey().getName());
auditEventDAO.createRowForExtractDataJobFailure(triggerBean);
// logger.debug("-- made it here for some reason, ds id: "
// + dsId);
}
// logger.debug("-- generated file: " + fileNameStr);
// dataSource.
} catch (Exception e) {
// TODO Auto-generated catch block -- ideally should generate a fail
// msg here, tbh 02/2009
logger.debug("-- found exception: " + e.getMessage());
e.printStackTrace();
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO 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());
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class Validator method validate.
protected HashMap validate(String fieldName, Validation v) {
switch(v.getType()) {
case NO_BLANKS:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_NUMBER:
if (!isNumber(fieldName)) {
addError(fieldName, v);
}
break;
case IS_IN_RANGE:
float lowerBound = v.getFloat(0);
float upperBound = v.getFloat(1);
if (!isInRange(fieldName, lowerBound, upperBound)) {
addError(fieldName, v);
}
break;
case IS_A_DATE:
if (!isDate(fieldName)) {
addError(fieldName, v);
}
break;
case IS_DATE_TIME:
if (!isDateTime(fieldName)) {
addError(fieldName, v);
}
break;
case CHECK_SAME:
String compareField = v.getString(0);
if (!isSame(fieldName, compareField)) {
addError(fieldName, v);
}
break;
case IS_A_EMAIL:
if (!isEmail(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_PHONE_NUMBER:
if (!isPhoneNumber(fieldName)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS:
EntityDAO edao = (EntityDAO) v.getArg(0);
if (!entityExists(fieldName, edao)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS_IN_STUDY:
AuditableEntityDAO dao = (AuditableEntityDAO) v.getArg(0);
StudyBean study = (StudyBean) v.getArg(1);
if (!entityExistsInStudy(fieldName, dao, study)) {
addError(fieldName, v);
}
break;
case USERNAME_UNIQUE:
UserAccountDAO udao = (UserAccountDAO) v.getArg(0);
if (!usernameUnique(fieldName, udao)) {
addError(fieldName, v);
}
break;
case IS_AN_INTEGER:
if (!isInteger(fieldName)) {
addError(fieldName, v);
}
break;
// break;
case IS_IN_SET:
ArrayList set = (ArrayList) v.getArg(0);
if (!isInSet(fieldName, set)) {
addError(fieldName, v);
}
break;
case IS_A_PASSWORD:
if (!lengthComparesToStaticValue(fieldName, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, PASSWORD_MINIMUM_LENGTH)) {
addError(fieldName, v);
}
break;
case IS_A_USERNAME:
if (!isUsername(fieldName)) {
addError(fieldName, v);
}
break;
case IS_VALID_TERM:
TermType termType = (TermType) v.getArg(0);
if (!isValidTerm(fieldName, termType)) {
addError(fieldName, v);
}
break;
case COMPARES_TO_STATIC_VALUE:
NumericComparisonOperator operator = (NumericComparisonOperator) v.getArg(0);
float compareTo = v.getFloat(1);
if (!comparesToStaticValue(fieldName, operator, compareTo)) {
addError(fieldName, v);
}
break;
case LENGTH_NUMERIC_COMPARISON:
NumericComparisonOperator operator2 = (NumericComparisonOperator) v.getArg(0);
int compareTo2 = v.getInt(1);
if (!lengthComparesToStaticValue(fieldName, operator2, compareTo2)) {
addError(fieldName, v);
}
break;
case DATE_IS_AFTER_OR_EQUAL:
String earlierDateFieldName = v.getString(0);
if (!isDateAfterOrEqual(fieldName, earlierDateFieldName)) {
addError(fieldName, v);
}
break;
case NO_BLANKS_SET:
if (isSetBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET:
ResponseSetBean rsb = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsb, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_COMMA_SEPERATED:
ResponseSetBean rsbs = (ResponseSetBean) v.getArg(0);
if (!isInResponseSetCommaSeperated(fieldName, rsbs, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_SINGLE_VALUE:
ResponseSetBean rsbSingle = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsbSingle, false)) {
addError(fieldName, v);
}
break;
case MATCHES_INITIAL_DATA_ENTRY_VALUE:
String oldValue = v.getString(0);
boolean isMultiple = v.getBoolean(1);
if (!valueMatchesInitialValue(fieldName, oldValue, isMultiple)) {
addError(fieldName, v);
}
break;
case DIFFERENT_NUMBER_OF_GROUPS_IN_DDE:
addError(fieldName, v);
break;
case IS_REQUIRED:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case DATE_IN_PAST:
if (!isDateInPast(fieldName)) {
addError(fieldName, v);
}
break;
case MATCHES_REGULAR_EXPRESSION:
if (!matchesRegex(fieldName, v.getString(0))) {
addError(fieldName, v);
}
break;
case CHECK_DIFFERENT:
String old = v.getString(0);
if (isSame(fieldName, old)) {
addError(fieldName, v);
}
break;
case IS_A_DATE_WITHOUT_REQUIRED_CHECK:
if (!isDateWithoutRequiredCheck(fieldName)) {
addError(fieldName, v);
}
break;
case CALCULATION_FAILED:
addError(fieldName, v);
break;
case IS_AN_RULE:
ArrayList<String> messages = (ArrayList<String>) v.getArg(0);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < messages.size(); i++) {
sb.append(messages.get(i));
if (i != messages.size() - 1)
sb.append(" , ");
logger.debug(messages.get(i));
}
v.setErrorMessage(sb.toString());
addError(fieldName, v);
break;
case IS_PARTIAL_DATE:
boolean isPDate = Boolean.FALSE;
String fieldValue = getFieldValue(fieldName);
if (fieldValue != null) {
// resformat.getString("date_format_string"))) {
if (StringUtil.isFormatDate(fieldValue, resformat.getString("date_format_string")) || StringUtil.isPartialYear(fieldValue, "yyyy") || StringUtil.isPartialYearMonth(fieldValue, resformat.getString("date_format_year_month"))) {
isPDate = true;
}
}
if (!isPDate) {
addError(fieldName, v);
}
break;
case IS_VALID_WIDTH_DECIMAL:
ArrayList<String> params = (ArrayList<String>) v.getArg(0);
String dataType = params.get(0);
String widthDecimal = params.get(1);
StringBuffer error = this.validateFieldWidthDecimal(fieldName, dataType, widthDecimal);
if (error.length() > 0) {
addError(fieldName, error.toString());
}
break;
case BARCODE_EAN_13:
EanCheckDigit eanChk = new EanCheckDigit();
if (!eanChk.isValid(getFieldValue(fieldName))) {
addError(fieldName, v);
}
break;
case TO_HIDE_CONDITIONAL_DISPLAY:
addError(fieldName, v);
break;
}
return errors;
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class SetUpUserInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
Locale locale = ResourceBundleProvider.localeMap.get(Thread.currentThread());
if (locale == null) {
ResourceBundleProvider.updateLocale(httpServletRequest.getLocale());
}
//Set up the user account bean: check the Session first
HttpSession currentSession = httpServletRequest.getSession();
UserAccountBean userBean = (UserAccountBean) currentSession.getAttribute("userBean");
String userName = "";
boolean userBeanIsInvalid;
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
if (userBean == null) {
userName = httpServletRequest.getRemoteUser();
userBeanIsInvalid = "".equalsIgnoreCase(userName);
if (!userBeanIsInvalid) {
userBean = (UserAccountBean) userAccountDAO.findByUserName(userName);
userBeanIsInvalid = (userBean == null);
if (!userBeanIsInvalid) {
currentSession.setAttribute(USER_BEAN_NAME, userBean);
}
}
}
//The user bean could still be null at this point
if (userBean == null) {
userBean = new UserAccountBean();
userBean.setName("unknown");
currentSession.setAttribute(USER_BEAN_NAME, userBean);
}
userBean = userBean.getId() > 0 ? (UserAccountBean) userAccountDAO.findByPK(userBean.getId()) : userBean;
SetUpStudyRole setupStudy = new SetUpStudyRole(dataSource);
setupStudy.setUp(currentSession, userBean);
return true;
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class UserPermissionInterceptor method handleRequest.
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
UserAccountBean userAccountBean = ((UserAccountBean) userAccountDao.findByUserName(username));
Boolean result = userAccountBean.getRunWebservices();
if (!result) {
SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
response.addClientOrSenderFault("Authorization is required to execute SOAP web services with this account.Please contact your administrator.", Locale.ENGLISH);
return false;
} else {
return result;
}
}
Aggregations