use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class RemoveStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
// find all sites
ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
// find all user and roles in the study, include ones in sites
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(studyId);
// find all subjects in the study, include ones in sites
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events in the study, include ones in sites
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_remove"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRemove", study);
request.setAttribute("sitesToRemove", sites);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
request.setAttribute("definitionsToRemove", definitions);
forwardPage(Page.REMOVE_STUDY);
} else {
logger.info("submit to remove the study");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (!site.getStatus().equals(Status.DELETED)) {
site.setOldStatus(site.getStatus());
site.setStatus(Status.AUTO_DELETED);
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
logger.info("remove user role" + role.getName());
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// YW << bug fix for that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
currentRole.setStatus(Status.DELETED);
} else // (auto-removed)
if (currentStudy.getParentStudyId() == study.getId()) {
currentStudy.setStatus(Status.AUTO_DELETED);
// we may need handle this later?
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
}
}
// remove all study_group_class
// changed by jxu on 08-31-06, to fix the problem of no study_id
// in study_group table
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
// YW 09-27-2007, enable status updating for StudyGroupClassBean
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgcdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
for (int i = 0; i < groupClasses.size(); i++) {
StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
if (!gc.getStatus().equals(Status.DELETED)) {
gc.setStatus(Status.AUTO_DELETED);
gc.setUpdater(ub);
gc.setUpdatedDate(new Date());
sgcdao.update(gc);
}
}
// remove all event definitions and event
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
if (!definition.getStatus().equals(Status.DELETED)) {
definition.setStatus(Status.AUTO_DELETED);
definition.setUpdater(ub);
definition.setUpdatedDate(new Date());
sefdao.update(definition);
ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
for (int j = 0; j < edcs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for definitions
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(resexception.getString("this_study_has_been_removed_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class ListUserAccountsServlet method setStudyNamesInStudyUserRoles.
/**
* For each user, for each study user role, set the study user role's
* studyName property.
*
* @param users
* The users to display in the table of users. Each element is a
* UserAccountBean.
*/
private void setStudyNamesInStudyUserRoles(ArrayList users) {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList allStudies = (ArrayList) sdao.findAll();
HashMap studiesById = new HashMap();
int i;
for (i = 0; i < allStudies.size(); i++) {
StudyBean sb = (StudyBean) allStudies.get(i);
studiesById.put(new Integer(sb.getId()), sb);
}
for (i = 0; i < users.size(); i++) {
UserAccountBean u = (UserAccountBean) users.get(i);
ArrayList roles = u.getRoles();
for (int j = 0; j < roles.size(); j++) {
StudyUserRoleBean surb = (StudyUserRoleBean) roles.get(j);
StudyBean sb = (StudyBean) studiesById.get(new Integer(surb.getStudyId()));
if (sb != null) {
surb.setStudyName(sb.getName());
surb.setParentStudyId(sb.getParentStudyId());
}
roles.set(j, surb);
}
u.setRoles(roles);
users.set(i, u);
}
return;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class ViewUserAccountServlet method getBean.
// public void processRequest(HttpServletRequest request,
// HttpServletResponse response)
// throws OpenClinicaException {
// session = request.getSession();
// session.setMaxInactiveInterval(60 * 60 * 3);
// logger.setLevel(Level.ALL);
// UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
// try {
// String userName = request.getRemoteUser();
//
// sm = new SessionManager(ub, userName);
// ub = sm.getUserBean();
// if (logger.isLoggable(Level.INFO)) {
// logger.info("user bean from DB" + ub.getName());
// }
//
// FormProcessor fp = new FormProcessor(request);
// int userId = fp.getInt(ARG_USER_ID);
//
// SQLFactory factory = SQLFactory.getInstance();
// UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
//
// UserAccountBean user = getBean(udao, userId);
//
// if ((user.getFirstName() != null) && (!user.getFirstName().equals(""))) {
// request.setAttribute("user", user);
// request.setAttribute("message", "");
// }
// else {
// request.setAttribute("user", new UserAccountBean());
// request.setAttribute("message", "The specified user does not exist!");
// }
//
// forwardPage(Page.VIEW_USER_ACCOUNT, request, response);
// } catch (Exception e) {
// e.printStackTrace();
// logger.warn("OpenClinicaException::
// OpenClinica.control.viewUserAccount: " + e.getMessage());
//
// forwardPage(Page.ERROR, request, response);
// }
// }
private UserAccountBean getBean(UserAccountDAO udao, int id) {
UserAccountBean answer = (UserAccountBean) udao.findByPK(id);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList roles = answer.getRoles();
for (int i = 0; i < roles.size(); i++) {
StudyUserRoleBean sur = (StudyUserRoleBean) roles.get(i);
StudyBean sb = (StudyBean) sdao.findByPK(sur.getStudyId());
sur.setStudyName(sb.getName());
roles.set(i, sur);
}
answer.setRoles(roles);
return answer;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class SecureController method process.
private void process(HttpServletRequest request, HttpServletResponse response) throws OpenClinicaException, UnsupportedEncodingException {
request.setCharacterEncoding("UTF-8");
session = request.getSession();
// BWP >> 1/8/2008
try {
// YW 10-03-2007 <<
session.setMaxInactiveInterval(Integer.parseInt(SQLInitServlet.getField("max_inactive_interval")));
// YW >>
} catch (NumberFormatException nfe) {
// BWP>>3600 is the datainfo.properties maxInactiveInterval on
// 1/8/2008
session.setMaxInactiveInterval(3600);
}
// If the session already has a value with key SUPPORT_URL don't reset
if (session.getAttribute(SUPPORT_URL) == null) {
session.setAttribute(SUPPORT_URL, SQLInitServlet.getSupportURL());
}
ub = (UserAccountBean) session.getAttribute(USER_BEAN_NAME);
currentStudy = (StudyBean) session.getAttribute("study");
currentRole = (StudyUserRoleBean) session.getAttribute("userRole");
// Set current language preferences
Locale locale = LocaleResolver.getLocale(request);
ResourceBundleProvider.updateLocale(locale);
resadmin = ResourceBundleProvider.getAdminBundle(locale);
resaudit = ResourceBundleProvider.getAuditEventsBundle(locale);
resexception = ResourceBundleProvider.getExceptionsBundle(locale);
resformat = ResourceBundleProvider.getFormatBundle(locale);
restext = ResourceBundleProvider.getTextsBundle(locale);
resterm = ResourceBundleProvider.getTermsBundle(locale);
resword = ResourceBundleProvider.getWordsBundle(locale);
respage = ResourceBundleProvider.getPageMessagesBundle(locale);
resworkflow = ResourceBundleProvider.getWorkflowBundle(locale);
local_df = I18nFormatUtil.getDateFormat(locale);
try {
String userName = request.getRemoteUser();
// BWP 1/8/08<< the sm variable may already be set with a mock
// object,
// from the perspective of
// JUnit servlets tests
/*
* if(sm==null && (!StringUtil.isBlank(userName))) {//check if user logged in, then create a new sessionmanger to
* get ub //create a new sm in order to get a new ub object sm = new SessionManager(ub, userName); }
*/
// BWP 01/08 >>
// sm = new SessionManager(ub, userName);
sm = new SessionManager(ub, userName, SpringServletAccess.getApplicationContext(context));
ub = sm.getUserBean();
session.setAttribute("userBean", ub);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (currentStudy == null || currentStudy.getId() <= 0) {
if (ub.getId() > 0 && ub.getActiveStudyId() > 0) {
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
currentStudy = (StudyBean) sdao.findByPK(ub.getActiveStudyId());
ArrayList studyParameters = spvdao.findParamConfigByStudy(currentStudy);
currentStudy.setStudyParameters(studyParameters);
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
if (currentStudy.getParentStudyId() <= 0) {
// top study
scs.setParametersForStudy(currentStudy);
} else {
// YW <<
currentStudy.setParentStudyName(((StudyBean) sdao.findByPK(currentStudy.getParentStudyId())).getName());
// YW >>
scs.setParametersForSite(currentStudy);
}
// set up the panel here, tbh
panel.reset();
/*
* panel.setData("Study", currentStudy.getName()); panel.setData("Summary", currentStudy.getSummary());
* panel.setData("Start Date", sdf.format(currentStudy.getDatePlannedStart())); panel.setData("End Date",
* sdf.format(currentStudy.getDatePlannedEnd())); panel.setData("Principal Investigator",
* currentStudy.getPrincipalInvestigator());
*/
session.setAttribute(STUDY_INFO_PANEL, panel);
} else {
currentStudy = new StudyBean();
}
session.setAttribute("study", currentStudy);
} else if (currentStudy.getId() > 0) {
// restored
if (currentStudy.getParentStudyId() > 0) {
currentStudy.setParentStudyName(((StudyBean) sdao.findByPK(currentStudy.getParentStudyId())).getName());
}
// YW >>
}
if (currentStudy.getParentStudyId() > 0) {
/*
* The Role decription will be set depending on whether the user logged in at study lever or site level.
* issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("site_Study_Coordinator");
break;
case 3:
role.setDescription("site_Study_Director");
break;
case 4:
role.setDescription("site_investigator");
break;
case 5:
role.setDescription("site_Data_Entry_Person");
break;
case 6:
role.setDescription("site_monitor");
break;
case 7:
role.setDescription("site_Data_Entry_Person2");
break;
default:
}
}
} else {
/*
* If the current study is a site, we will change the role description. issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("Study_Coordinator");
break;
case 3:
role.setDescription("Study_Director");
break;
case 4:
role.setDescription("Investigator");
break;
case 5:
role.setDescription("Data_Entry_Person");
break;
case 6:
role.setDescription("Monitor");
break;
default:
}
}
}
if (currentRole == null || currentRole.getId() <= 0) {
// kept as "invalid" -- YW 06-21-2007
if (ub.getId() > 0 && currentStudy.getId() > 0 && !currentStudy.getStatus().getName().equals("removed")) {
currentRole = ub.getRoleByStudy(currentStudy.getId());
if (currentStudy.getParentStudyId() > 0) {
// Checking if currentStudy has been removed or not will
// ge good enough -- YW 10-17-2007
StudyUserRoleBean roleInParent = ub.getRoleByStudy(currentStudy.getParentStudyId());
// inherited role from parent study, pick the higher
// role
currentRole.setRole(Role.max(currentRole.getRole(), roleInParent.getRole()));
}
// logger.info("currentRole:" + currentRole.getRoleName());
} else {
currentRole = new StudyUserRoleBean();
}
session.setAttribute("userRole", currentRole);
} else // active study has been removed.
if (currentRole.getId() > 0 && (currentStudy.getStatus().equals(Status.DELETED) || currentStudy.getStatus().equals(Status.AUTO_DELETED))) {
currentRole.setRole(Role.INVALID);
currentRole.setStatus(Status.DELETED);
session.setAttribute("userRole", currentRole);
}
// YW 06-19-2007 >>
request.setAttribute("isAdminServlet", getAdminServlet());
this.request = request;
this.response = response;
// logger.info(rq_names);
if (!request.getRequestURI().endsWith("ResetPassword")) {
passwdTimeOut();
}
mayProceed();
pingJobServer(request);
processRequest();
} catch (InconsistentStateException ise) {
ise.printStackTrace();
logger.warn("InconsistentStateException: org.akaza.openclinica.control.SecureController: " + ise.getMessage());
addPageMessage(ise.getOpenClinicaMessage());
forwardPage(ise.getGoTo());
} catch (InsufficientPermissionException ipe) {
ipe.printStackTrace();
logger.warn("InsufficientPermissionException: org.akaza.openclinica.control.SecureController: " + ipe.getMessage());
// addPageMessage(ipe.getOpenClinicaMessage());
forwardPage(ipe.getGoTo());
} catch (OutOfMemoryError ome) {
ome.printStackTrace();
long heapSize = Runtime.getRuntime().totalMemory();
session.setAttribute("ome", "yes");
} catch (Exception e) {
e.printStackTrace();
logger.error(SecureController.getStackTrace(e));
forwardPage(Page.ERROR);
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class RequestStudyServlet method confirm.
/**
*
* @param request
* @param response
*/
private void confirm() throws Exception {
Validator v = new Validator(request);
v.addValidation("studyId", Validator.IS_AN_INTEGER);
v.addValidation("studyRoleId", Validator.IS_VALID_TERM, TermType.ROLE);
HashMap errors = v.validate();
FormProcessor fp = new FormProcessor(request);
StudyUserRoleBean newRole = new StudyUserRoleBean();
if (fp.getInt("studyRoleId") > 0) {
newRole.setRole(Role.get(fp.getInt("studyRoleId")));
}
newRole.setStudyId(fp.getInt("studyId"));
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean studyRequested = (StudyBean) sdao.findByPK(newRole.getStudyId());
newRole.setStudyName(studyRequested.getName());
session.setAttribute("newRole", newRole);
if (!errors.isEmpty()) {
logger.info("after processing form,error is not empty");
request.setAttribute("formMessages", errors);
forwardPage(Page.REQUEST_STUDY);
} else {
logger.info("after processing form,no errors");
forwardPage(Page.REQUEST_STUDY_CONFIRM);
}
}
Aggregations