use of org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar in project OpenClinica by OpenClinica.
the class StudyModuleController method registerParticipate.
@RequestMapping(value = "/{study}/register", method = RequestMethod.POST)
public String registerParticipate(@PathVariable("study") String studyOid, HttpServletRequest request) throws Exception {
studyDao = new StudyDAO(dataSource);
StudyBean study = studyDao.findByOid(studyOid);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(dataSource);
StudyParameterValueBean spv = spvdao.findByHandleAndStudy(study.getId(), "participantPortal");
ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
Locale locale = LocaleResolver.getLocale(request);
ResourceBundleProvider.updateLocale(locale);
respage = ResourceBundleProvider.getPageMessagesBundle(locale);
// Check if desired hostName is available. If so, send OCUI registration request
String hostName = request.getParameter("hostName");
if (hostName == null || hostName.equals("")) {
addRegMessage(request, respage.getString("participate_hostname_invalid"));
return "redirect:/pages/studymodule";
}
String status = "";
String nameAvailability = registrar.getHostNameAvailability(hostName);
if (nameAvailability.equals(ParticipantPortalRegistrar.UNAVAILABLE)) {
addRegMessage(request, respage.getString("participate_hostname_not_available"));
return "redirect:/pages/studymodule";
} else if (nameAvailability.equals(ParticipantPortalRegistrar.UNKNOWN)) {
addRegMessage(request, respage.getString("participate_not_available"));
return "redirect:/pages/studymodule";
} else if (nameAvailability.equals(ParticipantPortalRegistrar.INVALID)) {
addRegMessage(request, respage.getString("participate_hostname_invalid"));
return "redirect:/pages/studymodule";
} else {
// Returned status was 'available'. Proceed with registration.
status = registrar.registerStudy(study.getOid(), hostName, study.getIdentifier());
}
// parameter.
if (status.equals("")) {
addRegMessage(request, respage.getString("participate_not_available"));
} else {
// Update OC Study configuration
spv.setStudyId(study.getId());
spv.setParameter("participantPortal");
spv.setValue("enabled");
if (spv.getId() > 0)
spvdao.update(spv);
else
spvdao.create(spv);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
currentStudy.getStudyParameterConfig().setParticipantPortal("enabled");
}
return "redirect:/pages/studymodule";
}
use of org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar in project OpenClinica by OpenClinica.
the class SystemController method getParticipateModule.
public HashMap<String, Object> getParticipateModule(StudyBean studyBean) {
String portalURL = CoreResources.getField("portalURL");
StudyParameterValueBean spvBean = getParticipateMod(studyBean, "participantPortal");
String ocParticipateStatus = "";
if (spvBean.isActive()) {
// enabled , disabled
ocParticipateStatus = spvBean.getValue().toString();
}
String ocuiParticipateStatus = "";
ParticipantPortalRegistrar participantPortalRegistrar = new ParticipantPortalRegistrar();
if (ocParticipateStatus.equals("enabled")) {
try {
ocuiParticipateStatus = participantPortalRegistrar.getRegistrationStatus(studyBean.getOid());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
HashMap<String, String> mapMetadata = new HashMap<>();
String url = "";
URL pManageUrl = null;
try {
pManageUrl = new URL(portalURL);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Authorization pManageAuthorization = participantPortalRegistrar.getAuthorization(studyBean.getOid());
if (pManageAuthorization != null) {
url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
mapMetadata.put("Participate Url", url);
}
HashMap<String, Object> mapParticipate = new HashMap<>();
mapParticipate.put("enabled", ocParticipateStatus.equals("enabled") ? "True" : "False");
mapParticipate.put("status", ocuiParticipateStatus.equals("") ? "INACTIVE" : ocuiParticipateStatus);
mapParticipate.put("metadata", mapMetadata);
HashMap<String, Object> mapModule = new HashMap<>();
mapModule.put("Participate", mapParticipate);
return mapModule;
}
Aggregations