Search in sources :

Example 21 with ParticipantPortalRegistrar

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";
}
Also used : Locale(java.util.Locale) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ParticipantPortalRegistrar

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;
}
Also used : Authorization(org.akaza.openclinica.service.pmanage.Authorization) MalformedURLException(java.net.MalformedURLException) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MailException(org.springframework.mail.MailException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

ParticipantPortalRegistrar (org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar)22 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)13 StudyParameterValueBean (org.akaza.openclinica.bean.service.StudyParameterValueBean)10 StudyParameterValueDAO (org.akaza.openclinica.dao.service.StudyParameterValueDAO)10 URL (java.net.URL)5 Authorization (org.akaza.openclinica.service.pmanage.Authorization)5 MalformedURLException (java.net.MalformedURLException)4 StudyParameterValue (org.akaza.openclinica.domain.datamap.StudyParameterValue)4 ArrayList (java.util.ArrayList)3 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)3 Study (org.akaza.openclinica.domain.datamap.Study)3 HashMap (java.util.HashMap)2 MessagingException (javax.mail.MessagingException)2 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)2 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)2 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 RandomizationRegistrar (org.akaza.openclinica.service.pmanage.RandomizationRegistrar)2 SeRandomizationDTO (org.akaza.openclinica.service.pmanage.SeRandomizationDTO)2 MailException (org.springframework.mail.MailException)2