-
Notifications
You must be signed in to change notification settings - Fork 264
/
InitUpdateEventDefinitionServlet.java
executable file
·206 lines (180 loc) · 9.27 KB
/
InitUpdateEventDefinitionServlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* OpenClinica is distributed under the
* GNU Lesser General Public License (GNU LGPL).
* For details see: http://www.openclinica.org/license
* copyright 2003-2005 Akaza Research
*/
package org.akaza.openclinica.control.managestudy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.akaza.openclinica.bean.admin.CRFBean;
import org.akaza.openclinica.bean.core.NullValue;
import org.akaza.openclinica.bean.core.Role;
import org.akaza.openclinica.bean.core.Status;
import org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean;
import org.akaza.openclinica.bean.managestudy.StudyBean;
import org.akaza.openclinica.bean.managestudy.StudyEventBean;
import org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean;
import org.akaza.openclinica.bean.service.StudyParameterValueBean;
import org.akaza.openclinica.bean.submit.CRFVersionBean;
import org.akaza.openclinica.control.core.SecureController;
import org.akaza.openclinica.core.form.StringUtil;
import org.akaza.openclinica.dao.admin.CRFDAO;
import org.akaza.openclinica.dao.core.CoreResources;
import org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO;
import org.akaza.openclinica.dao.managestudy.StudyDAO;
import org.akaza.openclinica.dao.managestudy.StudyEventDAO;
import org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO;
import org.akaza.openclinica.dao.service.StudyParameterValueDAO;
import org.akaza.openclinica.dao.submit.CRFVersionDAO;
import org.akaza.openclinica.domain.SourceDataVerification;
import org.akaza.openclinica.service.pmanage.Authorization;
import org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar;
import org.akaza.openclinica.view.Page;
import org.akaza.openclinica.web.InsufficientPermissionException;
/**
* Prepares to update study event definition
*
* @author jxu
*
*/
public class InitUpdateEventDefinitionServlet extends SecureController {
/**
* Checks whether the user has the correct privilege
*/
@Override
public void mayProceed() throws InsufficientPermissionException {
checkStudyLocked(Page.LIST_DEFINITION_SERVLET, respage.getString("current_study_locked"));
if (ub.isSysAdmin()) {
return;
}
StudyEventDAO sdao = new StudyEventDAO(sm.getDataSource());
// get current studyid
int studyId = currentStudy.getId();
if (ub.hasRoleInStudy(studyId)) {
Role r = ub.getRoleByStudy(studyId).getRole();
if (r.equals(Role.STUDYDIRECTOR) || r.equals(Role.COORDINATOR)) {
return;
} else {
addPageMessage(respage.getString("no_have_permission_to_update_study_event_definition")
+ respage.getString("please_contact_sysadmin_questions"));
throw new InsufficientPermissionException(Page.LIST_DEFINITION_SERVLET, resexception.getString("not_study_director"), "1");
}
}
// To Do: the following code doesn't apply to admin for now
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
logger.info("defId" + defId);
ArrayList events = (ArrayList) sdao.findAllByDefinition(defId);
if (events != null && events.size() > 0) {
logger.info("has events");
for (int i = 0; i < events.size(); i++) {
StudyEventBean sb = (StudyEventBean) events.get(i);
if (!sb.getStatus().equals(Status.DELETED) && !sb.getStatus().equals(Status.AUTO_DELETED)) {
logger.info("found one event");
addPageMessage(respage.getString("sorry_but_at_this_time_may_not_modufy_SED"));
throw new InsufficientPermissionException(Page.LIST_DEFINITION_SERVLET, resexception.getString("not_unpopulated"), "1");
}
}
}
}
@Override
public void processRequest() throws Exception {
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("definition id: " + idString);
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_definition_to_edit"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
// definition id
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled")) baseUrl();
request.setAttribute("participateFormStatus",participateFormStatus );
if (currentStudy.getId() != sed.getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study")
+ " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllParentsByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
ArrayList newEventDefinitionCRFs = new ArrayList();
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllActiveByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
edc.setCrf(crf);
edc.setParticipantForm(edc.isParticipantForm());
// TO DO: use a better way on JSP page,eg.function tag
edc.setNullFlags(processNullValues(edc));
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
newEventDefinitionCRFs.add(edc);
}
session.setAttribute("definition", sed);
session.setAttribute("eventDefinitionCRFs", newEventDefinitionCRFs);
// changed above to new list because static, in-place updating is
// updating all EDCs, tbh 102007
ArrayList<String> sdvOptions = new ArrayList<String>();
sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
request.setAttribute("sdvOptions", sdvOptions);
forwardPage(Page.UPDATE_EVENT_DEFINITION1);
}
}
private void baseUrl() throws MalformedURLException{
String portalURL = CoreResources.getField("portalURL");
URL pManageUrl = new URL(portalURL);
ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
Authorization pManageAuthorization = registrar.getAuthorization(currentStudy.getOid());
String url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost()
+ ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
System.out.println("the url : "+ url);
request.setAttribute("participantUrl",url+"/");
}
private HashMap processNullValues(EventDefinitionCRFBean edc) {
HashMap flags = new LinkedHashMap();
String s = "";// edc.getNullValues();
for (int j = 0; j < edc.getNullValuesList().size(); j++) {
NullValue nv1 = (NullValue) edc.getNullValuesList().get(j);
s = s + nv1.getName().toUpperCase() + ",";
}
// String s = edc.getNullValuesList().toString();
logger.info("********:" + s);
if (s != null) {
for (int i = 1; i <= NullValue.toArrayList().size(); i++) {
String nv = NullValue.get(i).getName().toUpperCase();
// if (s.indexOf(nv) >= 0) {
// indexOf won't save us
// because NA and NASK will come back both positive, for example
// rather, we need a regexp here
Pattern p = Pattern.compile(nv + "\\W");
// find our word with a non-word character after it (,)
Matcher m = p.matcher(s);
if (m.find()) {
flags.put(nv, "1");
logger.info("********1:" + nv + " found at " + m.start() + ", " + m.end());
} else {
flags.put(nv, "0");
logger.info("********0:" + nv);
}
}
}
return flags;
}
}