use of org.akaza.openclinica.dao.login.UserAccountDAO 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(triggerName, groupName);
if (trigger == null) {
groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
trigger = scheduler.getTrigger(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.getName());
triggerBean.setPreviousDate(trigger.getPreviousFireTime());
triggerBean.setNextDate(trigger.getNextFireTime());
// >> set active here, tbh 10/08/2009
if (scheduler.getTriggerState(triggerName, groupName) == Trigger.STATE_PAUSED) {
triggerBean.setActive(false);
logger.debug("setting active to false for trigger: " + trigger.getName());
} else {
triggerBean.setActive(true);
logger.debug("setting active to TRUE for trigger: " + trigger.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.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);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO 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);
techAdminProtect(user);
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);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class RuleController method getUserAccount.
private UserAccountBean getUserAccount() {
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);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteController method buidDiscrepancyNote.
@RequestMapping(value = "/dnote", method = RequestMethod.POST)
public ResponseEntity buidDiscrepancyNote(@RequestBody HashMap<String, String> map, HttpServletRequest request) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
System.out.println("I'm in EnketoForm DN Rest Method");
org.springframework.http.HttpStatus httpStatus = null;
String se_oid = map.get("EntityID");
String ordinal = map.get("Ordinal");
// start_date , end_date , location
String entityName = map.get("EntityName");
String studySubjectOid = map.get("SS_OID");
String noteType = map.get("NoteType");
String resolutionStatus = map.get("Status");
String assignedUser = map.get("AssignedUser");
String owner = map.get("Owner");
String description = map.get("Description");
String detailedNotes = map.get("DetailedNote");
String dn_id = map.get("DN_Id");
dn_id = dn_id != null ? dn_id.replaceFirst("DN_", "") : dn_id;
UserAccountDAO udao = new UserAccountDAO(dataSource);
StudySubjectDAO ssdao = new StudySubjectDAO(dataSource);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
StudyEventDAO sedao = new StudyEventDAO(dataSource);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(assignedUser);
UserAccountBean ownerBean = (UserAccountBean) request.getSession().getAttribute("userBean");
StudySubjectBean ssBean = ssdao.findByOid(studySubjectOid);
StudyEventDefinitionBean sedBean = seddao.findByOid(se_oid);
StudyBean studyBean = getStudy(sedBean.getStudyId());
StudyEventBean seBean = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(ssBean.getId(), sedBean.getId(), Integer.valueOf(ordinal));
String entityType = "studyEvent";
DiscrepancyNoteBean parent = (DiscrepancyNoteBean) dndao.findByPK(Integer.valueOf(dn_id));
if (!mayProceed(resolutionStatus, noteType, seBean, entityName, parent, ownerBean)) {
httpStatus = org.springframework.http.HttpStatus.BAD_REQUEST;
return new ResponseEntity(httpStatus);
}
if (!parent.isActive()) {
saveFieldNotes(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
} else {
createDiscrepancyNoteBean(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, parent.getId(), resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
}
return new ResponseEntity(httpStatus);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class AccountController method getAccountByUserName.
/**
* @api {post} /pages/accounts/login Retrieve a user account
* @apiName getAccountByUserName
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} username OC login Username.
* @apiParam {String} password OC login Password .
* @apiGroup User Account
* @apiDescription Retrieve a user account
* @apiParamExample {json} Request-Example:
* {
* "username": "usera",
* "password": "password"
* }
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 401 Bad Credentials
* {
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "lastName": "User",
* "username": "root",
* "roles": [
* {"roleName": "director", "studyOID": "S_DEFAULTS1"},
* {"roleName": "Data Specialist", "studyOID": "S_JAPSTUDY_5293"}
* ],
* "firstName": "Root",
* "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
* "apiKey": "6e8b69f6fb774e899f9a6c349c5adace"
* }
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<HashMap> getAccountByUserName(@RequestBody HashMap<String, String> requestMap) throws Exception {
String userName = (requestMap.get("username")).trim();
String password = (requestMap.get("password")).trim();
Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
try {
authentication = authenticationManager.authenticate(authentication);
} catch (Exception bce) {
return new ResponseEntity<HashMap>(new HashMap(), org.springframework.http.HttpStatus.UNAUTHORIZED);
}
ResourceBundleProvider.updateLocale(new Locale("en_US"));
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
HashMap<String, Object> userDTO = new HashMap<String, Object>();
UserAccountBean userAccountBean = (UserAccountBean) userAccountDAO.findByUserName(userName);
if (null != userAccountBean) {
userDTO.put("username", userName);
userDTO.put("password", userAccountBean.getPasswd());
userDTO.put("firstName", userAccountBean.getFirstName());
userDTO.put("lastName", userAccountBean.getLastName());
userDTO.put("apiKey", userAccountBean.getApiKey());
ArrayList<HashMap<String, String>> rolesDTO = new ArrayList<>();
for (StudyUserRoleBean role : (List<StudyUserRoleBean>) userAccountBean.getRoles()) {
if (role.getStatus().isAvailable()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("roleName", role.getRoleName());
map.put("studyOID", ((StudyBean) studyDAO.findByPK(role.getStudyId())).getOid());
rolesDTO.add(map);
}
}
userDTO.put("roles", rolesDTO);
} else {
return new ResponseEntity<HashMap>(new HashMap(), org.springframework.http.HttpStatus.UNAUTHORIZED);
}
return new ResponseEntity<HashMap>(userDTO, org.springframework.http.HttpStatus.OK);
}
Aggregations